feat(config): add vbs migrate to scaffold build.cpp from CMakeLists
This commit is contained in:
1 parent
1b803f7a22
commit
399b52c31c
10 files changed
+599
-1
No files matched your search
@@ -2,6 +2,7 @@
|
||||
#include <Void/Build/BootstrapConfig.hpp>
|
||||
#include <Void/Build/Bridge/CMakeBridge.hpp>
|
||||
#include <Void/Build/Config/BuildTree.hpp>
|
||||
#include <Void/Build/Config/CmakeImport.hpp>
|
||||
#include <Void/Build/Config/Frontend.hpp>
|
||||
#include <Void/Build/Config/Presets.hpp>
|
||||
#include <Void/Build/Config/Scaffold.hpp>
|
||||
@@ -1448,6 +1449,41 @@ int execute_compdb_entries_command(const CompdbEntriesCmdOptions &opts) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct MigrateCmdOptions {
|
||||
std::string input_arg{"CMakeLists.txt"};
|
||||
std::string output_arg{"build.cpp"};
|
||||
std::string project_arg{"."};
|
||||
bool force{false};
|
||||
bool dry_run{false};
|
||||
};
|
||||
|
||||
int execute_migrate_command(const MigrateCmdOptions &opts) {
|
||||
auto imported = Config::import_cmake_lists(opts.input_arg, opts.project_arg);
|
||||
if (!imported) {
|
||||
std::cerr << "vbs migrate: " << imported.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
const std::string rendered = Config::render_build_cpp(*imported);
|
||||
if (opts.dry_run) {
|
||||
std::cout << rendered;
|
||||
return 0;
|
||||
}
|
||||
std::error_code ec;
|
||||
if (!opts.force && std::filesystem::exists(opts.output_arg, ec)) {
|
||||
std::cerr << "vbs migrate: '" << opts.output_arg
|
||||
<< "' exists (pass --force to overwrite)\n";
|
||||
return 2;
|
||||
}
|
||||
auto written = Platform::atomic_write_file(opts.output_arg, rendered, false);
|
||||
if (!written) {
|
||||
std::cerr << "vbs migrate: " << written.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << "wrote " << opts.output_arg << " (" << imported->targets.size() << " target(s), "
|
||||
<< imported->notes.size() << " note(s))\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct PresetsCmdOptions {
|
||||
std::string file_arg{"CMakePresets.json"};
|
||||
std::string project_arg;
|
||||
@@ -2881,6 +2917,7 @@ int main(int argc, char **argv) {
|
||||
LockCmdOptions lock_opts;
|
||||
VerifyCmdOptions verify_opts;
|
||||
PresetsCmdOptions presets_opts;
|
||||
MigrateCmdOptions migrate_opts;
|
||||
CompdbEntriesCmdOptions compdb_entries_opts;
|
||||
publish_opts.project_arg = cwd;
|
||||
BridgeCmdOptions bridge_opts;
|
||||
@@ -3094,6 +3131,18 @@ int main(int argc, char **argv) {
|
||||
verify_opts.trusted_key_files);
|
||||
add_log_flags(verify_cmd, false); // `-v` is `--version` on verify.
|
||||
|
||||
auto &migrate_cmd = root.subcommand(
|
||||
"migrate", "Generate a build.cpp scaffold from a CMakeLists.txt (bounded subset)");
|
||||
migrate_cmd
|
||||
.option_default("--input", "-i", "CMakeLists.txt path", migrate_opts.input_arg,
|
||||
"CMakeLists.txt")
|
||||
.option_default("--output", "-o", "Output build.cpp path", migrate_opts.output_arg,
|
||||
"build.cpp")
|
||||
.option_default("--project", "-C", "Project root", migrate_opts.project_arg, ".")
|
||||
.flag("--force", "", "Overwrite an existing output file", migrate_opts.force)
|
||||
.flag("--dry-run", "", "Print the scaffold instead of writing it", migrate_opts.dry_run);
|
||||
add_log_flags(migrate_cmd);
|
||||
|
||||
auto &presets_cmd = root.subcommand(
|
||||
"presets", "Import CMake configure presets (CMakePresets.json) as VBS equivalents");
|
||||
presets_cmd
|
||||
@@ -3576,6 +3625,9 @@ int main(int argc, char **argv) {
|
||||
if (cmd == "presets") {
|
||||
return execute_presets_command(presets_opts);
|
||||
}
|
||||
if (cmd == "migrate") {
|
||||
return execute_migrate_command(migrate_opts);
|
||||
}
|
||||
if (cmd == "compdb-entries") {
|
||||
return execute_compdb_entries_command(compdb_entries_opts);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user