Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.1.0] Add environment variables to LTO backend actions. #25242

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading