Skip to content

Commit 371f6d4

Browse files
committed
Support test and doc commands.
1 parent 36d81dc commit 371f6d4

4 files changed

Lines changed: 34 additions & 14 deletions

File tree

android-build-tools/src/cargo.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ use crate::ndk::Ndk;
33
use crate::target::Target;
44
use std::process::Command;
55

6-
pub fn cargo_build(ndk: &Ndk, target: Target, sdk_version: u32) -> Result<Command, NdkError> {
6+
pub fn cargo_apk(ndk: &Ndk, target: Target, sdk_version: u32) -> Result<Command, NdkError> {
77
let triple = target.rust_triple();
88
let mut cargo = Command::new("cargo");
9-
cargo.arg("build");
109

1110
let clang = ndk.clang(target, sdk_version)?;
1211
cargo.env(format!("CC_{}", triple), &clang);

android-build-tools/src/config.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ pub struct Config {
2020

2121
#[derive(Clone, Debug, Default, Deserialize)]
2222
pub struct Metadata {
23-
pub(crate) target_sdk_version: Option<u32>,
24-
pub(crate) min_sdk_version: Option<u32>,
25-
pub(crate) icon: Option<String>,
26-
pub(crate) fullscreen: Option<bool>,
27-
pub(crate) opengles_version: Option<(u8, u8)>,
28-
pub(crate) feature: Option<Vec<FeatureConfig>>,
29-
pub(crate) permission: Option<Vec<PermissionConfig>>,
23+
pub target_sdk_version: Option<u32>,
24+
pub min_sdk_version: Option<u32>,
25+
pub icon: Option<String>,
26+
pub fullscreen: Option<bool>,
27+
pub opengles_version: Option<(u8, u8)>,
28+
pub feature: Option<Vec<FeatureConfig>>,
29+
pub permission: Option<Vec<PermissionConfig>>,
3030
}
3131

3232
#[derive(Clone, Debug, Deserialize)]
33-
pub(crate) struct FeatureConfig {
33+
pub struct FeatureConfig {
3434
name: String,
3535
required: Option<bool>,
3636
}
@@ -45,7 +45,7 @@ impl From<FeatureConfig> for Feature {
4545
}
4646

4747
#[derive(Clone, Debug, Deserialize)]
48-
pub(crate) struct PermissionConfig {
48+
pub struct PermissionConfig {
4949
name: String,
5050
max_sdk_version: Option<u32>,
5151
}

cargo-apk/src/apk.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::error::Error;
22
use crate::manifest::Manifest;
33
use android_build_tools::apk::{Apk, ApkConfig};
4-
use android_build_tools::cargo::{cargo_build, VersionCode};
4+
use android_build_tools::cargo::{cargo_apk, VersionCode};
55
use android_build_tools::config::Config;
66
use android_build_tools::error::NdkError;
77
use android_build_tools::ndk::Ndk;
@@ -75,7 +75,8 @@ impl<'a> ApkBuilder<'a> {
7575

7676
let target_sdk_version = config.manifest.target_sdk_version;
7777

78-
let mut cargo = cargo_build(&config.ndk, *target, target_sdk_version)?;
78+
let mut cargo = cargo_apk(&config.ndk, *target, target_sdk_version)?;
79+
cargo.arg("build");
7980
if self.cmd.target().is_none() {
8081
cargo.arg("--target").arg(target.rust_triple());
8182
}
@@ -110,4 +111,21 @@ impl<'a> ApkBuilder<'a> {
110111
Command::new("ndk-gdb").current_dir(target_dir).status()?;
111112
Ok(())
112113
}
114+
115+
pub fn default(&self) -> Result<(), Error> {
116+
let ndk = Ndk::from_env()?;
117+
let target_sdk_version = self
118+
.manifest
119+
.metadata
120+
.target_sdk_version
121+
.unwrap_or_else(|| ndk.default_platform());
122+
for target in &self.build_targets {
123+
let mut cargo = cargo_apk(&ndk, *target, target_sdk_version)?;
124+
cargo.args(self.cmd.args());
125+
if !cargo.status()?.success() {
126+
return Err(NdkError::CmdFailed(cargo).into());
127+
}
128+
}
129+
Ok(())
130+
}
113131
}

cargo-apk/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ fn main() -> Result<(), ExitDisplay<Error>> {
2222
return Err(Error::invalid_args().into());
2323
}
2424
}
25+
"--" => {
26+
builder.default()?;
27+
}
2528
"gdb" => {
2629
if cmd.artifacts().len() == 1 {
2730
builder.gdb(&cmd.artifacts()[0])?;
@@ -32,7 +35,7 @@ fn main() -> Result<(), ExitDisplay<Error>> {
3235
"help" => {
3336
if let Some(arg) = cmd.args().get(0) {
3437
match &**arg {
35-
"build" | "run" => run_cargo(&cmd)?,
38+
"build" | "run" | "test" | "doc" => run_cargo(&cmd)?,
3639
"gdb" => print_gdb_help(),
3740
_ => print_help(),
3841
}

0 commit comments

Comments
 (0)