-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBuildGraphExecutorAdapter.cpp
More file actions
122 lines (101 loc) · 2.7 KB
/
Copy pathBuildGraphExecutorAdapter.cpp
File metadata and controls
122 lines (101 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
*
* @file BuildGraphExecutorAdapter.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira. All rights reserved.
* https://github.com/vixcpp/vix
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Vix.cpp
*
* CLI adapters for target-aware graph execution
*
*/
#include <vix/cli/build/BuildGraphExecutorAdapter.hpp>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <utility>
#include <vix/cli/cmake/CMakeBuild.hpp>
namespace vix::cli::build
{
namespace
{
static bool graph_debug_logs_enabled()
{
const char *level = std::getenv("VIX_LOG_LEVEL");
if (!level || !*level)
return false;
std::string value(level);
for (char &c : value)
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
return value == "debug" || value == "trace";
}
static std::string read_text_file_or_empty(const fs::path &path)
{
std::ifstream in(path, std::ios::binary);
if (!in)
return {};
return std::string(
std::istreambuf_iterator<char>(in),
std::istreambuf_iterator<char>());
}
} // namespace
BuildGraphExecutorNinjaResult execute_graph_ninja_target(
const BuildGraphExecutorNinjaRequest &request,
bool quiet,
BuildOutputObserver outputObserver)
{
BuildGraphExecutorNinjaResult result;
const process::ExecResult execResult =
run_process_live_to_log(
request.command,
{},
request.buildDir / "build.log",
quiet,
/*cmakeVerbose=*/false,
/*progressOnly=*/false,
std::move(outputObserver));
result.started = true;
result.exitCode = execResult.exitCode;
result.producedOutput = execResult.producedOutput;
result.displayCommand = execResult.displayCommand;
if (execResult.exitCode != 0 && quiet)
{
result.output =
read_text_file_or_empty(
request.buildDir /
"build.log");
}
else if (execResult.producedOutput &&
!execResult.capturedFirstLine.empty())
{
result.output =
execResult.capturedFirstLine +
"\n";
}
return result;
}
void render_graph_debug_event(
const BuildGraphExecutorEvent &event,
bool quiet,
bool verbose)
{
if (quiet)
return;
if (!verbose)
return;
if (!graph_debug_logs_enabled())
return;
if (event.message.empty())
return;
std::cout << " " << event.message << "\n";
std::cout.flush();
}
} // namespace vix::cli::build