]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Hash environment variables that affect the preprocessor output
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 6 Jan 2012 15:02:42 +0000 (16:02 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 6 Jan 2012 15:02:42 +0000 (16:02 +0100)
ccache.c
test.sh

index 0af8c0909c505e6f8832412150e89d3f0b9d23c1..68f0acb1900bc374b6e4a2ce9d0dec9f393dec3b 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -949,6 +949,24 @@ calculate_object_hash(struct args *args, struct mdfour *hash, int direct_mode)
        }
 
        if (direct_mode) {
+               /* Hash environment variables that affect the preprocessor output. */
+               const char **p;
+               const char *envvars[] = {
+                       "CPATH",
+                       "C_INCLUDE_PATH",
+                       "CPLUS_INCLUDE_PATH",
+                       "OBJC_INCLUDE_PATH",
+                       "OBJCPLUS_INCLUDE_PATH", /* clang */
+                       NULL
+               };
+               for (p = envvars; *p != NULL ; ++p) {
+                       char *v = getenv(*p);
+                       if (v) {
+                               hash_delimiter(hash, *p);
+                               hash_string(hash, v);
+                       }
+               }
+
                if (!(sloppiness & SLOPPY_FILE_MACRO)) {
                        /*
                         * The source code file or an include file may contain
diff --git a/test.sh b/test.sh
index 85f1baa466facdc14827e8321236b501be2923d0..5f33a6711e12fe85bcbbdc2b677ea3b89767c7cf 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -3,7 +3,7 @@
 # A simple test suite for ccache.
 #
 # Copyright (C) 2002-2007 Andrew Tridgell
-# Copyright (C) 2009-2011 Joel Rosdahl
+# Copyright (C) 2009-2012 Joel Rosdahl
 #
 # This program is free software; you can redistribute it and/or modify it under
 # the terms of the GNU General Public License as published by the Free Software
@@ -1158,6 +1158,40 @@ EOF
     checkstat 'cache hit (direct)' 1
     checkstat 'cache hit (preprocessed)' 0
     checkstat 'cache miss' 1
+
+    ##################################################################
+    # Check that environment variables that affect the preprocessor are taken
+    # into account.
+    testname="environment variables"
+    $CCACHE -Cz >/dev/null
+    rm -rf subdir1 subdir2
+    mkdir subdir1 subdir2
+    cat <<EOF >subdir1/foo.h
+int foo;
+EOF
+    cat <<EOF >subdir2/foo.h
+int foo;
+EOF
+    cat <<EOF >foo.c
+#include <foo.h>
+EOF
+    backdate subdir1/foo.h subdir2/foo.h
+    CPATH=subdir1 $CCACHE $COMPILER -c foo.c
+    checkstat 'cache hit (direct)' 0
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 1
+    CPATH=subdir1 $CCACHE $COMPILER -c foo.c
+    checkstat 'cache hit (direct)' 1
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 1
+    CPATH=subdir2 $CCACHE $COMPILER -c foo.c
+    checkstat 'cache hit (direct)' 1
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 2 # subdir2 is part of the preprocessor output
+    CPATH=subdir2 $CCACHE $COMPILER -c foo.c
+    checkstat 'cache hit (direct)' 2
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 2
 }
 
 basedir_suite() {