From dd8ae472966b84f177c7207b9ad019f0722350dc Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sun, 30 Oct 2022 18:39:00 -0400 Subject: [PATCH] Plumb through 3dslink args for run + test commands --- src/command.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 11 +++++++++-- src/main.rs | 4 +--- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/command.rs b/src/command.rs index 0261474..c19be40 100644 --- a/src/command.rs +++ b/src/command.rs @@ -186,6 +186,49 @@ impl RemainingArgs { } } +impl Run { + /// Get the args to pass to `3dslink` based on these options. + pub fn get_3dslink_args(&self) -> Vec { + let mut args = Vec::new(); + + if let Some(address) = self.address { + args.extend(["--address".to_string(), address.to_string()]); + } + + if let Some(argv0) = &self.argv0 { + args.extend(["--arg0".to_string(), argv0.clone()]); + } + + if let Some(retries) = self.retries { + args.extend(["--retries".to_string(), retries.to_string()]); + } + + if self.server { + args.push("--server".to_string()); + } + + let exe_args = self.cargo_args.exe_args(); + if !exe_args.is_empty() { + // For some reason 3dslink seems to want 2 instances of `--`, one + // in front of all of the args like this... + args.extend(["--args".to_string(), "--".to_string()]); + + let mut escaped = false; + for arg in exe_args.iter().cloned() { + if arg.starts_with('-') && !escaped { + // And one before the first `-` arg that is passed in. + args.extend(["--".to_string(), arg]); + escaped = true; + } else { + args.push(arg); + } + } + } + + args + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/lib.rs b/src/lib.rs index ba8d41a..ccd36c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,7 +97,7 @@ pub fn make_cargo_build_command(cmd: &CargoCmd, message_format: &Option) .stdin(Stdio::inherit()) .stderr(Stdio::inherit()); - dbg!(command) + command } /// Finds the sysroot path of the current toolchain @@ -285,9 +285,16 @@ pub fn build_3dsx(config: &CTRConfig) { /// Link the generated 3dsx to a 3ds to execute and test using `3dslink`. /// This will fail if `3dslink` is not within the running directory or in a directory found in $PATH -pub fn link(config: &CTRConfig) { +pub fn link(config: &CTRConfig, cmd: &CargoCmd) { + let run_args = match cmd { + CargoCmd::Run(run) => run, + CargoCmd::Test(test) => &test.run_args, + _ => unreachable!(), + }; + let mut process = Command::new("3dslink") .arg(config.path_3dsx()) + .args(run_args.get_3dslink_args()) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) diff --git a/src/main.rs b/src/main.rs index ea2f47c..e943262 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,9 +38,7 @@ fn main() { build_3dsx(&app_conf); if input.cmd.should_link_to_device() { - // TODO plumb in exe_args and various 3dslink args - eprintln!("Running 3dslink"); - link(&app_conf); + link(&app_conf, &input.cmd); } }