-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
How to build all buildable targets and test all testable targets #4257
Comments
There's no way to do this (that I'm aware of), since building all buildable targets and testing all testable targets involve 2 different bazel commands with two different sets of targets. Unfortunately it's not how bazel was designed.
On the other hand, when |
@iirina wouldn't know how. @alexeagle why don't you do |
|
Nevermind. Nice! |
No, you can "bazel test" a non-test target. Bazel will warn you about it, but will build it anyway. |
@buchgr @laszlocsomor that's basically what I wish Bazel could do, without exhausting the command-line limit which seems like an easy pit to fall into. Consider this a feature request? |
@alexeagle : I'm afraid we don't have free cycles to work on this feature request right now. |
|
@buchgr not portable, but my main concern for this is CI where I control the environment. I can do this just for Linux/Mac builds to start with, and let Windows testing be slower. |
It's a bit more tricky. We use |
Can you clarify this? If I have a basic workspace with a cc_binary and a cc_test, |
If you didn't have a cc_test, it would build nothing.
For example, you might build a binary that you distribute, but don't have
an integration test for that binary. Then bazel test ... won't even try to
build the binary, and you might break it.
…On Thu, May 17, 2018 at 7:55 AM Rodrigo Queiro ***@***.***> wrote:
bazel test ... is bad because it doesn't build a target unless some test
depends on it. (probably surprising to new users)
Can you clarify this? If I have a basic workspace with a cc_binary and a
cc_test, bazel test //... builds both and then runs the test. If I pass
--build_tests_only then it behaves as you described.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4257 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC5I9nqOWzdE_SVEGP4BVhfK8Kj3RpQks5tzY9VgaJpZM4Q6hz5>
.
|
Even without the cc_test, the cc_binary gets built:
|
did you clean the output directory first?
…On Thu, May 17, 2018 at 8:29 AM Rodrigo Queiro ***@***.***> wrote:
Even without the cc_test, the cc_binary gets built:
> cat BUILD.bazel
cc_binary(
name = "main",
srcs = ["main.cc"],
)
#cc_test(
# name = "test",
# srcs = ["test.cc"],
#)
> ls bazel-bin
ls: cannot access 'bazel-bin': No such file or directory
> bazel test //...
INFO: Analysed target //:main (6 packages loaded).
INFO: Found 1 target and 0 test targets...
Target //:main up-to-date:
bazel-bin/main
INFO: Elapsed time: 1.043s, Critical Path: 0.24s
INFO: 3 processes: 2 linux-sandbox, 1 local.
INFO: Build completed successfully, 6 total actions
ERROR: No test targets were found, yet testing was requested
> ls bazel-bin
main main-2.params main.runfiles main.runfiles_manifest _objs
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4257 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC5I8g1ewZffLPhHk_kvF3QlLWK7ABbks5tzZdCgaJpZM4Q6hz5>
.
|
Yep. The bazel output also shows that it has built the binary (6 total actions) even through no test targets were found. |
@alexeagle hey :) does this mean we can simplify the instructions at |
Wow, I'm surprised to learn this. We have an elaborate |
@alexeagle : sorry, to learn what? I don't know if anything changed in Bazel about how it handles "...". |
I think target expansion is not what changed - it's that you can use Confirmed this is the case under Blaze as well. |
the behavior of bazel changed sometime in mid-2018 so that `test //...` now builds binaries, even if they aren't depended on by tests. see bazelbuild/bazel#4257.
Having something close to |
bazel test //... should be enough see bazelbuild/bazel#4257
Is this still true as of Bazel 4.2.1? It is not building all binaries for me. |
@ishaangandhi maybe you have the --build_tests_only flag? |
Thanks! Adding --nobuild_tests_only made it work. |
I want to "build and test all the things" on my CI.
bazel test ...
is bad because it doesn't build a target unless some test depends on it. (probably surprising to new users)bazel build ... && bazel test ...
is bad because the first test doesn't start running until the slowest build target is builtAt Google we give up on this, and use
build_test
(alluded to at https://docs.bazel.build/versions/master/be/functions.html#load) which is a special test target that always passes, but consumes the files from some given deps, forcing those deps to build, and thus making the test either fail with a build error, or pass. But I think this is bad because it's easy to forget to create abuild_test
for some target, and we shouldn't expect everyone to be ever-watchful for that gotcha.Is there some other way I don't know of?
The text was updated successfully, but these errors were encountered: