From: Joel Rosdahl Date: Fri, 6 Jan 2012 15:02:42 +0000 (+0100) Subject: Hash environment variables that affect the preprocessor output X-Git-Tag: v3.1.7~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8328b3b93525cb4091054bd2162cc3ddc970ef3d;p=thirdparty%2Fccache.git Hash environment variables that affect the preprocessor output --- diff --git a/ccache.c b/ccache.c index 0af8c0909..68f0acb19 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 85f1baa46..5f33a6711 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 <subdir1/foo.h +int foo; +EOF + cat <subdir2/foo.h +int foo; +EOF + cat <foo.c +#include +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() {