feat(daemon): generate native test registration units on request
This commit is contained in:
1 parent
716c049cff
commit
f60c2708e8
8 files changed
+129
-2
No files matched your search
@@ -15,6 +15,7 @@
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Provenance/TrustedKeys.hpp>
|
||||
#include <Void/Build/Provider/Provider.hpp>
|
||||
#include <Void/Build/SelfHost/TestRegistryGen.hpp>
|
||||
#include <Void/Build/State/StateStore.hpp>
|
||||
#include <Void/Build/Toolchain/Driver.hpp>
|
||||
#include <Void/Build/Util/Json.hpp>
|
||||
@@ -1884,6 +1885,52 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
if (*name == "ide_configs") {
|
||||
return {ide_configs_project(options), false};
|
||||
}
|
||||
if (*name == "gen_tests") {
|
||||
const auto input_entry = object->find("input");
|
||||
const auto output_entry = object->find("output_dir");
|
||||
if (input_entry == object->end() || output_entry == object->end()) {
|
||||
return {error_response("gen_tests requires \"input\" and \"output_dir\""), false};
|
||||
}
|
||||
const auto *input_value = std::get_if<std::string>(&input_entry->second.value);
|
||||
const auto *output_value = std::get_if<std::string>(&output_entry->second.value);
|
||||
if (input_value == nullptr || output_value == nullptr) {
|
||||
return {error_response("\"input\" and \"output_dir\" must be strings"), false};
|
||||
}
|
||||
const auto resolve = [](const std::filesystem::path &base, const std::string &value) {
|
||||
const std::filesystem::path raw{value};
|
||||
return raw.is_absolute() ? raw : base / raw;
|
||||
};
|
||||
std::error_code project_ec;
|
||||
std::error_code build_ec;
|
||||
std::error_code input_ec;
|
||||
std::error_code output_ec;
|
||||
const auto project_root =
|
||||
std::filesystem::weakly_canonical(options.project_root, project_ec);
|
||||
const auto build_root = std::filesystem::weakly_canonical(options.build_root, build_ec);
|
||||
const auto input_path = std::filesystem::weakly_canonical(
|
||||
resolve(options.project_root, *input_value), input_ec);
|
||||
const auto output_dir = std::filesystem::weakly_canonical(
|
||||
resolve(options.build_root, *output_value), output_ec);
|
||||
if (project_ec || input_ec ||
|
||||
!Void::Build::Platform::path_is_within(project_root, input_path)) {
|
||||
return {error_response("input must stay inside the project root"), false};
|
||||
}
|
||||
if (build_ec || output_ec ||
|
||||
!Void::Build::Platform::path_is_within(build_root, output_dir)) {
|
||||
return {error_response("output_dir must stay inside the build root"), false};
|
||||
}
|
||||
auto generated = SelfHost::generate_test_registration_unit(input_path, output_dir);
|
||||
if (!generated) {
|
||||
return {error_response(std::format("gen_tests: {}", generated.error().format())),
|
||||
false};
|
||||
}
|
||||
JsonValue::Object object;
|
||||
object.emplace("ok", JsonValue{true});
|
||||
object.emplace("op", JsonValue{std::string{"gen_tests"}});
|
||||
object.emplace("generated", JsonValue{generated->generated_cpp.string()});
|
||||
object.emplace("cases", JsonValue{static_cast<std::int64_t>(generated->cases.size())});
|
||||
return {serialize_response(JsonValue{std::move(object)}), false};
|
||||
}
|
||||
if (*name == "uninstall") {
|
||||
const auto entry = object->find("prefix");
|
||||
if (entry == object->end()) {
|
||||
|
||||
Reference in new issue
Block a user