Skip to content

Commit

Permalink
fix(core): allow hyphens and underscores on identifiers, closes #9707 (
Browse files Browse the repository at this point in the history
…#10700)

* fix(core): allow hyphens and underscores on identifiers, closes #9707

* fix build

* fix build

* lint

* move replace

* update tao

* update tao-macros
  • Loading branch information
lucasfernog authored Aug 21, 2024
1 parent da8c9a7 commit 793ee05
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 53 deletions.
8 changes: 8 additions & 0 deletions .changes/mobile-identifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"tauri-cli": patch:bug
"tauri-build": patch:bug
"@tauri-apps/cli": patch:bug
"tauri-runtime-wry": patch:bug
---

Allow hyphens and underscores on app identifiers.
10 changes: 5 additions & 5 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,12 @@ 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);
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
2 changes: 1 addition & 1 deletion core/tauri-runtime-wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rustdoc-args = [ "--cfg", "docsrs" ]

[dependencies]
wry = { version = "0.42", default-features = false, features = [ "drag-drop", "protocol", "os-webview" ] }
tao = { version = "0.29", default-features = false, features = [ "rwh_06" ] }
tao = { version = "0.29.1", default-features = false, features = [ "rwh_06" ] }
tauri-runtime = { version = "2.0.0-rc.5", path = "../tauri-runtime" }
tauri-utils = { version = "2.0.0-rc.5", path = "../tauri-utils" }
raw-window-handle = "0.6"
Expand Down
26 changes: 13 additions & 13 deletions examples/api/src-tauri/Cargo.lock

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

4 changes: 2 additions & 2 deletions tooling/cli/Cargo.lock

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

2 changes: 1 addition & 1 deletion tooling/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ name = "cargo-tauri"
path = "src/main.rs"

[dependencies]
cargo-mobile2 = { version = "0.13.4", default-features = false }
cargo-mobile2 = { version = "0.13.5", default-features = false }
jsonrpsee = { version = "0.24", features = [ "server" ] }
jsonrpsee-core = "0.24"
jsonrpsee-client-transport = { version = "0.24", features = [ "ws" ] }
Expand Down
6 changes: 5 additions & 1 deletion tooling/cli/src/mobile/android/android_studio_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ pub fn command(options: Options) -> Result<()> {
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
let cli_options = read_options(&tauri_config_.identifier);
let (config, metadata) = get_config(
&get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?),
&get_app(
MobileTarget::Android,
tauri_config_,
&AppInterface::new(tauri_config_, None)?,
),
tauri_config_,
None,
&cli_options,
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/src/mobile/android/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
let interface = AppInterface::new(tauri_config_, build_options.target.clone())?;
interface.build_options(&mut Vec::new(), &mut build_options.features, true);

let app = get_app(tauri_config_, &interface);
let app = get_app(MobileTarget::Android, tauri_config_, &interface);
let (config, metadata) = get_config(
&app,
tauri_config_,
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/src/mobile/android/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {

let interface = AppInterface::new(tauri_config_, dev_options.target.clone())?;

let app = get_app(tauri_config_, &interface);
let app = get_app(MobileTarget::Android, tauri_config_, &interface);
let (config, metadata) = get_config(
&app,
tauri_config_,
Expand Down
6 changes: 5 additions & 1 deletion tooling/cli/src/mobile/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ pub fn exec(
let tauri_config_guard = tauri_config.lock().unwrap();
let tauri_config_ = tauri_config_guard.as_ref().unwrap();

let app = get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?);
let app = get_app(
target,
tauri_config_,
&AppInterface::new(tauri_config_, None)?,
);

let (handlebars, mut map) = handlebars(&app);

Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/src/mobile/ios/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
let interface = AppInterface::new(tauri_config_, build_options.target.clone())?;
interface.build_options(&mut Vec::new(), &mut build_options.features, true);

let app = get_app(tauri_config_, &interface);
let app = get_app(MobileTarget::Ios, tauri_config_, &interface);
let (config, _metadata) = get_config(
&app,
tauri_config_,
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/src/mobile/ios/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {

let interface = AppInterface::new(tauri_config_, Some(target_triple))?;

let app = get_app(tauri_config_, &interface);
let app = get_app(MobileTarget::Ios, tauri_config_, &interface);
let (config, _metadata) = get_config(
&app,
tauri_config_,
Expand Down
6 changes: 5 additions & 1 deletion tooling/cli/src/mobile/ios/xcode_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ pub fn command(options: Options) -> Result<()> {
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
let cli_options = read_options(&tauri_config_.identifier);
let (config, metadata) = get_config(
&get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?),
&get_app(
MobileTarget::Ios,
tauri_config_,
&AppInterface::new(tauri_config_, None)?,
),
tauri_config_,
None,
&cli_options,
Expand Down
12 changes: 9 additions & 3 deletions tooling/cli/src/mobile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,19 @@ fn read_options(identifier: &str) -> CliOptions {
options
}

pub fn get_app(config: &TauriConfig, interface: &AppInterface) -> App {
pub fn get_app(target: Target, config: &TauriConfig, interface: &AppInterface) -> App {
let identifier = config
.identifier
.rsplit('.')
.collect::<Vec<&str>>()
.join(".");

let identifier = match target {
Target::Android => identifier.replace('-', "_"),
#[cfg(target_os = "macos")]
Target::Ios => identifier.replace('_', "-"),
};

if identifier.is_empty() {
log::error!("Bundle identifier set in `tauri.conf.json > identifier` cannot be empty");
exit(1);
Expand Down Expand Up @@ -318,7 +324,7 @@ fn ensure_init(
Target::Android => {
let java_folder = project_dir
.join("app/src/main/java")
.join(tauri_config_.identifier.replace('.', "/"));
.join(tauri_config_.identifier.replace('.', "/").replace('-', "_"));
if !java_folder.exists() {
project_outdated_reasons
.push("you have modified your \"identifier\" in the Tauri configuration");
Expand All @@ -330,7 +336,7 @@ fn ensure_init(
.context("missing project.yml file in the Xcode project directory")?;
if !project_yml.contains(&format!(
"PRODUCT_BUNDLE_IDENTIFIER: {}",
tauri_config_.identifier
tauri_config_.identifier.replace('_', "-")
)) {
project_outdated_reasons
.push("you have modified your \"identifier\" in the Tauri configuration");
Expand Down

0 comments on commit 793ee05

Please sign in to comment.