]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Rewrite argument to --sysroot if CCACHE_BASEDIR is used
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 27 Oct 2010 19:27:33 +0000 (20:27 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 30 May 2011 19:12:36 +0000 (21:12 +0200)
Based on a patch by Bo <yebo9098@gmail.com>.

ccache.c
test/test_argument_processing.c

index 66d813b7eb40d2715dc4b266bc6ca956b5afc9b9..0f4b4c761abb1954373331392cb604263e6bf37b 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -67,7 +67,7 @@ static const char USAGE_TEXT[] =
 "See also <http://ccache.samba.org>.\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;
index 11f33f3a02e1b1f4df4a246e9fe3106727339ca3..e6de579dccfa2ef4b352fe8049394b9089312ba1 100644 (file)
@@ -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(