19
19
20
20
import com .google .common .collect .ImmutableList ;
21
21
import com .google .common .collect .ImmutableMap ;
22
- import com .google .common .collect .Iterables ;
23
22
import com .google .devtools .build .lib .actions .Artifact .ArtifactExpander ;
24
23
import com .google .devtools .build .lib .actions .cache .OutputMetadataStore ;
25
24
import com .google .devtools .build .lib .analysis .config .BuildConfigurationValue .RunfileSymlinksMode ;
@@ -94,21 +93,24 @@ public String getWorkspaceName() {
94
93
95
94
/**
96
95
* An {@link InputMetadataProvider} wrapping another while overriding the materialization path of
97
- * the single runfiles tree it contains .
96
+ * a chosen runfiles tree.
98
97
*
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.
100
100
*/
101
101
private static class OverriddenRunfilesPathInputMetadataProvider
102
102
implements InputMetadataProvider {
103
103
private final InputMetadataProvider wrapped ;
104
+ private final ActionInput wrappedMiddleman ;
104
105
private final OverriddenPathRunfilesTree overriddenTree ;
105
106
106
107
private OverriddenRunfilesPathInputMetadataProvider (
107
- InputMetadataProvider wrapped , PathFragment execPath ) {
108
+ InputMetadataProvider wrapped , ActionInput wrappedMiddleman , PathFragment execPath ) {
108
109
this .wrapped = wrapped ;
110
+ this .wrappedMiddleman = wrappedMiddleman ;
109
111
this .overriddenTree =
110
112
new OverriddenPathRunfilesTree (
111
- Iterables . getOnlyElement ( wrapped .getRunfilesTrees () ), execPath );
113
+ wrapped .getRunfilesMetadata ( wrappedMiddleman ). getRunfilesTree ( ), execPath );
112
114
}
113
115
114
116
@ Nullable
@@ -127,9 +129,11 @@ public ActionInput getInput(String execPath) {
127
129
@ Override
128
130
public RunfilesArtifactValue getRunfilesMetadata (ActionInput input ) {
129
131
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
+ }
133
137
}
134
138
135
139
@ Override
@@ -556,10 +560,11 @@ public ActionExecutionContext withOutputsAsInputs(
556
560
new DelegatingPairInputMetadataProvider (additionalInputMetadata , inputMetadataProvider ));
557
561
}
558
562
559
- public ActionExecutionContext withOverriddenRunfilesPath (PathFragment overrideRunfilesPath ) {
563
+ public ActionExecutionContext withOverriddenRunfilesPath (
564
+ ActionInput overriddenMiddleman , PathFragment overrideRunfilesPath ) {
560
565
return withInputMetadataProvider (
561
566
new OverriddenRunfilesPathInputMetadataProvider (
562
- inputMetadataProvider , overrideRunfilesPath ));
567
+ inputMetadataProvider , overriddenMiddleman , overrideRunfilesPath ));
563
568
}
564
569
565
570
/**
0 commit comments