diff --git a/.changes/relative-mobile-args.md b/.changes/relative-mobile-args.md new file mode 100644 index 000000000..601f9f6a3 --- /dev/null +++ b/.changes/relative-mobile-args.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": patch:enhance +"@tauri-apps/cli": patch:enhance +--- + +Transform paths to relative to the mobile project for the IDE script runner script. diff --git a/tooling/cli/src/mobile/init.rs b/tooling/cli/src/mobile/init.rs index 4965f14ba..0c85f7223 100644 --- a/tooling/cli/src/mobile/init.rs +++ b/tooling/cli/src/mobile/init.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT use super::{get_app, Target}; -use crate::helpers::{config::get as get_tauri_config, template::JsonMap}; +use crate::helpers::{app_paths::tauri_dir, config::get as get_tauri_config, template::JsonMap}; use crate::Result; use cargo_mobile2::{ android::{ @@ -15,6 +15,7 @@ use cargo_mobile2::{ util::{ self, cli::{Report, TextWrapper}, + relativize_path, }, }; use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError}; @@ -97,6 +98,13 @@ pub fn exec( let (handlebars, mut map) = handlebars(&app); + // the CWD used when the the IDE runs the android-studio-script or the xcode-script + let ide_run_cwd = if target == Target::Android { + tauri_dir() + } else { + tauri_dir().join("gen/apple") + }; + let mut args = std::env::args_os(); let mut binary = args .next() @@ -104,7 +112,7 @@ pub fn exec( let path = PathBuf::from(&bin); if path.exists() { let absolute_path = util::prefix_path(¤t_dir, path); - return absolute_path.into(); + return relativize_path(absolute_path, &ide_run_cwd).into_os_string(); } bin }) @@ -114,11 +122,16 @@ pub fn exec( let path = PathBuf::from(&arg); if path.exists() { let absolute_path = util::prefix_path(¤t_dir, path); - build_args.push(absolute_path.to_string_lossy().into_owned()); + build_args.push( + relativize_path(absolute_path, &ide_run_cwd) + .to_string_lossy() + .into_owned(), + ); continue; } + let is_mobile_cmd_arg = arg == "android" || arg == "ios"; build_args.push(arg.to_string_lossy().into_owned()); - if arg == "android" || arg == "ios" { + if is_mobile_cmd_arg { break; } } @@ -163,7 +176,6 @@ pub fn exec( // Generate Android Studio project Target::Android => match AndroidEnv::new() { Ok(_env) => { - let app = get_app(tauri_config_); let (config, metadata) = super::android::get_config(&app, tauri_config_, &Default::default()); map.insert("android", &config);