From: Joel Rosdahl Date: Wed, 27 Oct 2010 19:27:33 +0000 (+0100) Subject: Rewrite argument to --sysroot if CCACHE_BASEDIR is used X-Git-Tag: v3.1.6~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5f7cf366b26fdfff98b0fab7b4af4ec4c460e8f3;p=thirdparty%2Fccache.git Rewrite argument to --sysroot if CCACHE_BASEDIR is used Based on a patch by Bo . --- diff --git a/ccache.c b/ccache.c index 66d813b7e..0f4b4c761 100644 --- a/ccache.c +++ b/ccache.c @@ -67,7 +67,7 @@ static const char USAGE_TEXT[] = "See also .\n"; /* current working directory taken from $PWD, or getcwd() if $PWD is bad */ -static char *current_working_dir; +char *current_working_dir = NULL; /* the base cache directory */ char *cache_dir = NULL; @@ -79,7 +79,7 @@ static char *temp_dir; char *cache_logfile = NULL; /* base directory (from CCACHE_BASEDIR) */ -static char *base_dir; +char *base_dir = NULL; /* the original argument list */ static struct args *orig_args; @@ -1410,6 +1410,14 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, } continue; } + if (str_startswith(argv[i], "--sysroot=")) { + char *relpath = make_relative_path(x_strdup(argv[i] + 10)); + char *option = format("--sysroot=%s", relpath); + args_add(stripped_args, option); + free(relpath); + free(option); + continue; + } if (str_startswith(argv[i], "-Wp,")) { if (str_startswith(argv[i], "-Wp,-MD,") && !strchr(argv[i] + 8, ',')) { generating_dependencies = true; diff --git a/test/test_argument_processing.c b/test/test_argument_processing.c index 11f33f3a0..e6de579dc 100644 --- a/test/test_argument_processing.c +++ b/test/test_argument_processing.c @@ -86,6 +86,30 @@ TEST(dependency_flags_that_take_an_argument_should_not_require_space_delimiter) args_free(orig); } +TEST(sysroot_should_be_rewritten_if_basedir_is_used) +{ + extern char *base_dir; + extern char *current_working_dir; + struct args *orig = + args_init_from_string("cc --sysroot=/some/directory -c foo.c"); + struct args *act_cpp = NULL, *act_cc = NULL; + create_file("foo.c", ""); + + CHECK(cc_process_args(orig, &act_cpp, &act_cc)); + CHECK_STR_EQ(act_cpp->argv[1], "--sysroot=/some/directory"); + + cc_reset(); + base_dir = "/some"; + current_working_dir = get_cwd(); + + CHECK(cc_process_args(orig, &act_cpp, &act_cc)); + CHECK(str_startswith(act_cpp->argv[1], "--sysroot=../")); + + args_free(orig); + base_dir = NULL; + current_working_dir = NULL; +} + TEST(MF_flag_with_immediate_argument_should_work_as_last_argument) { struct args *orig = args_init_from_string(