Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom CCACHE_DIR environment has no effect when running sandbox.sh #4749

Open
Goodwu opened this issue Jul 2, 2021 · 1 comment
Open

Custom CCACHE_DIR environment has no effect when running sandbox.sh #4749

Goodwu opened this issue Jul 2, 2021 · 1 comment
Assignees

Comments

@Goodwu
Copy link

Goodwu commented Jul 2, 2021

Let's have a look at add_ccache_mount() function in ${HOME}/.opam/opam-init/hooks/sandbox.sh

add_ccache_mount() {
  if command -v ccache > /dev/null; then
      CCACHE_DIR=$HOME/.ccache
      ccache_dir_regex='cache_dir = (.*)$'
      local IFS=$'\n'
      for f in $(ccache --print-config 2>/dev/null); do
        if [[ $f =~ $ccache_dir_regex ]]; then
          CCACHE_DIR=${BASH_REMATCH[1]}
        fi
      done
      add_mounts rw $CCACHE_DIR
  fi
}

$CCACHE_DIR is used by ccache to customize ccache directory, and it's overwritten here by

      CCACHE_DIR=$HOME/.ccache

and

          CCACHE_DIR=${BASH_REMATCH[1]}

So the environment variable I set before has no effect here.
The shell variable CCACHE_DIR should be renamed to avoid confliction.

@kit-ty-kate kit-ty-kate transferred this issue from ocaml/opam-repository Jul 10, 2021
@dra27
Copy link
Member

dra27 commented Jul 10, 2021

The first setting looks like a "complete" bug - the ccache manual has clear details on how it finds ccache.conf and setting it here skips steps 1-3 of its algorithm.

The second setting should be guarded with local to stop any change to the variable leaking to the exec call.

While we're there, the dance with a for loop can be much more simply converted to:

  local CCACHE_DIR="$(ccache --print-config 2>/dev/null | sed -n -e 's/cache_dir = //p')"
  test -z "$CCACHE_DIR" || add_mounts rw "$CCACHE_DIR"

that should then have the desired effect that cache_dir is read-write in the sandbox!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants