From 1c85b823c132a078ef5a3c8eb43df5c4060fa0e9 Mon Sep 17 00:00:00 2001 From: Isaac Van Doren <69181572+isaacvando@users.noreply.github.com> Date: Sun, 14 Jan 2024 15:39:10 -0600 Subject: [PATCH] add ignore-warnings flag to roc build --- crates/cli/src/lib.rs | 17 +++++++++++++++-- crates/reporting/src/cli.rs | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index c59c4c8ed7..126e47f3db 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -68,6 +68,7 @@ pub const FLAG_STDIN: &str = "stdin"; pub const FLAG_STDOUT: &str = "stdout"; pub const FLAG_WASM_STACK_SIZE_KB: &str = "wasm-stack-size-kb"; pub const FLAG_OUTPUT: &str = "output"; +pub const FLAG_IGNORE_WARNINGS: &str = "ignore-warnings"; pub const ROC_FILE: &str = "ROC_FILE"; pub const ROC_DIR: &str = "ROC_DIR"; pub const GLUE_DIR: &str = "GLUE_DIR"; @@ -139,6 +140,12 @@ pub fn build_app() -> Command { .value_parser(value_parser!(u32)) .required(false); + let flag_ignore_warnings = Arg::new(FLAG_IGNORE_WARNINGS) + .long(FLAG_IGNORE_WARNINGS) + .help("Return successful exit code even if there are warnings.") + .action(ArgAction::SetTrue) + .required(false); + let roc_file_to_run = Arg::new(ROC_FILE) .help("The .roc file of an app to run") .value_parser(value_parser!(PathBuf)) @@ -176,6 +183,7 @@ pub fn build_app() -> Command { .arg(flag_linker.clone()) .arg(flag_prebuilt.clone()) .arg(flag_wasm_stack_size_kb) + .arg(flag_ignore_warnings) .arg( Arg::new(FLAG_TARGET) .long(FLAG_TARGET) @@ -805,8 +813,13 @@ pub fn build( problems.print_to_stdout(total_time); println!(" while successfully building:\n\n {generated_filename}"); - // Return a nonzero exit code if there were problems - Ok(problems.exit_code()) + // If there were only warnings, and warnings are ignored, return successful exit code. Otherwise return exit code unaltered. + let exit_code = problems.exit_code(); + if exit_code == 2 && matches.get_flag(FLAG_IGNORE_WARNINGS) { + Ok(0) + } else { + Ok(exit_code) + } } BuildAndRun => { if problems.fatally_errored { diff --git a/crates/reporting/src/cli.rs b/crates/reporting/src/cli.rs index f50482df14..9c6582f7ce 100644 --- a/crates/reporting/src/cli.rs +++ b/crates/reporting/src/cli.rs @@ -18,8 +18,10 @@ impl Problems { // 0 means no problems, 1 means errors, 2 means warnings if self.errors > 0 { 1 + } else if self.warnings > 0 { + 2 } else { - self.warnings.min(1) as i32 + 0 } }