1 SUITE_basedir_SETUP() {
4 mkdir -p dir1/src dir1/include
5 cat <<EOF >dir1/src/test.c
9 cat <<EOF >dir1/include/test.h
13 backdate dir1/include/test.h dir2/include/test.h
17 # -------------------------------------------------------------------------
18 TEST "Enabled CCACHE_BASEDIR"
21 CCACHE_BASEDIR="`pwd`" $CCACHE_COMPILE -I`pwd`/include -c src/test.c
22 expect_stat 'cache hit (direct)' 0
23 expect_stat 'cache hit (preprocessed)' 0
24 expect_stat 'cache miss' 1
27 CCACHE_BASEDIR="`pwd`" $CCACHE_COMPILE -I`pwd`/include -c src/test.c
28 expect_stat 'cache hit (direct)' 1
29 expect_stat 'cache hit (preprocessed)' 0
30 expect_stat 'cache miss' 1
32 # -------------------------------------------------------------------------
33 TEST "Disabled (default) CCACHE_BASEDIR"
36 CCACHE_BASEDIR="`pwd`" $CCACHE_COMPILE -I`pwd`/include -c src/test.c
37 expect_stat 'cache hit (direct)' 0
38 expect_stat 'cache hit (preprocessed)' 0
39 expect_stat 'cache miss' 1
41 # CCACHE_BASEDIR="" is the default:
42 $CCACHE_COMPILE -I`pwd`/include -c src/test.c
43 expect_stat 'cache hit (direct)' 0
44 expect_stat 'cache hit (preprocessed)' 0
45 expect_stat 'cache miss' 2
47 # -------------------------------------------------------------------------
48 TEST "Path normalization"
51 CCACHE_BASEDIR="`pwd`" $CCACHE_COMPILE -I`pwd`/include -c src/test.c
52 expect_stat 'cache hit (direct)' 0
53 expect_stat 'cache hit (preprocessed)' 0
54 expect_stat 'cache miss' 1
57 ln -s `pwd`/include subdir/symlink
59 # Rewriting triggered by CCACHE_BASEDIR should handle paths with multiple
60 # slashes, redundant "/." parts and "foo/.." parts correctly. Note that the
61 # ".." part of the path is resolved after the symlink has been resolved.
62 CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`//./subdir/symlink/../include -c `pwd`/src/test.c
63 expect_stat 'cache hit (direct)' 1
64 expect_stat 'cache hit (preprocessed)' 0
65 expect_stat 'cache miss' 1
67 # -------------------------------------------------------------------------
68 TEST "Rewriting in stderr"
73 // Trigger warning by having no return statement.
81 CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -Wall -W -I`pwd` -c `pwd`/stderr.c -o `pwd`/stderr.o 2>stderr.txt
82 expect_stat 'cache hit (direct)' 0
83 expect_stat 'cache hit (preprocessed)' 0
84 expect_stat 'cache miss' 1
85 if grep `pwd` stderr.txt >/dev/null 2>&1; then
86 test_failed "Base dir (`pwd`) found in stderr:\n`cat stderr.txt`"
89 CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -Wall -W -I`pwd` -c `pwd`/stderr.c -o `pwd`/stderr.o 2>stderr.txt
90 expect_stat 'cache hit (direct)' 1
91 expect_stat 'cache hit (preprocessed)' 0
92 expect_stat 'cache miss' 1
93 if grep `pwd` stderr.txt >/dev/null 2>&1; then
94 test_failed "Base dir (`pwd`) found in stderr:\n`cat stderr.txt`"
97 # -------------------------------------------------------------------------
98 TEST "-MF/-MQ/-MT with absolute paths"
100 for option in MF "MF " MQ "MQ " MT "MT "; do
103 CCACHE_BASEDIR="`pwd`" $CCACHE_COMPILE -I`pwd`/include -MD -${option}`pwd`/test.d -c src/test.c
104 expect_stat 'cache hit (direct)' 0
105 expect_stat 'cache hit (preprocessed)' 0
106 expect_stat 'cache miss' 1
110 CCACHE_BASEDIR="`pwd`" $CCACHE_COMPILE -I`pwd`/include -MD -${option}`pwd`/test.d -c src/test.c
111 expect_stat 'cache hit (direct)' 1
112 expect_stat 'cache hit (preprocessed)' 0
113 expect_stat 'cache miss' 1
117 # -------------------------------------------------------------------------
118 # When BASEDIR is set to /, check that -MF, -MQ and -MT arguments with
119 # absolute paths are rewritten to relative and that the dependency file
120 # only contains relative paths.
121 TEST "-MF/-MQ/-MT with absolute paths and BASEDIR set to /"
123 for option in MF "MF " MQ "MQ " MT "MT "; do
126 CCACHE_BASEDIR="/" $CCACHE_COMPILE -I`pwd`/include -MD -${option}`pwd`/test.d -c src/test.c
127 expect_stat 'cache hit (direct)' 0
128 expect_stat 'cache hit (preprocessed)' 0
129 expect_stat 'cache miss' 1
130 # Check that there is no absolute path in the dependency file:
132 for file in $line; do
134 test_failed "Absolute file path '$file' found in dependency file '`pwd`/test.d'"
141 CCACHE_BASEDIR="/" $CCACHE_COMPILE -I`pwd`/include -MD -${option}`pwd`/test.d -c src/test.c
142 expect_stat 'cache hit (direct)' 1
143 expect_stat 'cache hit (preprocessed)' 0
144 expect_stat 'cache miss' 1