feat(daemon): export the target dependency graph as DOT or JSON
This commit is contained in:
1 parent
66d2fa6a2e
commit
ae57ee7666
9 files changed
+175
-4
No files matched your search
@@ -790,6 +790,69 @@ void build(Void::Build::Project &project) {
|
||||
Void::Testing::expect(run_result.has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, graph_exports_target_dependencies_as_json_and_dot) {
|
||||
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"});
|
||||
}
|
||||
)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}));
|
||||
|
||||
auto json_raw = Void::Build::Daemon::request(socket, R"({"op":"graph","format":"json"})",
|
||||
std::chrono::seconds{120});
|
||||
auto dot_raw =
|
||||
Void::Build::Daemon::request(socket, R"({"op":"graph"})", std::chrono::seconds{120});
|
||||
auto invalid =
|
||||
request_object(socket, R"({"op":"graph","format":"xml"})", std::chrono::seconds{120});
|
||||
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(json_raw.has_value());
|
||||
const auto json_parsed = parse_json(*json_raw);
|
||||
Void::Testing::require(json_parsed.has_value());
|
||||
const auto *json_object = as_object(*json_parsed);
|
||||
Void::Testing::require(json_object != nullptr);
|
||||
Void::Testing::expect_eq(str_field(*json_object, "format"), std::string{"json"});
|
||||
const std::string json_graph = str_field(*json_object, "graph");
|
||||
Void::Testing::expect(json_graph.find("\"name\":\"app\"") != std::string::npos);
|
||||
|
||||
Void::Testing::require(dot_raw.has_value());
|
||||
const auto dot_parsed = parse_json(*dot_raw);
|
||||
Void::Testing::require(dot_parsed.has_value());
|
||||
const auto *dot_object = as_object(*dot_parsed);
|
||||
Void::Testing::require(dot_object != nullptr);
|
||||
Void::Testing::expect_eq(str_field(*dot_object, "format"), std::string{"dot"});
|
||||
const std::string dot_graph = str_field(*dot_object, "graph");
|
||||
Void::Testing::expect(dot_graph.find("digraph vbs_targets") != std::string::npos);
|
||||
Void::Testing::expect(dot_graph.find("\"app\"") != std::string::npos);
|
||||
Void::Testing::require(invalid.has_value());
|
||||
Void::Testing::expect(!bool_field(*invalid, "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