From: Joel Rosdahl Date: Thu, 3 Oct 2019 18:21:54 +0000 (+0200) Subject: Only pass implicit -MQ to preprocessor if needed X-Git-Tag: v4.0~776 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b371cee80085564bac5fe12a9ecd6ea90903cdd3;p=thirdparty%2Fccache.git Only pass implicit -MQ to preprocessor if needed This is a bug fix of 76a9959f3d3e. (cherry picked from commit 19c3729d30640fc2c78242cb46136e619fdbd802) --- diff --git a/doc/NEWS.adoc b/doc/NEWS.adoc index d19e7e4a4..9f22e7e72 100644 --- a/doc/NEWS.adoc +++ b/doc/NEWS.adoc @@ -44,6 +44,11 @@ Bug fixes - Fixed a regression in 3.7.2 that could result in a warning message instead of an error in an edge case related to usage of “-Werror”. +- An implicit `-MQ` is now passed to the preprocessor only if the object file + extension is non-standard. This should make it easier to use EDG-based + compilers (e.g. GHS) which don’t understand `-MQ`. (This is a bug fix of the + corresponding improvement implemented in ccache 3.4.) + ccache 3.7.4 ------------ diff --git a/src/ccache.cpp b/src/ccache.cpp index 1d2a639b2..ba26a934f 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -3366,7 +3366,7 @@ cc_process_args(struct args* args, } if (!dependency_target_specified && !dependency_implicit_target_specified - && !str_eq(get_extension(output_dep), ".o")) { + && !str_eq(get_extension(output_obj), ".o")) { args_add(dep_args, "-MQ"); args_add(dep_args, output_obj); } diff --git a/unittest/test_argument_processing.cpp b/unittest/test_argument_processing.cpp index 1146c5e4c..70818993c 100644 --- a/unittest/test_argument_processing.cpp +++ b/unittest/test_argument_processing.cpp @@ -173,6 +173,36 @@ TEST(dependency_flags_that_take_an_argument_should_not_require_space_delimiter) args_free(orig); } +TEST(MQ_flag_should_not_be_added_for_standard_obj_extension) +{ + struct args* orig = args_init_from_string("cc -c -MD foo.c -o foo.o"); + struct args* exp_cpp = args_init_from_string("cc -MD -MF foo.d"); + struct args* exp_cc = args_init_from_string("cc -c"); + struct args *act_cpp = NULL, *act_cc = NULL; + create_file("foo.c", ""); + + CHECK(cc_process_args(orig, &act_cpp, NULL, &act_cc)); + CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp); + CHECK_ARGS_EQ_FREE12(exp_cc, act_cc); + + args_free(orig); +} + +TEST(MQ_flag_should_be_added_for_non_standard_obj_extension) +{ + struct args* orig = args_init_from_string("cc -c -MD foo.c -o foo.obj"); + struct args* exp_cpp = args_init_from_string("cc -MD -MF foo.d -MQ foo.obj"); + struct args* exp_cc = args_init_from_string("cc -c"); + struct args *act_cpp = NULL, *act_cc = NULL; + create_file("foo.c", ""); + + CHECK(cc_process_args(orig, &act_cpp, NULL, &act_cc)); + CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp); + CHECK_ARGS_EQ_FREE12(exp_cc, act_cc); + + args_free(orig); +} + TEST(sysroot_should_be_rewritten_if_basedir_is_used) { extern char* current_working_dir;