I try to query deps with a custom flags. For example,
bazel query --define=using_cuda=true "deps(#org_tensorflow//tensorflow/core:lib)"
Bazel complained:
ERROR: Unrecognized option: --define=using_cuda=true
How could I pass a custom flag to bazel query command?
bazel query doesn't support the --define flag because the command doesn't use it. Instead, use bazel cquery instead, which stands for "configurable query".
Related
given a bazel command, for example bazel build //..., is it possible to see what build command this expands to based on the bazelrc(s)?
bazelrcs are great to set default flags, like the default platform to build for setting some variables based on profiles.
They also allow for nested bazelrcs, that you can import and try-import leading to a rather complex expansion of bazel commands via bazelrcs.
To verify that the bazelrcs did indeed configure the correct things and did not override some flags accidentally, I would love to see the output of what bazel would expand a bazel command to.
Is that possible?
I tried setting --logging=0 and --logging=6 with bazel 5.3.0 but see no such output.
You can run your build using the --explain flag.
Something like
bazel build --explain explain.log //...
should produce a file explain.log where the first line contains the expanded flags.
I am trying to add Other Swift Flags with shell script
but i can't find a way
The reason why we want to add Other Swift Flags values in the shell is because we are operating the feature-flags dynamically.
Previously, we were passing it as a parameter of build_app on fastlane, but now we're switching CI to xcode-cloud, and for that, we're looking for a way to deliver the flag in ci_script
If there's any way to add it, could you tell me how to do 🙏
You will need a separate shell script which runs xcodebuild -showBuildSettings -json, then use jq to parse the output and find the flags you're looking for.
I would like to run bazel and all of its subprocesses at a higher IO-nice-ness level.
How can I achieve that?
You can use the bazel --io_nice_level=<your nice value here> option
Careful it's a startup option, so you need to pass that flag before the bazel action:
bazel --io_nice_level=8 build //...
We're considering migrating to Bazel from Make. To make the transition easier I would like to have bazel test (no flags / options) run the current directory's tests, if any.
So instead of bazel test my_tests bazel test would find the current directory's BUILD file, find any *_test rules and run those.
If you want to do exactly as you said then you can use your own script.
When you run “bazel” it actually looks to see if there is a script named “bazel” under tools directory of the current workspace. So if you have an executable under “$workspace/tools/bazel” bazel will run that instead of the bazel binary itself.
This means you can write a script that checks if the only argument is “test” and if so calls “bazel-real test :all”
It can also check the exit code to see if there were no tests (it’s a specific error code) and return 0 instead
You can use the all target pattern to match all targets in the current package: bazel test :all
You can read more about it here: https://docs.bazel.build/versions/master/user-manual.html#target-patterns
Note however that if there are no test targets in the current package, bazel will give an error: "ERROR: No test targets were found, yet testing was requested.". In this case bazel will give an exit code of 4: https://docs.bazel.build/versions/master/user-manual.html#what-exit-code-will-i-get
I recommend creating a alias called bazel-test to bazel test :all.
Suppose you have this:
$ bazel query "filter('_image_publish$', attr(generator_function, go_server_v1, ...))"
//helloworld/server:zurigo_server_image_publish
//bababot:bababot_server_image_publish
Is it possible to create rules or macros that let me do a single bazel build the builds all the targets above?
I'd like to do:
$ bazel build :all-servers
Which would implicitly build the ones from the output above. Is this possible?
Another way to put it, I'm looking for a Skylark alternative to doing a loop using bash on the output of the query.
You can write a genquery() rule, which will write the query result targets into a file in bazel-bin.
The final command will look something like:
bazel build //package:my_genquery && cat bazel-bin/package/my_genquery | xargs bazel build