Reduce number of C++ modules explicitly specified on the command line.
MOS_MIGRATED_REVID=144323833
@@ -215,6 +215,9 @@ public class CppCompileAction extends AbstractAction
/** Set when a two-stage input discovery is used. */
private Collection<Artifact> usedModules = null;
+ /** Used modules that are not transitively used through other topLevelModules. */
+ private Collection<Artifact> topLevelModules = null;
+
private CcToolchainFeatures.Variables overwrittenVariables = null;
private ImmutableList<Artifact> resolvedInputs = ImmutableList.<Artifact>of();
@@ -502,6 +505,7 @@ public class CppCompileAction extends AbstractAction
if (shouldPruneModules) {
Set<Artifact> initialResultSet = Sets.newLinkedHashSet(initialResult);
usedModules = Sets.newLinkedHashSet();
+ topLevelModules = null;
for (CppCompilationContext.TransitiveModuleHeaders usedModule :
context.getUsedModules(usePic, initialResultSet)) {
usedModules.add(usedModule.getModule());
@@ -557,6 +561,13 @@ public class CppCompileAction extends AbstractAction
}
}
}
+ ImmutableSet.Builder<Artifact> topLevelModules = ImmutableSet.builder();
+ for (Artifact artifact : this.usedModules) {
+ if (!additionalModules.contains(artifact)) {
+ topLevelModules.add(artifact);
+ }
+ }
+ this.topLevelModules = topLevelModules.build();
this.additionalInputs =
new ImmutableList.Builder<Artifact>()
.addAll(this.additionalInputs)
@@ -569,8 +580,11 @@ public class CppCompileAction extends AbstractAction
@Override
public Iterable<Artifact> getInputsWhenSkippingInputDiscovery() {
if (useHeaderModules) {
- this.additionalInputs = context.getTransitiveModules(usePic).toCollection();
- return this.additionalInputs;
+ additionalInputs = Sets.newLinkedHashSet(context.getTransitiveModules(usePic).toCollection());
+ // Here, we cannot really know what the top-level modules are, so we just mark all
+ // transitive modules as "top level".
+ topLevelModules = additionalInputs;
+ return additionalInputs;
}
return null;
}
@@ -1012,11 +1026,14 @@ public class CppCompileAction extends AbstractAction
/** Sets module file flags based on the action's inputs. */
protected void setModuleFileFlags() {
if (useHeaderModules) {
- // If modules pruning is used, modules will be supplied via additionalInputs, otherwise they
+ // If modules pruning is used, modules will be supplied via topLevelModules, otherwise they
// are regular inputs.
- Preconditions.checkNotNull(additionalInputs);
- this.overwrittenVariables =
- getOverwrittenVariables(shouldPruneModules ? additionalInputs : getInputs());
+ if (shouldPruneModules) {
+ Preconditions.checkNotNull(this.topLevelModules);
+ overwrittenVariables = getOverwrittenVariables(topLevelModules);
+ } else {
+ overwrittenVariables = getOverwrittenVariables(getInputs());
+ }
}
}
