summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2012-01-06 16:02:42 +0100
committerJoel Rosdahl <joel@rosdahl.net>2012-01-06 16:02:42 +0100
commit8328b3b93525cb4091054bd2162cc3ddc970ef3d (patch)
tree1b41b53fe4a77d26a753575bb7cb669d53e3900b
parent6802a3f6ca005138969a8badfa91abae2184de9f (diff)
downloadccache-8328b3b93525cb4091054bd2162cc3ddc970ef3d.tar.gz
Hash environment variables that affect the preprocessor output
-rw-r--r--ccache.c18
-rwxr-xr-xtest.sh36
2 files changed, 53 insertions, 1 deletions
diff --git a/ccache.c b/ccache.c
index 0af8c090..68f0acb1 100644
--- 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 85f1baa4..5f33a671 100755
--- 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() {