From: Joel Rosdahl Date: Wed, 27 Jul 2016 20:09:14 +0000 (+0200) Subject: Let hash_dir default to true X-Git-Tag: v3.3~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d9cb3dfdd91cd046a029a2fb01b6155934f0bee;p=thirdparty%2Fccache.git Let hash_dir default to true This results in a better out-of-the-box experience. Closes #117. --- diff --git a/MANUAL.txt b/MANUAL.txt index 0fe67e502..5020e65e3 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -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*):: diff --git a/NEWS.txt b/NEWS.txt index 4b16b7acc..83cf69ad8 100644 --- 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 f72bca12d..aafb0e3e2 100644 --- 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 d1f071a04..f2e359821 100755 --- 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 diff --git a/test/test_conf.c b/test/test_conf.c index ea809ac0a..560898d65 100644 --- a/test/test_conf.c +++ b/test/test_conf.c @@ -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);