Search code examples
pathabsolutedistccccache

How to get ccache to not pass the full path to the compiler to distcc


(This is different to the question ccache and absolute path as I want only the command path to not be expanded on the ccache host machine)

When using ccache and distcc together ccache is expanding the compiler to an absolute path, and then distcc cannot use the PATH on the remote machine to choose which compiler to use.

e.g. I call CCACHE_PREFIX=distcc ccache g++ foo.cc and ccache expands this into a local preprocessing step and cache check and then a call to distcc as distcc /usr/bin/g++, which is the wrong version (g++ lives in the path on the remote before /usr/bin, but this doesn't give it the chance to search the path at all).

I have various different machines being used as distcc hosts, and they have the same version of gcc/g++ installed in different locations (yes, this problem goes away if I put them all in somewhere like /usr/local, but I can't do that at the moment).

Is there a setting to get ccache to pass just g++ to distcc rather than expanding the path to the absolute path of the local compiler? I'm not completely against patching ccache if there is no setting yet, but that's a last resort :)


Solution

  • Turns out there's a simple way to do this : just use a wrapper for CCACHE_PREFIX instead of distcc directly, with something like this:

    File : distcc-wrap.sh

    #!/bin/sh
    compiler=$(basename $1)
    shift
    exec distcc "$compiler" "$@"
    

    export CCACHE_PREFIX=distcc-wrap.sh and then this allows the remote compiler to live at a different place and distcc will search the PATH for it.

    (Thanks to Joel on the ccache mailing list for this answer; see http://www.mail-archive.com/[email protected]/msg00670.html for original message)