Skip to content

Commit

Permalink
move replace
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 21, 2024
1 parent 41208c3 commit 70b9d14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
5 changes: 4 additions & 1 deletion core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,10 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
let mut android_package_prefix = String::new();
for (i, w) in s.enumerate() {
if i == last {
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={w}");
println!(
"cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={}",
w.replace('-', "_")
);
} else {
android_package_prefix.push_str(&w.replace(['_', '-'], "_1"));
android_package_prefix.push('_');
Expand Down
23 changes: 4 additions & 19 deletions core/tauri-macros/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ use quote::{format_ident, quote};
use std::env::var;
use syn::{parse_macro_input, spanned::Spanned, ItemFn};

fn get_env_var<R: FnOnce(String) -> String>(
name: &str,
replacer: R,
error: &mut Option<TokenStream2>,
function: &ItemFn,
) -> TokenStream2 {
fn get_env_var(name: &str, error: &mut Option<TokenStream2>, function: &ItemFn) -> TokenStream2 {
match var(name) {
Ok(value) => {
let ident = format_ident!("{}", replacer(value));
let ident = format_ident!("{value}");
quote!(#ident)
}
Err(_) => {
Expand All @@ -37,18 +32,8 @@ pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream {
let function_name = &function.sig.ident;

let mut error = None;
let domain = get_env_var(
"TAURI_ANDROID_PACKAGE_NAME_PREFIX",
|r| r,
&mut error,
&function,
);
let app_name = get_env_var(
"TAURI_ANDROID_PACKAGE_NAME_APP_NAME",
|r| r.replace('-', "_"),
&mut error,
&function,
);
let domain = get_env_var("TAURI_ANDROID_PACKAGE_NAME_PREFIX", &mut error, &function);
let app_name = get_env_var("TAURI_ANDROID_PACKAGE_NAME_APP_NAME", &mut error, &function);

if let Some(e) = error {
quote!(#e).into()
Expand Down

0 comments on commit 70b9d14

Please sign in to comment.