[ccache] Automatic fallback from preprocessed to direct mode in case of cache miss

Rémi Delmas remi.delmas at gmail.com
Thu Jun 23 09:15:21 MDT 2011


Sorry for the length of this post, I try to explain my usecase in details.
The actual question is at the end. :-)

Here is my usecase:

I have 2 projects, projectA and projectB. ProjectA contains the source files
that I want to compile, and ProjectB contains headers, included from files
in ProjectA.

Since those are two different projects, when a user starts working on them
he can place the folders whereever he wants on his user account, so we can
make no assumption on a relative path between ProjectA and ProjectB.

Let us imagine the following file structure:

    |-- ProjectA
    |   |-- file.c
    |   `-- header.c
    `-- ProjectB
        `-- header2.h

 |-- ProjectA
 |   |-- file.c
 |   `-- header.c
 `-- development
     `-- ProjectB
         `-- header2.h

The goal is obviously that each user can benefit from the other user's
compilation results thanks to ccache.

The problem is that command-line parameters to compile file.c are different
for user A and user B (we need to have "-I" for both projectA and projectB),
and CCACHE_BASE_DIR will not help here, as one can specify only one base dir
thanks to this variable, where I would need two or more. This will make
direct mode to fail.

Now, please correct me if I am wrong, but in this very specific case,
preprocessor mode would work without any problem, since the preprocessed
file.c would be the same for user A and user B, leading to a cache hit. The
problem is that this usecase will not be so common, and I would like to turn
direct mode on by default, since it is much faster (in this simplified
problem, we can assume that most users will have ProjectA and ProjectB in
the same directory, so they would both benefit from CCACHE_BASE_DIR... we
also cover simpler projects that do not have dependencies on sub-projects).

Soooo... the net result of all of this, is that I want to use direct mode
where possible, else fallback to preprocessed mode. I could do that myself,
with some heuristics, by setting CCACHE_BASE_DIR to the root of ProjectA,
and checking the command-line arguments to gcc to see if there is any
occurence of a path contained in $USER but not in $CCACHE_BASE_DIR, in which
case we need preprocessor mode, else direct mode is fine (or should be most
of the time, at least).

Another solution would be for ccache to automatically fallback to
preprocessed mode in case direct mode fails. Would that be possible? This
would increase the cost of "true" misses a bit (since more checks would be
needed), but in my case this would still be a big gain.

Is that possible in ccache? Is it planned?

Thanks a lot,

More information about the ccache mailing list