[M7] cargoxx vendor + build --offline + path: store-path codegen
This commit is contained in:
69
src/codegen/vendor.cpp
Normal file
69
src/codegen/vendor.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
module;
|
||||
|
||||
#include <toml.hpp>
|
||||
|
||||
module cargoxx.codegen;
|
||||
|
||||
import std;
|
||||
import cargoxx.util;
|
||||
|
||||
namespace cargoxx::codegen {
|
||||
|
||||
auto parse_vendor_toml(std::string_view body) -> util::Result<VendorIndex> {
|
||||
toml::table root;
|
||||
try {
|
||||
root = toml::parse(body);
|
||||
} catch (const toml::parse_error& e) {
|
||||
return std::unexpected(util::Error{
|
||||
util::ErrorCode::ManifestParseError,
|
||||
std::format("vendor.toml is not valid TOML: {}", e.description()),
|
||||
"", std::nullopt, std::nullopt,
|
||||
});
|
||||
}
|
||||
|
||||
auto missing = [](std::string msg) {
|
||||
return util::Error{
|
||||
util::ErrorCode::ManifestInvalidField, std::move(msg), "",
|
||||
std::nullopt, std::nullopt,
|
||||
};
|
||||
};
|
||||
|
||||
VendorIndex out;
|
||||
if (const auto* tbl = root["nixpkgs"].as_table()) {
|
||||
if (auto v = (*tbl)["store_path"].value<std::string>()) {
|
||||
out.nixpkgs_store_path = *v;
|
||||
} else {
|
||||
return std::unexpected(missing("vendor.toml: [nixpkgs].store_path is required"));
|
||||
}
|
||||
} else {
|
||||
return std::unexpected(missing("vendor.toml: [nixpkgs] table is required"));
|
||||
}
|
||||
if (const auto* tbl = root["flake_utils"].as_table()) {
|
||||
if (auto v = (*tbl)["store_path"].value<std::string>()) {
|
||||
out.flake_utils_store_path = *v;
|
||||
} else {
|
||||
return std::unexpected(missing("vendor.toml: [flake_utils].store_path is required"));
|
||||
}
|
||||
} else {
|
||||
return std::unexpected(missing("vendor.toml: [flake_utils] table is required"));
|
||||
}
|
||||
|
||||
if (const auto* arr = root["dep"].as_array()) {
|
||||
for (const auto& el : *arr) {
|
||||
const auto* tbl = el.as_table();
|
||||
if (!tbl) {
|
||||
return std::unexpected(missing("vendor.toml: [[dep]] entries must be tables"));
|
||||
}
|
||||
auto attr = (*tbl)["nixpkgs_attr"].value<std::string>();
|
||||
auto path = (*tbl)["store_path"].value<std::string>();
|
||||
if (!attr || !path) {
|
||||
return std::unexpected(missing(
|
||||
"vendor.toml: each [[dep]] needs nixpkgs_attr and store_path"));
|
||||
}
|
||||
out.dep_store_paths.emplace(*attr, *path);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace cargoxx::codegen
|
||||
Reference in New Issue
Block a user