// ccache -- a fast C/C++ compiler cache
//
// Copyright (C) 2002-2007 Andrew Tridgell
-// Copyright (C) 2009-2016 Joel Rosdahl
+// Copyright (C) 2009-2017 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
}
}
- // Let's hash the include file.
if (!(conf->sloppiness & SLOPPY_INCLUDE_FILE_MTIME)
&& st.st_mtime >= time_of_compilation) {
cc_log("Include file %s too new", path);
goto failure;
}
+ // Let's hash the include file content.
struct mdfour fhash;
hash_start(&fhash);
has_absolute_include_headers = is_absolute_path(inc_path);
}
inc_path = make_relative_path(inc_path);
+
+ bool should_hash_inc_path = true;
+ if (!conf->hash_dir) {
+ char *cwd = gnu_getcwd();
+ if (str_startswith(inc_path, cwd) && str_endswith(inc_path, "//")) {
+ // When compiling with -g or similar, GCC adds the absolute path to
+ // CWD like this:
+ //
+ // # 1 "CWD//"
+ //
+ // If the user has opted out of including the CWD in the hash, don't
+ // hash it. See also how debug_prefix_map is handled.
+ should_hash_inc_path = false;
+ }
+ free(cwd);
+ }
+ if (should_hash_inc_path) {
+ hash_string(hash, inc_path);
+ }
+
remember_include_file(inc_path, hash, system);
- p = q;
+ p = q; // Everything of interest between p and q has been hashed now.
} else if (q[0] == '.' && q[1] == 'i' && q[2] == 'n' && q[3] == 'c'
&& q[4] == 'b' && q[5] == 'i' && q[6] == 'n') {
// An assembler .incbin statement (which could be part of inline
}
}
- // Possibly hash input file location to avoid false positive cache hits since
- // the dependency file includes the source file path.
- if (generating_dependencies) {
- hash_delimiter(hash, "inputfile");
- hash_string(hash, input_file);
- }
-
// Possibly hash the coverage data file path.
if (generating_coverage && profile_arcs) {
char *dir = dirname(output_obj);
# A simple test suite for ccache.
#
# Copyright (C) 2002-2007 Andrew Tridgell
-# Copyright (C) 2009-2016 Joel Rosdahl
+# Copyright (C) 2009-2017 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
expect_stat 'cache miss' 0
expect_stat 'unsupported compiler option' 1
- # -------------------------------------------------------------------------
- TEST "-MMD for different source files"
-
- mkdir a b
- touch a/source.c b/source.c
- $CCACHE_COMPILE -MMD -c a/source.c
- expect_file_content source.d "source.o: a/source.c"
-
- $CCACHE_COMPILE -MMD -c b/source.c
- expect_file_content source.d "source.o: b/source.c"
-
- $CCACHE_COMPILE -MMD -c a/source.c
- expect_file_content source.d "source.o: a/source.c"
-
# -------------------------------------------------------------------------
TEST "-Wp,-P"
# -------------------------------------------------------------------------
TEST "CCACHE_NODIRECT"
- $CCACHE_COMPILE -c test.c
+ CCACHE_NODIRECT=1 $CCACHE_COMPILE -c test.c
expect_stat 'cache hit (direct)' 0
expect_stat 'cache hit (preprocessed)' 0
expect_stat 'cache miss' 1
done
expect_stat 'files in cache' 12
+ # -------------------------------------------------------------------------
+ TEST "-MMD for different source files"
+
+ mkdir a b
+ touch a/source.c b/source.c
+ backdate a/source.h b/source.h
+ $CCACHE_COMPILE -MMD -c a/source.c
+ expect_file_content source.d "source.o: a/source.c"
+
+ $CCACHE_COMPILE -MMD -c b/source.c
+ expect_file_content source.d "source.o: b/source.c"
+
+ $CCACHE_COMPILE -MMD -c a/source.c
+ expect_file_content source.d "source.o: a/source.c"
+
+ # -------------------------------------------------------------------------
+ TEST "-MMD for different include file paths"
+
+ mkdir a b
+ touch a/source.h b/source.h
+ backdate a/source.h b/source.h
+ echo '#include <source.h>' >source.c
+ $CCACHE_COMPILE -MMD -Ia -c source.c
+ expect_file_content source.d "source.o: source.c a/source.h"
+
+ $CCACHE_COMPILE -MMD -Ib -c source.c
+ expect_file_content source.d "source.o: source.c b/source.h"
+
+ $CCACHE_COMPILE -MMD -Ia -c source.c
+ expect_file_content source.d "source.o: source.c a/source.h"
+
# -------------------------------------------------------------------------
TEST "-Wp,-MD"
$CCACHE_COMPILE -c `pwd`/file.c
expect_stat 'cache hit (direct)' 1
- expect_stat 'cache hit (preprocessed)' 1
- expect_stat 'cache miss' 1
+ expect_stat 'cache hit (preprocessed)' 0
+ expect_stat 'cache miss' 2
# -------------------------------------------------------------------------
TEST "__FILE__ in include file disables direct mode"
$CCACHE_COMPILE -c `pwd`/file2_h.c
expect_stat 'cache hit (direct)' 1
- expect_stat 'cache hit (preprocessed)' 1
- expect_stat 'cache miss' 1
+ expect_stat 'cache hit (preprocessed)' 0
+ expect_stat 'cache miss' 2
# -------------------------------------------------------------------------
TEST "__FILE__ in source file ignored if sloppy"
CPATH=subdir2 $CCACHE_COMPILE -c foo.c
expect_stat 'cache hit (direct)' 1
- expect_stat 'cache hit (preprocessed)' 1
- expect_stat 'cache miss' 1
+ expect_stat 'cache hit (preprocessed)' 0
+ expect_stat 'cache miss' 2 # subdir2 is part of the preprocessor output
CPATH=subdir2 $CCACHE_COMPILE -c foo.c
expect_stat 'cache hit (direct)' 2
- expect_stat 'cache hit (preprocessed)' 1
- expect_stat 'cache miss' 1
+ expect_stat 'cache hit (preprocessed)' 0
+ expect_stat 'cache miss' 2
# -------------------------------------------------------------------------
TEST "Comment in strings"
# CCACHE_BASEDIR="" is the default:
$CCACHE_COMPILE -I`pwd`/include -c src/test.c
expect_stat 'cache hit (direct)' 0
- expect_stat 'cache hit (preprocessed)' 1
- expect_stat 'cache miss' 1
+ expect_stat 'cache hit (preprocessed)' 0
+ expect_stat 'cache miss' 2
# -------------------------------------------------------------------------
TEST "Path normalization"