}
}
- if (seen_split_dwarf) {
- // When using -gsplit-dwarf, object files include a link to the
- // corresponding .dwo file based on the target object filename, so we need
- // to include the target filename in the hash to avoid handing out an
- // object file with an incorrect .dwo link.
- hash_delimiter(hash, "filename");
- hash_string_view(hash, Util::base_name(output_obj));
+ if (generating_dependencies || seen_split_dwarf) {
+ // The output object file name is part of the .d file, so include the path
+ // in the hash if generating dependencies.
+ //
+ // Object files include a link to the corresponding .dwo file based on the
+ // target object filename when using -gsplit-dwarf, so hashing the object
+ // file path will do it, although just hashing the object file base name
+ // would be enough.
+ hash_delimiter(hash, "object file");
+ hash_string_view(hash, output_obj);
}
// Possibly hash the coverage data file path.
}
args_pop(preprocessor_args, 1);
}
- if (generating_dependencies) {
- // Nothing is actually created with -MF /dev/null
- if (!str_eq(output_dep, "/dev/null")) {
- cc_log("Preprocessor created %s", output_dep);
- }
- }
}
return result_name;
MTR_BEGIN("cache", "from_cache");
- // (If mode != FROMCACHE_DIRECT_MODE, the dependency file is created by gcc.)
- bool produce_dep_file = generating_dependencies
- && mode == FROMCACHE_DIRECT_MODE
- && !str_eq(output_dep, "/dev/null");
+ bool produce_dep_file =
+ generating_dependencies && !str_eq(output_dep, "/dev/null");
MTR_BEGIN("file", "file_get");
}
}
- // Add flags for dependency generation only to the preprocessor command line.
if (generating_dependencies) {
if (!dependency_filename_specified) {
std::string default_depfile_name =
Util::change_extension(output_obj, ".d");
- args_add(dep_args, "-MF");
- args_add(dep_args, default_depfile_name.c_str());
output_dep = make_relative_path(x_strdup(default_depfile_name.c_str()));
+ if (!g_config.run_second_cpp()) {
+ // If we're compiling preprocessed code we're sending dep_args to the
+ // preprocessor so we need to use -MF to write to the correct .d file
+ // location since the preprocessor doesn't know the final object path.
+ args_add(dep_args, "-MF");
+ args_add(dep_args, default_depfile_name.c_str());
+ }
}
- if (!dependency_target_specified && !dependency_implicit_target_specified) {
+ if (!dependency_target_specified && !dependency_implicit_target_specified
+ && !g_config.run_second_cpp()) {
+ // If we're compiling preprocessed code we're sending dep_args to the
+ // preprocessor so we need to use -MQ to get the correct target object
+ // file in the .d file.
args_add(dep_args, "-MQ");
args_add(dep_args, output_obj);
}
args_add(*compiler_args, arch_args[i]);
}
- // Only pass dependency arguments to the preprocessor since Intel's C++
- // compiler doesn't produce a correct .d file when compiling preprocessed
- // source.
- args_extend(cpp_args, dep_args);
-
*preprocessor_args = args_copy(common_args);
args_extend(*preprocessor_args, cpp_args);
+ if (g_config.run_second_cpp()) {
+ // When not compiling the preprocessed source code, only pass dependency
+ // arguments to the compiler to avoid having to add -MQ, supporting e.g.
+ // EDG-based compilers which don't support -MQ.
+ args_extend(*compiler_args, dep_args);
+ } else {
+ // When compiling the preprocessed source code, pass dependency arguments to
+ // the preprocessor since the compiler doesn't produce a .d file when
+ // compiling preprocessed source code.
+ args_extend(*preprocessor_args, dep_args);
+ }
+
*extra_args_to_hash = compiler_only_args;
+ if (g_config.run_second_cpp()) {
+ args_extend(*extra_args_to_hash, dep_args);
+ }
out:
args_free(expanded_args);
args_free(orig);
}
-TEST(dependency_flags_should_only_be_sent_to_the_preprocessor)
+TEST(dependency_args_to_preprocessor_if_run_second_cpp_is_false)
{
-#define CMD \
- "cc -MD -MMD -MP -MF foo.d -MT mt1 -MT mt2 -MQ mq1 -MQ mq2" \
- " -Wp,-MD,wpmd -Wp,-MMD,wpmmd -Wp,-MP -Wp,-MT,wpmt -Wp,-MQ,wpmq -Wp,-MF,wpf"
- struct args* orig = args_init_from_string(CMD " -c foo.c -o foo.o");
- struct args* exp_cpp = args_init_from_string(CMD);
+#define DEP_ARGS \
+ "-MD -MMD -MP -MF foo.d -MT mt1 -MT mt2 -MQ mq1 -MQ mq2 -Wp,-MD,wpmd" \
+ " -Wp,-MMD,wpmmd -Wp,-MP -Wp,-MT,wpmt -Wp,-MQ,wpmq -Wp,-MF,wpf"
+ struct args* orig =
+ args_init_from_string("cc " DEP_ARGS " -c foo.c -o foo.o");
+ struct args* exp_cpp = args_init_from_string("cc " DEP_ARGS);
struct args* exp_extra = args_init(0, NULL);
-#undef CMD
struct args* exp_cc = args_init_from_string("cc -c");
+#undef DEP_ARGS
+ struct args* act_cpp = NULL;
+ struct args* act_extra = NULL;
+ struct args* act_cc = NULL;
+ create_file("foo.c", "");
+
+ g_config.set_run_second_cpp(false);
+ CHECK(cc_process_args(orig, &act_cpp, &act_extra, &act_cc));
+ CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp);
+ CHECK_ARGS_EQ_FREE12(exp_extra, act_extra);
+ CHECK_ARGS_EQ_FREE12(exp_cc, act_cc);
+
+ args_free(orig);
+}
+
+TEST(dependency_args_to_compiler_if_run_second_cpp_is_true)
+{
+#define DEP_ARGS \
+ "-MD -MMD -MP -MF foo.d -MT mt1 -MT mt2 -MQ mq1 -MQ mq2 -Wp,-MD,wpmd" \
+ " -Wp,-MMD,wpmmd -Wp,-MP -Wp,-MT,wpmt -Wp,-MQ,wpmq -Wp,-MF,wpf"
+ struct args* orig =
+ args_init_from_string("cc " DEP_ARGS " -c foo.c -o foo.o");
+ struct args* exp_cpp = args_init_from_string("cc");
+ struct args* exp_extra = args_init_from_string(DEP_ARGS);
+ struct args* exp_cc = args_init_from_string("cc -c " DEP_ARGS);
+#undef DEP_ARGS
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
args_free(orig);
}
-TEST(cpp_only_flags_to_preprocessor_if_run_second_cpp_is_false)
+TEST(cpp_only_args_to_preprocessor_if_run_second_cpp_is_false)
{
-#define CMD \
- "cc -I. -idirafter . -iframework. -imacros . -imultilib ." \
- " -include test.h -include-pch test.pch -iprefix . -iquote ." \
- " -isysroot . -isystem . -iwithprefix . -iwithprefixbefore ." \
- " -DTEST_MACRO -DTEST_MACRO2=1 -F. -trigraphs -fworking-directory" \
- " -fno-working-directory -MD -MMD -MP -MF foo.d -MT mt1 -MT mt2" \
- " -MQ mq1 -MQ mq2 -Wp,-MD,wpmd -Wp,-MMD,wpmmd -Wp,-MP -Wp,-MT,wpmt" \
- " -Wp,-MQ,wpmq -Wp,-MF,wpf"
- struct args* orig = args_init_from_string(CMD " -c foo.c -o foo.o");
- struct args* exp_cpp = args_init_from_string(CMD);
+#define CPP_ARGS \
+ "-I. -idirafter . -iframework. -imacros . -imultilib . -include test.h" \
+ " -include-pch test.pch -iprefix . -iquote . -isysroot . -isystem ." \
+ " -iwithprefix . -iwithprefixbefore . -DTEST_MACRO -DTEST_MACRO2=1 -F." \
+ " -trigraphs -fworking-directory -fno-working-directory"
+#define DEP_ARGS \
+ "-MD -MMD -MP -MF foo.d -MT mt1 -MT mt2 -MQ mq1 -MQ mq2 -Wp,-MD,wpmd" \
+ " -Wp,-MMD,wpmmd -Wp,-MP -Wp,-MT,wpmt -Wp,-MQ,wpmq -Wp,-MF,wpf"
+ struct args* orig =
+ args_init_from_string("cc " CPP_ARGS " " DEP_ARGS " -c foo.c -o foo.o");
+ struct args* exp_cpp = args_init_from_string("cc " CPP_ARGS " " DEP_ARGS);
struct args* exp_extra = args_init(0, NULL);
-#undef CMD
struct args* exp_cc = args_init_from_string("cc -c");
+#undef DEP_ARGS
+#undef CPP_ARGS
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
args_free(orig);
}
-TEST(cpp_only_flags_to_preprocessor_and_compiler_if_run_second_cpp_is_true)
+TEST(cpp_only_args_to_preprocessor_and_compiler_if_run_second_cpp_is_true)
+{
+#define CPP_ARGS \
+ "-I. -idirafter . -iframework. -imacros . -imultilib . -include test.h" \
+ " -include-pch test.pch -iprefix . -iquote . -isysroot . -isystem ." \
+ " -iwithprefix . -iwithprefixbefore . -DTEST_MACRO -DTEST_MACRO2=1 -F." \
+ " -trigraphs -fworking-directory -fno-working-directory"
+#define DEP_ARGS \
+ " -MD -MMD -MP -MF foo.d -MT mt1 -MT mt2 -MQ mq1 -MQ mq2 -Wp,-MD,wpmd" \
+ " -Wp,-MMD,wpmmd"
+ struct args* orig =
+ args_init_from_string("cc " CPP_ARGS " " DEP_ARGS " -c foo.c -o foo.o");
+ struct args* exp_cpp = args_init_from_string("cc " CPP_ARGS);
+ struct args* exp_extra = args_init_from_string(DEP_ARGS);
+ struct args* exp_cc = args_init_from_string("cc " CPP_ARGS " -c " DEP_ARGS);
+#undef DEP_ARGS
+#undef CPP_ARGS
+ struct args* act_cpp = NULL;
+ struct args* act_extra = NULL;
+ struct args* act_cc = NULL;
+ create_file("foo.c", "");
+
+ CHECK(cc_process_args(orig, &act_cpp, &act_extra, &act_cc));
+ CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp);
+ CHECK_ARGS_EQ_FREE12(exp_extra, act_extra);
+ CHECK_ARGS_EQ_FREE12(exp_cc, act_cc);
+
+ args_free(orig);
+}
+
+TEST(dependency_args_that_take_an_argument_should_not_require_space_delimiter)
+{
+#define DEP_ARGS "-MMD -MFfoo.d -MT mt -MTmt -MQmq"
+ struct args* orig =
+ args_init_from_string("cc -c " DEP_ARGS " foo.c -o foo.o");
+ struct args* exp_cpp = args_init_from_string("cc");
+ struct args* exp_extra = args_init_from_string(DEP_ARGS);
+ struct args* exp_cc = args_init_from_string("cc -c " DEP_ARGS);
+#undef DEP_ARGS
+ struct args* act_cpp = NULL;
+ struct args* act_extra = NULL;
+ struct args* act_cc = NULL;
+ create_file("foo.c", "");
+
+ CHECK(cc_process_args(orig, &act_cpp, &act_extra, &act_cc));
+ CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp);
+ CHECK_ARGS_EQ_FREE12(exp_extra, act_extra);
+ CHECK_ARGS_EQ_FREE12(exp_cc, act_cc);
+
+ args_free(orig);
+}
+
+TEST(MQ_flag_should_not_be_added_if_run_second_cpp_is_true)
{
-#define CMD \
- "cc -I. -idirafter . -iframework. -imacros . -imultilib ." \
- " -include test.h -include-pch test.pch -iprefix . -iquote ." \
- " -isysroot . -isystem . -iwithprefix . -iwithprefixbefore ." \
- " -DTEST_MACRO -DTEST_MACRO2=1 -F. -trigraphs -fworking-directory" \
- " -fno-working-directory"
-#define DEP_OPTS \
- " -MD -MMD -MP -MF foo.d -MT mt1 -MT mt2 " \
- " -MQ mq1 -MQ mq2 -Wp,-MD,wpmd -Wp,-MMD,wpmmd"
- struct args* orig = args_init_from_string(CMD DEP_OPTS " -c foo.c -o foo.o");
- struct args* exp_cpp = args_init_from_string(CMD DEP_OPTS);
+ struct args* orig =
+ args_init_from_string("cc -c -MD foo.c -MF foo.d -o foo.o");
+ struct args* exp_cpp = args_init_from_string("cc");
+ struct args* exp_extra = args_init_from_string("-MD -MF foo.d");
+ struct args* exp_cc = args_init_from_string("cc -c -MD -MF foo.d");
+ struct args* act_cpp = NULL;
+ struct args* act_extra = NULL;
+ struct args* act_cc = NULL;
+ create_file("foo.c", "");
+
+ CHECK(cc_process_args(orig, &act_cpp, &act_extra, &act_cc));
+ CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp);
+ CHECK_ARGS_EQ_FREE12(exp_extra, act_extra);
+ CHECK_ARGS_EQ_FREE12(exp_cc, act_cc);
+
+ args_free(orig);
+}
+
+TEST(MQ_flag_should_be_added_if_run_second_cpp_is_false)
+{
+ struct args* orig =
+ args_init_from_string("cc -c -MD foo.c -MF foo.d -o foo.o");
+ struct args* exp_cpp = args_init_from_string("cc -MD -MF foo.d -MQ foo.o");
struct args* exp_extra = args_init(0, NULL);
- struct args* exp_cc = args_init_from_string(CMD " -c");
-#undef CMD
+ struct args* exp_cc = args_init_from_string("cc -c");
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
create_file("foo.c", "");
- g_config.set_run_second_cpp(true);
+ g_config.set_run_second_cpp(false);
CHECK(cc_process_args(orig, &act_cpp, &act_extra, &act_cc));
CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp);
CHECK_ARGS_EQ_FREE12(exp_extra, act_extra);
args_free(orig);
}
-TEST(dependency_flags_that_take_an_argument_should_not_require_space_delimiter)
+TEST(MF_should_be_added_if_run_second_cpp_is_false)
{
- struct args* orig = args_init_from_string(
- "cc -c -MMD -MFfoo.d -MT mt -MTmt -MQmq foo.c -o foo.o");
- struct args* exp_cpp =
- args_init_from_string("cc -MMD -MFfoo.d -MT mt -MTmt -MQmq");
+ 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 -MQ foo.o");
struct args* exp_extra = args_init(0, NULL);
struct args* exp_cc = args_init_from_string("cc -c");
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
+
+ create_file("foo.c", "");
+
+ g_config.set_run_second_cpp(false);
+ CHECK(cc_process_args(orig, &act_cpp, &act_extra, &act_cc));
+ CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp);
+ CHECK_ARGS_EQ_FREE12(exp_extra, act_extra);
+ CHECK_ARGS_EQ_FREE12(exp_cc, act_cc);
+
+ args_free(orig);
+}
+
+TEST(MF_should_not_be_added_if_run_second_cpp_is_true)
+{
+ struct args* orig = args_init_from_string("cc -c -MD foo.c -o foo.o");
+ struct args* exp_cpp = args_init_from_string("cc");
+ struct args* exp_extra = args_init_from_string("-MD");
+ struct args* exp_cc = args_init_from_string("cc -c -MD");
+ struct args* act_cpp = NULL;
+ struct args* act_extra = NULL;
+ struct args* act_cc = NULL;
+
create_file("foo.c", "");
CHECK(cc_process_args(orig, &act_cpp, &act_extra, &act_cc));
TEST(equal_sign_after_MF_should_be_removed)
{
struct args* orig = args_init_from_string("cc -c -MF=path foo.c -o foo.o");
- struct args* exp_cpp = args_init_from_string("cc -MFpath");
- struct args* exp_extra = args_init(0, NULL);
- struct args* exp_cc = args_init_from_string("cc -c");
+ struct args* exp_cpp = args_init_from_string("cc");
+ struct args* exp_extra = args_init_from_string("-MFpath");
+ struct args* exp_cc = args_init_from_string("cc -c -MFpath");
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
{
struct args* orig =
args_init_from_string("cc -c foo.c -o foo.o -MMD -MT bar -MFfoo.d");
- struct args* exp_cpp = args_init_from_string("cc -MMD -MT bar -MFfoo.d");
- struct args* exp_extra = args_init(0, NULL);
- struct args* exp_cc = args_init_from_string("cc -c");
+ struct args* exp_cpp = args_init_from_string("cc");
+ struct args* exp_extra = args_init_from_string("-MMD -MT bar -MFfoo.d");
+ struct args* exp_cc = args_init_from_string("cc -c -MMD -MT bar -MFfoo.d");
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
{
struct args* orig =
args_init_from_string("cc -c foo.c -o foo.o -MMD -MFfoo.d -MT foo -MTbar");
- struct args* exp_cpp =
- args_init_from_string("cc -MMD -MFfoo.d -MT foo -MTbar");
- struct args* exp_extra = args_init(0, NULL);
- struct args* exp_cc = args_init_from_string("cc -c");
+ struct args* exp_cpp = args_init_from_string("cc");
+ struct args* exp_extra =
+ args_init_from_string("-MMD -MFfoo.d -MT foo -MTbar");
+ struct args* exp_cc =
+ args_init_from_string("cc -c -MMD -MFfoo.d -MT foo -MTbar");
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
{
struct args* orig =
args_init_from_string("cc -c foo.c -o foo.o -MMD -MFfoo.d -MQ foo -MQbar");
- struct args* exp_cpp =
- args_init_from_string("cc -MMD -MFfoo.d -MQ foo -MQbar");
- struct args* exp_extra = args_init(0, NULL);
- struct args* exp_cc = args_init_from_string("cc -c");
+ struct args* exp_cpp = args_init_from_string("cc");
+ struct args* exp_extra =
+ args_init_from_string("-MMD -MFfoo.d -MQ foo -MQbar");
+ struct args* exp_cc =
+ args_init_from_string("cc -c -MMD -MFfoo.d -MQ foo -MQbar");
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
{
struct args* orig =
args_init_from_string("gcc -c -MD -MP -MFfoo.d -MQ foo.d foo.c");
- struct args* exp_cpp =
- args_init_from_string("gcc -MD -MP -MFfoo.d -MQ foo.d");
- struct args* exp_extra = args_init(0, NULL);
- struct args* exp_cc = args_init_from_string("gcc -c");
+ struct args* exp_cpp = args_init_from_string("gcc");
+ struct args* exp_extra = args_init_from_string("-MD -MP -MFfoo.d -MQ foo.d");
+ struct args* exp_cc =
+ args_init_from_string("gcc -c -MD -MP -MFfoo.d -MQ foo.d");
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
{
struct args* orig =
args_init_from_string("gcc -c -MD -MP -MFfoo.d -MT foo.d foo.c");
- struct args* exp_cpp =
- args_init_from_string("gcc -MD -MP -MFfoo.d -MT foo.d");
- struct args* exp_extra = args_init(0, NULL);
- struct args* exp_cc = args_init_from_string("gcc -c");
+ struct args* exp_cpp = args_init_from_string("gcc");
+ struct args* exp_extra = args_init_from_string("-MD -MP -MFfoo.d -MT foo.d");
+ struct args* exp_cc =
+ args_init_from_string("gcc -c -MD -MP -MFfoo.d -MT foo.d");
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
{
struct args* orig =
args_init_from_string("gcc -c -MD -MP -MFfoo.d -MQfoo.d foo.c");
- struct args* exp_cpp = args_init_from_string("gcc -MD -MP -MFfoo.d -MQfoo.d");
- struct args* exp_extra = args_init(0, NULL);
- struct args* exp_cc = args_init_from_string("gcc -c");
+ struct args* exp_cpp = args_init_from_string("gcc");
+ struct args* exp_extra = args_init_from_string("-MD -MP -MFfoo.d -MQfoo.d");
+ struct args* exp_cc =
+ args_init_from_string("gcc -c -MD -MP -MFfoo.d -MQfoo.d");
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;
{
struct args* orig =
args_init_from_string("gcc -c -MD -MP -MFfoo.d -MTfoo.d foo.c");
- struct args* exp_cpp = args_init_from_string("gcc -MD -MP -MFfoo.d -MTfoo.d");
- struct args* exp_extra = args_init(0, NULL);
- struct args* exp_cc = args_init_from_string("gcc -c");
+ struct args* exp_cpp = args_init_from_string("gcc");
+ struct args* exp_extra = args_init_from_string("-MD -MP -MFfoo.d -MTfoo.d");
+ struct args* exp_cc =
+ args_init_from_string("gcc -c -MD -MP -MFfoo.d -MTfoo.d");
struct args* act_cpp = NULL;
struct args* act_extra = NULL;
struct args* act_cc = NULL;