Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass trailing x run -- arguments to launch command #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions xbuild/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ quick-xml = { version = "0.26.0", features = ["serialize"] }
reqwest = { version = "0.11.13", default-features = false, features = ["blocking", "rustls-tls"] }
serde = { version = "1.0.151", features = ["derive"] }
serde_yaml = "0.9.16"
shlex = "1"
symlink = "0.1.0"
tar = "0.4.38"
toml = "0.5.10"
Expand Down
4 changes: 2 additions & 2 deletions xbuild/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ pub fn devices() -> Result<()> {
Ok(())
}

pub fn run(env: &BuildEnv) -> Result<()> {
pub fn run(env: &BuildEnv, launch_args: &[String]) -> Result<()> {
let out = env.executable();
if let Some(device) = env.target().device() {
device.run(env, &out)?;
device.run(env, &out, launch_args)?;
} else {
anyhow::bail!("no device specified");
}
Expand Down
16 changes: 14 additions & 2 deletions xbuild/src/devices/adb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,17 @@ impl Adb {
}

/// To run a native activity use "android.app.NativeActivity" as the activity name
fn start(&self, device: &str, package: &str, activity: &str) -> Result<()> {
fn start(
&self,
device: &str,
package: &str,
activity: &str,
launch_args: &[String],
) -> Result<()> {
// Quote arguments for `am` so that they don't already get parsed by `adb`.
let launch_args = shlex::try_join(launch_args.iter().map(String::as_str))
.context("Failed to re-quote launch arguments")?;

let status = self
.shell(device, None)
.arg("am")
Expand All @@ -102,6 +112,7 @@ impl Adb {
.arg("android.intent.action.MAIN")
.arg("-n")
.arg(format!("{}/{}", package, activity))
.arg(launch_args)
.status()?;
anyhow::ensure!(
status.success(),
Expand Down Expand Up @@ -340,6 +351,7 @@ impl Adb {
&self,
device: &str,
path: &Path,
launch_args: &[String],
debug_config: &AndroidDebugConfig,
debug: bool,
) -> Result<()> {
Expand All @@ -355,7 +367,7 @@ impl Adb {
self.install(device, path)?;
self.forward_reverse(device, debug_config)?;
let last_timestamp = self.logcat_last_timestamp(device)?;
self.start(device, package, activity)?;
self.start(device, package, activity, launch_args)?;
let uid = self.uidof(device, package)?;
let logcat = self.logcat(device, uid, &last_timestamp)?;
for line in logcat {
Expand Down
4 changes: 2 additions & 2 deletions xbuild/src/devices/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl Host {
}
}

pub fn run(&self, path: &Path) -> Result<()> {
Command::new(path).status()?;
pub fn run(&self, path: &Path, launch_args: &[String]) -> Result<()> {
Command::new(path).args(launch_args).status()?;
Ok(())
}

Expand Down
13 changes: 10 additions & 3 deletions xbuild/src/devices/imd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ impl IMobileDevice {
Ok(())
}

fn start(&self, device: &str, bundle_identifier: &str) -> Result<()> {
fn start(&self, device: &str, bundle_identifier: &str, launch_args: &[String]) -> Result<()> {
let status = Command::new(&self.idevicedebug)
.arg("--udid")
.arg(device)
.arg("run")
.arg(bundle_identifier)
.args(launch_args)
.status()?;
anyhow::ensure!(status.success(), "failed to run idevicedebug");
Ok(())
Expand Down Expand Up @@ -92,11 +93,17 @@ impl IMobileDevice {
Ok(())
}

pub fn run(&self, env: &BuildEnv, device: &str, path: &Path) -> Result<()> {
pub fn run(
&self,
env: &BuildEnv,
device: &str,
path: &Path,
launch_args: &[String],
) -> Result<()> {
let bundle_identifier = appbundle::app_bundle_identifier(path)?;
self.mount_disk_image(env, device)?;
self.install(device, path)?;
self.start(device, &bundle_identifier)?;
self.start(device, &bundle_identifier, launch_args)?;
Ok(())
}

Expand Down
14 changes: 10 additions & 4 deletions xbuild/src/devices/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,17 @@ impl Device {
}
}

pub fn run(&self, env: &BuildEnv, path: &Path) -> Result<()> {
pub fn run(&self, env: &BuildEnv, path: &Path, launch_args: &[String]) -> Result<()> {
match &self.backend {
Backend::Adb(adb) => adb.run(&self.id, path, &env.config.android().debug, false),
Backend::Host(host) => host.run(path),
Backend::Imd(imd) => imd.run(env, &self.id, path),
Backend::Adb(adb) => adb.run(
&self.id,
path,
launch_args,
&env.config.android().debug,
false,
),
Backend::Host(host) => host.run(path, launch_args),
Backend::Imd(imd) => imd.run(env, &self.id, path, launch_args),
}?;
Ok(())
}
Expand Down
14 changes: 12 additions & 2 deletions xbuild/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ enum Commands {
Run {
#[clap(flatten)]
args: BuildArgs,

/// Platform-specific arguments to pass to the launch command:
/// - **Host**: Passed to the running executable, similar to `cargo run -- <launch_args>`.
/// - **Android**: Passed to [`am start`], after the `-a MAIN` and `-n package/.Activity` flags.
/// - **iOS**: Passed to [`idevicedebug`] after `run <bundleid>`.
///
/// [`am start`]: https://developer.android.com/tools/adb#am
/// [`idevicedebug`]: https://manpages.debian.org/testing/libimobiledevice-utils/idevicedebug.1.en.html
#[clap(last = true)]
launch_args: Vec<String>,
},
/// Launch app in a debugger on an attached device
Lldb {
Expand Down Expand Up @@ -104,10 +114,10 @@ impl Commands {
let env = BuildEnv::new(args)?;
command::build(&env)?;
}
Self::Run { args } => {
Self::Run { args, launch_args } => {
let env = BuildEnv::new(args)?;
command::build(&env)?;
command::run(&env)?;
command::run(&env, &launch_args)?;
}
Self::Lldb { args } => {
let env = BuildEnv::new(args)?;
Expand Down
Loading