feat(config): import CMake configure presets
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s

This commit is contained in:
faumaray committed 2026-12-05 06:12:05 +03:00
1 parent 7772697a48
commit 083af6af79
10 files changed
+387 -1

No files matched your search

+49
View File
@@ -3,6 +3,7 @@
#include <Void/Build/Bridge/CMakeBridge.hpp>
#include <Void/Build/Config/BuildTree.hpp>
#include <Void/Build/Config/Frontend.hpp>
#include <Void/Build/Config/Presets.hpp>
#include <Void/Build/Config/Scaffold.hpp>
#include <Void/Build/Daemon/Daemon.hpp>
#include <Void/Build/Editor/CompDb.hpp>
@@ -1331,6 +1332,40 @@ int execute_compdb_entries_command(const CompdbEntriesCmdOptions &opts) {
return 0;
}
struct PresetsCmdOptions {
std::string file_arg{"CMakePresets.json"};
std::string project_arg;
std::optional<std::string> name_arg;
};
int execute_presets_command(const PresetsCmdOptions &opts) {
auto presets = Config::load_cmake_presets(opts.file_arg, opts.project_arg);
if (!presets) {
std::cerr << "vbs presets: " << presets.error().message() << '\n';
return 1;
}
if (opts.name_arg) {
const auto match =
std::ranges::find_if(*presets, [&](const Config::ImportedPreset &preset) {
return preset.name == *opts.name_arg;
});
if (match == presets->end()) {
std::cerr << "vbs presets: unknown preset '" << *opts.name_arg << "'\n";
return 1;
}
std::cout << Config::suggested_build_command(*match) << '\n';
return 0;
}
for (const auto &preset : *presets) {
std::cout << "preset=" << preset.name << " profile=" << preset.profile
<< " compiler=" << preset.compiler
<< " build_dir=" << (preset.build_dir ? *preset.build_dir : std::string{"-"})
<< " build_type=" << (preset.build_type.empty() ? "-" : preset.build_type)
<< '\n';
}
return 0;
}
struct VerifyCmdOptions {
std::optional<std::string> name_arg;
std::optional<std::string> version_arg;
@@ -2728,6 +2763,7 @@ int main(int argc, char **argv) {
TokensCmdOptions tokens_opts;
LockCmdOptions lock_opts;
VerifyCmdOptions verify_opts;
PresetsCmdOptions presets_opts;
CompdbEntriesCmdOptions compdb_entries_opts;
publish_opts.project_arg = cwd;
BridgeCmdOptions bridge_opts;
@@ -2934,6 +2970,16 @@ int main(int argc, char **argv) {
verify_opts.trusted_key_files);
add_log_flags(verify_cmd, false); // `-v` is `--version` on verify.
auto &presets_cmd = root.subcommand(
"presets", "Import CMake configure presets (CMakePresets.json) as VBS equivalents");
presets_cmd
.option_default("--file", "-f", "CMakePresets.json path", presets_opts.file_arg,
"CMakePresets.json")
.option_default("--project", "-C", "Project root for ${sourceDir}",
presets_opts.project_arg, cwd)
.option("--name", "-n", "Print the VBS command for one preset", presets_opts.name_arg);
add_log_flags(presets_cmd);
auto &lock_cmd = root.subcommand("lock", "Inspect the project's vbs.lock");
auto &lock_show_cmd = lock_cmd.subcommand("show", "Print lockfile contexts and entries");
lock_show_cmd.option_default("--project", "-C", "Project directory", lock_opts.project_arg,
@@ -3404,6 +3450,9 @@ int main(int argc, char **argv) {
if (cmd == "verify") {
return execute_verify_command(verify_opts);
}
if (cmd == "presets") {
return execute_presets_command(presets_opts);
}
if (cmd == "compdb-entries") {
return execute_compdb_entries_command(compdb_entries_opts);
}