From: Joel Rosdahl Date: Mon, 1 Apr 2019 19:46:21 +0000 (+0200) Subject: Don’t create missing output directory X-Git-Tag: v3.7~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=377efaef201a37ac38b357665238c7fde475f5b2;p=thirdparty%2Fccache.git Don’t create missing output directory This mimics the compiler behavior for “-o out/obj.o” when “out” doesn’t exist. Fixes #353. --- diff --git a/doc/NEWS.adoc b/doc/NEWS.adoc index 67587c56e..f3f6e0f59 100644 --- a/doc/NEWS.adoc +++ b/doc/NEWS.adoc @@ -18,7 +18,7 @@ Changes * Compilations with /dev/null as the input file are now cached. -* ccache now knows how to contruct the object filename if no “-o” option is +* ccache now knows how to contruct the object filename if no `-o` option is given and the source filename does not include a `.` or ends with a `.`. * Fixed a temporary file leak when depend mode is enabled and the compiler @@ -49,6 +49,9 @@ Changes * Added a new `--print-stats` command that prints statistics counters in machine-parsable (tab-separated) format. +* ccache no longer creates a missing output directory, thus mimicking the + compiler behavior for `-o out/obj.o` when “out” doesn’t exist. + ccache 3.6 ---------- diff --git a/src/ccache.c b/src/ccache.c index f6562a89b..6bb63a013 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -3294,11 +3294,21 @@ cc_process_args(struct args *args, struct args **preprocessor_args, && stat(output_obj, &st) == 0 && !S_ISREG(st.st_mode)) { cc_log("Not a regular file: %s", output_obj); - stats_update(STATS_DEVICE); + stats_update(STATS_BADOUTPUTFILE); result = false; goto out; } + char *output_dir = dirname(output_obj); + if (stat(output_dir, &st) != 0 || !S_ISDIR(st.st_mode)) { + cc_log("Directory does not exist: %s", output_dir); + stats_update(STATS_BADOUTPUTFILE); + result = false; + free(output_dir); + goto out; + } + free(output_dir); + // Some options shouldn't be passed to the real compiler when it compiles // preprocessed code: // diff --git a/src/ccache.h b/src/ccache.h index bdca4a514..d9acf0310 100644 --- a/src/ccache.h +++ b/src/ccache.h @@ -54,7 +54,7 @@ enum stats { STATS_OBSOLETE_MAXFILES = 13, STATS_OBSOLETE_MAXSIZE = 14, STATS_SOURCELANG = 15, - STATS_DEVICE = 16, + STATS_BADOUTPUTFILE = 16, STATS_NOINPUT = 17, STATS_MULTIPLE = 18, STATS_CONFTEST = 19, diff --git a/src/stats.c b/src/stats.c index 28392f564..1e8e4970a 100644 --- a/src/stats.c +++ b/src/stats.c @@ -218,9 +218,9 @@ static struct { 0 }, { - STATS_DEVICE, - "output_to_a_non_file", - "output to a non-regular file", + STATS_BADOUTPUTFILE, + "bad_output_file", + "could not write to output file", NULL, 0 }, diff --git a/test/suites/base.bash b/test/suites/base.bash index eaf3e4da1..d263ea69a 100644 --- a/test/suites/base.bash +++ b/test/suites/base.bash @@ -125,12 +125,28 @@ base_tests() { expect_stat 'compiler produced stdout' 1 # ------------------------------------------------------------------------- - TEST "Output to a non-regular file" + TEST "Output to directory" mkdir testd $CCACHE_COMPILE -o testd -c test1.c >/dev/null 2>&1 rmdir testd >/dev/null 2>&1 - expect_stat 'output to a non-regular file' 1 + expect_stat 'could not write to output file' 1 + + # ------------------------------------------------------------------------- + TEST "Output to file in nonexistent directory" + + mkdir out + + $CCACHE_COMPILE -c test1.c -o out/foo.o + expect_stat 'could not write to output file' "" + expect_stat 'cache miss' 1 + + rm -rf out + + $CCACHE_COMPILE -c test1.c -o out/foo.o 2>/dev/null + expect_stat 'could not write to output file' 1 + expect_stat 'cache miss' 1 + expect_file_missing out/foo.o # ------------------------------------------------------------------------- TEST "No input file"