Skip to content

Commit

Permalink
[8.1.0] Add environment variables to LTO backend actions. (#25242)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 700351238
Change-Id: If9e0686bee0756b0af56cda91ac70d184858fd72

Commit
0937e35

Co-authored-by: Googler <trybka@google.com>
  • Loading branch information
bazel-io and trybka authored Feb 11, 2025
1 parent f744b6a commit 9209fd5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public final class LtoBackendArtifacts implements LtoBackendArtifactsApi<Artifac
linkActionConstruction.getConfig().isSiblingRepositoryLayout()),
".dwo"));
}
addEnvironmentVariables(builder, buildVariables, featureConfiguration);
scheduleLtoBackendAction(
builder,
buildVariables,
Expand Down Expand Up @@ -329,6 +330,20 @@ private static void addOutputsToLtoBackendActionBuilder(
}
}

private static void addEnvironmentVariables(
LtoBackendAction.Builder builder,
CcToolchainVariables buildVariables,
FeatureConfiguration featureConfiguration)
throws EvalException {
try {
builder.setEnvironment(
featureConfiguration.getEnvironmentVariables(
CppActionNames.LTO_BACKEND, buildVariables, PathMapper.NOOP));
} catch (ExpansionException e) {
throw new EvalException(e.getMessage());
}
}

private static void addCommandLineToLtoBackendActionBuilder(
LtoBackendAction.Builder builder,
FeatureConfiguration featureConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ _static_env_feature = feature(
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.lto_backend,
],
env_entries = [
env_entry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,17 @@ private void validateDwp(
.containsExactlyElementsIn(expectedInputs);
}

@Test
public void testLtoBackendEnv() throws Exception {
createBuildFiles("features = ['env_feature'],");
setupThinLTOCrosstool(MockCcSupport.ENV_VAR_FEATURES);

LtoBackendAction backendAction =
getBackendAction("pkg/bin.lto/" + getRootExecPath() + "/pkg/_objs/bin/binfile.o");
assertThat(backendAction.getMnemonic()).isEqualTo("CcLtoBackendCompile");
assertThat(backendAction.getIncompleteEnvironmentForTesting()).containsEntry("cat", "meow");
}

@Test
public void testFission() throws Exception {
createBuildFiles();
Expand Down Expand Up @@ -1074,10 +1085,10 @@ public void testAutoFdo() throws Exception {
linkAction, "pkg/bin.lto/" + rootExecPath + "/pkg/_objs/bin/binfile.o");

// Checks that -fauto-profile is added to the LtoBackendAction.
assertThat(Joiner.on(" ").join(backendAction.getArguments())).containsMatch(
"-fauto-profile=[^ ]*/profile.afdo");
assertThat(ActionsTestUtil.baseArtifactNames(backendAction.getInputs())).contains(
"profile.afdo");
assertThat(Joiner.on(" ").join(backendAction.getArguments()))
.containsMatch("-fauto-profile=[^ ]*/profile.afdo");
assertThat(ActionsTestUtil.baseArtifactNames(backendAction.getInputs()))
.contains("profile.afdo");
}

private void setupThinLTOCrosstool(String... extraFeatures) throws Exception {
Expand Down

0 comments on commit 9209fd5

Please sign in to comment.