]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Skip '-index-store-path' when building with Xcode (#333)
authorjonnyyu <yingshen.yu@gmail.com>
Mon, 10 Dec 2018 19:49:22 +0000 (03:49 +0800)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 10 Dec 2018 19:49:22 +0000 (20:49 +0100)
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
src/ccache.c
src/ccache.h
src/confitems.c
unittest/test_conf.c

index 22c4381bf958b003eb522175e1c8ae5b75b08247..43eaa8db09159ecd7383df8f51491b4cce62ab6b 100644 (file)
@@ -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
index d09c16a34d22ed5eddba0defef3dfb9ef0856de2..b5d52f9a65b4e8d39ebbda759e25259a3841c3d7 100644 (file)
@@ -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.
index 9ed4571447d8e44b974a9e4db147e89b33f123e1..e47ebab06e550eb927c4e067ea72a9252ca801fc 100644 (file)
@@ -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) \
index 6e6e22af4b845541647686f3e81c6b143f3450e3..c7d37e1fef71c79a411575b8076e782964eb2e12 100644 (file)
@@ -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';
index 849a2c0b4c62cdf14bbc05853fab9b4639b2135e..9b58c3f8cf7effe95fe8c53ed1ebc2e23e3f826d 100644 (file)
@@ -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);