Skip to content

Conversation

@alexeagle
Copy link
Collaborator

Thanks for the patch @brett-patterson-ent

Fixes #1200

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 53 to 57
envs = {}
if RunEnvironmentInfo in ctx.attr.tool:
envs = ctx.attr.tool[RunEnvironmentInfo].environment
for k, v in ctx.attr.env.items():
envs[k] = expand_variables(ctx, ctx.expand_location(v, targets = ctx.attr.srcs), inputs = ctx.files.srcs, outs = outputs, attribute_name = "env")

Choose a reason for hiding this comment

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

P1 Badge Copy RunEnvironmentInfo.environment before mutating

The code assigns envs directly to ctx.attr.tool[RunEnvironmentInfo].environment and then mutates it. Providers returned from other targets are frozen; attempting to assign into the dict will fail with cannot modify frozen value for any tool that exports RunEnvironmentInfo. Even if mutation were allowed, it would leak our overrides back into the tool’s provider for other dependents. Make a copy (e.g. envs = dict(...)) before merging in additional env vars.

Useful? React with 👍 / 👎.

@aspect-workflows
Copy link

aspect-workflows bot commented Nov 3, 2025

Bazel 8 (Test)

2 test targets passed

Targets
//lib/tests/copy_to_directory:case_22_test [k8-fastbuild]                    74ms
//lib/tests/copy_to_directory_bin_action:test [k8-fastbuild]                 179ms

Total test execution time was 253ms. 128 tests (98.5%) were fully cached saving 42s.


Bazel 9 (Test)

2 test targets passed

Targets
//lib/tests/copy_to_directory:case_22_test [k8-fastbuild]                    96ms
//lib/tests/copy_to_directory_bin_action:test [k8-fastbuild]                 346ms

Total test execution time was 442ms. 128 tests (98.5%) were fully cached saving 16s.


Bazel 7 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 23ms.


Bazel 8 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 23ms.


Bazel 9 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Bazel 7 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 20ms.


Bazel 8 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 21ms.


Bazel 9 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 33ms.


Bazel 7 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 309ms.


Bazel 8 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 295ms.


Bazel 9 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 263ms.


Bazel 7 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 204ms.


Bazel 8 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 260ms.


Bazel 9 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 271ms.


Bazel 7 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 20ms.


Bazel 8 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 21ms.


Bazel 9 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 33ms.


Bazel 7 (Test)

e2e/smoke

Buildkite build #227 is running...


Bazel 8 (Test)

e2e/smoke

Buildkite build #227 is running...


Bazel 9 (Test)

e2e/smoke

Buildkite build #227 is running...


Bazel 7 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 30ms.


Bazel 8 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 28ms.


Bazel 9 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 35ms.

for a in ctx.attr.args:
args.add_all(split_args(expand_variables(ctx, ctx.expand_location(a, targets = ctx.attr.srcs), inputs = ctx.files.srcs, outs = outputs)))
envs = {}
if RunEnvironmentInfo in ctx.attr.tool:
Copy link
Member

Choose a reason for hiding this comment

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

I can see why this is useful, but it also deviates from pretty much all other rules by applying env transitively instead of only with bazel run/test. This could result in confusion and uncertainty, which may be worse than the status quo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there some good documentation that shows when env is forwarded and when not?

Copy link
Member

Choose a reason for hiding this comment

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

See https://bazel.build/reference/be/common-definitions#common-attributes-binaries, this is documented to only affect the behavior of bazel run (and bazel test for tests).

Copy link
Contributor

Choose a reason for hiding this comment

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

So when using this as part of a genrule or run_binary the env and args have to be set there as well, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's the documented status quo. I'm not against changing this in general, but doing so for a single rule feels wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well I love an ambitious plan. Reminds me of default_shell_env.
What would be the more principled (and maybe completely impractical) thing to do?
A rule that converts the args/env lost attributes to be baked into the binary?

Copy link
Member

Choose a reason for hiding this comment

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

Just generally a rule that takes an executable target and bakes in args/env via a wrapper. That would be quite composable and not too magical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

run_binary does not include executable environment from RunEnvironmentInfo

4 participants