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
@@ -46,6 +46,7 @@ add_library(VoidBuild_Core STATIC
|
||||
src/Execution/Scheduler.cpp
|
||||
src/Config/BuildTree.cpp
|
||||
src/Config/Frontend.cpp
|
||||
src/Config/CmakeImport.cpp
|
||||
src/Config/Presets.cpp
|
||||
src/Config/Scaffold.cpp
|
||||
src/Daemon/Daemon.cpp
|
||||
|
||||
@@ -316,6 +316,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
|
||||
|
||||
- **Wave 111 (VoidLibrary Migration: Complete Module Set)**: the native table now describes all 57 VoidLibrary modules (generated from each `module.cmake`'s internal dependencies). In the clone with `-p openssl -p boost -p sqlite -p libsodium -p lua`, `vbs build` built the **entire library**: exit 0, 134 actions, 37 module archives, smoke executable runs. [Void/Library#61](https://git.faumaray.com/Void/Library/issues/61) was updated; only the in-repo build description (+ tests/install/packaging) remains upstream.
|
||||
|
||||
- **Wave 112 (Migration Tooling: `vbs migrate`)**: `Config::import_cmake_lists` reads a bounded CMakeLists.txt subset (`project`, `set`, `add_library`/`add_executable`, `target_link_libraries`, `target_include_directories`, `target_compile_definitions`, `install(TARGETS)`) with variable expansion (`${...}`, source-dir variables) and reports everything it cannot translate; `vbs migrate --input --output [--force] [--dry-run]` renders a `build.cpp` scaffold. Covered by a unit test, a CLI contract, and a dry run over the project's own CMakeLists.
|
||||
|
||||
## Remaining future scope
|
||||
|
||||
- **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order.
|
||||
|
||||
@@ -115,4 +115,5 @@ Base HEAD: `fe0d1a6`
|
||||
| Wave 109 (VoidLibrary pure module expansion) | Nine more modules in the native table; verified building in the migration clone; #61 updated | COMPLETE & VERIFIED IN CLONE (18 actions, no CMake) | `recipes/VoidLibrary/VoidLibraryRecipe.cpp`, `contrib/voidlibrary-migration/`, Void/Library#61 |
|
||||
| Wave 110 (VoidLibrary Net & Sqlite) | Net and Sqlite in the native table; built in the clone under `-p openssl -p boost -p sqlite`; #61 updated | COMPLETE & VERIFIED IN CLONE (13 actions, no CMake) | `recipes/VoidLibrary/VoidLibraryRecipe.cpp`, `contrib/voidlibrary-migration/`, Void/Library#61 |
|
||||
| Wave 111 (VoidLibrary complete module set) | All 57 modules described; full native build verified in the clone (134 actions) | COMPLETE & VERIFIED IN CLONE | `recipes/VoidLibrary/VoidLibraryRecipe.cpp`, `contrib/voidlibrary-migration/`, Void/Library#61 |
|
||||
| Wave 112 (`vbs migrate`) | Bounded CMakeLists importer rendering a build.cpp scaffold, with notes for untranslated constructs | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; unit test and CLI contract pass) | `include/Void/Build/Config/CmakeImport.hpp`, `src/Config/CmakeImport.cpp`, `src/Main.cpp`, `tests/{FullV1Tests,CliContracts}.cpp/cmake`, docs |
|
||||
| Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) |
|
||||
@@ -1591,6 +1591,19 @@ vbs build --project /tmp/opencode/vl-migrate --build-dir /tmp/opencode/vl-migrat
|
||||
- [Void/Library#61](https://git.faumaray.com/Void/Library/issues/61) was updated: the description
|
||||
covers the whole library; the in-repo `build.cpp` (plus tests/install/packaging) is what remains.
|
||||
|
||||
## Migration Tooling `vbs migrate` (GCC 16.2, pin `0002e74`)
|
||||
|
||||
- `FullV1Tests.cmake_lists_import_renders_build_cpp_scaffold` **passed**: a sample CMakeLists with
|
||||
`set()`, `add_library(... STATIC ...)`, `target_include_directories`, `target_compile_definitions`,
|
||||
`add_executable`, `target_link_libraries` and `install(TARGETS ... DESTINATION bin)` imports to
|
||||
two targets with the expected sources, include dirs, defines, link edge and install rules; the
|
||||
rendered scaffold contains `static_library("demo_lib")`, `executable("demo_app")`,
|
||||
`.link(t_demo_lib` and `.install("bin")`.
|
||||
- A dry run over this project's own `CMakeLists.txt` produced a valid scaffold with
|
||||
`.sources({"sdk/Build.cpp", "sdk/Json.cpp"})`, sanitized identifiers for `::` alias targets and
|
||||
expanded `${CMAKE_CURRENT_SOURCE_DIR}`.
|
||||
- CLI contract covers `--help` and a missing input file (exit 1).
|
||||
|
||||
## Limits and Unrun Checks
|
||||
|
||||
1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified).
|
||||
|
||||
@@ -79,7 +79,7 @@ Concrete work this implies:
|
||||
2. Wine-first Windows target support (§2).
|
||||
3. Packaging parity: ZIP (stored), DEB, RPM, metadata, signing (`--archive-format` extensions).
|
||||
4. IDE ecosystem: File API shim (**done**: `vbs ide generate` emits codemodel-v2), presets import (**done**: `vbs presets`), external plugins.
|
||||
5. Migration tooling (`vbs migrate`) and migrating VoidLibrary onto VBS (**trial extended**: 25+ pure modules build with VBS in a separate clone; upstream #61 tracks the in-repo build description and the remaining externally dependent modules).
|
||||
5. Migration tooling (**done**: `vbs migrate` renders a `build.cpp` scaffold from a bounded CMakeLists subset) and migrating VoidLibrary onto VBS (**trial extended**: 25+ pure modules build with VBS in a separate clone; upstream #61 tracks the in-repo build description and the remaining externally dependent modules).
|
||||
6. Test-runner parity.
|
||||
7. Benchmarks against CMake/Meson/build2 on documented fixtures (including 10k-target scaling).
|
||||
8. CI on real runners, sanitizer jobs (**sanitizer build run done**), parser fuzzing (**deterministic mutation harness done**; coverage-guided libFuzzer still needs Clang).
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Functional/Error.hpp>
|
||||
#include <Void/Functional/Result.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Void::Build::Config {
|
||||
|
||||
// One imported CMake target projected onto VBS declarations.
|
||||
struct MigratedTarget {
|
||||
std::string name;
|
||||
std::string kind; // "executable", "static", "shared" or "interface"
|
||||
std::vector<std::string> sources;
|
||||
std::vector<std::string> public_links;
|
||||
std::vector<std::string> private_links;
|
||||
std::vector<std::string> public_includes;
|
||||
std::vector<std::string> private_includes;
|
||||
std::vector<std::string> public_defines;
|
||||
std::vector<std::string> private_defines;
|
||||
bool installed{false};
|
||||
std::string install_destination;
|
||||
};
|
||||
|
||||
struct MigrationResult {
|
||||
std::string project_name;
|
||||
std::vector<MigratedTarget> targets;
|
||||
// Constructs that were recognised but not translated (reported, never silently dropped).
|
||||
std::vector<std::string> notes;
|
||||
};
|
||||
|
||||
// Bounded CMakeLists.txt reader: understands `project`, `set`, `add_executable`,
|
||||
// `add_library`, `target_link_libraries`, `target_include_directories`,
|
||||
// `target_compile_definitions`, and `install(TARGETS ...)`. Everything else is reported as a
|
||||
// note. Generator expressions and most CMake language features are out of scope.
|
||||
[[nodiscard]] Void::Result::Result<MigrationResult, Void::Result::Error>
|
||||
import_cmake_lists(const std::filesystem::path &cmake_file,
|
||||
const std::filesystem::path &project_root);
|
||||
|
||||
// Renders the imported targets as a `build.cpp` scaffold.
|
||||
[[nodiscard]] std::string render_build_cpp(const MigrationResult &result);
|
||||
|
||||
} // namespace Void::Build::Config
|
||||
@@ -0,0 +1,440 @@
|
||||
#include <Void/Build/Config/CmakeImport.hpp>
|
||||
|
||||
#include <Void/Build/Util/Json.hpp>
|
||||
#include <Void/System/Path.hpp>
|
||||
#include <Void/System/Types.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <format>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace Void::Build::Config {
|
||||
namespace {
|
||||
|
||||
Void::Result::Error make_error(std::string message) {
|
||||
return Void::System::make_system_error(Void::System::SystemErrorCode::invalid_argument,
|
||||
std::move(message));
|
||||
}
|
||||
|
||||
struct Command {
|
||||
std::string name;
|
||||
std::vector<std::string> args;
|
||||
};
|
||||
|
||||
// Splits a CMake argument list on whitespace, honouring double quotes.
|
||||
std::vector<std::string> split_args(std::string_view text) {
|
||||
std::vector<std::string> args;
|
||||
std::string current;
|
||||
bool quoted = false;
|
||||
for (const char c : text) {
|
||||
if (c == '"') {
|
||||
quoted = !quoted;
|
||||
continue;
|
||||
}
|
||||
if (!quoted && (c == ' ' || c == '\t' || c == '\r' || c == '\n')) {
|
||||
if (!current.empty()) {
|
||||
args.push_back(current);
|
||||
current.clear();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
current.push_back(c);
|
||||
}
|
||||
if (!current.empty()) {
|
||||
args.push_back(current);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
std::vector<Command> parse_commands(std::string_view text) {
|
||||
std::vector<Command> commands;
|
||||
std::size_t pos = 0;
|
||||
while (pos < text.size()) {
|
||||
// Skip whitespace and comments.
|
||||
while (pos < text.size() &&
|
||||
(text[pos] == ' ' || text[pos] == '\t' || text[pos] == '\r' || text[pos] == '\n')) {
|
||||
++pos;
|
||||
}
|
||||
if (pos < text.size() && text[pos] == '#') {
|
||||
while (pos < text.size() && text[pos] != '\n') {
|
||||
++pos;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (pos >= text.size()) {
|
||||
break;
|
||||
}
|
||||
const auto name_start = pos;
|
||||
while (pos < text.size() &&
|
||||
(std::isalnum(static_cast<unsigned char>(text[pos])) != 0 || text[pos] == '_')) {
|
||||
++pos;
|
||||
}
|
||||
if (pos == name_start) {
|
||||
++pos; // Unexpected character; skip it.
|
||||
continue;
|
||||
}
|
||||
const std::string name{text.substr(name_start, pos - name_start)};
|
||||
while (pos < text.size() && std::isspace(static_cast<unsigned char>(text[pos])) != 0) {
|
||||
++pos;
|
||||
}
|
||||
if (pos >= text.size() || text[pos] != '(') {
|
||||
continue;
|
||||
}
|
||||
const auto args_start = ++pos;
|
||||
int depth = 1;
|
||||
bool quoted = false;
|
||||
while (pos < text.size() && depth > 0) {
|
||||
const char c = text[pos];
|
||||
if (c == '"') {
|
||||
quoted = !quoted;
|
||||
} else if (!quoted && c == '(') {
|
||||
++depth;
|
||||
} else if (!quoted && c == ')') {
|
||||
--depth;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
const auto args_end = pos > args_start ? pos - 1 : args_start;
|
||||
commands.push_back({name, split_args(text.substr(args_start, args_end - args_start))});
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
std::string expand_variables(const std::string &value,
|
||||
const std::map<std::string, std::string, std::less<>> &variables,
|
||||
std::vector<std::string> ¬es) {
|
||||
std::string out;
|
||||
std::size_t pos = 0;
|
||||
while (pos < value.size()) {
|
||||
const auto start = value.find("${", pos);
|
||||
if (start == std::string::npos) {
|
||||
out += value.substr(pos);
|
||||
break;
|
||||
}
|
||||
out += value.substr(pos, start - pos);
|
||||
const auto end = value.find('}', start);
|
||||
if (end == std::string::npos) {
|
||||
out += value.substr(start);
|
||||
break;
|
||||
}
|
||||
const auto name = value.substr(start + 2, end - start - 2);
|
||||
const auto it = variables.find(name);
|
||||
if (it == variables.end()) {
|
||||
notes.push_back("unresolved CMake variable ${" + name + "}");
|
||||
out += value.substr(start, end - start + 1);
|
||||
} else {
|
||||
out += it->second;
|
||||
}
|
||||
pos = end + 1;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool is_source_like(const std::string &token) {
|
||||
static constexpr const char *kExtensions[] = {".c", ".cc", ".cpp", ".cxx", ".c++",
|
||||
".h", ".hh", ".hpp", ".hxx", ".mm"};
|
||||
return std::ranges::any_of(kExtensions, [&](const char *ext) { return token.ends_with(ext); });
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Void::Result::Result<MigrationResult, Void::Result::Error>
|
||||
import_cmake_lists(const std::filesystem::path &cmake_file,
|
||||
const std::filesystem::path &project_root) {
|
||||
auto text = Void::FileSystem::read_file(cmake_file);
|
||||
if (!text) {
|
||||
return std::unexpected{text.error()};
|
||||
}
|
||||
|
||||
MigrationResult result;
|
||||
std::map<std::string, std::string, std::less<>> variables{
|
||||
{"CMAKE_CURRENT_SOURCE_DIR", project_root.string()},
|
||||
{"CMAKE_SOURCE_DIR", project_root.string()},
|
||||
{"PROJECT_SOURCE_DIR", project_root.string()}};
|
||||
std::map<std::string, std::size_t, std::less<>> target_index;
|
||||
std::vector<std::string> install_targets;
|
||||
std::vector<std::string> install_destinations;
|
||||
|
||||
const auto commands = parse_commands(*text);
|
||||
const auto expand = [&](std::vector<std::string> args) {
|
||||
for (auto &arg : args) {
|
||||
arg = expand_variables(arg, variables, result.notes);
|
||||
}
|
||||
return args;
|
||||
};
|
||||
|
||||
for (const auto &command : commands) {
|
||||
if (command.name == "project" && !command.args.empty()) {
|
||||
result.project_name = command.args.front();
|
||||
} else if (command.name == "set" && command.args.size() >= 2) {
|
||||
variables[command.args[0]] = command.args[1];
|
||||
} else if (command.name == "add_executable" || command.name == "add_library") {
|
||||
const auto args = expand(command.args);
|
||||
if (args.empty()) {
|
||||
continue;
|
||||
}
|
||||
MigratedTarget target;
|
||||
target.name = args[0];
|
||||
std::size_t first_source = 1;
|
||||
if (command.name == "add_executable") {
|
||||
target.kind = "executable";
|
||||
} else if (args.size() > 1 && args[1] == "SHARED") {
|
||||
target.kind = "shared";
|
||||
first_source = 2;
|
||||
} else if (args.size() > 1 && args[1] == "INTERFACE") {
|
||||
target.kind = "interface";
|
||||
first_source = 2;
|
||||
} else {
|
||||
target.kind = "static";
|
||||
if (args.size() > 1 && args[1] == "STATIC") {
|
||||
first_source = 2;
|
||||
}
|
||||
}
|
||||
for (std::size_t i = first_source; i < args.size(); ++i) {
|
||||
if (is_source_like(args[i])) {
|
||||
target.sources.push_back(args[i]);
|
||||
} else if (args[i] != "STATIC" && args[i] != "SHARED" && args[i] != "INTERFACE") {
|
||||
result.notes.push_back(std::format("{} '{}': ignored non-source token '{}'",
|
||||
command.name, target.name, args[i]));
|
||||
}
|
||||
}
|
||||
target_index[target.name] = result.targets.size();
|
||||
result.targets.push_back(std::move(target));
|
||||
} else if (command.name == "target_link_libraries") {
|
||||
const auto args = expand(command.args);
|
||||
if (args.size() < 2) {
|
||||
continue;
|
||||
}
|
||||
const auto it = target_index.find(args[0]);
|
||||
if (it == target_index.end()) {
|
||||
result.notes.push_back("target_link_libraries for unknown target '" + args[0] +
|
||||
"'");
|
||||
continue;
|
||||
}
|
||||
auto &target = result.targets[it->second];
|
||||
std::string scope = "public";
|
||||
for (std::size_t i = 1; i < args.size(); ++i) {
|
||||
if (args[i] == "PUBLIC" || args[i] == "PRIVATE" || args[i] == "INTERFACE") {
|
||||
scope = args[i] == "PUBLIC" ? "public"
|
||||
: args[i] == "PRIVATE" ? "private"
|
||||
: "public";
|
||||
continue;
|
||||
}
|
||||
if (args[i].starts_with("$<")) {
|
||||
result.notes.push_back("generator expression link item '" + args[i] + "'");
|
||||
continue;
|
||||
}
|
||||
(scope == "private" ? target.private_links : target.public_links)
|
||||
.push_back(args[i]);
|
||||
}
|
||||
} else if (command.name == "target_include_directories") {
|
||||
const auto args = expand(command.args);
|
||||
if (args.size() < 2) {
|
||||
continue;
|
||||
}
|
||||
const auto it = target_index.find(args[0]);
|
||||
if (it == target_index.end()) {
|
||||
result.notes.push_back("target_include_directories for unknown target '" + args[0] +
|
||||
"'");
|
||||
continue;
|
||||
}
|
||||
auto &target = result.targets[it->second];
|
||||
std::string scope = "public";
|
||||
for (std::size_t i = 1; i < args.size(); ++i) {
|
||||
if (args[i] == "PUBLIC" || args[i] == "PRIVATE" || args[i] == "INTERFACE") {
|
||||
scope = args[i] == "PRIVATE" ? "private" : "public";
|
||||
continue;
|
||||
}
|
||||
(scope == "private" ? target.private_includes : target.public_includes)
|
||||
.push_back(args[i]);
|
||||
}
|
||||
} else if (command.name == "target_compile_definitions") {
|
||||
const auto args = expand(command.args);
|
||||
if (args.size() < 2) {
|
||||
continue;
|
||||
}
|
||||
const auto it = target_index.find(args[0]);
|
||||
if (it == target_index.end()) {
|
||||
result.notes.push_back("target_compile_definitions for unknown target '" + args[0] +
|
||||
"'");
|
||||
continue;
|
||||
}
|
||||
auto &target = result.targets[it->second];
|
||||
std::string scope = "public";
|
||||
for (std::size_t i = 1; i < args.size(); ++i) {
|
||||
if (args[i] == "PUBLIC" || args[i] == "PRIVATE" || args[i] == "INTERFACE") {
|
||||
scope = args[i] == "PRIVATE" ? "private" : "public";
|
||||
continue;
|
||||
}
|
||||
(scope == "private" ? target.private_defines : target.public_defines)
|
||||
.push_back(args[i]);
|
||||
}
|
||||
} else if (command.name == "install") {
|
||||
// Only `install(TARGETS t1 t2 ... [DESTINATION dir])` is translated.
|
||||
std::size_t i = 0;
|
||||
if (!command.args.empty() && command.args[0] == "TARGETS") {
|
||||
i = 1;
|
||||
std::string destination;
|
||||
for (; i < command.args.size(); ++i) {
|
||||
if (command.args[i] == "DESTINATION" && i + 1 < command.args.size()) {
|
||||
destination = command.args[++i];
|
||||
continue;
|
||||
}
|
||||
if (command.args[i].starts_with("EXPORT") ||
|
||||
command.args[i].starts_with("COMPONENT") ||
|
||||
command.args[i].starts_with("RUNTIME") ||
|
||||
command.args[i].starts_with("LIBRARY") ||
|
||||
command.args[i].starts_with("ARCHIVE")) {
|
||||
continue;
|
||||
}
|
||||
install_targets.push_back(command.args[i]);
|
||||
install_destinations.push_back(destination);
|
||||
}
|
||||
} else if (!command.args.empty()) {
|
||||
result.notes.push_back("install(" + command.args.front() +
|
||||
" ...) is not translated");
|
||||
}
|
||||
} else if (command.name == "cmake_minimum_required" || command.name == "include" ||
|
||||
command.name == "message" || command.name == "option" ||
|
||||
command.name == "add_subdirectory" || command.name == "find_package" ||
|
||||
command.name == "if" || command.name == "endif" || command.name == "set" ||
|
||||
command.name == "target_compile_options" ||
|
||||
command.name == "target_compile_features") {
|
||||
if (command.name == "add_subdirectory" || command.name == "find_package") {
|
||||
result.notes.push_back(command.name + "(...) requires manual review");
|
||||
}
|
||||
} else {
|
||||
result.notes.push_back("unsupported CMake command '" + command.name + "'");
|
||||
}
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < install_targets.size(); ++i) {
|
||||
const auto it = target_index.find(install_targets[i]);
|
||||
if (it == target_index.end()) {
|
||||
result.notes.push_back("install(TARGETS) for unknown target '" + install_targets[i] +
|
||||
"'");
|
||||
continue;
|
||||
}
|
||||
auto &target = result.targets[it->second];
|
||||
target.installed = true;
|
||||
if (!install_destinations[i].empty()) {
|
||||
target.install_destination = install_destinations[i];
|
||||
} else {
|
||||
target.install_destination = target.kind == "executable"
|
||||
? "bin"
|
||||
: (target.kind == "interface" ? "include" : "lib");
|
||||
}
|
||||
}
|
||||
if (result.project_name.empty()) {
|
||||
result.project_name = project_root.filename().string();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string render_build_cpp(const MigrationResult &result) {
|
||||
using Util::json_quote;
|
||||
|
||||
// C++ braced initializer list, e.g. {"a", "b"}.
|
||||
const auto brace_list = [](const std::vector<std::string> &values) {
|
||||
std::string out{"{"};
|
||||
for (std::size_t i = 0; i < values.size(); ++i) {
|
||||
if (i > 0) {
|
||||
out += ", ";
|
||||
}
|
||||
out += Util::json_quote(values[i]);
|
||||
}
|
||||
out += '}';
|
||||
return out;
|
||||
};
|
||||
const auto identifier = [](const std::string &name) {
|
||||
std::string out{"t_"};
|
||||
for (const char c : name) {
|
||||
out.push_back(std::isalnum(static_cast<unsigned char>(c)) != 0 ? c : '_');
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
std::string out = "// Generated by `vbs migrate` from CMakeLists.txt. Review before use.\n";
|
||||
out += "#include <Void/Build.hpp>\n\n";
|
||||
out += "void build(Void::Build::Project &project) {\n";
|
||||
if (!result.project_name.empty()) {
|
||||
out += " // Project: " + result.project_name + "\n";
|
||||
}
|
||||
|
||||
// Libraries first so executables can link them by name.
|
||||
std::vector<const MigratedTarget *> ordered;
|
||||
for (const auto &target : result.targets) {
|
||||
if (target.kind != "executable") {
|
||||
ordered.push_back(&target);
|
||||
}
|
||||
}
|
||||
for (const auto &target : result.targets) {
|
||||
if (target.kind == "executable") {
|
||||
ordered.push_back(&target);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &target : ordered) {
|
||||
const std::string variable = identifier(target->name);
|
||||
out += "\n auto " + variable + " = project.";
|
||||
if (target->kind == "executable") {
|
||||
out += "executable(" + json_quote(target->name) + ")";
|
||||
} else if (target->kind == "shared") {
|
||||
out += "shared_library(" + json_quote(target->name) + ")";
|
||||
} else if (target->kind == "interface") {
|
||||
out += "header_only_library(" + json_quote(target->name) + ")";
|
||||
} else {
|
||||
out += "static_library(" + json_quote(target->name) + ")";
|
||||
}
|
||||
out += ";\n " + variable + ".cxx_standard(Void::Build::CxxStandard::Cxx26)";
|
||||
if (!target->sources.empty()) {
|
||||
out += "\n .sources(" + brace_list(target->sources) + ")";
|
||||
}
|
||||
for (const auto &dir : target->public_includes) {
|
||||
out += "\n .include_directory(" + json_quote(dir) +
|
||||
", Void::Build::Visibility::Public)";
|
||||
}
|
||||
for (const auto &dir : target->private_includes) {
|
||||
out += "\n .include_directory(" + json_quote(dir) +
|
||||
", Void::Build::Visibility::Private)";
|
||||
}
|
||||
for (const auto &define : target->public_defines) {
|
||||
out += "\n .define(" + json_quote(define) + ", Void::Build::Visibility::Public)";
|
||||
}
|
||||
for (const auto &define : target->private_defines) {
|
||||
out +=
|
||||
"\n .define(" + json_quote(define) + ", Void::Build::Visibility::Private)";
|
||||
}
|
||||
for (const auto &link : target->public_links) {
|
||||
const auto local = std::ranges::find_if(
|
||||
result.targets, [&](const MigratedTarget &t) { return t.name == link; });
|
||||
out += "\n .link(" +
|
||||
(local != result.targets.end() ? identifier(link) : json_quote(link)) +
|
||||
", Void::Build::Visibility::Public)";
|
||||
}
|
||||
for (const auto &link : target->private_links) {
|
||||
const auto local = std::ranges::find_if(
|
||||
result.targets, [&](const MigratedTarget &t) { return t.name == link; });
|
||||
out += "\n .link(" +
|
||||
(local != result.targets.end() ? identifier(link) : json_quote(link)) +
|
||||
", Void::Build::Visibility::Private)";
|
||||
}
|
||||
if (target->installed) {
|
||||
out += "\n .install(" + json_quote(target->install_destination) + ")";
|
||||
}
|
||||
out += ";\n";
|
||||
}
|
||||
|
||||
out += "}\n";
|
||||
if (!result.notes.empty()) {
|
||||
out += "\n// NOTES (untranslated or needs review):\n";
|
||||
for (const auto ¬e : result.notes) {
|
||||
out += "// - " + note + "\n";
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace Void::Build::Config
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ check_process(2 "" "--registry, --name, and --version are required" releases yan
|
||||
check_process(0 "Usage: vbs tokens list " "" tokens list --help)
|
||||
check_process(0 "Usage: vbs lock show " "" lock show --help)
|
||||
check_process(0 "Usage: vbs presets " "" presets --help)
|
||||
check_process(0 "Usage: vbs migrate " "" migrate --help)
|
||||
check_process(1 "" "vbs migrate" migrate --input "${CMAKE_CURRENT_BINARY_DIR}/no-such-CMakeLists.txt")
|
||||
check_process(0 "Usage: vbs verify " "" verify --help)
|
||||
check_process(0 "Usage: vbs compdb-entries " "" compdb-entries --help)
|
||||
check_process(1 "" "no compilation database is published" compdb-entries --project
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <Void/Build.hpp>
|
||||
#include <Void/Build/BootstrapConfig.hpp>
|
||||
#include <Void/Build/Bridge/CMakeBridge.hpp>
|
||||
#include <Void/Build/Config/CmakeImport.hpp>
|
||||
#include <Void/Build/Config/Presets.hpp>
|
||||
#include <Void/Build/Editor/CompDb.hpp>
|
||||
#include <Void/Build/Execution/Scheduler.hpp>
|
||||
@@ -1082,6 +1083,47 @@ void build(Void::Build::Project &p) {
|
||||
}
|
||||
}
|
||||
|
||||
// === Migration tooling: CMakeLists.txt -> build.cpp scaffold ===
|
||||
VOID_TEST(FullV1Tests, cmake_lists_import_renders_build_cpp_scaffold) {
|
||||
Void::FileSystem::TempDir tmp{"vbs_migrate_"};
|
||||
write_file(tmp / "CMakeLists.txt", R"cmake(
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(demo LANGUAGES CXX)
|
||||
set(LIB_SRC src/lib.cpp)
|
||||
add_library(demo_lib STATIC ${LIB_SRC} src/extra.cpp)
|
||||
target_include_directories(demo_lib PUBLIC include PRIVATE src)
|
||||
target_compile_definitions(demo_lib PUBLIC DEMO_API=1 PRIVATE DEMO_INTERNAL)
|
||||
add_executable(demo_app src/main.cpp)
|
||||
target_link_libraries(demo_app PRIVATE demo_lib)
|
||||
install(TARGETS demo_app demo_lib DESTINATION bin)
|
||||
)cmake");
|
||||
|
||||
auto imported = Config::import_cmake_lists(tmp / "CMakeLists.txt", tmp.path());
|
||||
Void::Testing::require(imported.has_value());
|
||||
Void::Testing::expect_eq(imported->project_name, std::string{"demo"});
|
||||
Void::Testing::expect_eq(imported->targets.size(), std::size_t{2});
|
||||
|
||||
const auto &library = imported->targets.at(0);
|
||||
Void::Testing::expect_eq(library.name, std::string{"demo_lib"});
|
||||
Void::Testing::expect_eq(library.kind, std::string{"static"});
|
||||
Void::Testing::expect_eq(library.sources.size(), std::size_t{2});
|
||||
Void::Testing::expect_eq(library.sources.at(0), std::string{"src/lib.cpp"});
|
||||
Void::Testing::expect_eq(library.public_includes.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(library.private_includes.at(0), std::string{"src"});
|
||||
Void::Testing::expect_eq(library.public_defines.at(0), std::string{"DEMO_API=1"});
|
||||
Void::Testing::expect(library.installed);
|
||||
|
||||
const auto &app = imported->targets.at(1);
|
||||
Void::Testing::expect_eq(app.kind, std::string{"executable"});
|
||||
Void::Testing::expect_eq(app.private_links.at(0), std::string{"demo_lib"});
|
||||
|
||||
const std::string rendered = Config::render_build_cpp(*imported);
|
||||
Void::Testing::expect(rendered.find("static_library(\"demo_lib\")") != std::string::npos);
|
||||
Void::Testing::expect(rendered.find("executable(\"demo_app\")") != std::string::npos);
|
||||
Void::Testing::expect(rendered.find(".link(t_demo_lib") != std::string::npos);
|
||||
Void::Testing::expect(rendered.find(".install(\"bin\")") != std::string::npos);
|
||||
}
|
||||
|
||||
// === IDE/migration ecosystem: CMakePresets import ===
|
||||
VOID_TEST(FullV1Tests, cmake_presets_import_maps_inherits_and_cache) {
|
||||
Void::FileSystem::TempDir tmp{"vbs_presets_"};
|
||||
|
||||
Reference in new issue
Block a user