Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v3
- uses: hecrj/setup-rust-action@v1
- run: cargo install --path xbuild --root .
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.host }}-x
path: bin/x${{ matrix.host == 'windows-latest' && '.exe' || '' }}
2 changes: 1 addition & 1 deletion apk/src/compiler/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub struct Entry<'a> {
entry: &'a ResTableEntry,
}

impl<'a> Entry<'a> {
impl Entry<'_> {
pub fn id(self) -> ResTableRef {
self.id
}
Expand Down
4 changes: 2 additions & 2 deletions mvn/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub struct Artifact<'a> {
pub version: &'a Version,
}

impl<'a> Artifact<'a> {
impl Artifact<'_> {
pub fn file_name(self, ext: &str) -> String {
format!(
"{}-{}-{}.{}",
Expand All @@ -163,7 +163,7 @@ impl<'a> Artifact<'a> {
}
}

impl<'a> std::fmt::Display for Artifact<'a> {
impl std::fmt::Display for Artifact<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
Expand Down
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", "rustls-tls-native-roots"] }
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 @@ -129,7 +129,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 @@ -138,6 +148,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 @@ -373,6 +384,7 @@ impl Adb {
&self,
device: &str,
path: &Path,
launch_args: &[String],
debug_config: &AndroidDebugConfig,
debug: bool,
) -> Result<()> {
Expand All @@ -388,7 +400,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
4 changes: 2 additions & 2 deletions xbuild/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct DownloadManager<'a> {
client: Client,
}

impl<'a> Download for DownloadManager<'a> {
impl Download for DownloadManager<'_> {
fn download(&self, url: &str, dest: &Path) -> Result<()> {
let pb = ProgressBar::with_draw_target(Some(0), ProgressDrawTarget::stdout())
.with_style(
Expand Down Expand Up @@ -234,7 +234,7 @@ impl WorkItem {
}
}

impl<'a> DownloadManager<'a> {
impl DownloadManager<'_> {
pub fn android_jar(&self) -> Result<()> {
let dir = self.env.android_sdk();
let sdk = self.env.target_sdk_version();
Expand Down
2 changes: 1 addition & 1 deletion xbuild/src/gradle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn build(env: &BuildEnv, libraries: Vec<(Target, PathBuf)>, out: &Path) -> R

let external_lib = format!(r#"task.dexDirs.from("{path}")"#);
dexes.push_str(&external_lib);
dexes.push_str("\n");
dexes.push('\n');
}

let dexes = if !dexes.is_empty() {
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