]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Let hash_dir default to true
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 27 Jul 2016 20:09:14 +0000 (22:09 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 27 Jul 2016 20:14:53 +0000 (22:14 +0200)
This results in a better out-of-the-box experience.

Closes #117.

MANUAL.txt
NEWS.txt
conf.c
test.sh
test/test_conf.c

index 0fe67e502b73cae5d18ff712b1861f249ef30aea..5020e65e33a2f87a458293aff6a1815af0b288d9 100644 (file)
@@ -369,14 +369,20 @@ WRAPPERS>>.
 
 *hash_dir* (*CCACHE_HASHDIR* or *CCACHE_NOHASHDIR*, see <<_boolean_values,Boolean values>> above)::
 
-    If true, ccache will include the current working directory in the hash that
-    is used to distinguish two compilations. This prevents a problem with the
-    storage of the current working directory in the debug info of an object
-    file, which can lead ccache to give a cached object file that has the
-    working directory in the debug info set incorrectly. This option is off by
-    default as the incorrect setting of this debug info rarely causes problems.
-    If you strike problems with GDB not using the correct directory then enable
-    this option. The option only applies when generating debug info (*-g*).
+    If true (which is the default), ccache will include the current working
+    directory (CWD) in the hash that is used to distinguish two compilations
+    when generating debug info (compiler option *-g* with variations).
+    Exception: The CWD will not be included in the hash if *base_dir* is set
+    (and matches the CWD) and the compiler option *-fdebug-prefix-map* is used.
+
+    The reason for including the CWD in the hash by default is to prevent a
+    problem with the storage of the current working directory in the debug info
+    of an object file, which can lead ccache to return a cached object file
+    that has the working directory in the debug info set incorrectly.
+
+    You can disable this setting to get cache hits when compiling the same
+    source code in different directories if you don't mind that CWD in the
+    debug info might be incorrect.
 
 *ignore_headers_in_manifest* (*CCACHE_IGNOREHEADERS*)::
 
index 4b16b7accbbe4f0d87456db15cb6ca2e0135366c..83cf69ad8c6c639a60f40b7909ee213795db7a04 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -19,6 +19,8 @@ New features and improvements
   can't compile their own preprocessed output with the same outcome as if they
   compiled the real source code directly, e.g. newer versions of GCC and Clang.
 
+- The configuration option `hash_dir` (`CCACHE_HASHDIR`) now defaults to true.
+
 - Added support for cuda including the -optf/--options-file option.
 
 - Added new sloppiness option `no_system_headers`, which tells ccache not to
diff --git a/conf.c b/conf.c
index f72bca12d1b0849f7fd2b040c43eb5fec8fc23b8..aafb0e3e294c1b2b201abcdb08e2d0aab6c30841 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -306,7 +306,7 @@ conf_create(void)
        conf->disable = false;
        conf->extra_files_to_hash = x_strdup("");
        conf->hard_link = false;
-       conf->hash_dir = false;
+       conf->hash_dir = true;
        conf->ignore_headers_in_manifest = x_strdup("");
        conf->keep_comments_cpp = false;
        conf->log_file = x_strdup("");
diff --git a/test.sh b/test.sh
index d1f071a04dc084294fef27108057a2c5a14a78cd..f2e359821edabfde45cff8f972e17cbbec107712 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -185,11 +185,11 @@ TEST() {
     unset CCACHE_EXTENSION
     unset CCACHE_EXTRAFILES
     unset CCACHE_HARDLINK
-    unset CCACHE_HASHDIR
     unset CCACHE_IGNOREHEADERS
     unset CCACHE_LOGFILE
     unset CCACHE_NLEVELS
     unset CCACHE_NOCPP2
+    unset CCACHE_NOHASHDIR
     unset CCACHE_NOSTATS
     unset CCACHE_PATH
     unset CCACHE_PREFIX
@@ -416,45 +416,65 @@ base_tests() {
     expect_stat 'files in cache' 1
 
     # -------------------------------------------------------------------------
-    TEST "CCACHE_HASHDIR with -g"
+    TEST "Directory is hashed if using -g"
 
     mkdir dir1 dir2
     cp test1.c dir1
     cp test1.c dir2
 
     cd dir1
-    CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -g
+    $CCACHE_COMPILE -c test1.c -g
     expect_stat 'cache hit (preprocessed)' 0
     expect_stat 'cache miss' 1
-    CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -g
+    $CCACHE_COMPILE -c test1.c -g
     expect_stat 'cache hit (preprocessed)' 1
     expect_stat 'cache miss' 1
 
     cd ../dir2
-    CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -g
+    $CCACHE_COMPILE -c test1.c -g
     expect_stat 'cache hit (preprocessed)' 1
     expect_stat 'cache miss' 2
-    CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -g
+    $CCACHE_COMPILE -c test1.c -g
     expect_stat 'cache hit (preprocessed)' 2
     expect_stat 'cache miss' 2
 
     # -------------------------------------------------------------------------
-    TEST "CCACHE_HASHDIR without -g"
+    TEST "Directory is not hashed if not using -g"
+
+    mkdir dir1 dir2
+    cp test1.c dir1
+    cp test1.c dir2
+
+    cd dir1
+    $CCACHE_COMPILE -c test1.c
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    $CCACHE_COMPILE -c test1.c
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+
+    cd ../dir2
+    $CCACHE_COMPILE -c test1.c
+    expect_stat 'cache hit (preprocessed)' 2
+    expect_stat 'cache miss' 1
+
+    # -------------------------------------------------------------------------
+    TEST "CCACHE_NOHASHDIR"
 
     mkdir dir1 dir2
     cp test1.c dir1
     cp test1.c dir2
 
     cd dir1
-    CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c
+    CCACHE_NOHASHDIR=1 $CCACHE_COMPILE -c test1.c -g
     expect_stat 'cache hit (preprocessed)' 0
     expect_stat 'cache miss' 1
-    CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c
+    CCACHE_NOHASHDIR=1 $CCACHE_COMPILE -c test1.c -g
     expect_stat 'cache hit (preprocessed)' 1
     expect_stat 'cache miss' 1
 
     cd ../dir2
-    CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c
+    CCACHE_NOHASHDIR=1 $CCACHE_COMPILE -c test1.c -g
     expect_stat 'cache hit (preprocessed)' 2
     expect_stat 'cache miss' 1
 
@@ -1233,7 +1253,7 @@ SUITE_debug_prefix_map() {
     TEST "Mapping of debug info CWD"
 
     cd dir1
-    CCACHE_HASHDIR=1 CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -g -fdebug-prefix-map=`pwd`=dir -c `pwd`/src/test.c -o `pwd`/test.o
+    CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -g -fdebug-prefix-map=`pwd`=dir -c `pwd`/src/test.c -o `pwd`/test.o
     expect_stat 'cache hit (direct)' 0
     expect_stat 'cache hit (preprocessed)' 0
     expect_stat 'cache miss' 1
@@ -1243,7 +1263,7 @@ SUITE_debug_prefix_map() {
     fi
 
     cd ../dir2
-    CCACHE_HASHDIR=1 CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -g -fdebug-prefix-map=`pwd`=dir -c `pwd`/src/test.c -o `pwd`/test.o
+    CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -g -fdebug-prefix-map=`pwd`=dir -c `pwd`/src/test.c -o `pwd`/test.o
     expect_stat 'cache hit (direct)' 1
     expect_stat 'cache hit (preprocessed)' 0
     expect_stat 'cache miss' 1
index ea809ac0a3f4f6e01072a854a84097f856d94070..560898d654dbd51e8ad43042e21a57fdcb4af5ba 100644 (file)
@@ -61,7 +61,7 @@ TEST(conf_create)
        CHECK(!conf->disable);
        CHECK_STR_EQ("", conf->extra_files_to_hash);
        CHECK(!conf->hard_link);
-       CHECK(!conf->hash_dir);
+       CHECK(conf->hash_dir);
        CHECK_STR_EQ("", conf->ignore_headers_in_manifest);
        CHECK(!conf->keep_comments_cpp);
        CHECK_STR_EQ("", conf->log_file);
@@ -111,7 +111,7 @@ TEST(conf_read_valid_config)
          "disable = true\n"
          "extra_files_to_hash = a:b c:$USER\n"
          "hard_link = true\n"
-         "hash_dir = true\n"
+         "hash_dir = false\n"
          "ignore_headers_in_manifest = a:b/c\n"
          "keep_comments_cpp = true\n"
          "log_file = $USER${USER} \n"
@@ -148,7 +148,7 @@ TEST(conf_read_valid_config)
        CHECK(conf->disable);
        CHECK_STR_EQ_FREE1(format("a:b c:%s", user), conf->extra_files_to_hash);
        CHECK(conf->hard_link);
-       CHECK(conf->hash_dir);
+       CHECK(!conf->hash_dir);
        CHECK_STR_EQ("a:b/c", conf->ignore_headers_in_manifest);
        CHECK(conf->keep_comments_cpp);
        CHECK_STR_EQ_FREE1(format("%s%s", user, user), conf->log_file);
@@ -373,7 +373,7 @@ TEST(conf_print_items)
                true,
                "efth",
                true,
-               true,
+               .hash_dir = false,
                "ihim",
                true,
                "lf",
@@ -421,7 +421,7 @@ TEST(conf_print_items)
        CHECK_STR_EQ("disable = true", received_conf_items[n++].descr);
        CHECK_STR_EQ("extra_files_to_hash = efth", received_conf_items[n++].descr);
        CHECK_STR_EQ("hard_link = true", received_conf_items[n++].descr);
-       CHECK_STR_EQ("hash_dir = true", received_conf_items[n++].descr);
+       CHECK_STR_EQ("hash_dir = false", received_conf_items[n++].descr);
        CHECK_STR_EQ("ignore_headers_in_manifest = ihim",
                     received_conf_items[n++].descr);
        CHECK_STR_EQ("keep_comments_cpp = true", received_conf_items[n++].descr);