I have some bazel rules like so:
//a/b/c:foo_x
//a/b/c:foo_y
//a/b/d:bar_x
//a/b/d:bar_y
//a/b/e/f/g:qux_x
//a/b/e/f/g:qux_y
Is there a way to say I want to build all rules with the "_x" suffix? I know that Bazel supports wildcards such as //a/... but I would like greater control over what exactly I am building.
Use a combination of query and grep.
$ bazel build $(bazel query //a/b/... | grep -E ":.+_x")
Related
For some background, my specific use case is actually in Rules Python's compile_pip_requirements rule. I do not want to use the default caching location for pip packages, so I am passing args to pip through compile_pip_requirements via:
compile_pip_requirements(
...
extra_args = [
"--allow-unsafe",
"--cache-dir",
"/tmp/pip-compile",
],
...)
I can easily hardcode the tmp dir there, but I would like to specifically use the same directory that Bazel uses to cache everything else, without making any magic assumptions about where that cache dir is.
I have tried to use $(bazel info | grep output_base | awk '{print $2}') but Bazel appears to only accept its own Make Variables within a variable expression, not to mention that this does not feel like a safe option anyway.
I have also tangled a bit with those make variables (most promisingly, $(location //foo)), but it seems this only returns the location of a given module relative to WORKSPACE.
Thanks!
nix-build ... --no-out-link gives a path in the Nix store.
Is it possible to find out that path without actually building the expression ?
Is it possible to find out the dependencies and the planned build operations without building the expression ?
How could I find the answer myself ?
The Nix manual, "Building and testing" section refers to nix-build documentation, which in the last "Description" paragraph mentions it is a combination of nix-instantiate and nix-store -r.
nix-instantiate does not build. It only calculates the plan, in the form of a derivation and its closure:
$ nix-instantiate '<nixpkgs>' -A hello
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/20bc2g6gfn44p9wk98s30pm346pmz0x9-hello-2.10.drv
However, I prefer to use nix repl to explore Nix expressions:
$ nix repl '<nixpkgs>'
Loading '<nixpkgs>'...
Added 8623 variables.
nix-repl> hello.outPath
"/nix/store/nic2bl8ry6vfyxr9717983d5b2l4sn1c-hello-2.10"
Its tab completion is very helpful when exploring expressions.
man nix-store has the answer, and in particular the --query section.
To know the output path:
nix-store -q --outputs $(nix-instanciate default.nix)
To know the build-time dependencies:
nix-store -qR --include-outputs $(nix-instanciate default.nix)
As for a build plan, the closer I get is to use the --tree flag.
Note that nix-shell exposes a $out variable too, so another possible solution to the first bullet point would be:
nix-shell --pure --run 'echo $out' some-file.nix
BSD (Mac) grep allows for this command:
grep -n "FIXME" **/*.rb
But GNU grep forces me to specify at least a folder to start from:
grep -n "FIXME" {lib,spec}/**/*.rb
Is there a way to get this to behave like it does in BSD grep?
Switch to ack. It uses the recursive strategy by default, and comes with loads of tricky regexes for types of language files available as flags.
For instance, writing:
ack FIXME --ruby
Will search the current directory recursively for anything that may be a Ruby file. This will work the same on Mac and Linux.
On a single-user system where security isn't an issue, is there any
advantage to using "updatedb" and "locate" (or slocate or mlocate)
instead of just doing "ls -laR > somefile" nightly and then using
"grep phrase somefile" to find files?
In fact, it would seem that grep is more flexible than locate since it
allows for regular expressions.
What am I missing here?
For your specific scenario, the differences are marginal, but the locate database is optimized for fast searches.
On a multiuser system, modern locate replacements have various additional security features so as to e.g. not reveal to another user what files you have in your private directories.
Is it possible to use wildcards in the Erlang compiler's -I option?
For example, I want to do something like this:
erlc -I deps/*/include -I deps src/foo.erl
I know that other solutions exist (like using rebar or make) but in this case, I am looking explicitly at erlc.
In Linux (and other unixoid systems) wildcards are never resolved by the invoked program.
The shell you use (e.g. bash) resolves all wildcards.
So erlc won't see the the asterix at all.
(If you read the documentation of find(1) you may find that my previous explanation is somewhat oversimplified.)
If you don't want to use an extra tool (I'd recommend looking at rebar oder make, though), you could try:
erlc $(find deps -name include -exec echo '-I {}' ';') -I deps src/foo.erl
(Weak substitute, I know.)