// The name of the cpp stderr file.
std::string cpp_stderr;
- // Compiler guessing is currently only based on the compiler name, so nothing
- // should hard-depend on it if possible.
- GuessedCompiler guessed_compiler = GuessedCompiler::unknown;
+ // The compiler type is by default a guess based on the compiler name, so
+ // nothing should hard-depend on it if possible.
+ CompilerType compiler_type = CompilerType::unknown;
// The .gch/.pch/.pth file used for compilation.
std::string included_pch_file;
// Clang stores the mtime of the included files in the precompiled header,
// and will error out if that header is later used without rebuilding.
- if ((ctx.guessed_compiler == GuessedCompiler::clang
- || ctx.guessed_compiler == GuessedCompiler::unknown)
+ if ((ctx.compiler_type == CompilerType::clang
+ || ctx.compiler_type == CompilerType::unknown)
&& ctx.args_info.output_is_precompiled_header
&& !ctx.args_info.fno_pch_timestamp && fi.mtime != fs.mtime) {
LOG("Precompiled header includes {}, which has a new mtime", path);
new_profile_path = arg.substr(arg.find('=') + 1);
} else if (arg == "-fprofile-generate" || arg == "-fprofile-instr-generate") {
ctx.args_info.profile_generate = true;
- if (ctx.guessed_compiler == GuessedCompiler::clang) {
+ if (ctx.compiler_type == CompilerType::clang) {
new_profile_path = ".";
} else {
// GCC uses $PWD/$(basename $obj).
}
// Handle cuda "-optf" and "--options-file" argument.
- if (ctx.guessed_compiler == GuessedCompiler::nvcc
+ if (ctx.compiler_type == CompilerType::nvcc
&& (args[i] == "-optf" || args[i] == "--options-file")) {
if (i == args.size() - 1) {
LOG("Expected argument after {}", args[i]);
if (compopt_affects_compiler_output(args[i])) {
state.compiler_only_args.push_back(args[i]);
if (compopt_takes_arg(args[i])
- || (ctx.guessed_compiler == GuessedCompiler::nvcc
- && args[i] == "-Werror")) {
+ || (ctx.compiler_type == CompilerType::nvcc && args[i] == "-Werror")) {
if (i == args.size() - 1) {
LOG("Missing argument to {}", args[i]);
return Statistic::bad_compiler_arguments;
// when using nvcc with separable compilation, -dc implies -c
if ((args[i] == "-dc" || args[i] == "--device-c")
- && ctx.guessed_compiler == GuessedCompiler::nvcc) {
+ && ctx.compiler_type == CompilerType::nvcc) {
state.found_dc_opt = true;
return nullopt;
}
// Alternate form of -o with no space. Nvcc does not support this.
if (Util::starts_with(args[i], "-o")
- && ctx.guessed_compiler != GuessedCompiler::nvcc) {
+ && ctx.compiler_type != CompilerType::nvcc) {
args_info.output_obj =
Util::make_relative_path(ctx, string_view(args[i]).substr(2));
return nullopt;
// 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 (ctx.compiler_type == CompilerType::clang) {
// Don't pass -fcolor-diagnostics when compiling assembler to avoid an
// "argument unused during compilation" warning.
if (args_info.actual_language != "assembler") {
diagnostics_color_arg = "-fcolor-diagnostics";
}
- } else if (ctx.guessed_compiler == GuessedCompiler::gcc) {
+ } else if (ctx.compiler_type == CompilerType::gcc) {
diagnostics_color_arg = "-fdiagnostics-color";
} else {
// Other compilers shouldn't output color, so no need to strip it.
}
}
-GuessedCompiler
+CompilerType
guess_compiler(string_view path)
{
std::string compiler_path(path);
const string_view name = Util::base_name(compiler_path);
if (name.find("clang") != nonstd::string_view::npos) {
- return GuessedCompiler::clang;
+ return CompilerType::clang;
} else if (name.find("gcc") != nonstd::string_view::npos
|| name.find("g++") != nonstd::string_view::npos) {
- return GuessedCompiler::gcc;
+ return CompilerType::gcc;
} else if (name.find("nvcc") != nonstd::string_view::npos) {
- return GuessedCompiler::nvcc;
+ return CompilerType::nvcc;
} else if (name == "pump" || name == "distcc-pump") {
- return GuessedCompiler::pump;
+ return CompilerType::pump;
} else {
- return GuessedCompiler::unknown;
+ return CompilerType::unknown;
}
}
{
UmaskScope umask_scope(ctx.original_umask);
- if (ctx.diagnostics_color_failed
- && ctx.guessed_compiler == GuessedCompiler::gcc) {
+ if (ctx.diagnostics_color_failed && ctx.compiler_type == CompilerType::gcc) {
args.erase_last("-fdiagnostics-color");
}
int status = execute(args.to_argv().data(),
std::move(tmp_stderr.fd),
&ctx.compiler_pid);
if (status != 0 && !ctx.diagnostics_color_failed
- && ctx.guessed_compiler == GuessedCompiler::gcc) {
+ && ctx.compiler_type == CompilerType::gcc) {
auto errors = Util::read_file(tmp_stderr.path);
if (errors.find("unrecognized command line option") != std::string::npos
&& errors.find("-fdiagnostics-color") != std::string::npos) {
// distcc-pump outputs lines like this:
// __________Using # distcc servers in pump mode
- if (st.size() != 0 && ctx.guessed_compiler != GuessedCompiler::pump) {
+ if (st.size() != 0 && ctx.compiler_type != CompilerType::pump) {
LOG_RAW("Compiler produced stdout");
throw Failure(Statistic::compiler_produced_stdout);
}
}
hash.hash_delimiter("cpp");
- bool is_pump = ctx.guessed_compiler == GuessedCompiler::pump;
+ bool is_pump = ctx.compiler_type == CompilerType::pump;
if (!process_preprocessed_file(ctx, hash, stdout_path, is_pump)) {
throw Failure(Statistic::internal_error);
}
}
// Possibly hash GCC_COLORS (for color diagnostics).
- if (ctx.guessed_compiler == GuessedCompiler::gcc) {
+ if (ctx.compiler_type == CompilerType::gcc) {
const char* gcc_colors = getenv("GCC_COLORS");
if (gcc_colors) {
hash.hash_delimiter("gcccolors");
// clang will emit warnings for unused linker flags, so we shouldn't skip
// those arguments.
- int is_clang = ctx.guessed_compiler == GuessedCompiler::clang
- || ctx.guessed_compiler == GuessedCompiler::unknown;
+ int is_clang = ctx.compiler_type == CompilerType::clang
+ || ctx.compiler_type == CompilerType::unknown;
// First the arguments.
for (size_t i = 1; i < args.size(); i++) {
//
// file 'foo.h' has been modified since the precompiled header 'foo.pch'
// was built
- if ((ctx.guessed_compiler == GuessedCompiler::clang
- || ctx.guessed_compiler == GuessedCompiler::unknown)
+ if ((ctx.compiler_type == CompilerType::clang
+ || ctx.compiler_type == CompilerType::unknown)
&& ctx.args_info.output_is_precompiled_header
&& !ctx.args_info.fno_pch_timestamp && mode == FromCacheCallMode::cpp) {
LOG_RAW("Not considering cached precompiled header in preprocessor mode");
}
static std::string
-guessed_compiler_to_string(GuessedCompiler guessed_compiler)
+compiler_type_to_string(CompilerType compiler_type)
{
#define CASE(type) \
- case GuessedCompiler::type: \
+ case CompilerType::type: \
return #type
- switch (guessed_compiler) {
+ switch (compiler_type) {
CASE(clang);
CASE(gcc);
CASE(nvcc);
LOG("Apparent working directory: {}", ctx.apparent_cwd);
}
- MTR_BEGIN("main", "guess_compiler");
- ctx.guessed_compiler = guess_compiler(ctx.orig_args[0]);
- LOG("Guessed compiler: {}", guessed_compiler_to_string(ctx.guessed_compiler));
- MTR_END("main", "guess_compiler");
+ ctx.compiler_type = guess_compiler(ctx.orig_args[0]);
+ LOG("Compiler type: {}", compiler_type_to_string(ctx.compiler_type));
MTR_BEGIN("main", "process_args");
ProcessArgsResult processed = process_args(ctx);
extern const char CCACHE_VERSION[];
-enum class GuessedCompiler { clang, gcc, nvcc, pump, unknown };
+enum class CompilerType { clang, gcc, nvcc, pump, unknown };
const uint32_t SLOPPY_INCLUDE_FILE_MTIME = 1 << 0;
const uint32_t SLOPPY_INCLUDE_FILE_CTIME = 1 << 1;
// Tested by unit tests.
void find_compiler(Context& ctx,
const FindExecutableFunction& find_executable_function);
-GuessedCompiler guess_compiler(nonstd::string_view path);
+CompilerType guess_compiler(nonstd::string_view path);
nonstd::optional<std::string>
rewrite_dep_file_paths(const Context& ctx, const std::string& file_content);
{
TestContext test_context;
Context ctx;
- ctx.guessed_compiler = GuessedCompiler::nvcc;
+ ctx.compiler_type = CompilerType::nvcc;
ctx.orig_args = Args::from_string("nvcc -optf foo.optf,bar.optf");
Util::write_file("foo.c", "");
Util::write_file("foo.optf", "-c foo.c -g -Wall -o");
SUBCASE("Compiler not in file system")
{
- CHECK(guess_compiler("/test/prefix/clang") == GuessedCompiler::clang);
- CHECK(guess_compiler("/test/prefix/clang-3.8") == GuessedCompiler::clang);
- CHECK(guess_compiler("/test/prefix/clang++") == GuessedCompiler::clang);
- CHECK(guess_compiler("/test/prefix/clang++-10") == GuessedCompiler::clang);
-
- CHECK(guess_compiler("/test/prefix/gcc") == GuessedCompiler::gcc);
- CHECK(guess_compiler("/test/prefix/gcc-4.8") == GuessedCompiler::gcc);
- CHECK(guess_compiler("/test/prefix/g++") == GuessedCompiler::gcc);
- CHECK(guess_compiler("/test/prefix/g++-9") == GuessedCompiler::gcc);
+ CHECK(guess_compiler("/test/prefix/clang") == CompilerType::clang);
+ CHECK(guess_compiler("/test/prefix/clang-3.8") == CompilerType::clang);
+ CHECK(guess_compiler("/test/prefix/clang++") == CompilerType::clang);
+ CHECK(guess_compiler("/test/prefix/clang++-10") == CompilerType::clang);
+
+ CHECK(guess_compiler("/test/prefix/gcc") == CompilerType::gcc);
+ CHECK(guess_compiler("/test/prefix/gcc-4.8") == CompilerType::gcc);
+ CHECK(guess_compiler("/test/prefix/g++") == CompilerType::gcc);
+ CHECK(guess_compiler("/test/prefix/g++-9") == CompilerType::gcc);
CHECK(guess_compiler("/test/prefix/x86_64-w64-mingw32-gcc-posix")
- == GuessedCompiler::gcc);
+ == CompilerType::gcc);
- CHECK(guess_compiler("/test/prefix/nvcc") == GuessedCompiler::nvcc);
- CHECK(guess_compiler("/test/prefix/nvcc-10.1.243")
- == GuessedCompiler::nvcc);
+ CHECK(guess_compiler("/test/prefix/nvcc") == CompilerType::nvcc);
+ CHECK(guess_compiler("/test/prefix/nvcc-10.1.243") == CompilerType::nvcc);
- CHECK(guess_compiler("/test/prefix/pump") == GuessedCompiler::pump);
- CHECK(guess_compiler("/test/prefix/distcc-pump") == GuessedCompiler::pump);
+ CHECK(guess_compiler("/test/prefix/pump") == CompilerType::pump);
+ CHECK(guess_compiler("/test/prefix/distcc-pump") == CompilerType::pump);
- CHECK(guess_compiler("/test/prefix/x") == GuessedCompiler::unknown);
- CHECK(guess_compiler("/test/prefix/cc") == GuessedCompiler::unknown);
- CHECK(guess_compiler("/test/prefix/c++") == GuessedCompiler::unknown);
+ CHECK(guess_compiler("/test/prefix/x") == CompilerType::unknown);
+ CHECK(guess_compiler("/test/prefix/cc") == CompilerType::unknown);
+ CHECK(guess_compiler("/test/prefix/c++") == CompilerType::unknown);
}
#ifndef _WIN32
const auto cc = FMT("{}/cc", cwd);
CHECK(symlink("intermediate", cc.c_str()) == 0);
- CHECK(guess_compiler(cc) == GuessedCompiler::gcc);
+ CHECK(guess_compiler(cc) == CompilerType::gcc);
}
#endif
}