return true;
}
- std::string new_profile_path;
+ std::filesystem::path new_profile_path;
bool new_profile_use = false;
if (util::starts_with(arg, "-fprofile-dir=")) {
new_profile_path = ".";
} else {
// GCC uses $PWD/$(basename $obj).
- new_profile_path = util::pstr(ctx.apparent_cwd);
+ new_profile_path = ctx.apparent_cwd;
}
} else if (util::starts_with(arg, "-fprofile-generate=")
|| util::starts_with(arg, "-fprofile-instr-generate=")) {
}
if (args_info.profile_path.empty()) {
- args_info.profile_path = util::pstr(ctx.apparent_cwd);
+ args_info.profile_path = ctx.apparent_cwd;
}
if (!state.explicit_language.empty() && state.explicit_language == "none") {
// Possibly hash the coverage data file path.
if (ctx.args_info.generating_coverage && ctx.args_info.profile_arcs) {
- std::string dir;
+ fs::path dir;
if (!ctx.args_info.profile_path.empty()) {
dir = ctx.args_info.profile_path;
} else {
const auto output_dir = ctx.args_info.output_obj.parent_path();
- dir = fs::canonical(output_dir).value_or(output_dir).string();
+ dir = fs::canonical(output_dir).value_or(output_dir);
}
- std::string gcda_path =
- FMT("{}/{}.gcda", dir, ctx.args_info.output_obj.stem());
+ fs::path gcda_path = dir / FMT("{}.gcda", ctx.args_info.output_obj.stem());
LOG("Hashing coverage path {}", gcda_path);
hash.hash_delimiter("gcda");
hash.hash(gcda_path);
static bool
hash_profile_data_file(const Context& ctx, Hash& hash)
{
- const std::string& profile_path = ctx.args_info.profile_path;
+ const fs::path& profile_path = ctx.args_info.profile_path;
const std::string base_name =
util::pstr(util::with_extension(ctx.args_info.output_obj, ""));
std::string hashified_cwd = util::pstr(ctx.apparent_cwd);
std::replace(hashified_cwd.begin(), hashified_cwd.end(), '/', '#');
- std::vector<std::string> paths_to_try{
+ std::vector<fs::path> paths_to_try{
// -fprofile-use[=dir]/-fbranch-probabilities (GCC <9)
- FMT("{}/{}.gcda", profile_path, base_name),
+ profile_path / FMT("{}.gcda", base_name),
// -fprofile-use[=dir]/-fbranch-probabilities (GCC >=9)
- FMT("{}/{}#{}.gcda", profile_path, hashified_cwd, base_name),
+ profile_path / FMT("{}#{}.gcda", hashified_cwd, base_name),
// -fprofile(-instr|-sample)-use=file (Clang), -fauto-profile=file (GCC >=5)
profile_path,
// -fprofile(-instr|-sample)-use=dir (Clang)
- FMT("{}/default.profdata", profile_path),
+ profile_path / "default.profdata",
// -fauto-profile (GCC >=5)
"fbdata.afdo", // -fprofile-dir is not used
};
bool found = false;
- for (const std::string& p : paths_to_try) {
+ for (const fs::path& p : paths_to_try) {
LOG("Checking for profile data file {}", p);
if (DirEntry(p).is_regular_file()) {
LOG("Adding profile data {} to the hash", p);
// For a relative profile directory D the compiler stores $PWD/D as part of
// the profile filename so we need to include the same information in the
// hash.
- const std::string profile_path =
- fs::path(ctx.args_info.profile_path).is_absolute()
+ const fs::path profile_path =
+ ctx.args_info.profile_path.is_absolute()
? ctx.args_info.profile_path
- : FMT("{}/{}", ctx.apparent_cwd, ctx.args_info.profile_path);
+ : ctx.apparent_cwd / ctx.args_info.profile_path;
LOG("Adding profile directory {} to our hash", profile_path);
hash.hash_delimiter("-fprofile-dir");
hash.hash(profile_path);