feat(cli): transform paths into relative for the mobile IDE script (#8128)

This commit is contained in:
Lucas Fernandes Nogueira
2023-10-30 10:53:18 -03:00
committed by GitHub
parent b5e1334149
commit 01a7a983ab
2 changed files with 23 additions and 5 deletions

View File

@@ -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.

View File

@@ -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(&current_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(&current_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);