Skip to content

Commit

Permalink
Add gdb command.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed Feb 15, 2020
1 parent 12a1f55 commit ca36e6b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions android-build-tools/src/apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl ApkConfig {
version_name: config.version_name,
version_code: config.version_code,
target_name: config.target_name,
debuggable: config.debuggable,
target_sdk_version,
min_sdk_version: metadata.min_sdk_version.unwrap_or(23),
opengles_version: metadata.opengles_version.unwrap_or((3, 1)),
Expand Down
1 change: 1 addition & 0 deletions android-build-tools/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Config {
pub version_name: String,
pub version_code: u32,
pub target_name: String,
pub debuggable: bool,
pub assets: Option<String>,
pub res: Option<String>,
}
Expand Down
3 changes: 3 additions & 0 deletions android-build-tools/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Manifest {
pub permissions: Vec<Permission>,
pub icon: Option<String>,
pub fullscreen: bool,
pub debuggable: bool,
}

impl Manifest {
Expand Down Expand Up @@ -54,6 +55,7 @@ impl Manifest {
<application
android:hasCode="false"
android:label="{package_label}"
android:debuggable="{debuggable}"
{icon}
{fullscreen}>
<activity
Expand All @@ -78,6 +80,7 @@ impl Manifest {
target_name = &self.target_name,
icon = icon,
fullscreen = fullscreen,
debuggable = self.debuggable,
features = features.join("\n"),
permissions = permissions.join("\n"),
)
Expand Down
2 changes: 1 addition & 1 deletion android-build-tools/src/ndk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl Ndk {
.output()?
.stdout;
let abi = std::str::from_utf8(&stdout).or(Err(NdkError::UnsupportedTarget))?;
Target::from_android_abi(abi)
Target::from_android_abi(abi.trim())
}
}

Expand Down
2 changes: 1 addition & 1 deletion cargo-ndk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
android-build-tools = { path = "../android-build-tools" }
cargo-subcommand = "0.1.0"
cargo-subcommand = { path = "../../cargo-subcommand" } #"0.1.0"
env_logger = "0.7.1"
log = "0.4.8"
serde = "1.0.104"
Expand Down
17 changes: 16 additions & 1 deletion cargo-ndk/src/apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use android_build_tools::config::Config;
use android_build_tools::error::NdkError;
use android_build_tools::ndk::Ndk;
use android_build_tools::target::Target;
use cargo_subcommand::{Artifact, CrateType, Subcommand};
use cargo_subcommand::{Artifact, CrateType, Profile, Subcommand};
use std::path::PathBuf;
use std::process::Command;

Expand Down Expand Up @@ -65,6 +65,7 @@ impl<'a> ApkBuilder<'a> {
version_name: self.manifest.version.clone(),
version_code: 1,
target_name: artifact.name().to_string(),
debuggable: *self.cmd.profile() == Profile::Dev,
assets: self.manifest.assets.clone(),
res: self.manifest.res.clone(),
};
Expand Down Expand Up @@ -97,6 +98,20 @@ impl<'a> ApkBuilder<'a> {
apk.start()?;
Ok(())
}

pub fn gdb(&self, artifact: &Artifact) -> Result<(), NdkError> {
self.run(artifact)?;
let abi = self.ndk.detect_abi()?;
let target_dir = self.build_dir.join(artifact);
let jni_dir = target_dir.join("jni");
std::fs::create_dir_all(&jni_dir)?;
std::fs::write(
jni_dir.join("Android.mk"),
format!("APP_ABI=\"{}\"\nTARGET_OUT=\"\"\n", abi.android_abi()),
)?;
Command::new("ndk-gdb").current_dir(target_dir).status()?;
Ok(())
}
}

fn cargo_env_target_cfg(tool: &str, target: &str) -> String {
Expand Down
13 changes: 11 additions & 2 deletions cargo-ndk/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use cargo_ndk::ApkBuilder;
use cargo_subcommand::Subcommand;
use cargo_subcommand::{Error, Subcommand};
use std::process::Command;

fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

let cmd = Subcommand::new("ndk")?;
let cmd = Subcommand::new("ndk", |_, _| Ok(false))?;
let builder = ApkBuilder::from_subcommand(&cmd)?;

match cmd.cmd() {
Expand All @@ -17,6 +17,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"run" => {
if cmd.artifacts().len() == 1 {
builder.run(&cmd.artifacts()[0])?;
} else {
return Err(Error::InvalidArgs.into());
}
}
"gdb" => {
if cmd.artifacts().len() == 1 {
builder.gdb(&cmd.artifacts()[0])?;
} else {
return Err(Error::InvalidArgs.into());
}
}
_ => {
Expand Down

0 comments on commit ca36e6b

Please sign in to comment.