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

[6.3.1] Fix a bug where frozen targets list was mutated while expanding env attribute for cc_test #19052

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
5 changes: 3 additions & 2 deletions src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,10 @@ def _expand_nested_variable(ctx, additional_vars, exp, execpath = True, targets
if not execpath:
if exp.startswith("location"):
exp = exp.replace("location", "rootpath", 1)
data_targets = []
if ctx.attr.data != None:
targets.extend(ctx.attr.data)
return ctx.expand_location("$({})".format(exp), targets = targets)
data_targets = ctx.attr.data
return ctx.expand_location("$({})".format(exp), targets = targets + data_targets)

# Recursively expand nested make variables, but since there is no recursion
# in Starlark we will do it via for loop.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
"//src/main/java/com/google/devtools/build/lib/analysis:run_environment_info",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.OutputGroupInfo;
import com.google.devtools.build.lib.analysis.RunEnvironmentInfo;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
import com.google.devtools.build.lib.analysis.util.AnalysisMock;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
Expand Down Expand Up @@ -805,6 +806,21 @@ public void testExpandedLinkopts() throws Exception {
.getPathString()));
}

@Test
public void testExpandedEnv() throws Exception {
scratch.file(
"a/BUILD",
"genrule(name = 'linker', cmd='generate', outs=['a.lds'])",
"cc_test(",
" name='bin_test',",
" srcs=['b.cc'],",
" env={'SOME_KEY': '-Wl,@$(location a.lds)'},",
" deps=['a.lds'])");
ConfiguredTarget starlarkTarget = getConfiguredTarget("//a:bin_test");
RunEnvironmentInfo provider = starlarkTarget.get(RunEnvironmentInfo.PROVIDER);
assertThat(provider.getEnvironment()).containsEntry("SOME_KEY", "-Wl,@a/a.lds");
}

@Test
public void testProvidesLinkerScriptToLinkAction() throws Exception {
scratch.file(
Expand Down