Skip to content

Commit 01a7a98

Browse files
authored
feat(cli): transform paths into relative for the mobile IDE script (#8128)
1 parent b5e1334 commit 01a7a98

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

.changes/relative-mobile-args.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:enhance
3+
"@tauri-apps/cli": patch:enhance
4+
---
5+
6+
Transform paths to relative to the mobile project for the IDE script runner script.

tooling/cli/src/mobile/init.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// SPDX-License-Identifier: MIT
44

55
use super::{get_app, Target};
6-
use crate::helpers::{config::get as get_tauri_config, template::JsonMap};
6+
use crate::helpers::{app_paths::tauri_dir, config::get as get_tauri_config, template::JsonMap};
77
use crate::Result;
88
use cargo_mobile2::{
99
android::{
@@ -15,6 +15,7 @@ use cargo_mobile2::{
1515
util::{
1616
self,
1717
cli::{Report, TextWrapper},
18+
relativize_path,
1819
},
1920
};
2021
use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError};
@@ -97,14 +98,21 @@ pub fn exec(
9798

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

101+
// the CWD used when the the IDE runs the android-studio-script or the xcode-script
102+
let ide_run_cwd = if target == Target::Android {
103+
tauri_dir()
104+
} else {
105+
tauri_dir().join("gen/apple")
106+
};
107+
100108
let mut args = std::env::args_os();
101109
let mut binary = args
102110
.next()
103111
.map(|bin| {
104112
let path = PathBuf::from(&bin);
105113
if path.exists() {
106114
let absolute_path = util::prefix_path(&current_dir, path);
107-
return absolute_path.into();
115+
return relativize_path(absolute_path, &ide_run_cwd).into_os_string();
108116
}
109117
bin
110118
})
@@ -114,11 +122,16 @@ pub fn exec(
114122
let path = PathBuf::from(&arg);
115123
if path.exists() {
116124
let absolute_path = util::prefix_path(&current_dir, path);
117-
build_args.push(absolute_path.to_string_lossy().into_owned());
125+
build_args.push(
126+
relativize_path(absolute_path, &ide_run_cwd)
127+
.to_string_lossy()
128+
.into_owned(),
129+
);
118130
continue;
119131
}
132+
let is_mobile_cmd_arg = arg == "android" || arg == "ios";
120133
build_args.push(arg.to_string_lossy().into_owned());
121-
if arg == "android" || arg == "ios" {
134+
if is_mobile_cmd_arg {
122135
break;
123136
}
124137
}
@@ -163,7 +176,6 @@ pub fn exec(
163176
// Generate Android Studio project
164177
Target::Android => match AndroidEnv::new() {
165178
Ok(_env) => {
166-
let app = get_app(tauri_config_);
167179
let (config, metadata) =
168180
super::android::get_config(&app, tauri_config_, &Default::default());
169181
map.insert("android", &config);

0 commit comments

Comments
 (0)