24
24
import com .google .common .collect .Iterables ;
25
25
import com .google .common .collect .Sets ;
26
26
import com .google .devtools .build .lib .actions .AbstractAction ;
27
+ import com .google .devtools .build .lib .actions .ActionEnvironment ;
27
28
import com .google .devtools .build .lib .actions .ActionExecutionContext ;
28
29
import com .google .devtools .build .lib .actions .ActionExecutionException ;
29
30
import com .google .devtools .build .lib .actions .ActionKeyContext ;
@@ -155,7 +156,6 @@ public class CppCompileAction extends AbstractAction
155
156
*/
156
157
public static final String CLIF_MATCH = "clif-match" ;
157
158
158
- private final ImmutableMap <String , String > localShellEnvironment ;
159
159
protected final Artifact outputFile ;
160
160
private final Artifact sourceFile ;
161
161
private final Artifact optionalSourceFile ;
@@ -278,7 +278,7 @@ public class CppCompileAction extends AbstractAction
278
278
@ Nullable Artifact dwoFile ,
279
279
@ Nullable Artifact ltoIndexingFile ,
280
280
Artifact optionalSourceFile ,
281
- ImmutableMap < String , String > localShellEnvironment ,
281
+ ActionEnvironment env ,
282
282
CcCompilationContext ccCompilationContext ,
283
283
CoptsFilter coptsFilter ,
284
284
Iterable <IncludeScannable > lipoScannables ,
@@ -298,7 +298,7 @@ public class CppCompileAction extends AbstractAction
298
298
gcnoFile ,
299
299
dwoFile ,
300
300
ltoIndexingFile ),
301
- localShellEnvironment ,
301
+ env ,
302
302
Preconditions .checkNotNull (outputFile ),
303
303
sourceFile ,
304
304
optionalSourceFile ,
@@ -346,7 +346,7 @@ public class CppCompileAction extends AbstractAction
346
346
ActionOwner owner ,
347
347
NestedSet <Artifact > inputs ,
348
348
ImmutableSet <Artifact > outputs ,
349
- ImmutableMap < String , String > localShellEnvironment ,
349
+ ActionEnvironment env ,
350
350
Artifact outputFile ,
351
351
Artifact sourceFile ,
352
352
Artifact optionalSourceFile ,
@@ -377,8 +377,7 @@ public class CppCompileAction extends AbstractAction
377
377
boolean needsIncludeValidation ,
378
378
IncludeProcessing includeProcessing ,
379
379
@ Nullable Artifact grepIncludes ) {
380
- super (owner , inputs , outputs );
381
- this .localShellEnvironment = localShellEnvironment ;
380
+ super (owner , inputs , outputs , env );
382
381
this .outputFile = outputFile ;
383
382
this .sourceFile = sourceFile ;
384
383
this .optionalSourceFile = optionalSourceFile ;
@@ -746,8 +745,15 @@ public ImmutableCollection<String> getDefines() {
746
745
}
747
746
748
747
@ Override
748
+ @ VisibleForTesting
749
749
public ImmutableMap <String , String > getEnvironment () {
750
- Map <String , String > environment = new LinkedHashMap <>(localShellEnvironment );
750
+ return getEnvironment (ImmutableMap .of ());
751
+ }
752
+
753
+ public ImmutableMap <String , String > getEnvironment (Map <String , String > clientEnv ) {
754
+ Map <String , String > environment = new LinkedHashMap <>(env .size ());
755
+ env .resolve (environment , clientEnv );
756
+
751
757
if (!getExecutionInfo ().containsKey (ExecutionRequirements .REQUIRES_DARWIN )) {
752
758
// Linux: this prevents gcc/clang from writing the unpredictable (and often irrelevant) value
753
759
// of getcwd() into the debug info. Not applicable to Darwin or Windows, which have no /proc.
@@ -786,6 +792,7 @@ public ExtraActionInfo.Builder getExtraActionInfo(ActionKeyContext actionKeyCont
786
792
info .addAllSourcesAndHeaders (
787
793
Artifact .toExecPaths (ccCompilationContext .getDeclaredIncludeSrcs ()));
788
794
}
795
+ // TODO(ulfjack): Extra actions currently ignore the client environment.
789
796
for (Map .Entry <String , String > envVariable : getEnvironment ().entrySet ()) {
790
797
info .addVariable (
791
798
EnvironmentVariable .newBuilder ()
@@ -1105,7 +1112,9 @@ public ResourceSet estimateResourceConsumptionLocal() {
1105
1112
@ Override
1106
1113
public void computeKey (ActionKeyContext actionKeyContext , Fingerprint fp ) {
1107
1114
fp .addUUID (actionClassId );
1108
- fp .addStringMap (getEnvironment ());
1115
+ fp .addStringMap (env .getFixedEnv ());
1116
+ fp .addStrings (env .getInheritedEnv ());
1117
+ fp .addStringMap (compileCommandLine .getEnvironment ());
1109
1118
fp .addStringMap (executionInfo );
1110
1119
1111
1120
// For the argv part of the cache key, ignore all compiler flags that explicitly denote module
0 commit comments