From 02aa916a26131f10ac2b6cf2aa48896e8b59cba8 Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Wed, 2 Dec 2026 23:49:26 +0900 Subject: [PATCH] fix(xcode): show a short command line instead of the run's launch script (#7485) An Xcode run or debug session printed its whole generated `/bin/sh -c 'set -e ...'` launch script as the console's first line. `RunExtras` gains a `display` override (never saved or sent to the frontend) that `invocation()` echoes instead of the real command line; `xcode::prepare` sets it to the xcodebuild build plus what happens to the app (install & launch on a simulator or device, or launch on the Mac). The real command line is still logged at debug level. Closes #7483 Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- crates/ide-run/src/config.rs | 1 + crates/ide-run/src/lib.rs | 6 +++++ crates/ide-run/src/process.rs | 14 +++++++--- crates/ide-run/src/xcode.rs | 45 +++++++++++++++++++++++++++++++++ crates/ide-run/tests/process.rs | 16 ++++++++++++ 5 files changed, 78 insertions(+), 4 deletions(-) diff --git a/crates/ide-run/src/config.rs b/crates/ide-run/src/config.rs index c99482faa0..4a87192654 100644 --- a/crates/ide-run/src/config.rs +++ b/crates/ide-run/src/config.rs @@ -205,6 +205,7 @@ fn convert(configs: Vec, local: bool) -> Vec { test_runner: non_empty(c.test_runner), watch: c.watch, executor: None, + display: None, }, }); } diff --git a/crates/ide-run/src/lib.rs b/crates/ide-run/src/lib.rs index e34279d3ca..4ee3fa0bba 100644 --- a/crates/ide-run/src/lib.rs +++ b/crates/ide-run/src/lib.rs @@ -211,6 +211,11 @@ pub struct RunExtras { #[serde(default, skip_serializing_if = "Option::is_none")] #[specta(optional)] pub executor: Option, + /// The command line the console shows instead of the one actually run, set while preparing + /// a launch whose real command is a generated script (an Xcode run); never saved. + #[serde(skip)] + #[specta(skip)] + pub display: Option, } impl Default for RunExtras { @@ -237,6 +242,7 @@ impl Default for RunExtras { test_runner: None, watch: false, executor: None, + display: None, } } } diff --git a/crates/ide-run/src/process.rs b/crates/ide-run/src/process.rs index c13dcf1227..6527dbfbfa 100644 --- a/crates/ide-run/src/process.rs +++ b/crates/ide-run/src/process.rs @@ -214,11 +214,17 @@ pub(crate) fn invocation(config: &RunConfig, cwd: &Path) -> Invocation { return shell_invocation(command, windows, std::env::var("COMSPEC").ok()); } let program = resolve_program(command, cwd, config, windows); - let mut display = quote(command); - for a in &config.args { - display.push(' '); - display.push_str("e(a)); + if config.extras.display.is_some() { + tracing::debug!(command = %command, args = ?config.args, "the console shows a shorter command line"); } + let display = config.extras.display.clone().unwrap_or_else(|| { + let mut display = quote(command); + for a in &config.args { + display.push(' '); + display.push_str("e(a)); + } + display + }); Invocation { program, args: config.args.clone(), raw_args: false, shell: false, display } } diff --git a/crates/ide-run/src/xcode.rs b/crates/ide-run/src/xcode.rs index be4f46e684..37cabb1718 100644 --- a/crates/ide-run/src/xcode.rs +++ b/crates/ide-run/src/xcode.rs @@ -756,6 +756,8 @@ pub fn prepare(dir: &Path, config: &mut crate::RunConfig, progress: Progress) -> .into_iter() .chain(app_args) .collect(); + let name = executable.file_name().map_or_else(|| executable.to_string_lossy(), |n| n.to_string_lossy()); + config.extras.display = Some(command_line(&args, "", &format!("launch {name}"))); // Foundation buffers a GUI app's stdout when it is not a terminal; Xcode sets this too. config.env.entry("NSUnbufferedIO".to_owned()).or_insert_with(|| "YES".to_owned()); return Ok(()); @@ -779,6 +781,8 @@ pub fn prepare(dir: &Path, config: &mut crate::RunConfig, progress: Progress) -> .into_iter() .chain(app_args) .collect(); + let then = format!("install & launch {bundle_id} on {}", device.name); + config.extras.display = Some(command_line(&args, " -allowProvisioningUpdates", &then)); let env = std::mem::take(&mut config.env); config.env = env.into_iter().map(|(k, v)| (format!("DEVICECTL_CHILD_{k}"), v)).collect(); return Ok(()); @@ -789,9 +793,23 @@ pub fn prepare(dir: &Path, config: &mut crate::RunConfig, progress: Progress) -> .chain(app_args) .collect(); config.env = std::mem::take(&mut config.env).into_iter().map(|(k, v)| (format!("SIMCTL_CHILD_{k}"), v)).collect(); + let simulators = output(dir, "xcrun", &["simctl", "list", "devices", "available", "-j"].map(String::from), None) + .and_then(|json| crate::simulator::parse_list(&json)) + .unwrap_or_default(); + let name = simulators.into_iter().find(|d| d.udid == udid).map_or(udid, |d| d.name); + config.extras.display = Some(command_line(&args, "", &format!("install & launch {bundle_id} on {name}"))); Ok(()) } +/// The command line an Xcode run's console shows in place of its generated script: the +/// `xcodebuild` build it starts with (`flags` after the build arguments), then `then`, what +/// happens to the built app. +fn command_line(build_args: &[String], flags: &str, then: &str) -> String { + let quote = |a: &String| if a.contains(char::is_whitespace) { sh_quote(a) } else { a.clone() }; + let build: Vec = build_args.iter().map(quote).collect(); + format!("xcodebuild {}{flags} build → {then}", build.join(" ")) +} + /// Error lines of a failed build shown on the console; the rest stay in the build log. const MAX_CONSOLE_ERRORS: usize = 100; @@ -1372,6 +1390,33 @@ mod tests { assert!(schemes(Path::new("/nonexistent")).is_empty()); } + #[test] + fn the_console_shows_the_build_and_what_happens_to_the_app_instead_of_the_script() { + let params = BTreeMap::from([ + ("container".to_owned(), "My App.xcodeproj".to_owned()), + ("scheme".to_owned(), "App".to_owned()), + ("configuration".to_owned(), "Debug".to_owned()), + ]); + let simulator = build_args(¶ms, Some("id=SIM-1")).unwrap(); + assert_eq!( + command_line(&simulator, "", "install & launch com.example.App on iPhone 17"), + "xcodebuild -project 'My App.xcodeproj' -scheme App -configuration Debug -destination id=SIM-1 build \ + → install & launch com.example.App on iPhone 17" + ); + let device = build_args(¶ms, Some("id=DEV-1")).unwrap(); + assert_eq!( + command_line(&device, " -allowProvisioningUpdates", "install & launch com.example.App on Ann's iPhone"), + "xcodebuild -project 'My App.xcodeproj' -scheme App -configuration Debug -destination id=DEV-1 \ + -allowProvisioningUpdates build → install & launch com.example.App on Ann's iPhone" + ); + let mac = build_args(¶ms, Some(MAC_DESTINATION)).unwrap(); + assert_eq!( + command_line(&mac, "", "launch App"), + "xcodebuild -project 'My App.xcodeproj' -scheme App -configuration Debug -destination platform=macOS build \ + → launch App" + ); + } + #[test] fn build_args_name_the_container_scheme_configuration_and_simulator() { let mut params: BTreeMap = diff --git a/crates/ide-run/tests/process.rs b/crates/ide-run/tests/process.rs index 7b62270946..551c294b29 100644 --- a/crates/ide-run/tests/process.rs +++ b/crates/ide-run/tests/process.rs @@ -121,6 +121,22 @@ fn output_streams_and_exit_code() { assert!(h.pm.write_stdin(id, "x").is_err()); } +#[test] +fn a_display_override_is_the_echoed_command_line() { + let h = harness(); + let mut config = cfg("t:display", "/bin/sh", &["-c", "set -e\necho built\necho launched", "xcode-run"]); + config.extras.display = Some("xcodebuild -scheme App build → install & launch com.example.App on iPhone".into()); + let (id, chunks) = start(&h, &config); + assert_eq!(wait_exit(&h, id, Duration::from_secs(10)), Some(0)); + assert_eq!( + chunks.lock().first(), + Some(&OutputChunk::System { + text: "xcodebuild -scheme App build → install & launch com.example.App on iPhone\n".into() + }) + ); + assert_eq!(text(&chunks, stdout), "built\nlaunched\n"); +} + #[test] fn test_reports_belong_to_the_completed_run_and_project() { let h = harness();