Skip to content

Commit c7e7d9e

Browse files
committed
fix(cli): clean build output by hiding internal steps and cache logs
- hide artifact cache line from default output (verbose only) - filter internal ninja step: 'Copy compile_commands.json to project root' - improve build UX by showing only meaningful compilation/link steps - keep output clean, product-focused, and user-friendly
1 parent 40af4b2 commit c7e7d9e

2 files changed

Lines changed: 49 additions & 6 deletions

File tree

src/cmake/CMakeBuild.cpp

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#include <cerrno>
3737
#include <cstddef>
3838

39+
#ifndef _WIN32
40+
#include <sys/ioctl.h>
41+
#endif
42+
3943
namespace
4044
{
4145
inline void write_all_fd(int fd, const char *data, std::size_t len) noexcept
@@ -59,6 +63,36 @@ namespace
5963
} // namespace
6064
#endif
6165

66+
#ifndef _WIN32
67+
namespace
68+
{
69+
std::size_t terminal_width() noexcept
70+
{
71+
struct winsize ws{};
72+
73+
if (::ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0 && ws.ws_col > 0)
74+
return static_cast<std::size_t>(ws.ws_col);
75+
76+
return 120;
77+
}
78+
79+
std::string truncate_progress_text(const std::string &line, std::size_t maxWidth)
80+
{
81+
if (maxWidth == 0)
82+
return "";
83+
84+
if (line.size() <= maxWidth)
85+
return line;
86+
87+
if (maxWidth <= 3)
88+
return std::string(maxWidth, '.');
89+
90+
const std::size_t keep = maxWidth - 3;
91+
return line.substr(0, keep) + "...";
92+
}
93+
}
94+
#endif
95+
6296
namespace vix::cli::build
6397
{
6498
namespace util = vix::cli::util;
@@ -355,15 +389,21 @@ namespace vix::cli::build
355389
if (quiet)
356390
return;
357391

358-
std::string out = "\r" + line;
392+
const std::size_t width = terminal_width();
393+
394+
std::string visibleLine = line;
395+
if (width > 1)
396+
visibleLine = truncate_progress_text(line, width - 1);
397+
398+
std::string out = "\r" + visibleLine;
359399

360-
if (lastRenderedWidth > line.size())
361-
out.append(lastRenderedWidth - line.size(), ' ');
400+
if (lastRenderedWidth > visibleLine.size())
401+
out.append(lastRenderedWidth - visibleLine.size(), ' ');
362402

363403
write_all_fd(STDOUT_FILENO, out.data(), out.size());
364404

365405
progressVisible = true;
366-
lastRenderedWidth = std::max(lastRenderedWidth, line.size());
406+
lastRenderedWidth = std::max(lastRenderedWidth, visibleLine.size());
367407
};
368408

369409
auto flush_progress_line = [&]() -> void
@@ -398,6 +438,9 @@ namespace vix::cli::build
398438
if (line.find("Re-running CMake...") != std::string::npos)
399439
return false;
400440

441+
if (line.find("Copy compile_commands.json to project root") != std::string::npos)
442+
return false;
443+
401444
if (line.rfind("FAILED:", 0) == 0)
402445
return true;
403446

src/commands/BuildCommand.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,11 +916,11 @@ namespace vix::commands::BuildCommand
916916
artifact_cache::Artifact projectArtifact =
917917
make_project_artifact(plan_, opt_, tc);
918918

919-
if (!opt_.quiet)
919+
if (verboseMode && !opt_.quiet)
920920
{
921921
if (artifact_cache::ArtifactCache::exists(projectArtifact))
922922
step("artifact cache: hit -> " + projectArtifact.root.string());
923-
else if (verboseMode)
923+
else
924924
step("artifact cache: miss -> " + projectArtifact.root.string());
925925
}
926926

0 commit comments

Comments
 (0)