Skip to content

Commit 9209fd5

Browse files
bazel-iotrybka
andauthored
[8.1.0] Add environment variables to LTO backend actions. (#25242)
PiperOrigin-RevId: 700351238 Change-Id: If9e0686bee0756b0af56cda91ac70d184858fd72 Commit 0937e35 Co-authored-by: Googler <[email protected]>
1 parent f744b6a commit 9209fd5

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendArtifacts.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public final class LtoBackendArtifacts implements LtoBackendArtifactsApi<Artifac
165165
linkActionConstruction.getConfig().isSiblingRepositoryLayout()),
166166
".dwo"));
167167
}
168+
addEnvironmentVariables(builder, buildVariables, featureConfiguration);
168169
scheduleLtoBackendAction(
169170
builder,
170171
buildVariables,
@@ -329,6 +330,20 @@ private static void addOutputsToLtoBackendActionBuilder(
329330
}
330331
}
331332

333+
private static void addEnvironmentVariables(
334+
LtoBackendAction.Builder builder,
335+
CcToolchainVariables buildVariables,
336+
FeatureConfiguration featureConfiguration)
337+
throws EvalException {
338+
try {
339+
builder.setEnvironment(
340+
featureConfiguration.getEnvironmentVariables(
341+
CppActionNames.LTO_BACKEND, buildVariables, PathMapper.NOOP));
342+
} catch (ExpansionException e) {
343+
throw new EvalException(e.getMessage());
344+
}
345+
}
346+
332347
private static void addCommandLineToLtoBackendActionBuilder(
333348
LtoBackendAction.Builder builder,
334349
FeatureConfiguration featureConfiguration,

src/test/java/com/google/devtools/build/lib/analysis/mock/cc_toolchain_config.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ _static_env_feature = feature(
369369
ACTION_NAMES.cpp_compile,
370370
ACTION_NAMES.cpp_header_parsing,
371371
ACTION_NAMES.cpp_module_compile,
372+
ACTION_NAMES.lto_backend,
372373
],
373374
env_entries = [
374375
env_entry(

src/test/java/com/google/devtools/build/lib/rules/cpp/CcBinaryThinLtoTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,17 @@ private void validateDwp(
413413
.containsExactlyElementsIn(expectedInputs);
414414
}
415415

416+
@Test
417+
public void testLtoBackendEnv() throws Exception {
418+
createBuildFiles("features = ['env_feature'],");
419+
setupThinLTOCrosstool(MockCcSupport.ENV_VAR_FEATURES);
420+
421+
LtoBackendAction backendAction =
422+
getBackendAction("pkg/bin.lto/" + getRootExecPath() + "/pkg/_objs/bin/binfile.o");
423+
assertThat(backendAction.getMnemonic()).isEqualTo("CcLtoBackendCompile");
424+
assertThat(backendAction.getIncompleteEnvironmentForTesting()).containsEntry("cat", "meow");
425+
}
426+
416427
@Test
417428
public void testFission() throws Exception {
418429
createBuildFiles();
@@ -1074,10 +1085,10 @@ public void testAutoFdo() throws Exception {
10741085
linkAction, "pkg/bin.lto/" + rootExecPath + "/pkg/_objs/bin/binfile.o");
10751086

10761087
// Checks that -fauto-profile is added to the LtoBackendAction.
1077-
assertThat(Joiner.on(" ").join(backendAction.getArguments())).containsMatch(
1078-
"-fauto-profile=[^ ]*/profile.afdo");
1079-
assertThat(ActionsTestUtil.baseArtifactNames(backendAction.getInputs())).contains(
1080-
"profile.afdo");
1088+
assertThat(Joiner.on(" ").join(backendAction.getArguments()))
1089+
.containsMatch("-fauto-profile=[^ ]*/profile.afdo");
1090+
assertThat(ActionsTestUtil.baseArtifactNames(backendAction.getInputs()))
1091+
.contains("profile.afdo");
10811092
}
10821093

10831094
private void setupThinLTOCrosstool(String... extraFeatures) throws Exception {

0 commit comments

Comments
 (0)