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 cfg = _test_arg_transition in configurations/cc_test/defs.bzl #367

Merged
merged 6 commits into from
Dec 8, 2023

Conversation

rwgk
Copy link
Contributor

@rwgk rwgk commented Nov 23, 2023

Question for the bazel experts: Does configurations/cc_test work as intended without the added cfg = _test_arg_transition in defs.bzl?

This PR changes mytest.cc to send argv to stdout.

Without the added cfg = _test_arg_transition in defs.bzl, new arg does not appear in the output. See below.

The other changes are optional, they just make this example more complete. Not being very familiar with the bazel mechanisms, it took me a while to figure out the two tricks to 1. ensure that args are handled correctly, and 2. the non-transitioned test is not run.


WITHOUT the added cfg = _test_arg_transition in defs.bzl

bazel test :all --test_output=all
MYTEST ARGV[0]: /usr/local/google/home/rwgk/.cache/bazel/_bazel_rwgk/bfd421ff56c7e52ce2de56579817e14d/sandbox/linux-sandbox/9/execroot/__main__/bazel-out/k8-fastbuild/bin/my-test.runfiles/__main__/my-test
MYTEST ARGV[1]: x
MYTEST ARGV[2]: y
MYTEST ARGV[3]: z

WITH the added cfg = _test_arg_transition in defs.bzl (i.e. this PR as is)

MYTEST ARGV[0]: /usr/local/google/home/rwgk/.cache/bazel/_bazel_rwgk/bfd421ff56c7e52ce2de56579817e14d/sandbox/linux-sandbox/4/execroot/__main__/bazel-out/k8-fastbuild-ST-54535d7cadf4/bin/my-test.runfiles/__main__/my-test
MYTEST ARGV[1]: x
MYTEST ARGV[2]: y
MYTEST ARGV[3]: z
MYTEST ARGV[4]: new arg

@gregestren
Copy link
Collaborator

Hi @rwgk .

Thanks for your contribution.

I agree the existing test is sparse. And adding more examples of using the idea makes the point more clear. So I like what you're doing.

The main impact of transitioning directly on the transition_rule_test as you're doing is the final output may no longer appear under bazel-bin. That's arguably not important if we're just running a test. See for example bazelbuild/bazel#18854.

Who produces new arg in your example?

Copy link
Collaborator

@gregestren gregestren left a comment

Choose a reason for hiding this comment

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

I think overall this s a nice improvement, and makes the example more complete as you describe.

There are all kinds of subtle implications in transitions that users should be aware of. But this example doesn't have to explore the full space, and a more complete example is better than a less complete one. So I'm strongly inclined to support your improvements without worrying too much.

I'd also update the README.md to walk through what's going on more cleanly. As written I think it's overly vague.

configurations/cc_test/defs.bzl Outdated Show resolved Hide resolved
@rwgk
Copy link
Contributor Author

rwgk commented Nov 29, 2023

I'd also update the README.md to walk through what's going on more cleanly. As written I think it's overly vague.

Done (28024ad). I'm simply showing the bazel command and expected output. Please let me know if you had something else in mind.

@gregestren
Copy link
Collaborator

I'd also update the README.md to walk through what's going on more cleanly. As written I think it's overly vague.

Done (28024ad). I'm simply showing the bazel command and expected output. Please let me know if you had something else in mind.

Looks great, thank you.

My final nit is I think the md formatting got messed up on the new README? https://github.com/bazelbuild/examples/blob/28024ade6658c129bed244481b119960b0bcff87/configurations/cc_test/README.md

@rwgk
Copy link
Contributor Author

rwgk commented Dec 8, 2023

@gregestren gregestren merged commit b051dc6 into bazelbuild:main Dec 8, 2023
2 checks passed
@rwgk rwgk deleted the cc_test_cfg branch December 8, 2023 19:16
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.

2 participants