Treat runfiles middlemen as aggregating middlemen.
The goal is to, for an action execution, make only a single skyframe
edge to every required runfiles tree rather than an edge to every
runfiles artifact directly. We accomplish this by pulling the runfiles
artifacts' metadata for a particular runfiles tree through the
appropriate runfiles middlemen artifact in one batch. This CL fixes
https://github.com/bazelbuild/bazel/issues/3217.
This change makes runfiles middlemen more similar to aggregating
middlemen. We however continue to treat runfiles middlemen slightly
differently than true aggregating middlemen. Namely, we do not expand
runfiles middlemen into the final action inputs. The reasons for this
are:
1. It can make latent bugs like
https://github.com/bazelbuild/bazel/issues/4033 more severe.
2. The runfiles tree builder action's output MANIFEST contains
absolute paths, which interferes with remote execution if its metadata
is added to a cache hash.
3. In the sandbox, it causes the runfiles artifacts to be mounted at
their exec path locations in addition to within the runfiles
trees. This makes the sandbox less strict. (Perhaps tolerably?)
4. It saves a modicum of (transient) memory and time to not expand.
If the first two issues are fixed, it could be a nice simplification
to completely replace runfiles middlemen with aggregating middlemen.
Change-Id: I2d2148297f897af4c4c6dc055d87f8a6fad0061e
PiperOrigin-RevId: 198307109
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
index 5cef0fc..1999166 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
@@ -290,16 +290,24 @@
}
inputs.add(Pair.of(input, (FileArtifactValue) inputValue));
}
- return new AggregatingArtifactValue(inputs.build(), value);
+ return (action.getActionType() == MiddlemanType.AGGREGATING_MIDDLEMAN)
+ ? new AggregatingArtifactValue(inputs.build(), value)
+ : new RunfilesArtifactValue(inputs.build(), value);
}
/**
* Returns whether this value needs to contain the data of all its inputs. Currently only tests to
- * see if the action is an aggregating middleman action. However, may include runfiles middleman
- * actions and Fileset artifacts in the future.
+ * see if the action is an aggregating or runfiles middleman action. However, may include Fileset
+ * artifacts in the future.
*/
private static boolean isAggregatingValue(ActionAnalysisMetadata action) {
- return action.getActionType() == MiddlemanType.AGGREGATING_MIDDLEMAN;
+ switch (action.getActionType()) {
+ case AGGREGATING_MIDDLEMAN:
+ case RUNFILES_MIDDLEMAN:
+ return true;
+ default:
+ return false;
+ }
}
@Override