[ccache] Solve Android building problem when using ccache direct mode

Qu Dongsheng qu.dongsheng at gmail.com
Sat Apr 5 09:24:15 MDT 2014


Hello

When I was building Android source code on our building server, which many people share this machine and use ccache. I got an error that it tried to stat other people's system headers! After some debugging, I found that wrong dependency file was generated from the ccache. 

it was caused by 
- ccache is using direct mode
- Every android source tree has prebuilt toolchain
- Android compiles the C/C++ code with dependency file generated
- We replaced Android prebuilt ccache with the ccache 3.1.7

In such case, ccache just returns a wrong dependcency file, in which it contains the system headers with absolute path to other person's directory! I think that direct mode is not safe when dependency file will be generated. This issue happens even on the latest ccache. I made a patch to solve it, as follows. Of course, setting CCACHE_NODIRECT or CCACHE_UNIFY can solve the above building problem, but doing such will totally disable direct mode, we will not benefit from it.

Is there better solution?



commit 63da529963afa9e69b217d4dd0624f9828e294df
Author: Qu Dongsheng <qu.dongsheng at gmail.com>
Date:   Sat Apr 5 22:45:14 2014 +0800

    Enabling direct mode is not safe when dependency file is generated.
    As the dependency file contains the absolute paths to the system headers, wrong dependency file can be returned if toochain's location is changed.
    This typically happens when multiple Android source trees are built on the same machine. (Every android source tree contains a copy of toolchain)

diff --git a/ccache.c b/ccache.c
index 02dbdfa..8efe921 100644
--- a/ccache.c
+++ b/ccache.c
@@ -1995,6 +1995,7 @@ ccache(int argc, char *argv[])
        cc_log("Source file: %s", input_file);
        if (generating_dependencies) {
                cc_log("Dependency file: %s", output_dep);
+               enable_direct = false;
        }
        cc_log("Object file: %s", output_obj);
 




Dongsheng


More information about the ccache mailing list