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

(This is different from the ccache question and the absolute path , since I want the ccache host machine to not expand only the path to the command line)

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

eg. I call CCACHE_PREFIX=distcc ccache g++ foo.cc , and ccache extends it to the local preprocessing step and cache check, and then calling distcc as distcc /usr/bin/g++ , which is the wrong version (g ++ lives in the path on the remote computer until / usr / bin, but this does not give him the ability to search on the path at all).

I have different machines used as distcc hosts, and they have the same gcc / g ++ version installed in different places (yes, this problem disappears if I put them all somewhere like / usr / local but I cannot do this at the moment).

Is there a parameter that allows ccache to pass only g++ to distcc, and not extend the path to the absolute path of the local compiler? I am not completely opposed to fixing ccache if there is no configuration yet, but this is the last resort :)

+4
source share
2 answers

Creates an easy way to do this: just use the 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 elsewhere, and distcc will look for the PATH for it.

(Thanks to Joel from the ccache mailing list for this answer, see http://www.mail-archive.com/ ccache@lists.samba.org /msg00670.html for the original message)

+6
source

I am trying to find a solution to David, but ran into the problem "distcc seems to have called recursively!" in distcc plain mode. This is due to the fact that when the host distcc request performs preprocessing (cpp), it will call the host ccache file, but distcc-wrap intercepts and spawns a nested distcc and generates a recursive call:

g ++ β†’ ccache β†’ distcc β†’ distcc-wrap β†’ preprocess using g ++ β†’ ccache β†’ distcc β†’ .... etc.

My solution is to use DISTCC_CMDLIST , from man distccd :

DISTCC_CMDLIST

If the DISTCC_CMDLIST environment variable is set, load the list of supported commands from a file named DISTCC_CMDLIST and refuse to service any command, the last last words of DISTCC_CMDLIST_MATCHWORDS do not match the last words of the command in this list. See Comments in src / serve.c.

Assuming you want to use /usr/local/ccache/g++ (which is a /usr/bin/ccache ) on the remote computer to run the compilation, instead of using the absolute path extended by the host machine, you can do it like this:

  • create the file /path/to/.distcc/DISTCC_CMDLIST with this line:

    /usr/local/ccache/g++

  • export DISTCC_CMDLIST=/path/to/.distcc/DISTCC_CMDLIST

  • restart the distccd daemon distccd distccd --no-detach -a <host IPs> --daemon

What happens when the remote distcc server receives an extended command from the host lke /usr/bin/g++ main.cc -c , it will map the real compiler from / usr / bin / g ++ to / usr / local / ccache / g ++. The mapping is performed using:

  • extracts the base name from the compiler path in the receiving command ( g++ in this case)

  • Look at the DIST_CMDLIST file to see if any basename string has a g++ value. In this case, it will be /usr/local/ccache/g++

  • rewrite the command /usr/local/ccache/g++ main.cc -c . which will invoke ccache on the remote server.

The above is just an example, and you can expand the compiler display by changing the DISTCC_CMDLIST_NUMWORDS value from 1 to other values ​​to do more tricks.

+1
source

All Articles