Skip to content

Commit 08184bb

Browse files
committed
refactor(cli): simplify compact watch output
1 parent dd3f663 commit 08184bb

2 files changed

Lines changed: 16 additions & 104 deletions

File tree

src/commands/BuildCommand.cpp

Lines changed: 11 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -323,53 +323,6 @@ namespace vix::commands::BuildCommand
323323
std::cout << std::flush;
324324
}
325325

326-
static void watch_print_started(
327-
const WatchDisplayContext &display,
328-
const vix::engine::watch::Batch &batch,
329-
WatchDisplayAction action,
330-
bool structuralChange)
331-
{
332-
if (display.verbose)
333-
return;
334-
335-
const bool configurationChange =
336-
action == WatchDisplayAction::Reconfigured;
337-
338-
const std::string subject =
339-
watch_change_subject(
340-
batch,
341-
display.projectDir,
342-
configurationChange,
343-
structuralChange);
344-
345-
const char *phaseColor = CYAN;
346-
const char *phase = "Building";
347-
const char *detail = "incremental graph";
348-
349-
if (configurationChange)
350-
{
351-
phase = "Configuring";
352-
detail = "project graph";
353-
}
354-
else if (structuralChange)
355-
{
356-
phaseColor = YELLOW;
357-
detail = "project structure";
358-
}
359-
360-
std::ostringstream changeLine;
361-
changeLine << watch_label(MAGENTA, "Change")
362-
<< WATCH_PRIMARY << subject << RESET;
363-
364-
watch_print_line(display, changeLine.str());
365-
366-
std::ostringstream phaseLine;
367-
phaseLine << watch_label(phaseColor, phase)
368-
<< detail;
369-
370-
watch_print_line(display, phaseLine.str());
371-
}
372-
373326
static bool watch_is_ninja_progress_line(const std::string &line)
374327
{
375328
if (line.empty() || line.front() != '[')
@@ -479,7 +432,8 @@ namespace vix::commands::BuildCommand
479432
const vix::engine::watch::Batch &batch,
480433
WatchDisplayAction action,
481434
bool structuralChange,
482-
long long ms)
435+
long long ms,
436+
std::string detail = {})
483437
{
484438
if (display.verbose)
485439
return;
@@ -519,6 +473,9 @@ namespace vix::commands::BuildCommand
519473
<< watch_format_duration(ms)
520474
<< RESET;
521475

476+
if (!detail.empty())
477+
line << GRAY << " (" << detail << ")" << RESET;
478+
522479
watch_print_line(display, line.str());
523480
}
524481

@@ -5120,15 +5077,6 @@ namespace vix::commands::BuildCommand
51205077
displayBatch.events.push_back(
51215078
{vix::engine::watch::EventKind::Modified, source, {}, false});
51225079

5123-
if (compactWatchOutput)
5124-
{
5125-
watch_print_started(
5126-
display,
5127-
displayBatch,
5128-
WatchDisplayAction::Rebuilt,
5129-
false);
5130-
}
5131-
51325080
if (!buildOpt.quiet && !compactWatchOutput)
51335081
std::cout << "\nchange " << source.filename().string() << "\n";
51345082

@@ -5360,15 +5308,6 @@ namespace vix::commands::BuildCommand
53605308
}
53615309
}
53625310

5363-
if (compactWatchOutput)
5364-
{
5365-
watch_print_started(
5366-
display,
5367-
*batchOpt,
5368-
action,
5369-
false);
5370-
}
5371-
53725311
if (!buildOpt.quiet && !compactWatchOutput)
53735312
{
53745313
if (batchOpt->events.size() == 1)
@@ -5467,7 +5406,8 @@ namespace vix::commands::BuildCommand
54675406
*batchOpt,
54685407
action,
54695408
false,
5470-
ms);
5409+
ms,
5410+
sourceOnlyChange ? std::string() : std::string("full refresh"));
54715411
else
54725412
watch_print_failed(
54735413
display,
@@ -5692,15 +5632,6 @@ namespace vix::commands::BuildCommand
56925632
const build::BuildGraphInvalidationResult &invalidation,
56935633
const vix::engine::watch::Batch &batch) -> int
56945634
{
5695-
if (compactWatchOutput)
5696-
{
5697-
watch_print_started(
5698-
watchDisplay,
5699-
batch,
5700-
WatchDisplayAction::Rebuilt,
5701-
false);
5702-
}
5703-
57045635
const auto t0 = std::chrono::steady_clock::now();
57055636

57065637
if (sessionOpt.explain && !sessionOpt.quiet)
@@ -5855,15 +5786,6 @@ namespace vix::commands::BuildCommand
58555786
? WatchDisplayAction::Reconfigured
58565787
: WatchDisplayAction::Rebuilt;
58575788

5858-
if (compactWatchOutput)
5859-
{
5860-
watch_print_started(
5861-
watchDisplay,
5862-
batch,
5863-
action,
5864-
action == WatchDisplayAction::Rebuilt);
5865-
}
5866-
58675789
const auto t0 = std::chrono::steady_clock::now();
58685790
WatchCapturedRun run = run_full_refresh();
58695791
lastCode = run.code;
@@ -5883,7 +5805,8 @@ namespace vix::commands::BuildCommand
58835805
batch,
58845806
action,
58855807
action == WatchDisplayAction::Rebuilt,
5886-
ms);
5808+
ms,
5809+
"full refresh");
58875810
else
58885811
watch_print_failed(
58895812
watchDisplay,
@@ -5926,15 +5849,6 @@ namespace vix::commands::BuildCommand
59265849
? WatchDisplayAction::Reconfigured
59275850
: WatchDisplayAction::Rebuilt;
59285851

5929-
if (compactWatchOutput)
5930-
{
5931-
watch_print_started(
5932-
watchDisplay,
5933-
batch,
5934-
action,
5935-
action == WatchDisplayAction::Rebuilt);
5936-
}
5937-
59385852
const auto t0 = std::chrono::steady_clock::now();
59395853
WatchCapturedRun run = run_full_refresh();
59405854
lastCode = run.code;
@@ -5954,7 +5868,8 @@ namespace vix::commands::BuildCommand
59545868
batch,
59555869
action,
59565870
action == WatchDisplayAction::Rebuilt,
5957-
ms);
5871+
ms,
5872+
"full refresh");
59585873
else
59595874
watch_print_failed(
59605875
watchDisplay,

tests/BuildWatchCliTest.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ reject_output "Built ("
108108
reject_output "Done in"
109109
reject_output "Watching project files"
110110
reject_output ""
111+
reject_output "^Change "
112+
reject_output "^Building incremental graph"
111113

112114
printf 'ignored\n' >"$PROJECT/build-ninja/ignored.tmp"
113115
sleep 0.2
@@ -122,8 +124,6 @@ cat >"$PROJECT/src/main.cpp" <<'CPP'
122124
int main() { return one() + two() + three() + 1; }
123125
CPP
124126

125-
wait_for_output "Change.*src/main.cpp"
126-
wait_for_output "Building.*incremental graph"
127127
wait_for_output "Finished.*rebuilt.*src/main.cpp.* in "
128128
sleep 0.4
129129
if [[ "$(grep -c 'Finished.*rebuilt.*src/main.cpp.* in ' "$WATCH_OUT" || true)" != "1" ]]; then
@@ -150,16 +150,13 @@ cat >"$PROJECT/src/three.cpp" <<'CPP'
150150
int three() { return 3; }
151151
CPP
152152

153-
wait_for_output "Change.*3 files"
154153
wait_for_output "Finished.*rebuilt.*3 files.* in "
155154

156155
cat >>"$PROJECT/CMakeLists.txt" <<'CMAKE'
157156
# watch reconfigure
158157
CMAKE
159158

160-
wait_for_output "Change.*CMakeLists.txt"
161-
wait_for_output "Configuring.*project graph"
162-
wait_for_output "Finished.*reconfigured.*CMakeLists.txt.* in "
159+
wait_for_output "Finished.*reconfigured.*CMakeLists.txt.* in .*full refresh"
163160
if grep -A1 'Finished.*reconfigured.*CMakeLists.txt.* in ' "$WATCH_OUT" | grep -q 'Finished.*rebuilt'; then
164161
cat "$WATCH_OUT" >&2
165162
echo "reconfigure iteration printed an extra rebuild line" >&2
@@ -262,9 +259,9 @@ cat >"$NATIVE_PROJECT/src/one.cpp" <<'CPP'
262259
int one() { return 3; }
263260
CPP
264261

265-
wait_for_output "Change.*src/one.cpp" "$NATIVE_OUT"
266-
wait_for_output "Building.*incremental graph" "$NATIVE_OUT"
267262
wait_for_output "Finished.*rebuilt.*src/one.cpp.* in " "$NATIVE_OUT"
263+
reject_output "^Change " "$NATIVE_OUT"
264+
reject_output "^Building incremental graph" "$NATIVE_OUT"
268265
reject_output "Configuring.*project graph" "$NATIVE_OUT"
269266

270267
kill -INT "$WATCH_PID" 2>/dev/null || true

0 commit comments

Comments
 (0)