feat(cli): impl BuildOutcome::status_code

This commit is contained in:
rvcas 2021-07-03 14:41:58 -04:00
parent 3fa5b4363e
commit a82b403aa4
2 changed files with 13 additions and 9 deletions

View file

@ -26,6 +26,16 @@ pub enum BuildOutcome {
Errors, Errors,
} }
impl BuildOutcome {
pub fn status_code(&self) -> i32 {
match self {
Self::NoProblems => 0,
Self::OnlyWarnings => 1,
Self::Errors => 2,
}
}
}
pub struct BuiltFile { pub struct BuiltFile {
pub binary_path: PathBuf, pub binary_path: PathBuf,
pub outcome: BuildOutcome, pub outcome: BuildOutcome,

View file

@ -196,13 +196,6 @@ pub fn build(target: &Triple, matches: &ArgMatches, config: BuildConfig) -> io::
.strip_prefix(env::current_dir().unwrap()) .strip_prefix(env::current_dir().unwrap())
.unwrap_or(&binary_path); .unwrap_or(&binary_path);
// Return a nonzero exit code if there were problems
let status_code = match outcome {
BuildOutcome::NoProblems => 0,
BuildOutcome::OnlyWarnings => 1,
BuildOutcome::Errors => 2,
};
// No need to waste time freeing this memory, // No need to waste time freeing this memory,
// since the process is about to exit anyway. // since the process is about to exit anyway.
std::mem::forget(arena); std::mem::forget(arena);
@ -213,7 +206,8 @@ pub fn build(target: &Triple, matches: &ArgMatches, config: BuildConfig) -> io::
total_time.as_millis() total_time.as_millis()
); );
Ok(status_code) // Return a nonzero exit code if there were problems
Ok(outcome.status_code())
} }
BuildAndRun { roc_file_arg_index } => { BuildAndRun { roc_file_arg_index } => {
let mut cmd = Command::new(binary_path); let mut cmd = Command::new(binary_path);
@ -232,7 +226,7 @@ pub fn build(target: &Triple, matches: &ArgMatches, config: BuildConfig) -> io::
} }
match outcome { match outcome {
BuildOutcome::Errors => Ok(2), BuildOutcome::Errors => Ok(outcome.status_code()),
_ => roc_run(cmd.current_dir(original_cwd)), _ => roc_run(cmd.current_dir(original_cwd)),
} }
} }