* ccache -- a fast C/C++ compiler cache
*
* Copyright (C) 2002-2007 Andrew Tridgell
- * Copyright (C) 2009-2015 Joel Rosdahl
+ * Copyright (C) 2009-2016 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
goto out;
}
- /* Rewrite to relative to increase hit rate. */
- input_file = make_relative_path(x_strdup(argv[i]));
+ lstat(argv[i], &st);
+ if (S_ISLNK(st.st_mode)) {
+ /* Don't rewrite source file path if it's a symlink since
+ make_relative_path resolves symlinks using realpath(3) and this leads
+ to potentially choosing incorrect relative header files. See the
+ "symlink to source file" test. */
+ input_file = x_strdup(argv[i]);
+ } else {
+ /* Rewrite to relative to increase hit rate. */
+ input_file = make_relative_path(x_strdup(argv[i]));
+ }
}
if (!input_file) {
# A simple test suite for ccache.
#
# Copyright (C) 2002-2007 Andrew Tridgell
-# Copyright (C) 2009-2015 Joel Rosdahl
+# Copyright (C) 2009-2016 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
checkstat 'cache miss' 2
}
+symlinks_suite() {
+ ##################################################################
+ testname="symlink to source directory"
+
+ mkdir dir
+ cd dir
+ mkdir -p d1/d2
+ echo '#define A "OK"' >d1/h.h
+ cat <<EOF >d1/d2/c.c
+#include <stdio.h>
+#include "../h.h"
+int main() { printf("%s\n", A); }
+EOF
+ echo '#define A "BUG"' >h.h
+ ln -s d1/d2 d3
+
+ CCACHE_BASEDIR=/ $CCACHE $COMPILER -c $PWD/d3/c.c
+ $COMPILER -c $PWD/d3/c.c
+ $COMPILER c.o -o c
+ result=$(./c)
+ if [ "$result" != OK ]; then
+ test_failed "Incorrect header file used"
+ fi
+
+ cd ..
+ rm -rf dir
+
+ ##################################################################
+ testname="symlink to source file"
+
+ mkdir dir
+ cd dir
+ mkdir d
+ echo '#define A "BUG"' >d/h.h
+ cat <<EOF >d/c.c
+#include <stdio.h>
+#include "h.h"
+int main() { printf("%s\n", A); }
+EOF
+ echo '#define A "OK"' >h.h
+ ln -s d/c.c c.c
+
+ CCACHE_BASEDIR=/ $CCACHE $COMPILER -c $PWD/c.c
+ $COMPILER c.o -o c
+ result=$(./c)
+ if [ "$result" != OK ]; then
+ test_failed "Incorrect header file used"
+ fi
+
+ cd ..
+ rm -rf dir
+}
+
######################################################################
# main program
extrafiles
cleanup
pch
+symlinks
"
host_os="`uname -s`"