Skip to content

Commit

Permalink
feat: allow setting a custom target dir resolver (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Dec 28, 2022
1 parent a7fe3f4 commit 74c150a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changes/target-dir-resolver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-mobile": patch
---

Allow specifying an app target dir resolver via `config::App::with_target_dir_resolver`.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions src/android/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,11 @@ impl<'a> Target<'a> {
let jnilibs =
JniLibs::create(config, *self).map_err(SymlinkLibsError::JniLibsCreationFailed)?;

let src = config.app().prefix_path(format!(
"target/{}/{}/{}",
&self.triple,
profile.as_str(),
config.so_name(),
));
let src = config
.app()
.target_dir(&self.triple, profile)
.join(config.so_name());

jnilibs
.symlink_lib(&src)
.map_err(SymlinkLibsError::SymlinkFailed)?;
Expand Down
3 changes: 3 additions & 0 deletions src/apple/ios_deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ struct DeviceInfo {
#[serde(tag = "Event")]
enum Event {
#[serde(rename_all = "PascalCase")]
#[allow(dead_code)]
BundleCopy {
percent: u32,
overall_percent: u32,
path: PathBuf,
},
#[serde(rename_all = "PascalCase")]
#[allow(dead_code)]
BundleInstall {
percent: u32,
overall_percent: u32,
Expand All @@ -36,6 +38,7 @@ enum Event {
#[serde(rename_all = "PascalCase")]
DeviceDetected { device: DeviceInfo },
#[serde(rename_all = "PascalCase")]
#[allow(dead_code)]
Error { code: u32, status: String },
#[serde(other)]
Unknown,
Expand Down
42 changes: 40 additions & 2 deletions src/config/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ mod raw;
pub use self::raw::*;

use crate::{
opts::Profile,
templating::{self, Pack},
util::{self, cli::Report},
};
use serde::Serialize;
use std::path::{Path, PathBuf};
use std::{
fmt::Debug,
path::{Path, PathBuf},
sync::Arc,
};
use thiserror::Error;

pub static KEY: &str = "app";
Expand Down Expand Up @@ -52,7 +57,7 @@ impl Error {
}
}

#[derive(Clone, Debug, Serialize)]
#[derive(Clone, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct App {
root_dir: PathBuf,
Expand All @@ -62,6 +67,21 @@ pub struct App {
asset_dir: PathBuf,
#[serde(skip)]
template_pack: Pack,
#[serde(skip)]
target_dir_resolver: Option<Arc<Box<dyn Fn(&str, Profile) -> PathBuf>>>,
}

impl Debug for App {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("App")
.field("root_dir", &self.root_dir)
.field("name", &self.name)
.field("stylized_name", &self.stylized_name)
.field("domain", &self.domain)
.field("asset_dir", &self.asset_dir)
.field("template_pack", &self.template_pack)
.finish()
}
}

impl App {
Expand Down Expand Up @@ -128,13 +148,31 @@ impl App {
domain,
asset_dir,
template_pack,
target_dir_resolver: None,
})
}

pub fn with_target_dir_resolver<F: Fn(&str, Profile) -> PathBuf + 'static>(
mut self,
resolver: F,
) -> Self {
self.target_dir_resolver
.replace(Arc::new(Box::new(resolver)));
self
}

pub fn root_dir(&self) -> &Path {
&self.root_dir
}

pub fn target_dir(&self, triple: &str, profile: Profile) -> PathBuf {
if let Some(resolver) = &self.target_dir_resolver {
resolver(triple, profile)
} else {
self.prefix_path(format!("target/{}/{}", triple, profile.as_str()))
}
}

pub fn prefix_path(&self, path: impl AsRef<Path>) -> PathBuf {
util::prefix_path(self.root_dir(), path)
}
Expand Down

0 comments on commit 74c150a

Please sign in to comment.