From 6e1916c71f45c844af645743fadeed426e82eaed Mon Sep 17 00:00:00 2001 From: jonnyyu Date: Tue, 11 Dec 2018 03:49:22 +0800 Subject: [PATCH] Skip '-index-store-path' when building with Xcode (#333) In Xcode 9 or later, Xcode calls clang with this new '-index-store-path' option. The Xcode usually sets IndexStore directory under a unique build location. This might break the manifest, especially when cache is shared among multple machines. --- doc/MANUAL.adoc | 5 +++++ src/ccache.c | 11 +++++++++++ src/ccache.h | 3 +++ src/confitems.c | 5 +++++ unittest/test_conf.c | 8 ++++---- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 22c4381bf..43eaa8db0 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -555,6 +555,11 @@ still has to do _some_ preprocessing (like macros). <<_precompiled_headers,PRECOMPILED HEADERS>> for more information. *time_macros*:: Ignore `__DATE__` and `__TIME__` being present in the source code. +*clang_index_store*:: + Ignore the Clang compiler option *-index-store-path* and its argument when + computing the manifest hash. This is useful if you use Xcode, which uses an + index store path derived from the local project path. Note that the index + store won't be updated correctly on cache hits if you enable this option. -- + See the discussion under <<_troubleshooting,TROUBLESHOOTING>> for more diff --git a/src/ccache.c b/src/ccache.c index d09c16a34..b5d52f9a6 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -2797,6 +2797,17 @@ cc_process_args(struct args *args, struct args **preprocessor_args, continue; } + if (conf->sloppiness & SLOPPY_CLANG_INDEX_STORE) { + // Xcode 9 or later calls clang with this option. + // The given path has a UUID path which might break the manifest + // especially when cache is shared among multple machines. + if (str_eq(argv[i], "-index-store-path")) { + i++; + cc_log("Skip argument -index-store-path %s", argv[i]); + continue; + } + } + // Options taking an argument that we may want to rewrite to relative paths // to get better hit rate. A secondary effect is that paths in the standard // error output produced by the compiler will be normalized. diff --git a/src/ccache.h b/src/ccache.h index 9ed457144..e47ebab06 100644 --- a/src/ccache.h +++ b/src/ccache.h @@ -98,6 +98,9 @@ extern enum guessed_compiler guessed_compiler; // Allow us to ignore ctimes when comparing file stats, so we can fake mtimes // if we want to (it is much harder to fake ctimes, requires changing clock) #define SLOPPY_FILE_STAT_MATCHES_CTIME 128 +// Allow us to not include -index-store-path option in the manifest, +// so that ccache can use with Xcode build. +#define SLOPPY_CLANG_INDEX_STORE 256 #define str_eq(s1, s2) (strcmp((s1), (s2)) == 0) #define str_startswith(s, prefix) \ diff --git a/src/confitems.c b/src/confitems.c index 6e6e22af4..c7d37e1fe 100644 --- a/src/confitems.c +++ b/src/confitems.c @@ -136,6 +136,8 @@ confitem_parse_sloppiness(const char *str, void *result, char **errmsg) *value |= SLOPPY_PCH_DEFINES; } else if (str_eq(word, "time_macros")) { *value |= SLOPPY_TIME_MACROS; + } else if (str_eq(word, "clang_index_store")) { + *value |= SLOPPY_CLANG_INDEX_STORE; } else { *errmsg = format("unknown sloppiness: \"%s\"", word); free(p); @@ -176,6 +178,9 @@ confitem_format_sloppiness(void *value) if (*sloppiness & SLOPPY_NO_SYSTEM_HEADERS) { reformat(&s, "%sno_system_headers, ", s); } + if (*sloppiness & SLOPPY_CLANG_INDEX_STORE) { + reformat(&s, "%sclang_index_store, ", s); + } if (*sloppiness) { // Strip last ", ". s[strlen(s) - 2] = '\0'; diff --git a/unittest/test_conf.c b/unittest/test_conf.c index 849a2c0b4..9b58c3f8c 100644 --- a/unittest/test_conf.c +++ b/unittest/test_conf.c @@ -130,7 +130,7 @@ TEST(conf_read_valid_config) "read_only_direct = true\n" "recache = true\n" "run_second_cpp = false\n" - "sloppiness = file_macro ,time_macros, include_file_mtime,include_file_ctime,file_stat_matches,file_stat_matches_ctime,pch_defines , no_system_headers \n" + "sloppiness = file_macro ,time_macros, include_file_mtime,include_file_ctime,file_stat_matches,file_stat_matches_ctime,pch_defines , no_system_headers,clang_index_store\n" "stats = false\n" "temporary_dir = ${USER}_foo\n" "umask = 777\n" @@ -172,7 +172,7 @@ TEST(conf_read_valid_config) CHECK_INT_EQ(SLOPPY_INCLUDE_FILE_MTIME|SLOPPY_INCLUDE_FILE_CTIME| SLOPPY_FILE_MACRO|SLOPPY_TIME_MACROS| SLOPPY_FILE_STAT_MATCHES|SLOPPY_FILE_STAT_MATCHES_CTIME| - SLOPPY_NO_SYSTEM_HEADERS|SLOPPY_PCH_DEFINES, + SLOPPY_NO_SYSTEM_HEADERS|SLOPPY_PCH_DEFINES|SLOPPY_CLANG_INDEX_STORE, conf->sloppiness); CHECK(!conf->stats); CHECK_STR_EQ_FREE1(format("%s_foo", user), conf->temporary_dir); @@ -462,7 +462,7 @@ TEST(conf_print_items) SLOPPY_FILE_MACRO|SLOPPY_INCLUDE_FILE_MTIME| SLOPPY_INCLUDE_FILE_CTIME|SLOPPY_TIME_MACROS| SLOPPY_FILE_STAT_MATCHES|SLOPPY_FILE_STAT_MATCHES_CTIME| - SLOPPY_PCH_DEFINES|SLOPPY_NO_SYSTEM_HEADERS, + SLOPPY_PCH_DEFINES|SLOPPY_NO_SYSTEM_HEADERS|SLOPPY_CLANG_INDEX_STORE, false, "td", 022, @@ -513,7 +513,7 @@ TEST(conf_print_items) CHECK_STR_EQ("run_second_cpp = false", received_conf_items[n++].descr); CHECK_STR_EQ("sloppiness = file_macro, include_file_mtime," " include_file_ctime, time_macros, pch_defines," - " file_stat_matches, file_stat_matches_ctime, no_system_headers", + " file_stat_matches, file_stat_matches_ctime, no_system_headers, clang_index_store", received_conf_items[n++].descr); CHECK_STR_EQ("stats = false", received_conf_items[n++].descr); CHECK_STR_EQ("temporary_dir = td", received_conf_items[n++].descr); -- 2.47.3