Skip to content

Commit 4c5eb37

Browse files
committed
refactor(cli): consume engine build context
1 parent e063a17 commit 4c5eb37

5 files changed

Lines changed: 117 additions & 245 deletions

File tree

‎include/vix/cli/build/BuildContext.hpp‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,38 @@
2121
#include <optional>
2222
#include <string>
2323

24+
#include <vix/engine/BuildContext.hpp>
25+
2426
#include <vix/cli/process/Process.hpp>
2527

2628
namespace vix::cli::build
2729
{
2830
namespace fs = std::filesystem;
2931
namespace process = vix::cli::process;
3032

31-
std::optional<process::Preset> resolve_builtin_preset(
32-
const std::string &name);
33+
using vix::engine::BuildTargetOptions;
34+
using vix::engine::resolve_builtin_preset;
3335

34-
std::string default_build_target_name(
36+
inline std::string default_build_target_name(
3537
const process::Options &opt,
36-
const process::Plan &plan);
38+
const process::Plan &plan)
39+
{
40+
return vix::engine::default_build_target_name(opt.buildTarget, plan);
41+
}
3742

38-
std::string default_graph_target_name(
43+
inline std::string default_graph_target_name(
3944
const process::Options &opt,
40-
const process::Plan &plan);
45+
const process::Plan &plan)
46+
{
47+
return vix::engine::default_graph_target_name(opt.buildTarget, plan);
48+
}
4149

42-
fs::path default_project_executable_path(
50+
inline fs::path default_project_executable_path(
4351
const process::Options &opt,
44-
const process::Plan &plan);
52+
const process::Plan &plan)
53+
{
54+
return vix::engine::default_project_executable_path(opt.buildTarget, plan);
55+
}
4556

4657
} // namespace vix::cli::build
4758

‎include/vix/cli/process/Process.hpp‎

Lines changed: 5 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#include <utility>
2020
#include <vector>
2121

22+
#include <vix/engine/ExecutionPlan.hpp>
23+
#include <vix/engine/Preset.hpp>
24+
2225
namespace vix::cli::process
2326
{
2427
namespace fs = std::filesystem;
@@ -206,148 +209,8 @@ namespace vix::cli::process
206209
std::string capturedFirstLine;
207210
};
208211

209-
/**
210-
* @brief Embedded build preset description.
211-
*/
212-
struct Preset
213-
{
214-
/**
215-
* @brief Preset public name.
216-
*/
217-
std::string name;
218-
219-
/**
220-
* @brief CMake generator name, usually "Ninja".
221-
*/
222-
std::string generator;
223-
224-
/**
225-
* @brief CMake build type, such as "Debug" or "Release".
226-
*/
227-
std::string buildType;
228-
229-
/**
230-
* @brief Build directory name associated with the preset.
231-
*/
232-
std::string buildDirName;
233-
};
234-
235-
/**
236-
* @brief Fully resolved execution plan for a build.
237-
*
238-
* This contains all derived paths, resolved tools, generated files,
239-
* and CMake variables needed to configure and build the project.
240-
*/
241-
struct Plan
242-
{
243-
/**
244-
* @brief User project root directory.
245-
*
246-
* This is the real directory where the user runs Vix from.
247-
* Build directories, exported binaries, local build state, and project
248-
* input snapshots should be based on this path.
249-
*
250-
* For normal CMake projects, this is the same as cmakeSourceDir.
251-
* For vix.app projects, this is the directory containing vix.app.
252-
*/
253-
fs::path userProjectDir;
254-
255-
/**
256-
* @brief CMake source directory passed to `cmake -S`.
257-
*
258-
* For normal CMake projects, this is the same as userProjectDir.
259-
* For vix.app projects, this points to the generated internal CMake
260-
* directory under `.vix/generated/app`.
261-
*/
262-
fs::path cmakeSourceDir;
263-
264-
/**
265-
* @brief Root project directory.
266-
*
267-
* Kept for backward compatibility with existing build code.
268-
* New code should prefer userProjectDir or cmakeSourceDir depending on
269-
* the operation being performed.
270-
*/
271-
fs::path projectDir;
272-
273-
/**
274-
* @brief Default target name used when --build-target is not provided.
275-
*
276-
* For normal CMake projects, this is usually the project directory name.
277-
* For vix.app projects, this is the manifest `name`.
278-
*/
279-
std::string defaultTargetName;
280-
281-
/**
282-
* @brief True when the active CMake project was generated from vix.app.
283-
*/
284-
bool generatedFromVixApp{false};
285-
286-
/**
287-
* @brief Resolved embedded preset.
288-
*/
289-
Preset preset;
290-
291-
/**
292-
* @brief Build directory used for configure/build artifacts.
293-
*/
294-
fs::path buildDir;
295-
296-
/**
297-
* @brief Path to the configure log file.
298-
*/
299-
fs::path configureLog;
300-
301-
/**
302-
* @brief Path to the build log file.
303-
*/
304-
fs::path buildLog;
305-
306-
/**
307-
* @brief Path to the configuration signature file.
308-
*/
309-
fs::path sigFile;
310-
311-
/**
312-
* @brief Path to the generated toolchain file when cross-compiling.
313-
*/
314-
fs::path toolchainFile;
315-
316-
/**
317-
* @brief Resolved Vix SDK CMake package directory, when SDK selection is required.
318-
*/
319-
fs::path sdkConfigDir;
320-
321-
/**
322-
* @brief Fatal managed SDK resolution error to report before configuring CMake.
323-
*/
324-
std::string sdkResolutionError;
325-
326-
/**
327-
* @brief Resolved CMake cache variables passed during configure.
328-
*/
329-
std::vector<std::pair<std::string, std::string>> cmakeVars;
330-
331-
/**
332-
* @brief Signature used to detect whether reconfigure is needed.
333-
*/
334-
std::string signature;
335-
336-
/**
337-
* @brief Resolved compiler launcher executable, if any.
338-
*/
339-
std::optional<std::string> launcher;
340-
341-
/**
342-
* @brief Resolved fast-linker compiler flag, if any.
343-
*/
344-
std::optional<std::string> fastLinkerFlag;
345-
346-
/**
347-
* @brief Fingerprint of important project files used for caching.
348-
*/
349-
std::string projectFingerprint;
350-
};
212+
using Preset = vix::engine::Preset;
213+
using Plan = vix::engine::ExecutionPlan;
351214

352215
/**
353216
* @brief Normalizes a raw process exit status into a standard exit code.

‎src/build/BuildContext.cpp‎

Lines changed: 0 additions & 95 deletions
This file was deleted.

‎tests/BuildContextCompatTests.cpp‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
*
3+
* @file BuildContextCompatTests.cpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*
13+
* CLI build context compatibility tests
14+
*
15+
*/
16+
17+
#include <vix/cli/build/BuildContext.hpp>
18+
19+
#include <cassert>
20+
#include <filesystem>
21+
#include <type_traits>
22+
23+
int main()
24+
{
25+
namespace build = vix::cli::build;
26+
namespace process = vix::cli::process;
27+
namespace engine = vix::engine;
28+
29+
static_assert(std::is_same_v<process::Preset, engine::Preset>);
30+
static_assert(std::is_same_v<process::Plan, engine::ExecutionPlan>);
31+
32+
const auto preset = build::resolve_builtin_preset("dev-ninja");
33+
assert(preset.has_value());
34+
assert(preset->name == "dev-ninja");
35+
assert(preset->generator == "Ninja");
36+
assert(preset->buildType == "Debug");
37+
assert(preset->buildDirName == "build-ninja");
38+
assert(!build::resolve_builtin_preset("unknown").has_value());
39+
40+
process::Options options;
41+
process::Plan plan;
42+
plan.userProjectDir = "/tmp/app";
43+
plan.cmakeSourceDir = "/tmp/app";
44+
plan.projectDir = "/tmp/app";
45+
plan.preset = *preset;
46+
plan.buildDir = "/tmp/app/build-ninja";
47+
48+
options.buildTarget = "explicit";
49+
assert(build::default_build_target_name(options, plan) == "explicit");
50+
assert(build::default_graph_target_name(options, plan) == "explicit");
51+
52+
options.buildTarget.clear();
53+
plan.defaultTargetName = "manifest-name";
54+
assert(build::default_build_target_name(options, plan) == "manifest-name");
55+
56+
plan.defaultTargetName.clear();
57+
assert(build::default_build_target_name(options, plan) == "app");
58+
#ifdef _WIN32
59+
const std::filesystem::path expectedExe = "/tmp/app/build-ninja/app.exe";
60+
#else
61+
const std::filesystem::path expectedExe = "/tmp/app/build-ninja/app";
62+
#endif
63+
assert(build::default_project_executable_path(options, plan) == expectedExe);
64+
65+
return 0;
66+
}

0 commit comments

Comments
 (0)