bazelbuild / examples

Examples for Bazel
http://bazel.build
Apache License 2.0
800 stars 497 forks source link

Add `cfg = _test_arg_transition` in configurations/cc_test/defs.bzl #367

Closed rwgk closed 7 months ago

rwgk commented 7 months ago

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 commented 7 months ago

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 https://github.com/bazelbuild/bazel/pull/18854.

Who produces new arg in your example?

rwgk commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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

Thanks for catching this! Fixed:

https://github.com/bazelbuild/examples/blob/eceab974529b0b748cd6498c3107c0aa0c18b88b/configurations/cc_test/README.md