Skip to content

Commit d5a86b3

Browse files
lberkicopybara-github
authored andcommitted
Make it possible to override a single runfiles tree in withOverriddenRunfilesPath().
RELNOTES: None. PiperOrigin-RevId: 622799182 Change-Id: I5b49723030d724e9179dba384282c7a964efb03e
1 parent 206c750 commit d5a86b3

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import com.google.common.collect.ImmutableList;
2121
import com.google.common.collect.ImmutableMap;
22-
import com.google.common.collect.Iterables;
2322
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
2423
import com.google.devtools.build.lib.actions.cache.OutputMetadataStore;
2524
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
@@ -94,21 +93,24 @@ public String getWorkspaceName() {
9493

9594
/**
9695
* An {@link InputMetadataProvider} wrapping another while overriding the materialization path of
97-
* the single runfiles tree it contains.
96+
* a chosen runfiles tree.
9897
*
99-
* <p>The wrapped input metadata provider must contain exactly one runfiles tree.
98+
* <p>The choice is made by passing in the runfiles middleman which represents the tree whose path
99+
* is to be overridden.
100100
*/
101101
private static class OverriddenRunfilesPathInputMetadataProvider
102102
implements InputMetadataProvider {
103103
private final InputMetadataProvider wrapped;
104+
private final ActionInput wrappedMiddleman;
104105
private final OverriddenPathRunfilesTree overriddenTree;
105106

106107
private OverriddenRunfilesPathInputMetadataProvider(
107-
InputMetadataProvider wrapped, PathFragment execPath) {
108+
InputMetadataProvider wrapped, ActionInput wrappedMiddleman, PathFragment execPath) {
108109
this.wrapped = wrapped;
110+
this.wrappedMiddleman = wrappedMiddleman;
109111
this.overriddenTree =
110112
new OverriddenPathRunfilesTree(
111-
Iterables.getOnlyElement(wrapped.getRunfilesTrees()), execPath);
113+
wrapped.getRunfilesMetadata(wrappedMiddleman).getRunfilesTree(), execPath);
112114
}
113115

114116
@Nullable
@@ -127,9 +129,11 @@ public ActionInput getInput(String execPath) {
127129
@Override
128130
public RunfilesArtifactValue getRunfilesMetadata(ActionInput input) {
129131
RunfilesArtifactValue original = wrapped.getRunfilesMetadata(input);
130-
// There is only one runfiles tree in the wrapped metadata provider so we can be sure that
131-
// we need to override this.
132-
return original == null ? null : original.withOverriddenRunfilesTree(overriddenTree);
132+
if (wrappedMiddleman.equals(input)) {
133+
return original.withOverriddenRunfilesTree(overriddenTree);
134+
} else {
135+
return original;
136+
}
133137
}
134138

135139
@Override
@@ -556,10 +560,11 @@ public ActionExecutionContext withOutputsAsInputs(
556560
new DelegatingPairInputMetadataProvider(additionalInputMetadata, inputMetadataProvider));
557561
}
558562

559-
public ActionExecutionContext withOverriddenRunfilesPath(PathFragment overrideRunfilesPath) {
563+
public ActionExecutionContext withOverriddenRunfilesPath(
564+
ActionInput overriddenMiddleman, PathFragment overrideRunfilesPath) {
560565
return withInputMetadataProvider(
561566
new OverriddenRunfilesPathInputMetadataProvider(
562-
inputMetadataProvider, overrideRunfilesPath));
567+
inputMetadataProvider, overriddenMiddleman, overrideRunfilesPath));
563568
}
564569

565570
/**

0 commit comments

Comments
 (0)