Skip to content

Commit d9010a5

Browse files
committed
Polish build progress and diagnostics
1 parent b27c687 commit d9010a5

7 files changed

Lines changed: 387 additions & 84 deletions

File tree

include/vix/cli/Style.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace vix::cli::style
2727
inline constexpr const char *YELLOW = "\033[33m";
2828
inline constexpr const char *CYAN = "\033[36m";
2929
inline constexpr const char *GRAY = "\033[90m";
30+
inline constexpr const char *MAGENTA = "\033[35m";
3031
inline constexpr const char *PAD = " ";
3132

3233
inline void error(const std::string &msg)
@@ -76,4 +77,4 @@ namespace vix::cli::style
7677

7778
} // namespace vix::cli::style
7879

79-
#endif // CLI_STYLE_HPP
80+
#endif // VIX_CLI_STYLE_HPP

include/vix/cli/build/BuildStyle.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ namespace vix::cli::build
133133
std::optional<BuildLocation> parse_build_location(
134134
const std::string &text);
135135

136+
void print_build_header_full(
137+
std::ostream &out,
138+
const std::string &target,
139+
const std::string &preset,
140+
const std::optional<std::string> &launcher,
141+
const std::optional<std::string> &fastLinkerFlag,
142+
int jobs);
143+
144+
void print_build_success_timed(
145+
std::ostream &out,
146+
const std::string &message,
147+
long long milliseconds);
148+
136149
} // namespace vix::cli::build
137150

138151
#endif

src/ErrorHandler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ namespace vix::cli
317317
if (handle_unrecognized_cli_option_as_script_runtime_args(cleanedLog))
318318
return true;
319319

320+
if (vix::cli::errors::build::handleBuildErrors(cleanedLog))
321+
return true;
322+
320323
if (RawLogDetectors::handleLinkerOrSanitizer(
321324
cleanedLog,
322325
sourceFile,
@@ -325,9 +328,6 @@ namespace vix::cli
325328
return true;
326329
}
327330

328-
if (vix::cli::errors::build::handleBuildErrors(cleanedLog))
329-
return true;
330-
331331
vix::cli::build::print_build_error(
332332
std::cerr,
333333
contextMessage.empty() ? "Build failed" : contextMessage);

src/build/BuildStyle.cpp

Lines changed: 119 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@
2121
#include <regex>
2222
#include <sstream>
2323
#include <system_error>
24+
#include <vector>
25+
#include <optional>
2426

2527
#include <vix/cli/Style.hpp>
2628

2729
namespace vix::cli::build
2830
{
2931
namespace style = vix::cli::style;
3032

33+
static std::string colorize(
34+
const char *color,
35+
const std::string &value)
36+
{
37+
return std::string(color) + value + style::RESET;
38+
}
39+
3140
namespace
3241
{
3342
static std::string trim_copy(const std::string &value)
@@ -51,13 +60,6 @@ namespace vix::cli::build
5160
return value.substr(begin, end - begin);
5261
}
5362

54-
static std::string colorize(
55-
const char *color,
56-
const std::string &value)
57-
{
58-
return std::string(color) + value + style::RESET;
59-
}
60-
6163
static bool is_absolute_or_relative_path_like(const std::string &value)
6264
{
6365
if (value.empty())
@@ -106,6 +108,9 @@ namespace vix::cli::build
106108
if (label == "code:")
107109
return style::CYAN;
108110

111+
if (label == "message:")
112+
return style::CYAN;
113+
109114
return style::GRAY;
110115
}
111116

@@ -131,6 +136,99 @@ namespace vix::cli::build
131136
}
132137
} // namespace
133138

139+
void print_build_header_full(
140+
std::ostream &out,
141+
const std::string &target,
142+
const std::string &preset,
143+
const std::optional<std::string> &launcher,
144+
const std::optional<std::string> &fastLinkerFlag,
145+
int jobs)
146+
{
147+
out << style::CYAN
148+
<< style::BOLD
149+
<< "Compiling"
150+
<< style::RESET;
151+
152+
if (!target.empty())
153+
{
154+
out << " "
155+
<< style::CYAN
156+
<< style::BOLD
157+
<< target
158+
<< style::RESET;
159+
}
160+
161+
if (!preset.empty())
162+
out << " " << colorize(style::GRAY, "(" + preset + ")");
163+
164+
out << "\n";
165+
166+
std::vector<std::string> meta;
167+
168+
if (launcher && !launcher->empty())
169+
{
170+
meta.push_back(
171+
"launcher: " + colorize(style::MAGENTA, *launcher));
172+
}
173+
174+
if (fastLinkerFlag && !fastLinkerFlag->empty())
175+
{
176+
const std::string name =
177+
fastLinkerFlag->find("mold") != std::string::npos
178+
? "mold"
179+
: "lld";
180+
181+
meta.push_back(
182+
"linker: " + colorize(style::MAGENTA, name));
183+
}
184+
185+
if (jobs > 0)
186+
{
187+
meta.push_back(
188+
"jobs: " + colorize(style::MAGENTA, std::to_string(jobs)));
189+
}
190+
191+
if (!meta.empty())
192+
{
193+
out << style::GRAY << " * " << style::RESET;
194+
195+
for (std::size_t i = 0; i < meta.size(); ++i)
196+
{
197+
if (i > 0)
198+
out << style::GRAY << " | " << style::RESET;
199+
200+
out << meta[i];
201+
}
202+
203+
out << "\n";
204+
}
205+
}
206+
207+
void print_build_success_timed(
208+
std::ostream &out,
209+
const std::string &message,
210+
long long milliseconds)
211+
{
212+
out << " "
213+
<< colorize(style::GREEN, "ok")
214+
<< " "
215+
<< message;
216+
217+
if (milliseconds > 0)
218+
{
219+
const double seconds = static_cast<double>(milliseconds) / 1000.0;
220+
221+
std::ostringstream time;
222+
time.setf(std::ios::fixed);
223+
time.precision(seconds >= 10.0 ? 1 : 2);
224+
time << seconds << "s";
225+
226+
out << " " << colorize(style::GRAY, "| " + time.str());
227+
}
228+
229+
out << "\n";
230+
}
231+
134232
bool BuildLocation::valid() const
135233
{
136234
return !file.empty();
@@ -289,17 +387,24 @@ namespace vix::cli::build
289387
std::ostream &out,
290388
const BuildDiagnostic &diagnostic)
291389
{
292-
out << "\n";
390+
const std::string title =
391+
diagnostic.title.empty()
392+
? std::string("Build failed")
393+
: diagnostic.title;
394+
293395
out << " "
294-
<< colorize(style::RED, "")
295-
<< " "
296-
<< colorize(style::BOLD, diagnostic.title.empty()
297-
? std::string("Build failed")
298-
: diagnostic.title)
396+
<< style::RED
397+
<< style::BOLD
398+
<< ""
399+
<< title
400+
<< style::RESET
299401
<< "\n\n";
300402

301403
if (!diagnostic.message.empty())
302-
out << " " << diagnostic.message << "\n\n";
404+
{
405+
print_label(out, "message:");
406+
out << " " << diagnostic.message << "\n\n";
407+
}
303408

304409
if (diagnostic.has_location())
305410
{

0 commit comments

Comments
 (0)