feat(ide): emit a CMake File API codemodel reply
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 8s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s

This commit is contained in:
faumaray committed 2026-12-05 06:41:50 +03:00
1 parent 083af6af79
commit 6cf8c53a02
6 files changed
+334 -19

No files matched your search

+99
View File
@@ -2593,6 +2593,105 @@ VOID_TEST(FullV1Tests, ide_integration_compdb_build_cpp_and_editor_configs_end_t
Void::Testing::expect(parsed.has_value());
}
}
// The CMake File API shim emits a codemodel-v2 reply tree from the lowered graph.
{
const auto reply_dir = bdir / ".cmake" / "api" / "v1" / "reply";
Void::Testing::expect(std::filesystem::exists(reply_dir));
std::filesystem::path index_file;
if (std::filesystem::exists(reply_dir)) {
for (const auto &entry : std::filesystem::directory_iterator(reply_dir)) {
if (entry.path().filename().string().starts_with("index-")) {
index_file = entry.path();
}
}
}
Void::Testing::require(!index_file.empty());
const auto read_json =
[](const std::filesystem::path &path) -> std::optional<Void::Json::Strict::Value> {
auto text = Void::FileSystem::read_file(path);
if (!text) {
return std::nullopt;
}
auto parsed = Void::Json::Strict::parse(*text);
if (!parsed) {
return std::nullopt;
}
return std::move(*parsed);
};
using JsonObject = Void::Json::Strict::Value::Object;
const auto get_object = [](const JsonObject &object,
std::string_view key) -> const JsonObject * {
const auto it = object.find(key);
return it == object.end() ? nullptr : std::get_if<JsonObject>(&it->second.value);
};
const auto get_string = [](const JsonObject &object, std::string_view key) -> std::string {
const auto it = object.find(key);
if (it == object.end()) {
return {};
}
const auto *text = std::get_if<std::string>(&it->second.value);
return text ? *text : std::string{};
};
const auto index_json = read_json(index_file);
Void::Testing::require(index_json.has_value());
const auto *index_object = std::get_if<JsonObject>(&index_json->value);
Void::Testing::require(index_object != nullptr);
const auto *reply = get_object(*index_object, "reply");
Void::Testing::require(reply != nullptr);
const auto *codemodel_entry = get_object(*reply, "codemodel-v2");
Void::Testing::require(codemodel_entry != nullptr);
const auto codemodel_file = get_string(*codemodel_entry, "jsonFile");
Void::Testing::require(!codemodel_file.empty());
const auto codemodel_json = read_json(reply_dir / codemodel_file);
Void::Testing::require(codemodel_json.has_value());
const auto *codemodel_object = std::get_if<JsonObject>(&codemodel_json->value);
Void::Testing::require(codemodel_object != nullptr);
const auto configs_it = codemodel_object->find("configurations");
Void::Testing::require(configs_it != codemodel_object->end());
const auto *configs =
std::get_if<Void::Json::Strict::Value::Array>(&configs_it->second.value);
Void::Testing::require(configs != nullptr && !configs->empty());
const auto *configuration = std::get_if<JsonObject>(&configs->front().value);
Void::Testing::require(configuration != nullptr);
const auto targets_it = configuration->find("targets");
Void::Testing::require(targets_it != configuration->end());
const auto *targets =
std::get_if<Void::Json::Strict::Value::Array>(&targets_it->second.value);
Void::Testing::require(targets != nullptr && !targets->empty());
const auto *first_target = std::get_if<JsonObject>(&targets->front().value);
Void::Testing::require(first_target != nullptr);
const auto target_file = get_string(*first_target, "jsonFile");
Void::Testing::require(!target_file.empty());
const auto target_json = read_json(reply_dir / target_file);
Void::Testing::require(target_json.has_value());
const auto *target_object = std::get_if<JsonObject>(&target_json->value);
Void::Testing::require(target_object != nullptr);
Void::Testing::expect_eq(get_string(*target_object, "kind"), std::string{"target"});
Void::Testing::expect(!get_string(*target_object, "type").empty());
Void::Testing::expect(!get_string(*target_object, "name").empty());
auto target_text = Void::FileSystem::read_file(reply_dir / target_file);
Void::Testing::require(target_text.has_value());
// At least one emitted target is the executable, with artifacts and compile groups.
bool saw_executable = false;
for (const auto &entry : std::filesystem::directory_iterator(reply_dir)) {
const auto name = entry.path().filename().string();
if (!name.starts_with("target-")) {
continue;
}
auto text = Void::FileSystem::read_file(entry.path());
if (text && text->find("\"type\":\"EXECUTABLE\"") != std::string::npos) {
saw_executable = true;
Void::Testing::expect(text->find("\"artifacts\":[{") != std::string::npos);
Void::Testing::expect(text->find("\"compileGroups\":[{") != std::string::npos);
}
}
Void::Testing::expect(saw_executable);
}
// The generated IDE tasks include install/package entries.
if (auto tasks = Void::FileSystem::read_file(proj / ".vscode" / "tasks.json"); tasks) {
Void::Testing::expect(tasks->find("vbs: install") != std::string::npos);