Make include() work with remote repositories.
This in itself is not very interesting because include() is deprecated, but it paves the way for fetching the appropriate dependencies for the eventual label-based load() statements.
--
MOS_MIGRATED_REVID=97849076
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
index dc0995a..35a9af8 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
@@ -41,6 +41,8 @@
private ImmutableSet<String> subincludes;
+ private ImmutableSet<Label> includes;
+
/**
* Whether any errors were encountered during scanning or parsing.
*/
@@ -94,6 +96,40 @@
return subincludes.build();
}
+ private ImmutableSet<Label> fetchIncludes(List<Statement> stmts) {
+ ImmutableSet.Builder<Label> result = new ImmutableSet.Builder<>();
+ for (Statement stmt : stmts) {
+ if (!(stmt instanceof ExpressionStatement)) {
+ continue;
+ }
+
+ ExpressionStatement expr = (ExpressionStatement) stmt;
+ if (!(expr.getExpression() instanceof FuncallExpression)) {
+ continue;
+ }
+
+ FuncallExpression funcall = (FuncallExpression) expr.getExpression();
+ if (!funcall.getFunction().getName().equals("include")
+ || funcall.getArguments().size() != 1) {
+ continue;
+ }
+
+ Expression arg = funcall.getArguments().get(0).value;
+ if (!(arg instanceof StringLiteral)) {
+ continue;
+ }
+
+ try {
+ Label label = Label.parseAbsolute(((StringLiteral) arg).getValue());
+ result.add(label);
+ } catch (Label.SyntaxException e) {
+ // Ignore. This will be reported when the BUILD file is actually evaluated.
+ }
+ }
+
+ return result.build();
+ }
+
/** Collects paths from all load statements */
private ImmutableSet<PathFragment> fetchLoads(List<Statement> stmts) {
ImmutableSet.Builder<PathFragment> loads = new ImmutableSet.Builder<>();
@@ -149,6 +185,14 @@
return subincludes;
}
+ public synchronized ImmutableSet<Label> getIncludes() {
+ if (includes == null) {
+ includes = fetchIncludes(stmts);
+ }
+
+ return includes;
+ }
+
/**
* Executes this build file in a given Environment.
*