From 1c70e25cb57eb813707cec996ef557e80203de1a Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 27 Oct 2010 21:27:33 +0200 Subject: [PATCH] Rewrite argument to --sysroot if CCACHE_BASEDIR is used Based on a patch by Bo . --- ccache.c | 12 ++++++++++-- test/test_argument_processing.c | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ccache.c b/ccache.c index efe0cdb04..df8c42c1c 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; @@ -76,7 +76,7 @@ char *cache_dir = NULL; 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; @@ -1403,6 +1403,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 9e76ae86f..8a9cf832c 100644 --- a/test/test_argument_processing.c +++ b/test/test_argument_processing.c @@ -57,4 +57,28 @@ TEST(dependency_flags_should_only_be_sent_to_the_preprocessor) 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_SUITE_END -- 2.47.3