Skip to content

Commit

Permalink
feat(apple): enhance log output (#388)
Browse files Browse the repository at this point in the history
- always use verbose output when running `xcodebuild build` to show cargo output
- enhance simulator and device run output by only displaying app logs by default, and printing full process logs when pedantic verbosity is requested
  • Loading branch information
lucasfernog authored Sep 11, 2024
1 parent 6ce163d commit cdb6ed3
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changes/enhance-apple-log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-mobile2": patch
---

Only display logs from the actual iOS application unless pedantic verbosity is requested.
5 changes: 5 additions & 0 deletions .changes/ios-build-logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-mobile2": patch
---

Always use verbose logging when building the app on iOS (`Target::build`) to display cargo build output.
14 changes: 13 additions & 1 deletion src/apple/device/devicectl/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{env::temp_dir, fs::read_to_string};
use crate::{
apple::config::Config,
env::{Env, ExplicitEnv as _},
opts::NoiseLevel,
util::cli::{Report, Reportable},
DuctExpressionExt,
};
Expand Down Expand Up @@ -57,6 +58,7 @@ pub fn run(
non_interactive: bool,
id: &str,
paired: bool,
noise_level: NoiseLevel,
) -> Result<duct::Handle, RunError> {
if !paired {
println!("Pairing with device...");
Expand Down Expand Up @@ -127,7 +129,17 @@ pub fn run(
.wait()
.map_err(RunError::DeployFailed)?;

duct::cmd("idevicesyslog", ["--process", config.app().stylized_name()])
let app_name = config.app().stylized_name().to_string();

duct::cmd("idevicesyslog", ["--process", &app_name])
.before_spawn(move |cmd| {
if !noise_level.pedantic() {
// when not in pedantic log mode, filter out logs that are not from the actual app
// e.g. `App Name(UIKitCore)[processID]: message` vs `App Name[processID]: message`
cmd.arg("--match").arg(format!("{app_name}["));
}
Ok(())
})
.vars(env.explicit_env())
.dup_stdio()
.start()
Expand Down
15 changes: 14 additions & 1 deletion src/apple/device/ios_deploy/run.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
apple::config::Config,
env::{Env, ExplicitEnv as _},
opts::NoiseLevel,
util::cli::{Report, Reportable},
DuctExpressionExt,
};
Expand All @@ -25,6 +26,7 @@ pub fn run_and_debug(
env: &Env,
non_interactive: bool,
id: &str,
noise_level: NoiseLevel,
) -> Result<duct::Handle, RunAndDebugError> {
println!("Deploying app to device...");

Expand All @@ -50,7 +52,18 @@ pub fn run_and_debug(
.map_err(RunAndDebugError::DeployFailed)?
.wait()
.map_err(RunAndDebugError::DeployFailed)?;
duct::cmd("idevicesyslog", ["--process", config.app().stylized_name()])

let app_name = config.app().stylized_name().to_string();

duct::cmd("idevicesyslog", ["--process", &app_name])
.before_spawn(move |cmd| {
if !noise_level.pedantic() {
// when not in pedantic log mode, filter out logs that are not from the actual app
// e.g. `App Name(UIKitCore)[processID]: message` vs `App Name[processID]: message`
cmd.arg("--match").arg(format!("{app_name}["));
}
Ok(())
})
.vars(env.explicit_env())
.dup_stdio()
.start()
Expand Down
19 changes: 14 additions & 5 deletions src/apple/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ impl<'a> Device<'a> {
.map_err(RunError::ArchiveFailed)?;

match self.kind {
DeviceKind::Simulator => simctl::run(config, env, non_interactive, &self.id)
.map_err(|e| RunError::DeployFailed(e.to_string())),
DeviceKind::Simulator => {
simctl::run(config, env, non_interactive, noise_level, &self.id)
.map_err(|e| RunError::DeployFailed(e.to_string()))
}
DeviceKind::IosDeployDevice | DeviceKind::DeviceCtlDevice => {
println!("Exporting app...");
self.target
Expand Down Expand Up @@ -181,11 +183,18 @@ impl<'a> Device<'a> {
cmd.run().map_err(RunError::UnzipFailed)?;

if self.kind == DeviceKind::IosDeployDevice {
ios_deploy::run_and_debug(config, env, non_interactive, &self.id)
ios_deploy::run_and_debug(config, env, non_interactive, &self.id, noise_level)
.map_err(|e| RunError::DeployFailed(e.to_string()))
} else {
devicectl::run(config, env, non_interactive, &self.id, self.paired)
.map_err(|e| RunError::DeployFailed(e.to_string()))
devicectl::run(
config,
env,
non_interactive,
&self.id,
self.paired,
noise_level,
)
.map_err(|e| RunError::DeployFailed(e.to_string()))
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/apple/device/simctl/run.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
apple::config::Config,
env::{Env, ExplicitEnv as _},
opts::NoiseLevel,
util::cli::{Report, Reportable},
DuctExpressionExt,
};
Expand All @@ -24,6 +25,7 @@ pub fn run(
config: &Config,
env: &Env,
non_interactive: bool,
noise_level: NoiseLevel,
id: &str,
) -> Result<duct::Handle, RunError> {
println!("Deploying app to device...");
Expand Down Expand Up @@ -76,7 +78,11 @@ pub fn run(
"--level",
"debug",
"--predicate",
&format!("process == \"{}\"", config.app().stylized_name()),
&if noise_level.pedantic() {
format!("process == \"{}\"", config.app().stylized_name())
} else {
format!("subsystem = \"{}\"", config.app().identifier())
},
],
)
.vars(env.explicit_env())
Expand Down
5 changes: 1 addition & 4 deletions src/apple/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl<'a> Target<'a> {
&self,
config: &Config,
env: &Env,
noise_level: opts::NoiseLevel,
_noise_level: opts::NoiseLevel,
profile: opts::Profile,
build_config: BuildConfig,
) -> Result<(), BuildError> {
Expand All @@ -446,9 +446,6 @@ impl<'a> Target<'a> {
.before_spawn(move |cmd| {
build_config.xcodebuild_options.args_for(cmd);

if let Some(v) = verbosity(noise_level) {
cmd.arg(v);
}
if let Some(a) = &arch {
cmd.args(["-arch", a]);
}
Expand Down

0 comments on commit cdb6ed3

Please sign in to comment.