]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix -fprofile-*=dir handling when dir doesn't exist
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 15 Aug 2011 20:38:26 +0000 (22:38 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 15 Aug 2011 20:38:26 +0000 (22:38 +0200)
ccache.c
test/test_argument_processing.c

index 339ce5fe6db2c67b81a49f76f01f4693b7ef73e8..23c7758c902290fa42b3caea4c89eea3f07669a1 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -1605,15 +1605,21 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args,
 
                        if (arg_profile_dir) {
                                char* option = x_strndup(argv[i], arg_profile_dir - argv[i]);
+                               char *dir;
 
                                /* Convert to absolute path. */
-                               arg_profile_dir = x_realpath(arg_profile_dir + 1);
+                               dir = x_realpath(arg_profile_dir + 1);
+                               if (!dir) {
+                                       /* Directory doesn't exist. */
+                                       dir = x_strdup(arg_profile_dir + 1);
+                               }
 
                                /* We can get a better hit rate by using the real path here. */
                                free(arg);
-                               arg = format("%s=%s", option, profile_dir);
-                               cc_log("Rewriting arg to %s", arg);
+                               arg = format("%s=%s", option, dir);
+                               cc_log("Rewriting %s to %s", argv[i], arg);
                                free(option);
+                               free(dir);
                        }
 
                        if (str_startswith(argv[i], "-fprofile-generate")
index a1fdb81689d79ed493093e31095747b6b4a8ae55..18dcaea452b2938ee48340a0454409ec84133ae1 100644 (file)
@@ -230,4 +230,48 @@ TEST(MT_flag_with_immediate_argument_should_add_MQobj)
        args_free(orig);
 }
 
+TEST(fprofile_flag_with_existing_dir_should_be_rewritten_to_real_path)
+{
+       struct args *orig = args_init_from_string(
+               "gcc -c -fprofile-generate=some/dir foo.c");
+       struct args *exp_cpp = args_init_from_string("gcc");
+       struct args *exp_cc = args_init_from_string("gcc");
+       struct args *act_cpp = NULL, *act_cc = NULL;
+       char *s;
+
+       create_file("foo.c", "");
+       mkdir("some", 0777);
+       mkdir("some/dir", 0777);
+       s = format("-fprofile-generate=%s", x_realpath("some/dir"));
+       args_add(exp_cpp, s);
+       args_add(exp_cc, s);
+       args_add(exp_cc, "-c");
+       free(s);
+
+       CHECK(cc_process_args(orig, &act_cpp, &act_cc));
+       CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp);
+       CHECK_ARGS_EQ_FREE12(exp_cc, act_cc);
+
+       args_free(orig);
+}
+
+TEST(fprofile_flag_with_nonexisting_dir_not_be_rewritten)
+{
+       struct args *orig = args_init_from_string(
+               "gcc -c -fprofile-generate=some/dir foo.c");
+       struct args *exp_cpp = args_init_from_string(
+               "gcc -fprofile-generate=some/dir");
+       struct args *exp_cc = args_init_from_string(
+               "gcc -fprofile-generate=some/dir -c");
+       struct args *act_cpp = NULL, *act_cc = NULL;
+
+       create_file("foo.c", "");
+
+       CHECK(cc_process_args(orig, &act_cpp, &act_cc));
+       CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp);
+       CHECK_ARGS_EQ_FREE12(exp_cc, act_cc);
+
+       args_free(orig);
+}
+
 TEST_SUITE_END