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 <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-12-02 22:49:26 +08:00
1 джерело a7b9529109
коміт 02aa916a26
5 files changed
+78 -4

No files matched your search

+1
Переглянути файл
@@ -205,6 +205,7 @@ fn convert(configs: Vec<FileConfig>, local: bool) -> Vec<RunConfig> {
test_runner: non_empty(c.test_runner),
watch: c.watch,
executor: None,
display: None,
},
});
}
+6
Переглянути файл
@@ -211,6 +211,11 @@ pub struct RunExtras {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[specta(optional)]
pub executor: Option<String>,
/// 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<String>,
}
impl Default for RunExtras {
@@ -237,6 +242,7 @@ impl Default for RunExtras {
test_runner: None,
watch: false,
executor: None,
display: None,
}
}
}
+10 -4
Переглянути файл
@@ -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(&quote(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(&quote(a));
}
display
});
Invocation { program, args: config.args.clone(), raw_args: false, shell: false, display }
}
+45
Переглянути файл
@@ -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<String> = 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(&params, 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(&params, 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(&params, 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<String, String> =
+16
Переглянути файл
@@ -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();