Skip to content

Commit

Permalink
Simplify some code in ndk-macro and ndk-build (#162)
Browse files Browse the repository at this point in the history
* ndk-macro/helper: Use `as_deref()` instead of temporary in `map()`

* ndk-build: Deduplicate library path formatting in UnalignedApk::add_lib
  • Loading branch information
MarijnS95 committed Jul 26, 2021
1 parent 49e8ed5 commit 2dc644c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
14 changes: 5 additions & 9 deletions ndk-build/src/apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,13 @@ impl<'a> UnalignedApk<'a> {
return Err(NdkError::PathNotFound(path.into()));
}
let abi = target.android_abi();
let file_name = path.file_name().unwrap();
let out = self.0.build_dir.join("lib").join(abi);
std::fs::create_dir_all(&out)?;
std::fs::copy(path, out.join(&file_name))?;
let lib_path = Path::new("lib").join(abi).join(path.file_name().unwrap());
let out = self.0.build_dir.join(&lib_path);
std::fs::create_dir_all(out.parent().unwrap())?;
std::fs::copy(path, out)?;

let mut aapt = self.0.build_tool(bin!("aapt"))?;
aapt.arg("add").arg(self.0.unaligned_apk()).arg(format!(
"lib/{}/{}",
abi,
file_name.to_str().unwrap()
));
aapt.arg("add").arg(self.0.unaligned_apk()).arg(&lib_path);
if !aapt.status()?.success() {
return Err(NdkError::CmdFailed(aapt));
}
Expand Down
7 changes: 1 addition & 6 deletions ndk-macro/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,11 @@ fn crate_name(name: &str) -> Result<String> {
pub fn crate_path(name: &str, overridden_path: &Option<Path>) -> Path {
// try to use overridden crate path
overridden_path.clone().unwrap_or_else(|| {
// the binding to hold string from `crate_name` fn
let mut detected_name = None;
Ident::new(
// try to determine crate name from Cargo.toml
crate_name(name)
.ok()
.map(|name| {
detected_name = Some(name);
detected_name.as_ref().unwrap().as_str()
})
.as_deref()
// or use default crate name
// (this may cause compilation error when crate is not found)
.unwrap_or_else(|| name),
Expand Down

0 comments on commit 2dc644c

Please sign in to comment.