// compiler_only_args contains arguments that should only be passed to the
// compiler, not the preprocessor.
Args compiler_only_args;
+
+ // compiler_only_args_no_hash contains arguments that should only be passed to
+ // the compiler, not the preprocessor, and that also should not be part of the
+ // hash identifying the result.
+ Args compiler_only_args_no_hash;
};
bool
return true;
}
-// The compiler is invoked with the original arguments in the depend mode.
-// Collect extra arguments that should be added.
-void
-add_depend_mode_extra_original_args(Context& ctx, const std::string& arg)
-{
- if (ctx.config.depend_mode()) {
- ctx.args_info.depend_extra_args.push_back(arg);
- }
-}
-
optional<Statistic>
process_arg(Context& ctx,
Args& args,
if (args[i] == "-fcolor-diagnostics" || args[i] == "-fdiagnostics-color"
|| args[i] == "-fdiagnostics-color=always") {
state.color_diagnostics = ColorDiagnostics::always;
+ state.compiler_only_args_no_hash.push_back(args[i]);
return nullopt;
}
if (args[i] == "-fno-color-diagnostics" || args[i] == "-fno-diagnostics-color"
|| args[i] == "-fdiagnostics-color=never") {
state.color_diagnostics = ColorDiagnostics::never;
+ state.compiler_only_args_no_hash.push_back(args[i]);
return nullopt;
}
if (args[i] == "-fdiagnostics-color=auto") {
state.color_diagnostics = ColorDiagnostics::automatic;
+ state.compiler_only_args_no_hash.push_back(args[i]);
return nullopt;
}
state.color_diagnostics != ColorDiagnostics::automatic
? state.color_diagnostics == ColorDiagnostics::never
: !color_output_possible();
+
// Since output is redirected, compilers will not color their output by
// default, so force it explicitly.
+ nonstd::optional<std::string> diagnostics_color_arg;
if (ctx.guessed_compiler == GuessedCompiler::clang) {
if (args_info.actual_language != "assembler") {
- if (!config.run_second_cpp()) {
- state.cpp_args.push_back("-fcolor-diagnostics");
- }
- state.compiler_only_args.push_back("-fcolor-diagnostics");
- add_depend_mode_extra_original_args(ctx, "-fcolor-diagnostics");
+ diagnostics_color_arg = "-fcolor-diagnostics";
}
} else if (ctx.guessed_compiler == GuessedCompiler::gcc) {
- if (!config.run_second_cpp()) {
- state.cpp_args.push_back("-fdiagnostics-color");
- }
- state.compiler_only_args.push_back("-fdiagnostics-color");
- add_depend_mode_extra_original_args(ctx, "-fdiagnostics-color");
+ diagnostics_color_arg = "-fdiagnostics-color";
} else {
// Other compilers shouldn't output color, so no need to strip it.
args_info.strip_diagnostics_colors = false;
}
Args compiler_args = state.common_args;
+ compiler_args.push_back(state.compiler_only_args_no_hash);
compiler_args.push_back(state.compiler_only_args);
if (config.run_second_cpp()) {
extra_args_to_hash.push_back(state.dep_args);
}
+ if (diagnostics_color_arg) {
+ compiler_args.push_back(*diagnostics_color_arg);
+ if (!config.run_second_cpp()) {
+ // If we're compiling preprocessed code we're keeping any warnings from
+ // the preprocessor, so we need to make sure that they are in color.
+ preprocessor_args.push_back(*diagnostics_color_arg);
+ }
+ if (ctx.config.depend_mode()) {
+ // The compiler is invoked with the original arguments in the depend mode.
+ ctx.args_info.depend_extra_args.push_back(*diagnostics_color_arg);
+ }
+ }
+
return {preprocessor_args, extra_args_to_hash, compiler_args};
}
cat <<'EOF' >test_no_obj.c
int test_no_obj;
EOF
- cat <<'EOF' >prefix-remove.sh
+ cat <<'EOF' >no-object-prefix
#!/bin/sh
-"$@"
-[ x$2 = x-fcolor-diagnostics ] && shift
-[ x$2 = x-fdiagnostics-color ] && shift
-[ x$2 = x-std=gnu99 ] && shift
-[ x$3 = x-o ] && rm $4
+# Emulate no object file from the compiler.
EOF
- chmod +x prefix-remove.sh
- CCACHE_PREFIX=`pwd`/prefix-remove.sh $CCACHE_COMPILE -c test_no_obj.c
+ chmod +x no-object-prefix
+ CCACHE_PREFIX=$(pwd)/no-object-prefix $CCACHE_COMPILE -c test_no_obj.c
expect_stat 'compiler produced no output' 1
# -------------------------------------------------------------------------
cat <<'EOF' >test_empty_obj.c
int test_empty_obj;
EOF
- cat <<'EOF' >prefix-empty.sh
+ cat <<'EOF' >empty-object-prefix
#!/bin/sh
-"$@"
-[ x$2 = x-fcolor-diagnostics ] && shift
-[ x$2 = x-fdiagnostics-color ] && shift
-[ x$2 = x-std=gnu99 ] && shift
-[ x$3 = x-o ] && cp /dev/null $4
+# Emulate empty object file from the compiler.
+touch test_empty_obj.o
EOF
- chmod +x prefix-empty.sh
- CCACHE_PREFIX=`pwd`/prefix-empty.sh $CCACHE_COMPILE -c test_empty_obj.c
+ chmod +x empty-object-prefix
+ CCACHE_PREFIX=`pwd`/empty-object-prefix $CCACHE_COMPILE -c test_empty_obj.c
expect_stat 'compiler produced empty output' 1
# -------------------------------------------------------------------------