]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Make all concatenated option path arguments relative
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 21 Jul 2016 19:08:06 +0000 (21:08 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 21 Jul 2016 19:11:22 +0000 (21:11 +0200)
Only when a base directory is used, of course. Also added a test case
for the important -I/some/path case.

Hopefully fixes issue #84. A more generic alternative to PR #85.

ccache.c
test/test_argument_processing.c

index 98fd43f9afeda76049b404cbe8e81dc106eba982..faa39f0df93319734d5952001b82778661e169a9 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -2724,45 +2724,29 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
                        continue;
                }
 
-               /* Same as above but short options with concatenated argument. */
-               if (compopt_short(compopt_takes_path, argv[i])) {
-                       char *relpath;
-                       char *option;
-                       relpath = make_relative_path(x_strdup(argv[i] + 2));
-                       option = format("-%c%s", argv[i][1], relpath);
-
-                       if (compopt_short(compopt_affects_cpp, argv[i])) {
-                               args_add(cpp_args, option);
-                       } else {
-                               args_add(stripped_args, option);
-                       }
-
-                       free(relpath);
-                       free(option);
-                       continue;
-               }
-
-               /* Same as above but long options with concatenated argument beginning with
-                * a slash. */
+               /*
+                * Same as above but options with concatenated argument beginning with a
+                * slash.
+                */
                if (argv[i][0] == '-') {
                        char *slash_pos = strchr(argv[i], '/');
                        if (slash_pos) {
                                char *option = x_strndup(argv[i], slash_pos - argv[i]);
-                               if (compopt_affects_cpp(option)) {
-                                       if (compopt_takes_concat_arg(option)) {
-                                               char *relpath = make_relative_path(x_strdup(slash_pos));
-                                               args_add(cpp_args, option);
-                                               args_add(cpp_args, relpath);
-                                               free(relpath);
+                               if (compopt_takes_concat_arg(option) && compopt_takes_path(option)) {
+                                       char *relpath = make_relative_path(x_strdup(slash_pos));
+                                       char *new_option = format("%s%s", option, relpath);
+                                       if (compopt_affects_cpp(option)) {
+                                               args_add(cpp_args, new_option);
                                        } else {
-                                               args_add(cpp_args, argv[i]);
+                                               args_add(stripped_args, new_option);
                                        }
+                                       free(new_option);
+                                       free(relpath);
+                                       free(option);
+                                       continue;
                                } else {
-                                       args_add(stripped_args, argv[i]);
+                                       free(option);
                                }
-
-                               free(option);
-                               continue;
                        }
                }
 
index 461d4e968800c8affbdbb6129c8166800954d80f..001a68cea68e0bb1ebf0adb810b7e863897544d8 100644 (file)
@@ -379,8 +379,34 @@ TEST(isystem_flag_with_concat_arg_should_be_rewritten_if_basedir_is_used)
        free(arg_string);
 
        CHECK(cc_process_args(orig, &act_cpp, &act_cc));
-       CHECK_STR_EQ("-isystem", act_cpp->argv[1]);
-       CHECK_STR_EQ("./foo", act_cpp->argv[2]);
+       CHECK_STR_EQ("-isystem./foo", act_cpp->argv[1]);
+
+       free(cwd);
+       args_free(orig);
+       args_free(act_cpp);
+       args_free(act_cc);
+}
+
+TEST(I_flag_with_concat_arg_should_be_rewritten_if_basedir_is_used)
+{
+       extern char *current_working_dir;
+       char *cwd;
+       char *arg_string;
+       struct args *orig;
+       struct args *act_cpp = NULL, *act_cc = NULL;
+
+       create_file("foo.c", "");
+       free(conf->base_dir);
+       conf->base_dir = x_strdup("/"); /* posix */
+       current_working_dir = get_cwd();
+       /* windows path don't work concatenated */
+       cwd = get_posix_path(current_working_dir);
+       arg_string = format("cc -I%s/foo -c foo.c", cwd);
+       orig = args_init_from_string(arg_string);
+       free(arg_string);
+
+       CHECK(cc_process_args(orig, &act_cpp, &act_cc));
+       CHECK_STR_EQ("-I./foo", act_cpp->argv[1]);
 
        free(cwd);
        args_free(orig);