From: Joel Rosdahl Date: Thu, 21 Jul 2016 19:08:06 +0000 (+0200) Subject: Make all concatenated option path arguments relative X-Git-Tag: v3.3~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fdb77458a0d34a4d24e2ca82138197bcd083685;p=thirdparty%2Fccache.git Make all concatenated option path arguments relative 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. --- diff --git a/ccache.c b/ccache.c index 98fd43f9a..faa39f0df 100644 --- 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; } } diff --git a/test/test_argument_processing.c b/test/test_argument_processing.c index 461d4e968..001a68cea 100644 --- a/test/test_argument_processing.c +++ b/test/test_argument_processing.c @@ -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);