Files
Build-System/include/Void/Build/Snapshot/Snapshot.hpp
T
faumaray ab64147f9d
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
Implement VoidBuildSystem v1 (Plans 01-19) with VoidLibrary integration
2026-11-26 20:45:54 +03:00

88 lines
3.4 KiB
C++

#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <cstdint>
#include <filesystem>
#include <map>
#include <optional>
#include <string>
#include <vector>
namespace Void::Build::Snapshot {
enum class EntryKind { RegularFile, Symlink, Directory };
struct SnapshotEntry {
std::string logical_path;
EntryKind kind{EntryKind::RegularFile};
std::string sha256;
std::uint64_t size{0};
std::uint32_t mode{0644};
std::string symlink_target;
std::filesystem::path materialized_path;
};
struct DirectoryMembership {
std::string logical_dir;
std::vector<std::string> entries; // Sorted lexicographically.
};
// Tracks header/include search lookup order across include directories so that
// a newly created shadowing header or newly true __has_include invalidates consumers.
struct LookupGuard {
std::vector<std::string> search_roots;
std::string lookup_name;
int matched_root_index{-1}; // -1 = negative lookup (absent across all search_roots)
std::string matched_sha256;
};
struct InputSnapshot {
std::string snapshot_id;
std::filesystem::path project_root;
std::filesystem::path materialized_root;
std::int64_t reproducibility_epoch{0};
std::map<std::string, SnapshotEntry, std::less<>> entries;
std::map<std::string, DirectoryMembership, std::less<>> memberships;
std::vector<LookupGuard> lookup_guards;
};
struct SnapshotOptions {
std::filesystem::path project_root;
std::filesystem::path snapshot_store_dir;
std::vector<std::filesystem::path> allowed_external_roots;
std::vector<std::string> excluded_names{".git", ".vbs", "build", ".serena",
".cache", ".env", "keys", "WG.conf"};
std::int64_t reproducibility_epoch{0};
int max_revalidate_retries{5};
bool materialize{true};
};
// Captures explicit files, recursive search/include roots, and lookup guards into
// a content-verified immutable InputSnapshot. Never hardlinks editable sources;
// revalidates every captured byte and directory membership before sealing.
[[nodiscard]] Void::Result::Result<InputSnapshot, Void::Result::Error> capture_snapshot(
const SnapshotOptions &options, const std::vector<std::filesystem::path> &explicit_files,
const std::vector<std::filesystem::path> &directory_roots,
const std::vector<std::pair<std::vector<std::string>, std::string>> &lookup_queries = {});
// Re-checks a sealed snapshot against the live filesystem (content + membership +
// lookup guards + symlink targets), detecting same-size/same-mtime mutations.
[[nodiscard]] Void::Result::Result<bool, Void::Result::Error>
is_snapshot_fresh(const InputSnapshot &snapshot, const SnapshotOptions &options);
// Promotes a validated generated file into the immutable snapshot store with
// canonical metadata and returns its sealed SnapshotEntry.
[[nodiscard]] Void::Result::Result<SnapshotEntry, Void::Result::Error>
seal_generated_artifact(const std::filesystem::path &staged_file, std::string logical_path,
const std::filesystem::path &snapshot_store_dir,
std::int64_t reproducibility_epoch);
// Persists a sealed snapshot manifest atomically as UTF-8 JSON.
[[nodiscard]] Void::Result::Result<std::filesystem::path, Void::Result::Error>
write_snapshot_manifest(const InputSnapshot &snapshot,
const std::filesystem::path &snapshot_store_dir);
} // namespace Void::Build::Snapshot