]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Hash preprocessed headers located in “.gch directories” correctly
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 21 Feb 2018 19:58:45 +0000 (20:58 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 21 Feb 2018 19:59:38 +0000 (20:59 +0100)
Previously, ccache would not pick up changes to such precompiled
headers, risking false positive cache hits.

doc/NEWS.txt
src/ccache.c
test/suites/pch.bash

index f8c7d98fcce643f6a2e472825826db1cbb73fdb6..e306fb34061448919363cb1b86295ebb6a1af32d 100644 (file)
@@ -1,6 +1,18 @@
 ccache news
 ===========
 
+ccache 3.4.2
+------------
+Release date: unknown
+
+Bug fixes
+~~~~~~~~~
+
+- Correctly hash preprocessed headers located in a ``.gch directory''.
+  Previously, ccache would not pick up changes to such precompiled headers,
+  risking false positive cache hits.
+
+
 ccache 3.4.1
 ------------
 Release date: 2018-02-11
index 9dfdbfc1b84bbf183c4713a38da0ee0f1fb5804f..9503174148422230ce685f1b23548f259243c98d 100644 (file)
@@ -2077,7 +2077,15 @@ bool
 is_precompiled_header(const char *path)
 {
        const char *ext = get_extension(path);
-       return str_eq(ext, ".gch") || str_eq(ext, ".pch") || str_eq(ext, ".pth");
+       char *dir = dirname(path);
+       const char *dir_ext = get_extension(dir);
+       bool result =
+               str_eq(ext, ".gch")
+               || str_eq(ext, ".pch")
+               || str_eq(ext, ".pth")
+               || str_eq(dir_ext, ".gch"); // See "Precompiled Headers" in GCC docs.
+       free(dir);
+       return result;
 }
 
 static bool
index 34c225bd5356e8d589c66d0437a1a9935dd6e25d..c098e7f41ce6a3405d6eb57785d6c47564f98d30 100644 (file)
@@ -246,6 +246,50 @@ pch_suite_gcc() {
     expect_stat 'cache hit (direct)' 0
     expect_stat 'cache hit (preprocessed)' 1
     expect_stat 'cache miss' 2
+
+    # -------------------------------------------------------------------------
+    TEST "Create and use .gch directory"
+
+    mkdir pch.h.gch
+
+    CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -x c-header -c pch.h -o pch.h.gch/foo
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    rm pch.h.gch/foo
+
+    CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -x c-header -c pch.h -o pch.h.gch/foo
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    if [ ! -f pch.h.gch/foo ]; then
+        test_failed "pch.h.gch/foo missing"
+    fi
+
+    backdate pch.h.gch/foo
+
+    CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -c -include pch.h pch2.c
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 2
+
+    CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -c -include pch.h pch2.c
+    expect_stat 'cache hit (direct)' 2
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 2
+
+    echo "updated" >>pch.h.gch/foo # GCC seems to cope with this...
+    backdate pch.h.gch/foo
+
+    CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -c -include pch.h pch2.c
+    expect_stat 'cache hit (direct)' 2
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 3
+
+    CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -c -include pch.h pch2.c
+    expect_stat 'cache hit (direct)' 3
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 3
 }
 
 pch_suite_clang() {