96 lines
3.9 KiB
C++
96 lines
3.9 KiB
C++
#pragma once
|
|
|
|
#include <Void/Build.hpp>
|
|
#include <Void/Build/Package/Solver.hpp>
|
|
#include <Void/Build/Package/Toml.hpp>
|
|
#include <Void/Functional/Error.hpp>
|
|
#include <Void/Functional/Result.hpp>
|
|
|
|
#include <filesystem>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace Void::Build::Package {
|
|
|
|
inline constexpr int kLockfileSchemaVersion = 1;
|
|
|
|
struct LockedSourceEntry {
|
|
std::string alias;
|
|
std::string source_kind; // "git", "package", "path", "archive", "conan"
|
|
std::string registry_authority;
|
|
std::string package_name;
|
|
std::string version;
|
|
std::string location;
|
|
std::string revision;
|
|
std::string sha256;
|
|
std::string builder;
|
|
std::vector<std::string> features;
|
|
bool build_dependency{false};
|
|
std::optional<std::string> signature; // Ed25519 detached signature hex (package entries)
|
|
std::optional<std::string> public_key; // Signer public key hex (package entries)
|
|
};
|
|
|
|
struct LockContextRecord {
|
|
std::string context_key; // e.g. "debug:gcc:Linux:x86_64:target"
|
|
std::string profile_name;
|
|
std::string compiler;
|
|
std::string os;
|
|
std::string architecture;
|
|
std::string machine_role; // "target" or "build"
|
|
std::string declaration_fingerprint;
|
|
std::vector<LockedSourceEntry> entries;
|
|
};
|
|
|
|
struct LockfileDocument {
|
|
int schema_version{kLockfileSchemaVersion};
|
|
std::string revision_hash; // SHA-256 of canonical contexts payload.
|
|
std::map<std::string, LockContextRecord, std::less<>> contexts;
|
|
};
|
|
|
|
// Immutable lock payload pinned at the start of a build so concurrent updates never mix revisions.
|
|
struct PinnedLock {
|
|
std::string revision_hash;
|
|
std::string raw_json;
|
|
LockfileDocument document;
|
|
};
|
|
|
|
// Computes canonical declaration fingerprint for a profile/role context (used to detect
|
|
// incompatible manifest/option changes before running any build action!).
|
|
[[nodiscard]] std::string
|
|
compute_declaration_fingerprint(const ProfileContext &profile, std::string_view machine_role,
|
|
const std::vector<NormalizedDependency> &declarations);
|
|
|
|
[[nodiscard]] std::string make_lock_context_key(const ProfileContext &profile,
|
|
std::string_view machine_role);
|
|
|
|
// Serializes and parses vbs.lock deterministically (never stores credentials!).
|
|
[[nodiscard]] std::string serialize_lockfile(const LockfileDocument &doc);
|
|
[[nodiscard]] Void::Result::Result<LockfileDocument, Void::Result::Error>
|
|
parse_lockfile(std::string_view json_text);
|
|
|
|
// Reads and pins one immutable lockfile revision from disk (returns nullopt if absent).
|
|
[[nodiscard]] Void::Result::Result<std::optional<PinnedLock>, Void::Result::Error>
|
|
load_pinned_lock(const std::filesystem::path &lock_path);
|
|
|
|
// Validates an existing pinned lock against current declarations for `context_key`.
|
|
// Fails explicitly if declarations/options/platform facts are incompatible (requires
|
|
// resolve/update).
|
|
[[nodiscard]] Void::Result::Result<const LockContextRecord *, Void::Result::Error>
|
|
validate_locked_context(const LockfileDocument &doc, std::string_view context_key,
|
|
std::string_view expected_declaration_fingerprint);
|
|
|
|
// Atomic CAS lockfile publication (D-025 / Plan 11):
|
|
// Acquires short project mutex (`vbs.lock.mutex`), compares on-disk revision hash against
|
|
// `expected_base_revision` (empty if creating a new lock), merges `updated_context` without
|
|
// discarding other profiles' contexts, and atomically replaces `vbs.lock`.
|
|
// Fails with SystemErrorCode::busy on a competing revision conflict so caller can re-resolve/retry!
|
|
[[nodiscard]] Void::Result::Result<PinnedLock, Void::Result::Error>
|
|
publish_lock_context_cas(const std::filesystem::path &lock_path,
|
|
std::string_view expected_base_revision,
|
|
const LockContextRecord &updated_context, bool locked_mode = false);
|
|
|
|
} // namespace Void::Build::Package
|