How to get workspace directory in bazelrc

618 Views Asked by At

I want to specify a ASAN suppression file in .bazelrc. And the suppression file is located in workspace directory. I tried as following:

build:debug --action_env=LSAN_OPTIONS=suppressions=${workspace}/asan_leaks.supp

and

build:debug --action_env=LSAN_OPTIONS=suppressions=%workspace%/asan_leaks.supp

But what I got is:

AddressSanitizer: failed to read suppressions file
'/projects/mytest/bazel-output/execroot/mytest/bazel-out/aarch64-dbg/bin/mytest/${workspace}/asan_leaks.supp'

and

AddressSanitizer: failed to read suppressions file 
'/projects/mytest/bazel-output/execroot/mytest/bazel-out/aarch64-dbg/bin/mytest/%workspace%/asan_leaks.supp'

It works if I hardcoded an absolute path, so I try to get the absolute path of workspace. Any suggestions are welcome, thanks.

1

There are 1 best solutions below

0
garry On

Just update my workaround in case that somebody encouter similar issue:

  1. Hardcode the suppression file with absolute path as following:

    build:debug --action_env=suppressions=/tmp/asan_leaks.supp

  2. Specify workspace_status_command relative to workspace directory

    build --workspace_status_command=./bazel/cmd.sh

  3. Make soft link to the suppression file in cmd.sh

    bazel_dir=$(dirname -- "$(readlink -f $0;)") ln -sf ${bazel_dir}/asan_leaks.supp /tmp/asan_leaks.supp