Hash.cpp
Lockfile.cpp
Logging.cpp
+ Manifest.cpp
MiniTrace.cpp
NullCompressor.cpp
NullDecompressor.cpp
execute.cpp
hashutil.cpp
language.cpp
- manifest.cpp
stats.cpp
version.cpp)
// this program; if not, write to the Free Software Foundation, Inc., 51
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#include "manifest.hpp"
+#include "Manifest.hpp"
#include "AtomicFile.hpp"
#include "CacheEntryReader.hpp"
using nonstd::nullopt;
using nonstd::optional;
-const uint8_t k_manifest_magic[4] = {'c', 'C', 'm', 'F'};
-const uint8_t k_manifest_version = 2;
const uint32_t k_max_manifest_entries = 100;
const uint32_t k_max_manifest_file_info_entries = 10000;
} // namespace std
+namespace {
+
struct ResultEntry
{
// Indexes to file_infos.
int64_t ctime;
};
-static std::unique_ptr<ManifestData>
+std::unique_ptr<ManifestData>
read_manifest(const std::string& path, FILE* dump_stream = nullptr)
{
File file(path, "rb");
return {};
}
- CacheEntryReader reader(file.get(), k_manifest_magic, k_manifest_version);
+ CacheEntryReader reader(file.get(), Manifest::k_magic, Manifest::k_version);
if (dump_stream) {
reader.dump_header(dump_stream);
return mf;
}
-static bool
+bool
write_manifest(const Config& config,
const std::string& path,
const ManifestData& mf)
AtomicFile atomic_manifest_file(path, AtomicFile::Mode::binary);
CacheEntryWriter writer(atomic_manifest_file.stream(),
- k_manifest_magic,
- k_manifest_version,
+ Manifest::k_magic,
+ Manifest::k_version,
Compression::type_from_config(config),
Compression::level_from_config(config),
payload_size);
return true;
}
-static bool
+bool
verify_result(const Context& ctx,
const ManifestData& mf,
const ResultEntry& result,
return true;
}
+} // namespace
+
+namespace Manifest {
+
+const uint8_t k_magic[4] = {'c', 'C', 'm', 'F'};
+const uint8_t k_version = 2;
+
// Try to get the result name from a manifest file. Returns nullopt on failure.
optional<Digest>
-manifest_get(const Context& ctx, const std::string& path)
+get(const Context& ctx, const std::string& path)
{
std::unique_ptr<ManifestData> mf;
try {
// Put the result name into a manifest file given a set of included files.
// Returns true on success, otherwise false.
bool
-manifest_put(const Config& config,
- const std::string& path,
- const Digest& result_name,
- const std::unordered_map<std::string, Digest>& included_files,
+put(const Config& config,
+ const std::string& path,
+ const Digest& result_name,
+ const std::unordered_map<std::string, Digest>& included_files,
- time_t time_of_compilation,
- bool save_timestamp)
+ time_t time_of_compilation,
+ bool save_timestamp)
{
// We don't bother to acquire a lock when writing the manifest to disk. A
// race between two processes will only result in one lost entry, which is
}
bool
-manifest_dump(const std::string& path, FILE* stream)
+dump(const std::string& path, FILE* stream)
{
std::unique_ptr<ManifestData> mf;
try {
return true;
}
+
+} // namespace Manifest
class Context;
class Digest;
-extern const uint8_t k_manifest_magic[4];
-extern const uint8_t k_manifest_version;
-
-nonstd::optional<Digest> manifest_get(const Context& ctx,
- const std::string& path);
-bool manifest_put(const Config& config,
- const std::string& path,
- const Digest& result_name,
- const std::unordered_map<std::string, Digest>& included_files,
- time_t time_of_compilation,
- bool save_timestamp);
-bool manifest_dump(const std::string& path, FILE* stream);
+namespace Manifest {
+
+extern const uint8_t k_magic[4];
+extern const uint8_t k_version;
+
+nonstd::optional<Digest> get(const Context& ctx, const std::string& path);
+bool put(const Config& config,
+ const std::string& path,
+ const Digest& result_name,
+ const std::unordered_map<std::string, Digest>& included_files,
+ time_t time_of_compilation,
+ bool save_timestamp);
+bool dump(const std::string& path, FILE* stream);
+
+} // namespace Manifest
#include "FormatNonstdStringView.hpp"
#include "Hash.hpp"
#include "Logging.hpp"
+#include "Manifest.hpp"
#include "MiniTrace.hpp"
#include "ProgressBar.hpp"
#include "Result.hpp"
#include "execute.hpp"
#include "hashutil.hpp"
#include "language.hpp"
-#include "manifest.hpp"
#include "stats.hpp"
#include "third_party/fmt/core.h"
MTR_BEGIN("manifest", "manifest_put");
log("Adding result name to {}", ctx.manifest_path());
- if (!manifest_put(ctx.config,
- ctx.manifest_path(),
- ctx.result_name(),
- ctx.included_files,
- ctx.time_of_compilation,
- save_timestamp)) {
+ if (!Manifest::put(ctx.config,
+ ctx.manifest_path(),
+ ctx.result_name(),
+ ctx.included_files,
+ ctx.time_of_compilation,
+ save_timestamp)) {
log("Failed to add result name to {}", ctx.manifest_path());
} else {
auto st = Stat::stat(ctx.manifest_path(), Stat::OnError::log);
if (direct_mode) {
hash.hash_delimiter("manifest version");
- hash.hash(k_manifest_version);
+ hash.hash(Manifest::k_version);
}
// clang will emit warnings for unused linker flags, so we shouldn't skip
log("Looking for result name in {}", ctx.manifest_path());
MTR_BEGIN("manifest", "manifest_get");
- result_name = manifest_get(ctx, ctx.manifest_path());
+ result_name = Manifest::get(ctx, ctx.manifest_path());
MTR_END("manifest", "manifest_get");
if (result_name) {
log("Got result name from manifest");
}
case DUMP_MANIFEST:
- return manifest_dump(arg, stdout) ? 0 : 1;
+ return Manifest::dump(arg, stdout) ? 0 : 1;
case DUMP_RESULT: {
ResultDumper result_dumper(stdout);
#include "Context.hpp"
#include "File.hpp"
#include "Logging.hpp"
+#include "Manifest.hpp"
#include "Result.hpp"
#include "StdMakeUnique.hpp"
#include "ThreadPool.hpp"
#include "ZstdCompressor.hpp"
-#include "manifest.hpp"
#include "stats.hpp"
#include "third_party/fmt/core.h"
case CacheFile::Type::manifest:
return std::make_unique<CacheEntryReader>(
- stream, k_manifest_magic, k_manifest_version);
+ stream, Manifest::k_magic, Manifest::k_version);
case CacheFile::Type::unknown:
assert(false); // Handled at function entry.