feat(install): generate RPM packages
This commit is contained in:
1 parent
2b80718f98
commit
3198b32f2b
7 files changed
+365
-82
No files matched your search
@@ -308,6 +308,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
|
||||
|
||||
- **Wave 107 (CI Workflow Groundwork & RPM Prototype Finding)**: `.github/workflows/ci.yml` gained a sanitizer job (ASan+UBSan configure/build, core-safe suites) and a MinGW+Wine job running the Windows-target regression test, and the formatting job now covers `sdk/`, nested platform dirs, `registry/cli/` and all recipes. The workflow remains a template that has never run on real runners. An RPM prototype (validated with `rpm` 6.1 from `dev cpp-gcc -p rpm`) showed that RPM 6.1 rejects hand-built headers unless the signature-region conventions are exact, so the native RPM generator is deferred rather than shipped unverified.
|
||||
|
||||
- **Wave 108 (Native RPM Generator)**: `vbs install --archive FILE --archive-format rpm` writes a real RPM (lead, signature header with header SHA-256, main header with name/version/release/summary/description/build/size/license/group/OS/arch/file metadata/payload tags, and an uncompressed newc cpio payload). Validated with rpm 6.1: `rpm -qip`, `rpm -qlp` and `rpm2cpio | cpio -it` all accept the package; the install test asserts the lead/header magic and cpio payload markers.
|
||||
|
||||
## Remaining future scope
|
||||
|
||||
- **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order.
|
||||
|
||||
@@ -111,4 +111,5 @@ Base HEAD: `fe0d1a6`
|
||||
| Wave 105 (Sanitizer groundwork) | ASan+UBSan build runs core tests clean; found and filed Void/Library#62 (Argparse aliasing UAF) with a de-aliasing workaround | COMPLETE & VERIFIED (core 7/7 under ASan; normal CTest 8/8) | `src/Main.cpp`, `docs/agent-workflow/VERIFICATION.md`, Void/Library#62 |
|
||||
| Wave 106 (Parser fuzzing) | Deterministic mutation fuzz test over TOML/JSON/lockfile/tar parsers with seed sanity checks; ASan-clean | COMPLETE & VERIFIED (normal build and ASan+UBSan) | `tests/CoreEngineTests.cpp`, docs |
|
||||
| Wave 107 (CI groundwork + RPM finding) | Sanitizer and MinGW/Wine CI jobs added to the template; RPM prototype investigated with real rpm tooling and deferred | PARTIAL: CI template updated (unverified on runners), RPM generator deferred with recorded evidence | `.github/workflows/ci.yml`, `docs/agent-workflow/STATE.md` |
|
||||
| Wave 108 (Native RPM generator) | `--archive-format rpm`: lead + signature/main headers + uncompressed cpio payload; validated with rpm 6.1 | COMPLETE & VERIFIED (rpm -qip/-qlp/rpm2cpio accept it; full CTest 8/8) | `src/Install/Installer.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs |
|
||||
| Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) |
|
||||
@@ -1512,6 +1512,20 @@ ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 \
|
||||
reports.
|
||||
- Seed sanity assertions ensure the unmutated inputs still parse.
|
||||
|
||||
## Native RPM Generator (GCC 16.2, pin `0002e74`)
|
||||
|
||||
```sh
|
||||
vbs install --project <proj> --build-dir <build> --prefix <prefix> \
|
||||
--package-name CliHiPkg --archive cli_hi.rpm --archive-format rpm
|
||||
dev cpp-gcc -p rpm -c sh -c 'rpm --dbpath <db> -qip cli_hi.rpm; rpm --dbpath <db> -qlp cli_hi.rpm; rpm2cpio cli_hi.rpm | cpio -it'
|
||||
```
|
||||
|
||||
Observed with rpm 6.1.0:
|
||||
- `rpm -qip`: `Name: CliHiPkg`, `Version: 0.1.0`, `Release: 1`, `Architecture: x86_64`.
|
||||
- `rpm -qlp`: all four installed files (`bin/cli_hi`, `share/vbs/CliHiPkg/package.json`, both CMake config files).
|
||||
- `rpm2cpio | cpio -it`: the payload entries are readable.
|
||||
- The install test asserts the lead magic, the header magic at offset 96, the package name, the cpio magic, and the `TRAILER!!!` marker. Full CTest: **8 / 8 passed** in 292.72 s.
|
||||
|
||||
## RPM Prototype Investigation (GCC 16.2, pin `0002e74`)
|
||||
|
||||
With `dev cpp-gcc -p rpm` (rpm 6.1.0, `rpm2cpio`, `rpmbuild`) a hand-built RPM prototype was
|
||||
|
||||
@@ -52,7 +52,7 @@ Concrete work this implies:
|
||||
| Languages | C, C++, CUDA, Fortran, ObjC, ASM, HIP… | C, C++, Rust, D, Fortran, Java… | C/C++ focused | C, C++ | ASM/CUDA/ObjC or a documented extension API |
|
||||
| Toolchains | MSVC, clang-cl, GCC, Clang, Apple, many | GCC, Clang, MSVC, many | GCC, Clang, MSVC | GCC, Clang (Linux) | MinGW target; MSVC deferred |
|
||||
| Package/registry | External (vcpkg, Conan, FetchContent) | wrapdb, subprojects | cppget.org / brep | **Built-in registry + solver + lock + binary variants + signatures + SBOM** | federation, mirrors, key distribution |
|
||||
| Install/package | `install()`, `install(EXPORT)`, CPack (TGZ/ZIP/DEB/RPM/WIX/DMG/NuGet/APK…) | `install_data`, `install_headers`, dist scripts | install module | prefix staging, components, relocatable CMake + native exports, tar, self-extracting `sh`, **stored ZIP**, **DEB (dpkg-validated)**, SBOM, **Ed25519-signed archives with checksums** | RPM (deferred: rpm 6.1 rejects hand-built headers without exact signature-region semantics; tooling is available via `dev cpp-gcc -p rpm`), MSI/DMG-style |
|
||||
| Install/package | `install()`, `install(EXPORT)`, CPack (TGZ/ZIP/DEB/RPM/WIX/DMG/NuGet/APK…) | `install_data`, `install_headers`, dist scripts | install module | prefix staging, components, relocatable CMake + native exports, tar, self-extracting `sh`, **stored ZIP**, **DEB (dpkg-validated)**, SBOM, **Ed25519-signed archives with checksums** | **RPM (rpm 6.1-validated)**, MSI/DMG-style |
|
||||
| IDE integration | File API, presets, every IDE | `meson-info` introspection | limited | `vbs ide generate/query`, CompDB, daemon protocol | File API shim, `CMakePresets.json` import, plugins |
|
||||
| Test runner | CTest: fixtures, labels, resource locks, timeouts, JUnit/CDash | `meson test`: suites, timeouts, JUnit | test module | `VOID_TEST` runner; `vbs test --junit --test-timeout` | fixtures, labels, resource locks, CDash |
|
||||
| Incremental / cache | compiler depfiles, ccache external | depfiles, ccache | internal caching model | **content-addressed state, immutable snapshots, remote action cache** | scale benchmarks |
|
||||
|
||||
+322
-75
@@ -9,6 +9,7 @@
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
#include <Void/System/Path.hpp>
|
||||
#include <Void/System/Types.hpp>
|
||||
#include <Void/Text/Str.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
@@ -115,10 +116,10 @@ write_stored_zip(const std::filesystem::path &output,
|
||||
records.push_back(
|
||||
{entry.archive_path, crc, size, static_cast<std::uint32_t>(local.size()), entry.mode});
|
||||
put_u32(local, 0x04034b50u);
|
||||
put_u16(local, 20); // version needed
|
||||
put_u16(local, 0); // flags
|
||||
put_u16(local, 0); // stored
|
||||
put_u16(local, 0); // time
|
||||
put_u16(local, 20); // version needed
|
||||
put_u16(local, 0); // flags
|
||||
put_u16(local, 0); // stored
|
||||
put_u16(local, 0); // time
|
||||
put_u16(local, 0x21); // 1980-01-01
|
||||
put_u32(local, crc);
|
||||
put_u32(local, size);
|
||||
@@ -172,10 +173,10 @@ void append_ar_member(std::string &out, std::string_view name, std::string_view
|
||||
header.reserve(60);
|
||||
header += padded_name;
|
||||
header.resize(16, ' ');
|
||||
header += std::format("{:<12}", 0); // mtime
|
||||
header += std::format("{:<6}", 0); // uid
|
||||
header += std::format("{:<6}", 0); // gid
|
||||
header += std::format("{:<8}", 100644); // mode
|
||||
header += std::format("{:<12}", 0); // mtime
|
||||
header += std::format("{:<6}", 0); // uid
|
||||
header += std::format("{:<6}", 0); // gid
|
||||
header += std::format("{:<8}", 100644); // mode
|
||||
header += std::format("{:<10}", data.size()); // size
|
||||
header += "`\n";
|
||||
out += header;
|
||||
@@ -185,6 +186,248 @@ void append_ar_member(std::string &out, std::string_view name, std::string_view
|
||||
}
|
||||
}
|
||||
|
||||
// ── Minimal native RPM writer (uncompressed newc cpio payload) ──────────────────────────────
|
||||
namespace rpm {
|
||||
|
||||
constexpr std::uint32_t kInt16 = 3;
|
||||
constexpr std::uint32_t kInt32 = 4;
|
||||
constexpr std::uint32_t kString = 6;
|
||||
constexpr std::uint32_t kBin = 7;
|
||||
constexpr std::uint32_t kStringArray = 8;
|
||||
constexpr std::uint32_t kI18nString = 9;
|
||||
|
||||
struct Tag {
|
||||
std::uint32_t tag{0};
|
||||
std::uint32_t type{0};
|
||||
std::string data;
|
||||
std::uint32_t count{0};
|
||||
};
|
||||
|
||||
void put_be32(std::string &out, std::uint32_t value) {
|
||||
out.push_back(static_cast<char>((value >> 24) & 0xFFu));
|
||||
out.push_back(static_cast<char>((value >> 16) & 0xFFu));
|
||||
out.push_back(static_cast<char>((value >> 8) & 0xFFu));
|
||||
out.push_back(static_cast<char>(value & 0xFFu));
|
||||
}
|
||||
|
||||
Tag string_tag(std::uint32_t tag, std::string value, std::uint32_t type = kString) {
|
||||
value.push_back('\0');
|
||||
return Tag{tag, type, std::move(value), 1};
|
||||
}
|
||||
|
||||
Tag int32_tag(std::uint32_t tag, std::vector<std::uint32_t> values) {
|
||||
std::string data;
|
||||
for (const auto value : values) {
|
||||
put_be32(data, value);
|
||||
}
|
||||
return Tag{tag, kInt32, std::move(data), static_cast<std::uint32_t>(values.size())};
|
||||
}
|
||||
|
||||
Tag int16_tag(std::uint32_t tag, std::vector<std::uint16_t> values) {
|
||||
std::string data;
|
||||
for (const auto value : values) {
|
||||
data.push_back(static_cast<char>((value >> 8) & 0xFFu));
|
||||
data.push_back(static_cast<char>(value & 0xFFu));
|
||||
}
|
||||
return Tag{tag, kInt16, std::move(data), static_cast<std::uint32_t>(values.size())};
|
||||
}
|
||||
|
||||
Tag string_array_tag(std::uint32_t tag, const std::vector<std::string> &values) {
|
||||
std::string data;
|
||||
for (const auto &value : values) {
|
||||
data += value;
|
||||
data.push_back('\0');
|
||||
}
|
||||
return Tag{tag, kStringArray, std::move(data), static_cast<std::uint32_t>(values.size())};
|
||||
}
|
||||
|
||||
std::string build_header(std::vector<Tag> tags, std::uint32_t region_tag) {
|
||||
std::ranges::sort(tags, {}, &Tag::tag);
|
||||
std::string store;
|
||||
struct Index {
|
||||
std::uint32_t tag;
|
||||
std::uint32_t type;
|
||||
std::uint32_t offset;
|
||||
std::uint32_t count;
|
||||
};
|
||||
std::vector<Index> index;
|
||||
for (const auto &entry : tags) {
|
||||
if (entry.type == kInt16 || entry.type == kInt32) {
|
||||
while (store.size() % 4 != 0) {
|
||||
store.push_back('\0');
|
||||
}
|
||||
}
|
||||
index.push_back(
|
||||
{entry.tag, entry.type, static_cast<std::uint32_t>(store.size()), entry.count});
|
||||
store += entry.data;
|
||||
}
|
||||
const auto trailer_pos = static_cast<std::uint32_t>(store.size());
|
||||
const auto nindex = static_cast<std::uint32_t>(index.size() + 1);
|
||||
put_be32(store, region_tag);
|
||||
put_be32(store, kBin);
|
||||
put_be32(store, 0u - nindex * 16u);
|
||||
put_be32(store, 16);
|
||||
index.insert(index.begin(), Index{region_tag, kBin, trailer_pos, 16});
|
||||
|
||||
std::string out{'\x8e', '\xad', '\xe8', 1, 0, 0, 0, 0};
|
||||
put_be32(out, static_cast<std::uint32_t>(index.size()));
|
||||
put_be32(out, static_cast<std::uint32_t>(store.size()));
|
||||
for (const auto &entry : index) {
|
||||
put_be32(out, entry.tag);
|
||||
put_be32(out, entry.type);
|
||||
put_be32(out, entry.offset);
|
||||
put_be32(out, entry.count);
|
||||
}
|
||||
out += store;
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string cpio_entry(std::string_view name, std::string_view data, std::uint32_t mode,
|
||||
std::uint32_t ino) {
|
||||
std::string out = std::format(
|
||||
"070701{:08X}{:08X}{:08X}{:08X}{:08X}{:08X}{:08X}{:08X}{:08X}{:08X}{:08X}{:08X}{:08X}", ino,
|
||||
mode, 0u, 0u, 1u, 0u, static_cast<std::uint32_t>(data.size()), 0u, 0u, 0u, 0u,
|
||||
static_cast<std::uint32_t>(name.size() + 1), 0u);
|
||||
out += name;
|
||||
out.push_back('\0');
|
||||
out += data;
|
||||
while (out.size() % 4 != 0) {
|
||||
out.push_back('\0');
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string cpio_archive(
|
||||
const std::vector<std::pair<std::string, std::pair<std::string, std::uint32_t>>> &files) {
|
||||
std::string out;
|
||||
std::uint32_t ino = 1;
|
||||
for (const auto &[name, content] : files) {
|
||||
out += cpio_entry(name, content.first, content.second, ino++);
|
||||
}
|
||||
out += cpio_entry("TRAILER!!!", "", 0, 0);
|
||||
while (out.size() % 512 != 0) {
|
||||
out.push_back('\0');
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string arch_name(std::string arch) {
|
||||
arch = Void::Str::to_lower_ascii(arch);
|
||||
if (arch == "amd64") {
|
||||
return "x86_64";
|
||||
}
|
||||
if (arch == "arm64") {
|
||||
return "aarch64";
|
||||
}
|
||||
return arch;
|
||||
}
|
||||
|
||||
} // namespace rpm
|
||||
|
||||
// RPM package: lead + signature header + main header + uncompressed newc cpio payload.
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
write_rpm_package(const std::filesystem::path &output, const InstallOptions &options,
|
||||
const Graph::BuildGraph &graph,
|
||||
const std::vector<Package::ArchiveEntrySpec> &entries) {
|
||||
std::vector<std::pair<std::string, std::pair<std::string, std::uint32_t>>> payload_files;
|
||||
std::vector<std::string> basenames;
|
||||
std::vector<std::string> dirnames;
|
||||
std::vector<std::uint32_t> dirindexes;
|
||||
std::vector<std::uint32_t> file_sizes;
|
||||
std::vector<std::uint16_t> file_modes;
|
||||
std::vector<std::uint16_t> file_rdevs;
|
||||
std::vector<std::uint32_t> file_mtimes;
|
||||
std::vector<std::uint32_t> file_flags;
|
||||
std::vector<std::string> file_digests;
|
||||
std::vector<std::string> file_users;
|
||||
std::vector<std::string> file_groups;
|
||||
|
||||
for (const auto &entry : entries) {
|
||||
auto content = Void::FileSystem::read_file(entry.source_file);
|
||||
if (!content) {
|
||||
return std::unexpected{content.error()};
|
||||
}
|
||||
const auto dir = std::filesystem::path{entry.archive_path}.parent_path();
|
||||
std::string dirname = dir.empty() ? std::string{} : dir.generic_string() + "/";
|
||||
const auto dir_it = std::ranges::find(dirnames, dirname);
|
||||
if (dir_it == dirnames.end()) {
|
||||
dirnames.push_back(dirname);
|
||||
dirindexes.push_back(static_cast<std::uint32_t>(dirnames.size() - 1));
|
||||
} else {
|
||||
dirindexes.push_back(
|
||||
static_cast<std::uint32_t>(std::distance(dirnames.begin(), dir_it)));
|
||||
}
|
||||
basenames.push_back(std::filesystem::path{entry.archive_path}.filename().string());
|
||||
file_sizes.push_back(static_cast<std::uint32_t>(content->size()));
|
||||
file_modes.push_back(static_cast<std::uint16_t>(entry.mode == 0755u ? 0100755u : 0100644u));
|
||||
file_rdevs.push_back(0);
|
||||
file_mtimes.push_back(0);
|
||||
file_flags.push_back(0);
|
||||
file_digests.push_back(Util::sha256_hex(*content));
|
||||
file_users.emplace_back("root");
|
||||
file_groups.emplace_back("root");
|
||||
payload_files.emplace_back(entry.archive_path, std::pair{std::move(*content), entry.mode});
|
||||
}
|
||||
const std::string payload = rpm::cpio_archive(payload_files);
|
||||
|
||||
std::uint64_t total_size = 0;
|
||||
for (const auto size : file_sizes) {
|
||||
total_size += size;
|
||||
}
|
||||
std::vector<rpm::Tag> main_tags;
|
||||
main_tags.push_back(rpm::string_tag(1000, options.package_name));
|
||||
main_tags.push_back(rpm::string_tag(1001, options.package_version));
|
||||
main_tags.push_back(rpm::string_tag(1002, "1"));
|
||||
main_tags.push_back(rpm::string_tag(
|
||||
1004,
|
||||
options.package_description.empty() ? options.package_name : options.package_description,
|
||||
rpm::kI18nString));
|
||||
main_tags.push_back(rpm::string_tag(1005, "Generated by VoidBuildSystem", rpm::kI18nString));
|
||||
main_tags.push_back(rpm::int32_tag(1006, {0}));
|
||||
main_tags.push_back(rpm::string_tag(1007, "localhost"));
|
||||
main_tags.push_back(rpm::int32_tag(1009, {static_cast<std::uint32_t>(total_size)}));
|
||||
main_tags.push_back(rpm::string_tag(1014, "MIT"));
|
||||
main_tags.push_back(rpm::string_tag(1016, "Applications/System", rpm::kI18nString));
|
||||
main_tags.push_back(rpm::string_tag(1021, "linux"));
|
||||
main_tags.push_back(rpm::string_tag(1022, rpm::arch_name(graph.profile.architecture)));
|
||||
main_tags.push_back(rpm::int32_tag(1028, file_sizes));
|
||||
main_tags.push_back(rpm::int16_tag(1030, file_modes));
|
||||
main_tags.push_back(rpm::int16_tag(1033, file_rdevs));
|
||||
main_tags.push_back(rpm::int32_tag(1034, file_mtimes));
|
||||
main_tags.push_back(rpm::string_array_tag(1035, file_digests));
|
||||
main_tags.push_back(rpm::string_array_tag(1039, file_users));
|
||||
main_tags.push_back(rpm::string_array_tag(1040, file_groups));
|
||||
main_tags.push_back(rpm::int32_tag(1045, file_flags));
|
||||
main_tags.push_back(rpm::int32_tag(1116, dirindexes));
|
||||
main_tags.push_back(rpm::string_array_tag(1117, basenames));
|
||||
main_tags.push_back(rpm::string_array_tag(1118, dirnames));
|
||||
main_tags.push_back(rpm::string_tag(1124, "cpio"));
|
||||
main_tags.push_back(rpm::string_tag(1126, ""));
|
||||
main_tags.push_back(rpm::int32_tag(5011, {8})); // SHA-256 file digests
|
||||
main_tags.push_back(rpm::string_array_tag(5092, {Util::sha256_hex(payload)}));
|
||||
|
||||
const std::string main_header = rpm::build_header(std::move(main_tags), 63);
|
||||
|
||||
std::vector<rpm::Tag> sig_tags;
|
||||
sig_tags.push_back(rpm::string_tag(273, Util::sha256_hex(main_header)));
|
||||
sig_tags.push_back(
|
||||
rpm::int32_tag(1000, {static_cast<std::uint32_t>(main_header.size() + payload.size())}));
|
||||
std::string signature = rpm::build_header(std::move(sig_tags), 62);
|
||||
while ((96 + signature.size()) % 8 != 0) {
|
||||
signature.push_back('\0');
|
||||
}
|
||||
|
||||
std::string lead{'\xed', '\xab', '\xee', '\xdb', 3, 0, 0, 0, 0, 1};
|
||||
const std::string name_version = options.package_name + "-" + options.package_version + "-1";
|
||||
lead += name_version;
|
||||
lead.resize(10 + 66, '\0');
|
||||
lead += {0, 1, 0, 5};
|
||||
lead.resize(96, '\0');
|
||||
|
||||
const std::string package = lead + signature + main_header + payload;
|
||||
return Platform::atomic_write_file(output, package, true);
|
||||
}
|
||||
|
||||
// Debian package: ar container with debian-binary, control.tar and data.tar (uncompressed).
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
write_deb_package(const std::filesystem::path &output, const InstallOptions &options,
|
||||
@@ -219,13 +462,11 @@ write_deb_package(const std::filesystem::path &output, const InstallOptions &opt
|
||||
}
|
||||
const std::string control_text =
|
||||
"Package: " + options.package_name + "\n" + "Version: " + options.package_version + "\n" +
|
||||
"Architecture: " + deb_arch + "\n" +
|
||||
"Maintainer: " +
|
||||
"Architecture: " + deb_arch + "\n" + "Maintainer: " +
|
||||
(options.maintainer.empty() ? "Void Build <noreply@localhost>" : options.maintainer) +
|
||||
"\n" + "Installed-Size: " + std::to_string(installed_size / 1024) + "\n" +
|
||||
"Section: misc\nPriority: optional\n" + "Description: " +
|
||||
(options.package_description.empty() ? options.package_name
|
||||
: options.package_description) +
|
||||
(options.package_description.empty() ? options.package_name : options.package_description) +
|
||||
"\n";
|
||||
|
||||
const auto control_file = scratch / "control";
|
||||
@@ -233,8 +474,8 @@ write_deb_package(const std::filesystem::path &output, const InstallOptions &opt
|
||||
return std::unexpected{wrote.error()};
|
||||
}
|
||||
const auto control_tar = scratch / "control.tar";
|
||||
auto control = Package::create_deterministic_tar(
|
||||
control_tar, {{"control", control_file, 0644u}}, 0);
|
||||
auto control =
|
||||
Package::create_deterministic_tar(control_tar, {{"control", control_file, 0644u}}, 0);
|
||||
if (!control) {
|
||||
return std::unexpected{control.error()};
|
||||
}
|
||||
@@ -583,9 +824,8 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
|
||||
archive_entries.reserve(report.installed_files.size());
|
||||
for (const auto &file : report.installed_files) {
|
||||
const auto meta = Platform::stat_lstat(file);
|
||||
archive_entries.push_back(
|
||||
{file.lexically_relative(prefix_abs).generic_string(), file,
|
||||
meta ? (meta->mode & 0777u) : 0644u});
|
||||
archive_entries.push_back({file.lexically_relative(prefix_abs).generic_string(), file,
|
||||
meta ? (meta->mode & 0777u) : 0644u});
|
||||
}
|
||||
|
||||
if (options.archive_format == "zip") {
|
||||
@@ -593,67 +833,74 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
|
||||
return std::unexpected{zipped.error()};
|
||||
}
|
||||
} else if (options.archive_format == "deb") {
|
||||
if (auto packed = write_deb_package(*options.archive_path, options, graph,
|
||||
archive_entries);
|
||||
if (auto packed =
|
||||
write_deb_package(*options.archive_path, options, graph, archive_entries);
|
||||
!packed) {
|
||||
return std::unexpected{packed.error()};
|
||||
}
|
||||
} else if (options.archive_format == "rpm") {
|
||||
if (auto packed =
|
||||
write_rpm_package(*options.archive_path, options, graph, archive_entries);
|
||||
!packed) {
|
||||
return std::unexpected{packed.error()};
|
||||
}
|
||||
} else {
|
||||
const bool archive_as_script = options.archive_format == "sh";
|
||||
const auto archive_target = archive_as_script
|
||||
? stage_root / "installer-payload.tar"
|
||||
: std::filesystem::path{*options.archive_path};
|
||||
auto archived = Package::create_deterministic_tar(archive_target,
|
||||
std::move(archive_entries), 0);
|
||||
if (!archived) {
|
||||
return std::unexpected{archived.error()};
|
||||
}
|
||||
const bool archive_as_script = options.archive_format == "sh";
|
||||
const auto archive_target = archive_as_script
|
||||
? stage_root / "installer-payload.tar"
|
||||
: std::filesystem::path{*options.archive_path};
|
||||
auto archived =
|
||||
Package::create_deterministic_tar(archive_target, std::move(archive_entries), 0);
|
||||
if (!archived) {
|
||||
return std::unexpected{archived.error()};
|
||||
}
|
||||
|
||||
if (archive_as_script) {
|
||||
// Self-extracting installer: a POSIX sh header followed by the tar payload.
|
||||
const auto make_header = [&](std::size_t payload_line) {
|
||||
return "#!/bin/sh\n"
|
||||
"# VoidBuildSystem self-extracting installer for " +
|
||||
options.package_name + " " + options.package_version +
|
||||
"\n"
|
||||
"# Usage: sh <installer> [--prefix DIR] (default: ${PREFIX:-/usr/local})\n"
|
||||
"set -eu\n"
|
||||
"prefix=\"${PREFIX:-/usr/local}\"\n"
|
||||
"if [ \"${1:-}\" = \"--prefix\" ]; then\n"
|
||||
" prefix=\"${2:?--prefix requires a directory}\"\n"
|
||||
"fi\n"
|
||||
"tmp=\"$(mktemp -d)\"\n"
|
||||
"trap 'rm -rf \"$tmp\"' EXIT\n"
|
||||
"tail -n +" +
|
||||
std::to_string(payload_line) +
|
||||
" \"$0\" > \"$tmp/payload.tar\"\n"
|
||||
"mkdir -p \"$prefix\"\n"
|
||||
"tar -x -f \"$tmp/payload.tar\" -C \"$prefix\"\n"
|
||||
"echo \"installed " +
|
||||
options.package_name +
|
||||
" to $prefix\"\n"
|
||||
"exit 0\n";
|
||||
};
|
||||
std::size_t header_lines = 0;
|
||||
for (const char c : make_header(0)) {
|
||||
if (c == '\n') {
|
||||
++header_lines;
|
||||
if (archive_as_script) {
|
||||
// Self-extracting installer: a POSIX sh header followed by the tar payload.
|
||||
const auto make_header = [&](std::size_t payload_line) {
|
||||
return "#!/bin/sh\n"
|
||||
"# VoidBuildSystem self-extracting installer for " +
|
||||
options.package_name + " " + options.package_version +
|
||||
"\n"
|
||||
"# Usage: sh <installer> [--prefix DIR] (default: "
|
||||
"${PREFIX:-/usr/local})\n"
|
||||
"set -eu\n"
|
||||
"prefix=\"${PREFIX:-/usr/local}\"\n"
|
||||
"if [ \"${1:-}\" = \"--prefix\" ]; then\n"
|
||||
" prefix=\"${2:?--prefix requires a directory}\"\n"
|
||||
"fi\n"
|
||||
"tmp=\"$(mktemp -d)\"\n"
|
||||
"trap 'rm -rf \"$tmp\"' EXIT\n"
|
||||
"tail -n +" +
|
||||
std::to_string(payload_line) +
|
||||
" \"$0\" > \"$tmp/payload.tar\"\n"
|
||||
"mkdir -p \"$prefix\"\n"
|
||||
"tar -x -f \"$tmp/payload.tar\" -C \"$prefix\"\n"
|
||||
"echo \"installed " +
|
||||
options.package_name +
|
||||
" to $prefix\"\n"
|
||||
"exit 0\n";
|
||||
};
|
||||
std::size_t header_lines = 0;
|
||||
for (const char c : make_header(0)) {
|
||||
if (c == '\n') {
|
||||
++header_lines;
|
||||
}
|
||||
}
|
||||
const std::string header = make_header(header_lines + 1);
|
||||
|
||||
auto payload = Void::FileSystem::read_file(archive_target);
|
||||
if (!payload) {
|
||||
return std::unexpected{payload.error()};
|
||||
}
|
||||
std::string script = header;
|
||||
script += *payload;
|
||||
if (auto written =
|
||||
Platform::atomic_write_file(*options.archive_path, script, true, 0755);
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
}
|
||||
const std::string header = make_header(header_lines + 1);
|
||||
|
||||
auto payload = Void::FileSystem::read_file(archive_target);
|
||||
if (!payload) {
|
||||
return std::unexpected{payload.error()};
|
||||
}
|
||||
std::string script = header;
|
||||
script += *payload;
|
||||
if (auto written =
|
||||
Platform::atomic_write_file(*options.archive_path, script, true, 0755);
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
}
|
||||
}
|
||||
report.archive_path = *options.archive_path;
|
||||
|
||||
@@ -684,14 +931,14 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
|
||||
return std::unexpected{public_key.error()};
|
||||
}
|
||||
report.signature_path = options.archive_path->string() + ".sig";
|
||||
if (auto written = Platform::atomic_write_file(*report.signature_path,
|
||||
*signature + "\n", true);
|
||||
if (auto written =
|
||||
Platform::atomic_write_file(*report.signature_path, *signature + "\n", true);
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
report.public_key_path = options.archive_path->string() + ".pub";
|
||||
if (auto written = Platform::atomic_write_file(*report.public_key_path,
|
||||
*public_key + "\n", true);
|
||||
if (auto written =
|
||||
Platform::atomic_write_file(*report.public_key_path, *public_key + "\n", true);
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
|
||||
+5
-6
@@ -514,7 +514,6 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
const std::string target_os = opts.target_os_arg.value_or(Toolchain::host_os_name());
|
||||
const std::string target_arch =
|
||||
opts.target_arch_arg.value_or(Toolchain::host_architecture_name());
|
||||
@@ -1877,9 +1876,10 @@ int execute_install_command(const InstallCmdOptions &opts) {
|
||||
iopts.export_native_metadata = !opts.no_native_export;
|
||||
iopts.bundle_runtime_dependencies = opts.bundle_dependencies;
|
||||
if (opts.archive_format_arg != "tar" && opts.archive_format_arg != "sh" &&
|
||||
opts.archive_format_arg != "zip" && opts.archive_format_arg != "deb") {
|
||||
opts.archive_format_arg != "zip" && opts.archive_format_arg != "deb" &&
|
||||
opts.archive_format_arg != "rpm") {
|
||||
std::cerr << "vbs install: unsupported --archive-format '" << opts.archive_format_arg
|
||||
<< "' (expected tar, sh, zip or deb)\n";
|
||||
<< "' (expected tar, sh, zip, deb or rpm)\n";
|
||||
return 2;
|
||||
}
|
||||
if (opts.archive_arg && !opts.archive_arg->empty()) {
|
||||
@@ -3040,7 +3040,7 @@ int main(int argc, char **argv) {
|
||||
.option("--archive", "", "Write a deterministic installer archive of the prefix",
|
||||
install_opts.archive_arg)
|
||||
.option_default("--archive-format", "",
|
||||
"Installer archive format: tar (default), sh, zip or deb",
|
||||
"Installer archive format: tar (default), sh, zip, deb or rpm",
|
||||
install_opts.archive_format_arg, "tar")
|
||||
.option("--signing-key", "",
|
||||
"Ed25519 seed file; signs the archive and writes .sha256/.sig/.pub",
|
||||
@@ -3213,8 +3213,7 @@ int main(int argc, char **argv) {
|
||||
auto &gc_cmd =
|
||||
root.subcommand("gc", "Recover interrupted state and garbage-collect unreferenced blobs");
|
||||
gc_cmd
|
||||
.option_default("--build-dir", "-B", "Build directory", gc_opts.build_arg,
|
||||
gc_default_build)
|
||||
.option_default("--build-dir", "-B", "Build directory", gc_opts.build_arg, gc_default_build)
|
||||
.option_default("--max-bytes", "",
|
||||
"Target maximum retained CAS bytes (0=unreferenced only)",
|
||||
gc_opts.max_bytes_arg, "0");
|
||||
|
||||
@@ -1053,6 +1053,26 @@ void build(Void::Build::Project &p) {
|
||||
Void::Testing::expect(sign_res.has_value() && !sign_res->succeeded());
|
||||
}
|
||||
|
||||
// RPM package generator: lead + header magic + newc cpio payload.
|
||||
const auto rpm_archive = tmp / "cli_hi.rpm";
|
||||
auto rpm_req = inst_req;
|
||||
for (auto &arg : rpm_req.arguments) {
|
||||
if (arg == installer_archive.string()) {
|
||||
arg = rpm_archive.string();
|
||||
}
|
||||
}
|
||||
rpm_req.arguments.push_back("--archive-format");
|
||||
rpm_req.arguments.push_back("rpm");
|
||||
auto rpm_res = Platform::run_supervised(rpm_req);
|
||||
Void::Testing::expect(rpm_res.has_value() && rpm_res->succeeded());
|
||||
auto rpm_bytes = Void::FileSystem::read_file(rpm_archive);
|
||||
Void::Testing::require(rpm_bytes.has_value());
|
||||
Void::Testing::expect(rpm_bytes->starts_with(std::string("\xed\xab\xee\xdb", 4)));
|
||||
Void::Testing::expect(rpm_bytes->substr(96, 3) == std::string("\x8e\xad\xe8", 3));
|
||||
Void::Testing::expect(rpm_bytes->find("CliHiPkg") != std::string::npos);
|
||||
Void::Testing::expect(rpm_bytes->find("070701") != std::string::npos);
|
||||
Void::Testing::expect(rpm_bytes->find("TRAILER!!!") != std::string::npos);
|
||||
|
||||
Platform::ProcessRequest uninst_req;
|
||||
uninst_req.executable = vbs_bin;
|
||||
uninst_req.arguments = {"uninstall", "--prefix", cli_prefix.string()};
|
||||
|
||||
Reference in new issue
Block a user