fix(tauri-macros): escape _ in mobile entry point's app name (#5029)

This commit is contained in:
Lucas Fernandes Nogueira 2022-08-24 14:02:08 -03:00 committed by GitHub
parent 641d56dcb3
commit ff4cb56b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -4,10 +4,15 @@ use quote::{format_ident, quote};
use std::env::var;
use syn::{parse_macro_input, spanned::Spanned, ItemFn};
fn get_env_var(name: &str, error: &mut Option<TokenStream2>, function: &ItemFn) -> TokenStream2 {
fn get_env_var<R: FnOnce(String) -> String>(
name: &str,
replacer: R,
error: &mut Option<TokenStream2>,
function: &ItemFn,
) -> TokenStream2 {
match var(name) {
Ok(value) => {
let ident = format_ident!("{}", value);
let ident = format_ident!("{}", replacer(value));
quote!(#ident)
}
Err(_) => {
@ -31,8 +36,13 @@ pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream {
let function_name = function.sig.ident.clone();
let mut error = None;
let domain = get_env_var("TAURI_ANDROID_DOMAIN", &mut error, &function);
let app_name = get_env_var("CARGO_PKG_NAME", &mut error, &function);
let domain = get_env_var("TAURI_ANDROID_DOMAIN", |r| r, &mut error, &function);
let app_name = get_env_var(
"CARGO_PKG_NAME",
|r| r.replace('_', "_1"),
&mut error,
&function,
);
if let Some(e) = error {
quote!(#e).into()

View File

@ -3107,8 +3107,7 @@ dependencies = [
[[package]]
name = "tao"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2093fa6bba3cc0c185b21c900de1b757e66637e78848cbcdda967b836d8c0ec"
source = "git+https://github.com/tauri-apps/tao?branch=dev#816ca49dc648a5286eab943c6fc936629fd3a596"
dependencies = [
"bitflags",
"cairo-rs",

View File

@ -8,6 +8,7 @@ license = "Apache-2.0 OR MIT"
[patch.crates-io]
wry = { git = "https://github.com/tauri-apps/wry", branch = "dev" }
tao = { git = "https://github.com/tauri-apps/tao", branch = "dev" }
[lib]
crate-type = ["staticlib", "cdylib", "rlib"]