feat(install,ide): self-extracting installers and install tasks
This commit is contained in:
1 parent
83ec08390f
commit
d23a878eec
9 files changed
+232
-5
No files matched your search
@@ -874,6 +874,21 @@ generate_ide_configs(const Graph::BuildGraph &graph, const IdeConfigOptions &opt
|
||||
vs_tasks.push_back(make_vs_task("vbs: refresh compile_commands.json",
|
||||
{"compdb", "export", "--profile", graph.profile.name}, "",
|
||||
false));
|
||||
vs_tasks.push_back(make_vs_task(
|
||||
"vbs: install",
|
||||
{"install", "--profile", graph.profile.name, "--prefix",
|
||||
(options.build_root / "install").string(),
|
||||
"--bundle-dependencies",
|
||||
"--archive", (options.build_root / "install" / "installer.tar").string()},
|
||||
"", false));
|
||||
vs_tasks.push_back(make_vs_task(
|
||||
"vbs: package installer",
|
||||
{"install", "--profile", graph.profile.name, "--prefix",
|
||||
(options.build_root / "install").string(),
|
||||
"--bundle-dependencies",
|
||||
"--archive", (options.build_root / "install" / "installer.sh").string(),
|
||||
"--archive-format", "sh"},
|
||||
"", false));
|
||||
for (const auto &tname : buildable_targets) {
|
||||
vs_tasks.push_back(make_vs_task(
|
||||
"vbs: build " + tname,
|
||||
@@ -964,6 +979,10 @@ generate_ide_configs(const Graph::BuildGraph &graph, const IdeConfigOptions &opt
|
||||
ztasks.push_back(make_zed_task("vbs: build", {"build", "--profile", graph.profile.name}));
|
||||
ztasks.push_back(make_zed_task("vbs: test", {"test", "--profile", graph.profile.name}));
|
||||
ztasks.push_back(make_zed_task("vbs: clean", {"clean"}));
|
||||
ztasks.push_back(make_zed_task(
|
||||
"vbs: install",
|
||||
{"install", "--profile", graph.profile.name, "--prefix",
|
||||
(options.build_root / "install").string(), "--bundle-dependencies"}));
|
||||
for (const auto &rt : runnables) {
|
||||
ztasks.push_back(
|
||||
make_zed_task("vbs: build " + rt.name,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <Void/Build/Install/Installer.hpp>
|
||||
|
||||
#include <Void/Build/Package/Archive.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Util/Json.hpp>
|
||||
#include <Void/Build/Util/Sha256.hpp>
|
||||
@@ -128,6 +129,8 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
|
||||
std::vector<std::string> local_deps;
|
||||
};
|
||||
std::vector<ExportedTarget> exported_targets;
|
||||
std::set<std::string> bundled_library_names;
|
||||
std::vector<std::filesystem::path> bundled_libraries;
|
||||
|
||||
for (const auto &trec : description.targets) {
|
||||
if (!trec.install_rule) {
|
||||
@@ -177,6 +180,20 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
|
||||
}
|
||||
et.rel_artifact = rel_dest;
|
||||
}
|
||||
// Bundle runtime shared libraries so the prefix is self-contained.
|
||||
if (options.bundle_runtime_dependencies) {
|
||||
for (const auto &library_path : sum_it->runtime_shared_libraries) {
|
||||
const std::string filename = library_path.filename().string();
|
||||
if (!bundled_library_names.insert(filename).second) {
|
||||
continue;
|
||||
}
|
||||
const auto rel_dest = std::filesystem::path{"lib"} / filename;
|
||||
if (auto r = add_item(library_path, rel_dest, 0755u, trec.name); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
bundled_libraries.push_back(library_path);
|
||||
}
|
||||
}
|
||||
exported_targets.push_back(std::move(et));
|
||||
}
|
||||
|
||||
@@ -364,6 +381,76 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
|
||||
if (!mw) {
|
||||
return std::unexpected{mw.error()};
|
||||
}
|
||||
report.bundled_libraries = std::move(bundled_libraries);
|
||||
|
||||
// 7. Optional deterministic installer archive of the published prefix.
|
||||
if (options.archive_path) {
|
||||
std::vector<Package::ArchiveEntrySpec> archive_entries;
|
||||
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});
|
||||
}
|
||||
|
||||
const auto archive_target =
|
||||
options.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 (options.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()};
|
||||
}
|
||||
}
|
||||
report.archive_path = *options.archive_path;
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
|
||||
+22
-1
@@ -1668,8 +1668,11 @@ struct InstallCmdOptions {
|
||||
std::optional<std::string> pkg_name_arg;
|
||||
std::string pkg_ver{"0.1.0"};
|
||||
std::optional<std::string> component_arg;
|
||||
std::optional<std::string> archive_arg;
|
||||
std::string archive_format_arg{"tar"};
|
||||
bool no_cmake_export{false};
|
||||
bool no_native_export{false};
|
||||
bool bundle_dependencies{false};
|
||||
};
|
||||
|
||||
int execute_install_command(const InstallCmdOptions &opts) {
|
||||
@@ -1698,6 +1701,16 @@ int execute_install_command(const InstallCmdOptions &opts) {
|
||||
iopts.component = opts.component_arg;
|
||||
iopts.export_cmake_config = !opts.no_cmake_export;
|
||||
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") {
|
||||
std::cerr << "vbs install: unsupported --archive-format '"
|
||||
<< opts.archive_format_arg << "' (expected tar or sh)\n";
|
||||
return 2;
|
||||
}
|
||||
if (opts.archive_arg && !opts.archive_arg->empty()) {
|
||||
iopts.archive_path = std::filesystem::path{*opts.archive_arg};
|
||||
iopts.archive_as_script = opts.archive_format_arg == "sh";
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
if (opts.pkg_name_arg && !opts.pkg_name_arg->empty()) {
|
||||
@@ -2827,7 +2840,15 @@ int main(int argc, char **argv) {
|
||||
.flag("--no-cmake-export", "", "Disable CMake Config.cmake export",
|
||||
install_opts.no_cmake_export)
|
||||
.flag("--no-native-export", "", "Disable native VBS package metadata export",
|
||||
install_opts.no_native_export);
|
||||
install_opts.no_native_export)
|
||||
.flag("--bundle-dependencies", "",
|
||||
"Bundle runtime shared libraries of installed targets into <prefix>/lib",
|
||||
install_opts.bundle_dependencies)
|
||||
.option("--archive", "", "Write a deterministic installer archive of the prefix",
|
||||
install_opts.archive_arg)
|
||||
.option_default("--archive-format", "",
|
||||
"Installer archive format: tar (default) or sh (self-extracting)",
|
||||
install_opts.archive_format_arg, "tar");
|
||||
add_log_flags(install_cmd);
|
||||
|
||||
auto &uninstall_cmd =
|
||||
|
||||
Reference in new issue
Block a user