User name in .bazelrc

1.6k Views Asked by At

I would like to add this to my .bazelrc, but the $(whoami) doesn't expand like if it was in a shell.

startup --output_user_root=/tmp/bazel/out/$(whoami)                                                                                                                             

It produces the literal result:

/tmp/bazel/out/$(whoami)/faedb999bdce730c9c495251de1ca1a4/execroot/__main__/bazel-out/

Is there any way to do what I want: adding a name/hash to the option in the .bashrc file?

Edit: what I really want is to set the outputRoot to /tmp/bazel/out without using an environment variable and to let bazel create it's user and workspace hash directories there.

2

There are 2 best solutions below

1
László On BEST ANSWER

You can run Bazel from a wrapper script. In fact, that's exactly what the bazel binary is (at least on Linux): it's a wrapper script that calls bazel-real. You can edit this wrapper script if you like, or rename it to bazel.sh and write your own wrapper.

1
Austin Schuh On

/usr/bin/bazel is a script which looks for //tools/bazel, and if it exists, calls it. Otherwise, it calls bazel-real. This lets you check Bazel into your repo, or otherwise modify how it gets called. We use that to download a specific version of bazel, extract it, and then call it.

I would recommend creating //tools/bazel, and having that do your modification. It can then either call a versioned version of bazel, or call bazel-real. That keeps your modifications local to your repo rather than global.