]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Don't set CCACHE_BASEDIR by default
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 24 Apr 2010 19:39:23 +0000 (21:39 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 24 Apr 2010 19:39:31 +0000 (21:39 +0200)
Disabled by default because it gives a different result than the real compiler
would give when -g is being used.

NEWS.txt
ccache.c
ccache.txt
test.sh

index c7c314a0da809052bec873be79fcc24a1ee5fd55..82f1bc2b75f347a5e69c128a57fb96079bac8121 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -46,14 +46,12 @@ New features and improvements
       speedup will be higher when I/O is fast (e.g., when files are in the disk
       cache). The direct mode can be disabled by setting +CCACHE_NODIRECT+.
 
-    - When hashing the output from the preprocessor, absolute paths are
-      rewritten to relative paths, but only for paths under the directory
-      specified by `CCACHE_BASEDIR`. Paths specified by `-I` and similar
-      options get the same treatment. This is done to get cache hits even when
-      compiling with `-g` and when using absolute include directory paths.
-      Absolute paths in the standard error text will also be more accurate. The
-      default value of `CCACHE_BASEDIR` is the current working directory. To
-      disable the rewriting, set `CCACHE_BASEDIR` to the empty string.
+    - Support has been added for rewriting absolute paths to relative paths
+      when hashing, in order to increase cache hit rate when building the same
+      source code in different directories even when compiling with `-g` and
+      when using absolute include directory paths. This is done by setting the
+      `CCACHE_BASEDIR` environment variable to an absolute path that specifies
+      which paths to rewrite.
 
     - Object files are now by default stored compressed in the cache. The
       runtime cost is negligible, and more files will fit in the ccache
index 9a7c457faeba05a61680380c139d8eec496e1c3b..d96571c1d1a7593feb2de38ea7979f881cebae7d 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -1848,12 +1848,9 @@ int main(int argc, char *argv[])
        cache_logfile = getenv("CCACHE_LOGFILE");
 
        base_dir = getenv("CCACHE_BASEDIR");
-       if (base_dir) {
-               if (strcmp(base_dir, "") == 0) {
-                       base_dir = NULL;
-               }
-       } else {
-               base_dir = get_cwd();
+       if (base_dir && base_dir[0] != '/') {
+               cc_log("Ignoring non-absolute base directory %s", base_dir);
+               base_dir = NULL;
        }
 
        compile_preprocessed_source_code = !getenv("CCACHE_CPP2");
index 07ab956e1f64b4c559b3bb02d75a32c948802f19..29a6320fbea60f083d8ed3e09db4fbb03866926b 100644 (file)
@@ -156,13 +156,11 @@ cases you won't need any of these as the defaults will be fine.
 
 *CCACHE_BASEDIR*::
 
-    When hashing the output from the preprocessor, absolute paths are rewritten
-    to relative paths, but only for paths under the directory specified by
-    *CCACHE_BASEDIR*. Paths specified by *-I* and similar options get the same
-    treatment. This is done to get cache hits even when compiling with *-g* and
-    when using absolute include directory paths. The default value of
-    *CCACHE_BASEDIR* is the current working directory. To disable the
-    rewriting, set *CCACHE_BASEDIR* to the empty string.
+    If you set the environment variable *CCACHE_BASEDIR* to an absolute path,
+    ccache rewrites absolute paths into relative paths before computing the
+    hash that identifies the compilation, but only for paths under the
+    specified directory. See the discussion under
+    <<_compiling_in_different_directories,COMPILING IN DIFFERENT DIRECTORIES>>.
 
 *CCACHE_CC*::
 
@@ -401,21 +399,40 @@ In the preprocessor mode, the hash is formed of:
   preprocessor output if they have any effect at all)
 * the real compiler's size and modification time (unless
   *CCACHE_COMPILERCHECK* says something else)
-* Any stderr output generated by the preprocessor
-
-
-USING CCACHE WITH DISTCC
-------------------------
-
-``distcc'' is a very useful program for distributing compilation across a range
-of compiler servers. It is often useful to combine distcc with ccache so that
-compilations that are done are sped up by distcc, but ccache avoids the
-compilation completely where possible.
-
-The recommended way of combining distcc and ccache is by using the
-*CCACHE_PREFIX* option. You just need to set the environment variable
-*CCACHE_PREFIX* to *distcc* and ccache will prefix the command line used with
-the compiler with the command ``distcc''.
+* any standard error output generated by the preprocessor
+
+
+COMPILING IN DIFFERENT DIRECTORIES
+----------------------------------
+
+Some information included in the hash that identifies a unique compilation may
+contain absolute paths:
+
+* The preprocessed source code may contain absolute paths to include files if
+  the compiler option *-g* is used or if absolute paths are given to *-I* and
+  similar compiler options.
+* Paths specified by compiler options (such as *-I*, *-MF*, etc) may be
+  absolute.
+* The source code file path may be absolute, and that path may be included in
+  warnings emitted to standard error by the preprocessor.
+
+This means that if you compile the same code in different locations, you can't
+share compilation results between the different build directories since you get
+cache misses because of the absolute build directory paths that are part of the
+hash. To mitigate this problem, you can specify a ``base directory'' by setting
+the *CCACHE_BASEDIR* variable to an absolute path. ccache will then rewrite
+absolute paths that are under the base directory (i.e., paths that have the
+base directory as a prefix) to relative paths when constructing the hash. The
+typical path to use as base directory is your home directory or another
+directory that is a parent of your build directories. (Don't use +/+ as the
+base directory since that will make ccache also rewrite paths to system header
+files, which doesn't gain anything.)
+
+The only drawback of using *CCACHE_BASEDIR* is that if you compile with *-g*
+and use absolute paths to the source code files, the source code paths that are
+stored in the object files may point to the wrong directory, which may prevent
+debuggers like GDB from finding the source code. Sometimes, a work-around is to
+change the directory explicitly with the ``cd'' command in GDB.
 
 
 SHARING A CACHE
@@ -443,6 +460,23 @@ timestamp-based build systems whenever another user links to an existing file.
 Typically, users will see that their libraries and binaries are relinked
 without reason.
 
+You may also want to make sure that the developers have *CCACHE_BASEDIR* set
+appropriately, as discussed in the previous section.
+
+
+USING CCACHE WITH DISTCC
+------------------------
+
+``distcc'' is a very useful program for distributing compilation across a range
+of compiler servers. It is often useful to combine distcc with ccache so that
+compilations that are done are sped up by distcc, but ccache avoids the
+compilation completely where possible.
+
+The recommended way of combining distcc and ccache is by using the
+*CCACHE_PREFIX* option. You just need to set the environment variable
+*CCACHE_PREFIX* to *distcc* and ccache will prefix the command line used with
+the compiler with the command ``distcc''.
+
 
 MORE INFORMATION
 ----------------
diff --git a/test.sh b/test.sh
index 751e9f5d6231888d1766758f5cca8a2934cf2cc5..a406cc035c07b6811aec953ea1dc92eccb6cbcc8 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -842,14 +842,14 @@ EOF
     export CCACHE_NODIRECT
 
     ##################################################################
-    # CCACHE_BASEDIR="$PWD" is the default.
+    # CCACHE_BASEDIR="" is the default.
     testname="default CCACHE_BASEDIR"
     cd dir1
     $CCACHE -z >/dev/null
     $CCACHE $COMPILER -I$PWD/include -c src/test.c
     checkstat 'cache hit (direct)' 0
-    checkstat 'cache hit (preprocessed)' 1
-    checkstat 'cache miss' 0
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 1
     cd ..
 
     ##################################################################
@@ -859,7 +859,7 @@ EOF
     cd dir1
     $CCACHE -z >/dev/null
     unset CCACHE_NODIRECT
-    $CCACHE $COMPILER -I$PWD//include -c $PWD//.///src/test.c
+    CCACHE_BASEDIR=$PWD $CCACHE $COMPILER -I$PWD//include -c $PWD//.///src/test.c
     export CCACHE_NODIRECT=1
     checkstat 'cache hit (direct)' 1
     checkstat 'cache hit (preprocessed)' 0
@@ -870,7 +870,7 @@ EOF
     # Check that rewriting triggered by CCACHE_BASEDIR also affects stderr.
     testname="stderr"
     $CCACHE -z >/dev/null
-    $CCACHE $COMPILER -Wall -W -I$PWD -c $PWD/stderr.c -o $PWD/stderr.o 2>stderr.txt
+    CCACHE_BASEDIR=$PWD $CCACHE $COMPILER -Wall -W -I$PWD -c $PWD/stderr.c -o $PWD/stderr.o 2>stderr.txt
     checkstat 'cache hit (direct)' 0
     checkstat 'cache hit (preprocessed)' 0
     checkstat 'cache miss' 1
@@ -878,7 +878,7 @@ EOF
         test_failed "Base dir ($PWD) found in stderr:\n`cat stderr.txt`"
     fi
 
-    $CCACHE $COMPILER -Wall -W -I$PWD -c $PWD/stderr.c -o $PWD/stderr.o 2>stderr.txt
+    CCACHE_BASEDIR=$PWD $CCACHE $COMPILER -Wall -W -I$PWD -c $PWD/stderr.c -o $PWD/stderr.o 2>stderr.txt
     checkstat 'cache hit (direct)' 0
     checkstat 'cache hit (preprocessed)' 1
     checkstat 'cache miss' 1