static void
init_hash_debug(Context& ctx,
Hash& hash,
- const char* obj_path,
+ string_view obj_path,
char type,
- const char* section_name,
+ string_view section_name,
FILE* debug_text_file)
{
if (!ctx.config.debug()) {
}
static GuessedCompiler
-guess_compiler(const char* path)
+guess_compiler(string_view path)
{
string_view name = Util::base_name(path);
GuessedCompiler result = GuessedCompiler::unknown;
// - Stores the paths and hashes of included files in the global variable
// g_included_files.
static bool
-process_preprocessed_file(Context& ctx, Hash& hash, const char* path, bool pump)
+process_preprocessed_file(Context& ctx,
+ Hash& hash,
+ const std::string& path,
+ bool pump)
{
std::string data;
try {
hash.hash_delimiter("cpp");
bool is_pump = ctx.guessed_compiler == GuessedCompiler::pump;
- if (!process_preprocessed_file(ctx, hash, stdout_path.c_str(), is_pump)) {
+ if (!process_preprocessed_file(ctx, hash, stdout_path, is_pump)) {
failed(STATS_ERROR);
}
hash_compiler(const Context& ctx,
Hash& hash,
const Stat& st,
- const char* path,
+ const std::string& path,
bool allow_command)
{
if (ctx.config.compiler_check() == "none") {
hash.hash(st.mtime());
} else if (Util::starts_with(ctx.config.compiler_check(), "string:")) {
hash.hash_delimiter("cc_hash");
- hash.hash(ctx.config.compiler_check().c_str() + strlen("string:"));
+ hash.hash(&ctx.config.compiler_check()[7]);
} else if (ctx.config.compiler_check() == "content" || !allow_command) {
hash.hash_delimiter("cc_content");
hash_binary_file(ctx, hash, path);
// Hash the host compiler(s) invoked by nvcc.
//
-// If ccbin_st and ccbin are set, they refer to a directory or compiler set
-// with -ccbin/--compiler-bindir. If they are NULL, the compilers are looked up
-// in PATH instead.
+// If `ccbin_st` and `ccbin` are set, they refer to a directory or compiler set
+// with -ccbin/--compiler-bindir. If `ccbin_st` is nullptr or `ccbin` is the
+// empty string, the compilers are looked up in PATH instead.
static void
hash_nvcc_host_compiler(const Context& ctx,
Hash& hash,
- const Stat* ccbin_st,
- const char* ccbin)
+ const Stat* ccbin_st = nullptr,
+ const std::string& ccbin = {})
{
// From <http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html>:
//
// Linux, clang and clang++ on Mac OS X, and cl.exe on Windows) found in
// the current execution search path will be used".
- if (!ccbin || ccbin_st->is_directory()) {
+ if (ccbin.empty() || !ccbin_st || ccbin_st->is_directory()) {
#if defined(__APPLE__)
const char* compilers[] = {"clang", "clang++"};
#elif defined(_WIN32)
const char* compilers[] = {"gcc", "g++"};
#endif
for (const char* compiler : compilers) {
- if (ccbin) {
+ if (!ccbin.empty()) {
std::string path = fmt::format("{}/{}", ccbin, compiler);
auto st = Stat::stat(path);
if (st) {
- hash_compiler(ctx, hash, st, path.c_str(), false);
+ hash_compiler(ctx, hash, st, path, false);
}
} else {
std::string path = find_executable(ctx, compiler, MYNAME);
}
// Hash information about the compiler.
- hash_compiler(ctx, hash, st, compiler_path.c_str(), true);
+ hash_compiler(ctx, hash, st, compiler_path, true);
// Also hash the compiler name as some compilers use hard links and behave
// differently depending on the real name.
const char* envvars[] = {
"LANG", "LC_ALL", "LC_CTYPE", "LC_MESSAGES", nullptr};
for (const char** p = envvars; *p; ++p) {
- char* v = getenv(*p);
+ const char* v = getenv(*p);
if (v) {
hash.hash_delimiter(*p);
hash.hash(v);
}
}
- const char* p = nullptr;
- if (Util::starts_with(args[i], "-specs=")) {
- p = args[i].c_str() + 7;
- } else if (Util::starts_with(args[i], "--specs=")) {
- p = args[i].c_str() + 8;
- }
-
- if (p) {
- auto st = Stat::stat(p, Stat::OnError::log);
+ if (Util::starts_with(args[i], "-specs=")
+ || Util::starts_with(args[i], "--specs=")) {
+ std::string path = args[i].substr(args[i].find('=') + 1);
+ auto st = Stat::stat(path, Stat::OnError::log);
if (st) {
// If given an explicit specs file, then hash that file, but don't
// include the path to it in the hash.
hash.hash_delimiter("specs");
- hash_compiler(ctx, hash, st, p, false);
+ hash_compiler(ctx, hash, st, path, false);
continue;
}
}
if (Util::starts_with(args[i], "-fplugin=")) {
- auto st = Stat::stat(args[i].c_str() + 9, Stat::OnError::log);
+ auto st = Stat::stat(&args[i][9], Stat::OnError::log);
if (st) {
hash.hash_delimiter("plugin");
- hash_compiler(ctx, hash, st, args[i].c_str() + 9, false);
+ hash_compiler(ctx, hash, st, &args[i][9], false);
continue;
}
}
auto st = Stat::stat(args[i + 3], Stat::OnError::log);
if (st) {
hash.hash_delimiter("plugin");
- hash_compiler(ctx, hash, st, args[i + 3].c_str(), false);
+ hash_compiler(ctx, hash, st, args[i + 3], false);
i += 3;
continue;
}
if (st) {
found_ccbin = true;
hash.hash_delimiter("ccbin");
- hash_nvcc_host_compiler(ctx, hash, &st, args[i + 1].c_str());
+ hash_nvcc_host_compiler(ctx, hash, &st, args[i + 1]);
i++;
continue;
}
}
if (!found_ccbin && ctx.args_info.actual_language == "cu") {
- hash_nvcc_host_compiler(ctx, hash, nullptr, nullptr);
+ hash_nvcc_host_compiler(ctx, hash);
}
// For profile generation (-fprofile(-instr)-generate[=path])
"OBJCPLUS_INCLUDE_PATH", // clang
nullptr};
for (const char** p = envvars; *p; ++p) {
- char* v = getenv(*p);
+ const char* v = getenv(*p);
if (v) {
hash.hash_delimiter(*p);
hash.hash(v);
static void
set_up_config(Config& config)
{
- char* p = getenv("CCACHE_CONFIGPATH");
+ const char* p = getenv("CCACHE_CONFIGPATH");
if (p) {
config.set_primary_config_path(p);
} else {
std::min(std::max(ctx.config.limit_multiple(), 0.0), 1.0));
MTR_BEGIN("main", "guess_compiler");
- ctx.guessed_compiler = guess_compiler(ctx.orig_args[0].c_str());
+ ctx.guessed_compiler = guess_compiler(ctx.orig_args[0]);
MTR_END("main", "guess_compiler");
// Arguments (except -E) to send to the preprocessor.
: nullptr;
Hash common_hash;
- init_hash_debug(ctx,
- common_hash,
- ctx.args_info.output_obj.c_str(),
- 'c',
- "COMMON",
- debug_text_file);
+ init_hash_debug(
+ ctx, common_hash, ctx.args_info.output_obj, 'c', "COMMON", debug_text_file);
MTR_BEGIN("hash", "common_hash");
hash_common_info(ctx, preprocessor_args, common_hash, ctx.args_info);
Hash direct_hash = common_hash;
init_hash_debug(ctx,
direct_hash,
- ctx.args_info.output_obj.c_str(),
+ ctx.args_info.output_obj,
'd',
"DIRECT MODE",
debug_text_file);
Hash cpp_hash = common_hash;
init_hash_debug(ctx,
cpp_hash,
- ctx.args_info.output_obj.c_str(),
+ ctx.args_info.output_obj,
'p',
"PREPROCESSOR MODE",
debug_text_file);