feat(daemon): stage installs on request
This commit is contained in:
1 parent
3f181dc241
commit
2c602fc3e7
8 files changed
+205
-3
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#include <Void/Build/Daemon/Daemon.hpp>
|
||||
#include <Void/Build/Util/Json.hpp>
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
@@ -1411,6 +1412,56 @@ void build(Void::Build::Project &project) {
|
||||
Void::Testing::expect(!bool_field(*invalid, "ok", true));
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, install_stages_prefix_and_writes_manifest) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
const auto options = make_options(temp->path());
|
||||
|
||||
{
|
||||
std::ofstream descriptor{options.project_root / "build.cpp"};
|
||||
descriptor << R"cpp(#include <Void/Build.hpp>
|
||||
|
||||
void build(Void::Build::Project &project) {
|
||||
auto app = project.executable("app");
|
||||
app.sources({"main.cpp"}).install("bin");
|
||||
}
|
||||
)cpp";
|
||||
Void::Testing::require(descriptor.good());
|
||||
}
|
||||
{
|
||||
std::ofstream source{options.project_root / "main.cpp"};
|
||||
source << "int main() { return 0; }\n";
|
||||
Void::Testing::require(source.good());
|
||||
}
|
||||
|
||||
auto server = Void::Build::Daemon::DaemonServer::create(options);
|
||||
Void::Testing::require(server.has_value());
|
||||
const auto socket = server->socket_path();
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> run_result;
|
||||
std::jthread worker{[&] { run_result = server->run(); }};
|
||||
Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5}));
|
||||
|
||||
const auto prefix = temp->path() / "prefix";
|
||||
const std::string install_request =
|
||||
std::format(R"({{"op":"install","prefix":{},"package_name":"demo"}})",
|
||||
Void::Build::Util::json_quote(prefix.string()));
|
||||
auto installed = request_object(socket, install_request, std::chrono::seconds{120});
|
||||
auto missing_prefix = request_object(socket, R"({"op":"install"})");
|
||||
auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})");
|
||||
Void::Testing::expect(shutdown.has_value());
|
||||
worker.join();
|
||||
Void::Testing::expect(run_result.has_value());
|
||||
|
||||
Void::Testing::require(installed.has_value());
|
||||
Void::Testing::expect(bool_field(*installed, "ok"));
|
||||
Void::Testing::expect(int_field(*installed, "files") >= 1);
|
||||
Void::Testing::expect(std::filesystem::exists(prefix / "bin" / "app"));
|
||||
Void::Testing::expect(std::filesystem::exists(str_field(*installed, "manifest")));
|
||||
Void::Testing::require(missing_prefix.has_value());
|
||||
Void::Testing::expect(!bool_field(*missing_prefix, "ok", true));
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, describe_empty_project_reports_zero_targets) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
|
||||
Reference in new issue
Block a user