Allow bypassing input file discovery in package building -- MOS_MIGRATED_REVID=136594531
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java index cbd672e..54ccc3e 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Package.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java
@@ -1253,7 +1253,7 @@ addRuleUnchecked(rule); } - private Builder beforeBuild() throws InterruptedException { + private Builder beforeBuild(boolean discoverAssumedInputFiles) throws InterruptedException { Preconditions.checkNotNull(pkg); Preconditions.checkNotNull(filename); Preconditions.checkNotNull(buildFileLabel); @@ -1270,15 +1270,17 @@ List<Rule> rules = Lists.newArrayList(getTargets(Rule.class)); - // All labels mentioned in a rule that refer to an unknown target in the - // current package are assumed to be InputFiles, so let's create them: - for (final Rule rule : rules) { - AggregatingAttributeMapper.of(rule).visitLabels(new AcceptsLabelAttribute() { - @Override - public void acceptLabelAttribute(Label label, Attribute attribute) { - createInputFileMaybe(label, rule.getAttributeLocation(attribute.getName())); - } - }); + if (discoverAssumedInputFiles) { + // All labels mentioned in a rule that refer to an unknown target in the + // current package are assumed to be InputFiles, so let's create them: + for (final Rule rule : rules) { + AggregatingAttributeMapper.of(rule).visitLabels(new AcceptsLabelAttribute() { + @Override + public void acceptLabelAttribute(Label label, Attribute attribute) { + createInputFileMaybe(label, rule.getAttributeLocation(attribute.getName())); + } + }); + } } // "test_suite" rules have the idiosyncratic semantics of implicitly @@ -1310,7 +1312,7 @@ if (alreadyBuilt) { return this; } - return beforeBuild(); + return beforeBuild(/*discoverAssumedInputFiles=*/ true); } /** @@ -1355,10 +1357,18 @@ } public Package build() throws InterruptedException { + return build(/*discoverAssumedInputFiles=*/ true); + } + + /** + * Build the package, optionally adding any labels in the package not already associated with + * a target as an input file. + */ + public Package build(boolean discoverAssumedInputFiles) throws InterruptedException { if (alreadyBuilt) { return pkg; } - beforeBuild(); + beforeBuild(discoverAssumedInputFiles); return finishBuild(); }