Skip to content

Commit

Permalink
feat(cli): transform paths into relative for the mobile IDE script (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Oct 30, 2023
1 parent b5e1334 commit 01a7a98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changes/relative-mobile-args.md
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 17 additions & 5 deletions tooling/cli/src/mobile/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -15,6 +15,7 @@ use cargo_mobile2::{
util::{
self,
cli::{Report, TextWrapper},
relativize_path,
},
};
use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError};
Expand Down Expand Up @@ -97,14 +98,21 @@ 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()
.map(|bin| {
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
})
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 01a7a98

Please sign in to comment.