Handle missing or empty object file from compiler properly

This commit is contained in:
Joel Rosdahl 2010-02-22 08:36:40 +01:00
parent 196baceaef
commit 131111cd58
5 changed files with 46 additions and 0 deletions

4
NEWS
View File

@ -49,6 +49,10 @@ New features and improvements:
- Standard error output from the compiler is now only stored in the cache if
it's non-empty.
- If the compiler produces no object file or an empty object file, but gives
a zero exit status (could be due to a file system problem, a buggy program
specified by CCACHE_PREFIX, etc.), ccache copes with it properly.
- Added installcheck and distcheck make targets.
- Clarified cache size limit options' semantics

View File

@ -546,6 +546,17 @@ static void to_cache(ARGS *args)
failed();
}
if (stat(tmp_obj, &st) != 0) {
cc_log("The compiler didn't produce an object file");
stats_update(STATS_NOOUTPUT);
failed();
}
if (st.st_size == 0) {
cc_log("The compiler produced an empty object file");
stats_update(STATS_EMPTYOUTPUT);
failed();
}
compress = !getenv("CCACHE_NOCOMPRESS");
if (stat(tmp_stderr, &st) != 0) {

View File

@ -43,6 +43,8 @@ enum stats {
STATS_UNSUPPORTED,
STATS_OUTSTDOUT,
STATS_CACHEHIT_DIR,
STATS_NOOUTPUT,
STATS_EMPTYOUTPUT,
STATS_END
};

View File

@ -54,6 +54,8 @@ static struct {
{ STATS_LINK, "called for link ", NULL, 0 },
{ STATS_MULTIPLE, "multiple source files ", NULL, 0 },
{ STATS_STDOUT, "compiler produced stdout ", NULL, 0 },
{ STATS_NOOUTPUT, "compiler produced no output ", NULL, 0 },
{ STATS_EMPTYOUTPUT, "compiler produced empty output ", NULL, 0 },
{ STATS_STATUS, "compile failed ", NULL, 0 },
{ STATS_ERROR, "ccache internal error ", NULL, 0 },
{ STATS_PREPROCESSOR, "preprocessor error ", NULL, 0 },

27
test.sh
View File

@ -275,6 +275,33 @@ base_tests() {
checkstat 'cache hit (preprocessed)' 11
checkstat 'cache miss' 39
testname="no object file"
cat <<'EOF' >test_no_obj.c
int test_no_obj;
EOF
cat <<'EOF' >prefix-remove.sh
#!/bin/sh
echo "$*" >>/tmp/foo
"$@"
[ x$3 = x-o ] && rm $4
EOF
chmod +x prefix-remove.sh
CCACHE_PREFIX=$PWD/prefix-remove.sh $CCACHE_COMPILE -c test_no_obj.c
checkstat 'compiler produced no output' 1
testname="empty object file"
cat <<'EOF' >test_empty_obj.c
int test_empty_obj;
EOF
cat <<'EOF' >prefix-empty.sh
#!/bin/sh
"$@"
[ x$3 = x-o ] && cp /dev/null $4
EOF
chmod +x prefix-empty.sh
CCACHE_PREFIX=$PWD/prefix-empty.sh $CCACHE_COMPILE -c test_empty_obj.c
checkstat 'compiler produced empty output' 1
testname="stderr-files"
num=`find $CCACHE_DIR -name '*.stderr' | wc -l`
if [ $num -ne 0 ]; then