Fix a bug in which Bazel reports action conflicts between ActionTemplates and associated expanded actions.
--
MOS_MIGRATED_REVID=136212908
diff --git a/src/main/java/com/google/devtools/build/lib/actions/Actions.java b/src/main/java/com/google/devtools/build/lib/actions/Actions.java
index 44397d8..b8bd981 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/Actions.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/Actions.java
@@ -190,6 +190,19 @@
if (pathJ.startsWith(pathI)) { // prefix conflict.
Artifact artifactI = Preconditions.checkNotNull(artifactPathMap.get(pathI), pathI);
Artifact artifactJ = Preconditions.checkNotNull(artifactPathMap.get(pathJ), pathJ);
+
+ // We ignore the artifact prefix conflict between a TreeFileArtifact and its parent
+ // TreeArtifact.
+ // We can only have such a conflict here if:
+ // 1. The TreeArtifact is generated by an ActionTemplate. And the TreeFileArtifact is
+ // generated by an expanded action created at execution time from the ActionTemplate.
+ // 2. This is an incremental build with invalidated configured targets. In this case,
+ // the action graph contains expanded actions from previous builds and they will be
+ // checked for artifact conflicts.
+ if (artifactJ.hasParent() && artifactJ.getParent().equals(artifactI)) {
+ continue;
+ }
+
ActionAnalysisMetadata actionI =
Preconditions.checkNotNull(actionGraph.getGeneratingAction(artifactI), artifactI);
ActionAnalysisMetadata actionJ =