some packages

This commit is contained in:
2026-02-15 14:49:42 +01:00
parent b4564fa5bb
commit a19e668908
23 changed files with 231 additions and 24 deletions

View File

@@ -27,18 +27,20 @@ void install_package(const std::string &name) {
}
}
Expr src = pkg.get("src").children[0];
std::cout << "\n\n\tInstalling " << pkg.get_one("name").value << " ("
<< pkg.get_one("version").value << ")...\n\n\n";
Expr src = pkg.get_one("src");
std::string src_type = src.children[0].value;
std::string src_url = src.get("url").children[0].value;
std::string src_path = "/tmp/shrap/" + src.get("dir").children[0].value;
std::string src_url = src.get_one("url").value;
std::string src_path = "/tmp/shrap/" + src.get_one("dir").value;
if (src_type == "tar") {
std::string archive_path = "/tmp/shrap/" + Util::basename(src_url);
// TODO: ship ca certificates
Util::shell_command("./curl -k -L -o " + archive_path + " " + src_url);
Util::shell_command("./curl -L -o " + archive_path + " " + src_url);
std::string expected_hash = src.get("blake3").children[0].value;
std::string expected_hash = src.get_one("blake3").value;
std::string hash = Util::hash_file(archive_path);
if (expected_hash != hash) {
@@ -61,7 +63,7 @@ void install_package(const std::string &name) {
if (step_type == "configure_make") {
std::string configure_flags;
try {
configure_flags = step.get("configure_flags").children[0].value;
configure_flags = step.get_one("configure_flags").value;
} catch (std::out_of_range &) {
}
@@ -69,6 +71,43 @@ void install_package(const std::string &name) {
src_path);
Util::shell_command("make -j " + jobs, src_path);
Util::shell_command("make install", src_path);
} else if (step_type == "perl_configure_make") {
std::string configure_flags;
try {
configure_flags = step.get_one("configure_flags").value;
} catch (std::out_of_range &) {
}
Util::shell_command("./Configure " + configure_flags, src_path);
Util::shell_command("make -j " + jobs, src_path);
Util::shell_command("make install", src_path);
} else if (step_type == "make") {
std::string make_flags;
try {
make_flags = step.get_one("make_flags").value;
} catch (std::out_of_range &) {
}
std::string install_flags;
try {
install_flags = step.get_one("install_flags").value;
} catch (std::out_of_range &) {
}
Util::shell_command("make " + make_flags + " -j " + jobs, src_path);
Util::shell_command("make install " + install_flags, src_path);
} else if (step_type == "meson") {
std::string configure_flags;
try {
configure_flags = step.get_one("configure_flags").value;
} catch (std::out_of_range &) {
}
Util::shell_command(
"meson setup --prefix=/usr builddir " + configure_flags, src_path);
Util::shell_command("meson compile -C builddir -j" + jobs, src_path);
Util::shell_command("meson install -C builddir", src_path);
} else if (step_type == "shell") {
Util::shell_command(step.children[1].value, src_path);
} else {
throw std::runtime_error("unrecognized step type");
}

View File

@@ -28,6 +28,20 @@ public:
throw std::out_of_range("key not found: " + key);
}
[[nodiscard]] Expr get_one(const std::string &key) const {
if (type != Type::List) {
throw std::runtime_error("get() called on non-list");
}
for (const auto &child : children) {
if (child.type == Type::List && child.children.size() >= 2 &&
child.children[0].type == Type::Atom &&
child.children[0].value == key) {
return child.children[1];
}
}
throw std::out_of_range("key not found: " + key);
}
static Expr parse(std::istream &in) { return parse_expr(in); }
private:
@@ -82,10 +96,23 @@ private:
}
auto c = static_cast<char>(in.get());
if (c == '"') {
if (c == '\\') {
if (!in) {
throw std::runtime_error("unexpected EOF after escape character");
}
auto next = static_cast<char>(in.get());
if (next == '"') {
result += '"'; // handle escaped quote
} else {
result += '\\';
result += next;
}
} else if (c == '"') {
break;
} else {
result += c;
}
result += c;
}
return result;
}