Skip to content

Commit 21ebac9

Browse files
committed
Rewatch: use CompilationOutcome enum
1 parent 9dd5fc1 commit 21ebac9

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

rewatch/src/build.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ pub struct CompilerArgs {
5757
}
5858

5959
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
60-
pub struct IncrementalBuildResult {
61-
pub has_warnings: bool,
60+
pub enum CompilationOutcome {
61+
Clean,
62+
Warnings,
6263
}
6364

6465
fn has_output(output: &str) -> bool {
@@ -75,14 +76,16 @@ fn has_config_warnings(build_state: &BuildCommandState) -> bool {
7576

7677
pub fn format_finished_compilation_message(
7778
compilation_kind: Option<&str>,
78-
has_warnings: bool,
79+
outcome: CompilationOutcome,
7980
duration: Duration,
8081
) -> String {
8182
let compilation_kind = compilation_kind
8283
.map(|kind| format!("{kind} "))
8384
.unwrap_or_default();
84-
let status = if has_warnings { WARNING } else { CHECKMARK };
85-
let warning_suffix = if has_warnings { " with warnings" } else { "" };
85+
let (status, warning_suffix) = match outcome {
86+
CompilationOutcome::Clean => (CHECKMARK, ""),
87+
CompilationOutcome::Warnings => (WARNING, " with warnings"),
88+
};
8689

8790
format!(
8891
"{LINE_CLEAR}{status}Finished {compilation_kind}compilation{warning_suffix} in {:.2}s",
@@ -280,7 +283,7 @@ pub fn incremental_build(
280283
only_incremental: bool,
281284
create_sourcedirs: bool,
282285
plain_output: bool,
283-
) -> Result<IncrementalBuildResult, IncrementalBuildError> {
286+
) -> Result<CompilationOutcome, IncrementalBuildError> {
284287
let build_folder = build_state.root_folder.to_string_lossy().to_string();
285288

286289
let _lock = get_lock_or_exit(LockKind::Build, &build_folder);
@@ -443,7 +446,11 @@ pub fn incremental_build(
443446
} else {
444447
let has_compile_warnings = has_output(&compile_warnings);
445448
let has_config_warning_output = initial_build && has_config_warnings(build_state);
446-
let has_warnings = has_parse_warnings || has_compile_warnings || has_config_warning_output;
449+
let outcome = if has_parse_warnings || has_compile_warnings || has_config_warning_output {
450+
CompilationOutcome::Warnings
451+
} else {
452+
CompilationOutcome::Clean
453+
};
447454

448455
if show_progress {
449456
if plain_output {
@@ -471,7 +478,7 @@ pub fn incremental_build(
471478
write_compiler_info(build_state);
472479

473480
let _lock = drop_lock(LockKind::Build, &build_folder);
474-
Ok(IncrementalBuildResult { has_warnings })
481+
Ok(outcome)
475482
}
476483
}
477484

@@ -565,7 +572,7 @@ pub fn build(
565572
"\n{}",
566573
format_finished_compilation_message(
567574
None,
568-
result.has_warnings,
575+
result,
569576
default_timing.unwrap_or(timing_total_elapsed),
570577
)
571578
);
@@ -589,15 +596,19 @@ mod tests {
589596
#[test]
590597
fn formats_successful_completion_message() {
591598
assert_eq!(
592-
format_finished_compilation_message(None, false, Duration::from_millis(1500)),
599+
format_finished_compilation_message(None, CompilationOutcome::Clean, Duration::from_millis(1500),),
593600
format!("{LINE_CLEAR}{}Finished compilation in 1.50s", CHECKMARK)
594601
);
595602
}
596603

597604
#[test]
598605
fn formats_warning_completion_message() {
599606
assert_eq!(
600-
format_finished_compilation_message(Some("incremental"), true, Duration::from_millis(1500)),
607+
format_finished_compilation_message(
608+
Some("incremental"),
609+
CompilationOutcome::Warnings,
610+
Duration::from_millis(1500),
611+
),
601612
format!(
602613
"{LINE_CLEAR}{}Finished incremental compilation with warnings in 1.50s",
603614
WARNING

rewatch/src/watcher.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ async fn async_watch(
400400
"\n{}\n",
401401
build::format_finished_compilation_message(
402402
Some(compilation_type),
403-
result.has_warnings,
403+
result,
404404
timing_total_elapsed,
405405
)
406406
);
@@ -452,11 +452,7 @@ async fn async_watch(
452452
if !plain_output && show_progress {
453453
println!(
454454
"\n{}\n",
455-
build::format_finished_compilation_message(
456-
None,
457-
result.has_warnings,
458-
timing_total_elapsed,
459-
)
455+
build::format_finished_compilation_message(None, result, timing_total_elapsed,)
460456
);
461457
}
462458
}

0 commit comments

Comments
 (0)