From 6ca852cfaf08f35e018555762aff71db3c95c151 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Fri, 30 Aug 2013 22:29:28 +0200 Subject: [PATCH] Avoid creating ccache directory when CCACHE_DISABLE is set --- ccache.c | 18 ++++++++++-------- test.sh | 5 +++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ccache.c b/ccache.c index b20c087bc..7cd32a162 100644 --- a/ccache.c +++ b/ccache.c @@ -1964,7 +1964,7 @@ setup_uncached_err(void) /* the main ccache driver function */ static void -ccache(int argc, char *argv[]) +ccache(char *argv[]) { bool put_object_in_manifest = false; struct file_hash *object_hash; @@ -1980,14 +1980,8 @@ ccache(int argc, char *argv[]) /* Arguments to send to the real compiler. */ struct args *compiler_args; - find_compiler(argc, argv); setup_uncached_err(); - if (getenv("CCACHE_DISABLE")) { - cc_log("ccache is disabled"); - failed(); - } - if (!getenv("CCACHE_READONLY")) { if (create_cachedirtag(cache_dir) != 0) { cc_log("failed to create %s/CACHEDIR.TAG (%s)\n", @@ -2286,6 +2280,14 @@ ccache_main(int argc, char *argv[]) } free(program_name); + /* find_compiler sets up orig_args, needed by failed(), so do it early. */ + find_compiler(argc, argv); + + if (getenv("CCACHE_DISABLE")) { + cc_log("ccache is disabled"); + failed(); + } + check_cache_dir(); temp_dir = getenv("CCACHE_TEMPDIR"); @@ -2317,6 +2319,6 @@ ccache_main(int argc, char *argv[]) exit(1); } - ccache(argc, argv); + ccache(argv); return 1; } diff --git a/test.sh b/test.sh index 71912ce33..d74e520c6 100755 --- a/test.sh +++ b/test.sh @@ -216,7 +216,12 @@ base_tests() { checkstat 'no input file' 1 testname="CCACHE_DISABLE" + mv $CCACHE_DIR $CCACHE_DIR.saved CCACHE_DISABLE=1 $CCACHE_COMPILE -c test1.c 2> /dev/null + if [ -d $CCACHE_DIR ]; then + test_failed "$CCACHE_DIR created dispite CCACHE_DISABLE being set" + fi + mv $CCACHE_DIR.saved $CCACHE_DIR checkstat 'cache hit (preprocessed)' 3 $CCACHE_COMPILE -c test1.c checkstat 'cache hit (preprocessed)' 4 -- 2.47.2