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

Add common envs attribute for *_binary and *_test rules #7624

Closed
wants to merge 2 commits into from

Conversation

blico
Copy link
Member

@blico blico commented Mar 5, 2019

Addresses #7364

envs is a string_dict attribute common for all *_binary and *_test rules. Bazel will set the environment variables specified in envs in the run/test environment before executing the given target. Variables specified in --test_env and --action_env will take priority over the envs attribute, and the envs attribute does not support bringing in environment values from the invocation environment.

Given the large impact of this change, I expect a lot of feedback. I thought it would be good to get this PR out early to get the discussion going.

@Globegitter
Copy link

What does and the envs attribute does not support bringing in environment values from the invocation environment. mean exactly? I don't fully understand.

@aiuto aiuto requested a review from hlopko March 6, 2019 03:53
@hlopko hlopko requested a review from lberki March 7, 2019 10:19
@hlopko
Copy link
Member

hlopko commented Mar 7, 2019

Hmm I don't see anything controversial here. @lberki wdyt? I can then proceed with the code review (quickly glancing over I'd use ImmutableMap, look into documenting the attribute (so people don't assume it's the env under which the target is built or smth), add more tests (e.g. for cc_binary), and try to propagate the env in arguments and not access ruleContext and rule attributes from e.g. TestActionBuilder).

@hlopko
Copy link
Member

hlopko commented Mar 21, 2019

Friendly ping @lberki

@jin jin added the team-Core Skyframe, bazel query, BEP, options parsing, bazelrc label Mar 25, 2019
@@ -83,6 +84,7 @@
private final Artifact owningExecutable;
private final boolean createSymlinks;
private final CommandLine args;
private final Map<String, String > envs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this an ImmutableMap; otherwise, RunfilesSupport would not be immutable.

private static Map<String, String> computeEnvs(
RuleContext ruleContext) {
if (!ruleContext.getRule().isAttrDefined("envs", Type.STRING_DICT)) {
return new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ImmutableMap.of()

@linzhp
Copy link
Contributor

linzhp commented Mar 27, 2019

@lberki Without this PR, what's the recommended way to run a binary that relies on environment variables with bazel run? I know there are different options:

  • export ENV=value && bazel run --action_env=ENV //path/to:target
  • bazel run --run_under='ENV=value' //path/to:target

@hlopko hlopko removed their request for review April 17, 2019 14:48
@aiuto
Copy link
Contributor

aiuto commented Aug 21, 2019

Friendly ping

@jin
Copy link
Member

jin commented Oct 2, 2019

Looks like activity has stalled on this PR - please address the review comments and rebase this branch if you'd like to continue working on it.

@jin jin closed this Oct 2, 2019
@linzhp
Copy link
Contributor

linzhp commented Oct 2, 2019

@blico Should we continue working on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-Core Skyframe, bazel query, BEP, options parsing, bazelrc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants