]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Deduce output filename from source filename without or ending with dot
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 27 Mar 2019 20:22:28 +0000 (21:22 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 27 Mar 2019 20:22:28 +0000 (21:22 +0100)
doc/NEWS.adoc
src/ccache.c
test/suites/base.bash

index 9461f5a96dd9d3d497ccc3ba9fe2ddfb895ab4a4..cea25ef9ca35c9bd76916d1bcd6d9e1eda95f752 100644 (file)
@@ -18,6 +18,9 @@ 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
+  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
   produces standard error output.
 
index 43512d782afbcb61a64542fbb40c987efc2088df..d0c378548c2a7807d5d0d4ff776a824ac11e5ed5 100644 (file)
@@ -3247,16 +3247,17 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
                if (output_is_precompiled_header) {
                        output_obj = format("%s.gch", input_file);
                } else {
+                       char extension = found_S_opt ? 's' : 'o';
                        output_obj = basename(input_file);
                        char *p = strrchr(output_obj, '.');
-                       if (!p || !p[1]) {
-                               cc_log("Badly formed object filename");
-                               stats_update(STATS_ARGS);
-                               result = false;
-                               goto out;
+                       if (!p) {
+                               reformat(&output_obj, "%s.%c", output_obj, extension);
+                       } else if (!p[1]) {
+                               reformat(&output_obj, "%s%c", output_obj, extension);
+                       } else {
+                               p[1] = extension;
+                               p[2] = 0;
                        }
-                       p[1] = found_S_opt ? 's' : 'o';
-                       p[2] = 0;
                }
        }
 
index ed3eab1e68bf894ac504fb7e01705ee6b38fe3c9..eaf3e4da15f3a12837150a0b8bdd13f8584b3038 100644 (file)
@@ -138,6 +138,66 @@ base_tests() {
     $CCACHE_COMPILE -c -O2 2>/dev/null
     expect_stat 'no input file' 1
 
+    # -------------------------------------------------------------------------
+    TEST "No file extension"
+
+    mkdir src
+    touch src/foo
+
+    $CCACHE_COMPILE -x c -c src/foo
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_file_exists foo.o
+    rm foo.o
+
+    $CCACHE_COMPILE -x c -c src/foo
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+    expect_file_exists foo.o
+    rm foo.o
+
+    rm -rf src
+
+    # -------------------------------------------------------------------------
+    TEST "Source file ending with dot"
+
+    mkdir src
+    touch src/foo.
+
+    $CCACHE_COMPILE -x c -c src/foo.
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_file_exists foo.o
+    rm foo.o
+
+    $CCACHE_COMPILE -x c -c src/foo.
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+    expect_file_exists foo.o
+    rm foo.o
+
+    rm -rf src
+
+    # -------------------------------------------------------------------------
+    TEST "Multiple file extensions"
+
+    mkdir src
+    touch src/foo.c.c
+
+    $CCACHE_COMPILE -c src/foo.c.c
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_file_exists foo.c.o
+    rm foo.c.o
+
+    $CCACHE_COMPILE -c src/foo.c.c
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+    expect_file_exists foo.c.o
+    rm foo.c.o
+
+    rm -rf src
+
     # -------------------------------------------------------------------------
     TEST "LANG"