From fb0f163ba1f870158410a3851740101ecdc9d3ff Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 18 Aug 2025 17:03:29 +0200 Subject: xa65: Introduce the -s/--strict option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This further iterates on the previous -e/--error flag and it asks 'xa65' to error out in any case: when 'nasm' errors out, but also when the diff is not empty. Signed-off-by: Miquel Sabaté Solà --- crates/xa65/src/main.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'crates/xa65/src') diff --git a/crates/xa65/src/main.rs b/crates/xa65/src/main.rs index 379dec9..6ac51c6 100644 --- a/crates/xa65/src/main.rs +++ b/crates/xa65/src/main.rs @@ -14,7 +14,7 @@ struct Args { config: Option, target: Option, out: String, - error: bool, + strict: bool, } // Print the help message and quit. @@ -24,7 +24,7 @@ fn print_help() { println!("Options:"); println!(" -b, --bin \tAlternative to the binary for 'nasm'."); println!(" -C, --config \tLinker configuration to be used, whether an identifier or a file path."); - println!(" -e, --error\tDon't dismiss errors from 'nasm' and use the same exit code."); + println!(" -s, --strict\tError out if the output differ or 'nasm' has produced an error."); println!(" -o, --out \tFile path where the output should be located after execution."); println!(" --target nes\t\tUsed for compatibility with 'ca65'."); std::process::exit(0); @@ -57,7 +57,6 @@ fn parse_arguments() -> Args { } }, }, - "-e" | "--error" => res.error = true, "-h" | "--help" => print_help(), "-o" | "--out" => { if res.out.is_empty() { @@ -71,6 +70,7 @@ fn parse_arguments() -> Args { die("only specify the '-o/--out' flag once".to_string()); } } + "-s" | "--strict" => res.strict = true, "--target" => match res.target { Some(_) => die("only specify the '--target' flag once".to_string()), None => match args.next() { @@ -209,6 +209,8 @@ fn attempt_hexdump(dir: &Path) { } fn main() { + let mut exit_code = 0; + // Parse arguments. let args = parse_arguments(); @@ -242,7 +244,7 @@ fn main() { .status() { Ok(cmd) => { - if !cmd.success() && args.error { + if !cmd.success() && args.strict { std::process::exit(cmd.code().unwrap_or(1)); } } @@ -296,6 +298,12 @@ fn main() { "xa65 (error): 'nasm' and 'ca65' have a mismatch. Check the results at {}", dir.display() ); + + // If 'strict' was enabled, an error should be produced in the + // end. + if args.strict { + exit_code = 1; + } } } Err(e) => { @@ -310,4 +318,6 @@ fn main() { if let Err(e) = std::fs::copy(dir.join("cl65.nes"), args.out) { die(format!("could not copy the resulting binary: {e}")); } + + std::process::exit(exit_code); } -- cgit v1.2.3