Currently, bazel based ebuilds fail when FEATURES=ccache is enabled due to a sandbox violation. The issue can be roughly summarized as follows. Bazel clears the environment variable CCACHE_DIR. When CCACHE_DIR is unset, ccache defaults to using "${HOME}/.ccache" as the cache directory. For portage, "${HOME}/.ccache" expands to "/var/lib/portage/home/.ccache". Therefore, when ccache is enabled, it tries to cache files in "/var/lib/portage/home/.ccache" that results in the sandbox violation. Example of the ebuild that triggers this issue is `tensorflow`. So, the steps to reproduce are: 1. Install and configure ccache. 2. FEATURES=ccache emerge tensorflow Unfortunately, I am no longer using bazel nor tensorflow, so I cannot provide the exact logs, but I think this bug might be helpful to other users. This issue can be solved by modifying the `bazel.eclass` eclass and adding the following lines ``` build --action_env CCACHE_DIR build --host_action_env CCACHE_DIR ``` right below the line containing `build --action_env HOME` of `bazel_setup_bazelrc` function.
I have found a solution: set `cache_dir` in `/etc/ccache.conf`, like this: ``` cache_dir=/var/cache/ccache max_size=300G umask=002 compiler_check=%compiler% -v compress=false ``` I am not familiar with bazel too and I have tried to pass `CCACHE_DIR` and `-d $CCACHE_DIR` into bazel but all get failed, only this method works.