]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Simplify and correct calculation of default dependency file name
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Feb 2010 21:53:04 +0000 (22:53 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Feb 2010 21:53:04 +0000 (22:53 +0100)
ccache.c
test.sh

index 75837371ea1a60e1da39ff4eb18550bf44ded714..e1036139c071064869c542759de01dcc47f5046f 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -1464,29 +1464,20 @@ static void process_args(int argc, char **argv)
 
        if (generating_dependencies) {
                if (!dependency_filename_specified) {
-                       char *default_depfile_name = x_strdup(output_obj);
-                       char *p = strrchr(default_depfile_name, '.');
-
-                       if (p) {
-                               if (strlen(p) < 2) {
-                                       stats_update(STATS_ARGS);
-                                       cc_log("Too short file extension in %s",
-                                              default_depfile_name);
-                                       failed();
-                                       return;
-                               }
-                               *p = 0;
-                       }
-                       else  {
-                               int len = p - default_depfile_name;
-
-                               p = x_malloc(len + 3);
-                               strncpy(default_depfile_name, p, len - 1);
-                               free(default_depfile_name);
-                               default_depfile_name = p;
+                       char *default_depfile_name;
+                       char *last_dot, *last_slash;
+
+                       last_dot = strrchr(output_obj, '.');
+                       last_slash = strrchr(output_obj, '/');
+                       if (!last_dot
+                           || (last_slash && last_dot < last_slash)) {
+                               /* No extension, just add .d. */
+                               last_dot = output_obj + strlen(output_obj);
                        }
-
-                       strcat(default_depfile_name, ".d");
+                       x_asprintf(&default_depfile_name,
+                                  "%.*s.d",
+                                  (int)(last_dot - output_obj),
+                                  output_obj);
                        args_add(stripped_args, "-MF");
                        args_add(stripped_args, default_depfile_name);
                        output_dep = make_relative_path(
diff --git a/test.sh b/test.sh
index 1afc1b394515c100a963165b2eac6e98874bb376..fcaf4fb70888e527c13132017db3b21bdcfee14e 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -483,6 +483,22 @@ EOF
 
     rm -f other.d
 
+    ##################################################################
+    # Check calculation of dependency file names.
+    $CCACHE -z >/dev/null
+    mkdir test.dir
+    # Make sure the dependency file is in the cache:
+    $CCACHE $COMPILER -MD -c test.c
+    for ext in .obj "" . .foo.bar; do
+        testname="dependency file calculation from object file 'test$ext'"
+        dep_file=test.dir/`echo test$ext | sed 's/\.[^.]*\$//'`.d
+        rm -f $dep_file
+        $CCACHE $COMPILER -MD -c test.c -o test.dir/test$ext
+        if [ ! -f $dep_file ]; then
+            test_failed "$dep_file missing"
+        fi
+    done
+
     ##################################################################
     # Check that -Wp,-MD,file.d works.
     testname="-Wp,-MD"