Simplify the logic in CppCompileAction#updateActionInputs().
This way, we'll eventually get closer to the ideal world where inputs are clearly classified as either mandatory, prunable, discovered or discovered and prunable.
--
PiperOrigin-RevId: 150061912
MOS_MIGRATED_REVID=150061912
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
index 268dbff..8c3a18e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
@@ -956,7 +956,6 @@
if (optionalSourceFile != null) {
inputs.add(optionalSourceFile);
}
- inputs.addAll(context.getTransitiveCompilationPrerequisites());
inputs.addTransitive(discoveredInputs);
updateInputs(inputs.build());
} finally {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
index aa666f1..2646692 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
@@ -339,6 +339,20 @@
prunableInputBuilder.addTransitive(context.getDeclaredIncludeSrcs());
prunableInputBuilder.addTransitive(cppSemantics.getAdditionalPrunableIncludes());
+ Iterable<IncludeScannable> lipoScannables = getLipoScannables(realMandatoryInputs);
+ // We need to add "legal generated scanner files" coming through LIPO scannables here. These
+ // usually contain pre-grepped source files, i.e. files just containing the #include lines
+ // extracted from generated files. With LIPO, some of these files can be accessed, even though
+ // there is no direct dependency on them. Adding the artifacts as inputs to this compile
+ // action ensures that the action generating them is actually executed.
+ for (IncludeScannable lipoScannable : lipoScannables) {
+ for (Artifact value : lipoScannable.getLegalGeneratedScannerFileMap().values()) {
+ if (value != null) {
+ prunableInputBuilder.add(value);
+ }
+ }
+ }
+
NestedSet<Artifact> prunableInputs = prunableInputBuilder.build();
// Copying the collections is needed to make the builder reusable.
@@ -415,6 +429,8 @@
NestedSet<Artifact> buildMandatoryInputs() {
NestedSetBuilder<Artifact> realMandatoryInputsBuilder = NestedSetBuilder.compileOrder();
realMandatoryInputsBuilder.addTransitive(mandatoryInputsBuilder.build());
+ realMandatoryInputsBuilder.addAll(ccToolchain.getBuiltinIncludeFiles());
+ realMandatoryInputsBuilder.addAll(context.getTransitiveCompilationPrerequisites());
if (useHeaderModules() && !shouldPruneModules()) {
realMandatoryInputsBuilder.addTransitive(context.getTransitiveModules(usePic));
}
@@ -431,22 +447,7 @@
if (optionalSourceFile != null) {
builder.add(optionalSourceFile);
}
- builder.addAll(context.getTransitiveCompilationPrerequisites());
- builder.addAll(ccToolchain.getBuiltinIncludeFiles());
builder.addTransitive(mandatoryInputs);
- Iterable<IncludeScannable> lipoScannables = getLipoScannables(mandatoryInputs);
- // We need to add "legal generated scanner files" coming through LIPO scannables here. These
- // usually contain pre-grepped source files, i.e. files just containing the #include lines
- // extracted from generated files. With LIPO, some of these files can be accessed, even though
- // there is no direct dependency on them. Adding the artifacts as inputs to this compile
- // action ensures that the action generating them is actually executed.
- for (IncludeScannable lipoScannable : lipoScannables) {
- for (Artifact value : lipoScannable.getLegalGeneratedScannerFileMap().values()) {
- if (value != null) {
- builder.add(value);
- }
- }
- }
return builder.build();
}