#pragma once
+#include <ccache/util/PathString.hpp>
+#include <ccache/util/conversion.hpp>
+
#include <blake3/blake3.h>
#include <nonstd/span.hpp>
#include <tl/expected.hpp>
#include <array>
#include <cstdint>
#include <cstdio>
+#include <filesystem>
#include <string>
#include <string_view>
// input file, plus a final newline character.
Hash& hash(nonstd::span<const uint8_t> data);
Hash& hash(const char* data, size_t size);
+ Hash& hash(const char* data);
Hash& hash(std::string_view data);
+ Hash& hash(const std::string& data);
+ Hash& hash(const std::filesystem::path& data);
// Add an integer to the hash.
//
void add_debug_text(nonstd::span<const uint8_t> text);
void add_debug_text(std::string_view text);
};
+
+inline Hash&
+Hash::hash(const char* data, size_t size)
+{
+ hash(util::to_span({data, size}));
+ return *this;
+}
+
+inline Hash&
+Hash::hash(const char* data)
+{
+ hash(std::string_view(data));
+ return *this;
+}
+
+inline Hash&
+Hash::hash(std::string_view data)
+{
+ hash(util::to_span(data));
+ return *this;
+}
+
+inline Hash&
+Hash::hash(const std::string& data)
+{
+ hash(std::string_view(data));
+ return *this;
+}
+
+inline Hash&
+Hash::hash(const std::filesystem::path& path)
+{
+ hash(util::PathString(path).str());
+ return *this;
+}
}
if (inc_path != ctx.apparent_cwd || ctx.config.hash_dir()) {
- hash.hash(pstr(inc_path).str());
+ hash.hash(inc_path);
}
TRY(remember_include_file(ctx, inc_path, hash, system, nullptr));
&& !ctx.args_info.generating_pch) {
fs::path pch_path =
core::make_relative_path(ctx, ctx.args_info.included_pch_file);
- hash.hash(pstr(pch_path).str());
+ hash.hash(pch_path);
TRY(remember_include_file(ctx, pstr(pch_path), hash, false, nullptr));
}
&& !ctx.args_info.generating_pch) {
fs::path pch_path =
core::make_relative_path(ctx, ctx.args_info.included_pch_file);
- hash.hash(pstr(pch_path).str());
+ hash.hash(pch_path);
TRY(remember_include_file(ctx, pstr(pch_path), hash, false, nullptr));
}
// Also hash the compiler name as some compilers use hard links and behave
// differently depending on the real name.
hash.hash_delimiter("cc_name");
- hash.hash(pstr(fs::path(args[0]).filename()).str());
+ hash.hash(fs::path(args[0]).filename());
// Hash variables that may affect the compilation.
const char* always_hash_env_vars[] = {
// the directory in the hash for now.
LOG_RAW("Hashing apparent CWD due to generating a .gcno file");
hash.hash_delimiter("CWD in .gcno");
- hash.hash(pstr(ctx.apparent_cwd).str());
+ hash.hash(ctx.apparent_cwd);
}
// Possibly hash the coverage data file path.
if (processed.hash_actual_cwd) {
common_hash.hash_delimiter("actual_cwd");
- common_hash.hash(pstr(ctx.actual_cwd).str());
+ common_hash.hash(ctx.actual_cwd);
}
// Try to find the hash using the manifest.