Reputation: 1359
I wish to run bazel build :...all
command and skip test
rules and targets. Is this possible?
I can conceive of two ways to distinguish the tests, either by their type (cc_test in my case), or by pattern-matching on the name, as the project I'm working in suffixes all test rules/targets with "_test".
Please, refrain from making comments telling me that I should always build and run tests upon compilation, unless Bazel actually makes it technically impossible to use "all" wildcard and also filter out all tests. We have a tiered system where builds and tests are all run together, and then after success, another system just builds the minimum artifacts.
Upvotes: 5
Views: 10723
Reputation: 23
This is an addition to hlopko's answer https://stackoverflow.com/a/46543959/427652.
testonly
targetshttps://bazel.build/query/language#attr
bazel query 'attr(testonly, 1, //...)'
testonly
targetsbazel query 'attr(testonly, 0, //...)'
bazel query 'attr(testonly, 0, //...)' | xargs bazel build
Upvotes: 1
Reputation: 3268
There is bazel query. It's quite powerful so I advise to read through the documentation page to design the query command precisely. To quickly answer your concrete question, I think this will work for you:
bazel query '//... except kind(.*test, //...)' | xargs bazel build
Upvotes: 11