return nullopt;
}
- if (config.compiler_type() == CompilerType::gcc
- && (args[i] == "-fcolor-diagnostics"
- || args[i] == "-fno-color-diagnostics")) {
- // Special case: If a GCC compiler gets -f(no-)color-diagnostics we'll bail
- // out and just execute the compiler. The reason is that we don't include
- // -f(no-)color-diagnostics in the hash so there can be a false cache hit in
- // the following scenario:
- //
- // 1. ccache gcc -c example.c # adds a cache entry
- // 2. ccache gcc -c example.c -fcolor-diagnostics # unexpectedly succeeds
- return Statistic::unsupported_compiler_option;
- }
-
- // In the "-Xclang -fcolor-diagnostics" form, -Xclang is skipped and the
- // -fcolor-diagnostics argument which is passed to cc1 is handled below.
- if (args[i] == "-Xclang" && i + 1 < args.size()
- && args[i + 1] == "-fcolor-diagnostics") {
- state.compiler_only_args_no_hash.push_back(args[i]);
- ++i;
- }
-
- 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;
+ if (config.compiler_type() == CompilerType::gcc) {
+ if (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;
+ } else if (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;
+ } else if (args[i] == "-fdiagnostics-color=auto") {
+ state.color_diagnostics = ColorDiagnostics::automatic;
+ state.compiler_only_args_no_hash.push_back(args[i]);
+ return nullopt;
+ }
+ } else if (config.is_compiler_group_clang()) {
+ // In the "-Xclang -fcolor-diagnostics" form, -Xclang is skipped and the
+ // -fcolor-diagnostics argument which is passed to cc1 is handled below.
+ if (args[i] == "-Xclang" && i + 1 < args.size()
+ && args[i + 1] == "-fcolor-diagnostics") {
+ state.compiler_only_args_no_hash.push_back(args[i]);
+ ++i;
+ }
+ if (args[i] == "-fcolor-diagnostics") {
+ state.color_diagnostics = ColorDiagnostics::always;
+ state.compiler_only_args_no_hash.push_back(args[i]);
+ return nullopt;
+ } else if (args[i] == "-fno-color-diagnostics") {
+ state.color_diagnostics = ColorDiagnostics::never;
+ state.compiler_only_args_no_hash.push_back(args[i]);
+ return nullopt;
+ }
}
// GCC
if $CCACHE_COMPILE -fcolor-diagnostics -c test.c >&/dev/null; then
test_failed "-fcolor-diagnostics unexpectedly accepted by GCC"
fi
- expect_stat unsupported_compiler_option 1
+ expect_stat preprocessor_error 1
# ---------------------------------------------------------------------
TEST "-fcolor-diagnostics not accepted for GCC for cached result"
if ! $CCACHE_COMPILE -c test.c >&/dev/null; then
test_failed "unknown error compiling"
fi
-
if $CCACHE_COMPILE -fcolor-diagnostics -c test.c >&/dev/null; then
test_failed "-fcolor-diagnostics unexpectedly accepted by GCC"
fi
- expect_stat unsupported_compiler_option 1
+ expect_stat preprocessor_error 1
# ---------------------------------------------------------------------
TEST "-fcolor-diagnostics passed to underlying compiler for unknown compiler type"
generate_code 1 test.c
+ CCACHE_COMPILERTYPE=other $CCACHE_COMPILE -c test.c
+ expect_stat cache_miss 1
+
if CCACHE_COMPILERTYPE=other $CCACHE_COMPILE -fcolor-diagnostics -c test.c >&/dev/null; then
test_failed "-fcolor-diagnostics unexpectedly accepted by GCC"
fi
-
- # Verify that -fcolor-diagnostics was passed to the compiler for the
- # unknown compiler case, i.e. ccache did not exit early with
- # "unsupported compiler option".
- expect_stat compile_failed 1
+ expect_stat preprocessor_error 1
fi
if $COMPILER_TYPE_CLANG; then
-// Copyright (C) 2010-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2010-2022 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
{
TestContext test_context;
Context ctx;
+ ctx.config.set_compiler_type(CompilerType::clang);
+
const std::string common_args =
"-Xclang -fno-pch-timestamp"
" -Xclang unsupported";
" -Xclang -include-pth -Xclang pth_path2";
ctx.orig_args =
- Args::from_string("gcc -c foo.c " + common_args + " " + color_diag + " "
+ Args::from_string("clang -c foo.c " + common_args + " " + color_diag + " "
+ extra_args + " " + pch_pth_variants);
Util::write_file("foo.c", "");
const ProcessArgsResult result = process_args(ctx);
CHECK(result.preprocessor_args.to_string()
- == "gcc " + common_args + " " + pch_pth_variants);
+ == "clang " + common_args + " " + pch_pth_variants);
CHECK(result.extra_args_to_hash.to_string() == extra_args);
CHECK(result.compiler_args.to_string()
- == "gcc " + common_args + " " + color_diag + " " + extra_args + " "
- + pch_pth_variants + " -c");
+ == "clang " + common_args + " " + color_diag + " " + extra_args + " "
+ + pch_pth_variants + " -c -fcolor-diagnostics");
}
TEST_CASE("-x")