mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-11 16:08:21 +03:00
fix(cli): CLI path issues on mobile project initialization (#9009)
* fix(cli): fix panic when `android init` using cargo or yarn closes #8531 * clippy * try with fullpath * clippy * move cli * Update test-android.yml * add to path instead * clippy * try moving * use cargo subcommand * delete unused logic [skip ci] * truncate on init [skip ci] * enhance binary/args check * update change files --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
cb92cfd6a6
commit
f5f3ed5f6f
6
.changes/cli-mobile-init-partition.md
Normal file
6
.changes/cli-mobile-init-partition.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
'tauri-cli': 'patch:bug'
|
||||||
|
'@tauri-apps/cli': 'patch:bug'
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes Android and iOS project initialization when the Tauri CLI is on a different disk partition.
|
12
.github/workflows/test-android.yml
vendored
12
.github/workflows/test-android.yml
vendored
@ -85,6 +85,14 @@ jobs:
|
|||||||
- name: build CLI
|
- name: build CLI
|
||||||
run: cargo build --manifest-path ./tooling/cli/Cargo.toml
|
run: cargo build --manifest-path ./tooling/cli/Cargo.toml
|
||||||
|
|
||||||
|
- name: move CLI to cargo bin dir
|
||||||
|
if: matrix.os != "windows-latest"
|
||||||
|
run: mv ./tooling/cli/target/debug/cargo-tauri $HOME/.cargo/bin
|
||||||
|
|
||||||
|
- name: move CLI to cargo bin dir
|
||||||
|
if: matrix.os == "windows-latest"
|
||||||
|
run: mv ./tooling/cli/target/debug/cargo-tauri.exe $HOME/.cargo/bin
|
||||||
|
|
||||||
- name: build Tauri API
|
- name: build Tauri API
|
||||||
working-directory: ./tooling/api
|
working-directory: ./tooling/api
|
||||||
run: yarn && yarn build
|
run: yarn && yarn build
|
||||||
@ -95,12 +103,12 @@ jobs:
|
|||||||
|
|
||||||
- name: init Android Studio project
|
- name: init Android Studio project
|
||||||
working-directory: ./examples/api
|
working-directory: ./examples/api
|
||||||
run: ../../tooling/cli/target/debug/cargo-tauri android init
|
run: cargo tauri android init
|
||||||
env:
|
env:
|
||||||
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
|
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
|
||||||
|
|
||||||
- name: build APK
|
- name: build APK
|
||||||
working-directory: ./examples/api
|
working-directory: ./examples/api
|
||||||
run: ../../tooling/cli/target/debug/cargo-tauri android build
|
run: cargo tauri android build
|
||||||
env:
|
env:
|
||||||
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
|
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
|
||||||
|
67
examples/api/src-tauri/Cargo.lock
generated
67
examples/api/src-tauri/Cargo.lock
generated
@ -679,7 +679,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"redox_users",
|
"redox_users",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -706,7 +706,7 @@ dependencies = [
|
|||||||
"dlopen2_derive",
|
"dlopen2_derive",
|
||||||
"libc",
|
"libc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1204,7 +1204,7 @@ dependencies = [
|
|||||||
"gobject-sys",
|
"gobject-sys",
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps",
|
"system-deps",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1613,7 +1613,7 @@ dependencies = [
|
|||||||
"jni-sys",
|
"jni-sys",
|
||||||
"log",
|
"log",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"walkdir 2.4.0",
|
"walkdir",
|
||||||
"windows-sys 0.45.0",
|
"windows-sys 0.45.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1644,16 +1644,6 @@ dependencies = [
|
|||||||
"treediff",
|
"treediff",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "kernel32-sys"
|
|
||||||
version = "0.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
|
||||||
dependencies = [
|
|
||||||
"winapi 0.2.8",
|
|
||||||
"winapi-build",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "keyboard-types"
|
name = "keyboard-types"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@ -1721,7 +1711,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
|
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1958,7 +1948,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"overload",
|
"overload",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2643,16 +2633,6 @@ version = "0.3.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
|
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "same-file"
|
|
||||||
version = "0.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7"
|
|
||||||
dependencies = [
|
|
||||||
"kernel32-sys",
|
|
||||||
"winapi 0.2.8",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "same-file"
|
name = "same-file"
|
||||||
version = "1.0.6"
|
version = "1.0.6"
|
||||||
@ -3238,7 +3218,7 @@ dependencies = [
|
|||||||
"tauri-utils",
|
"tauri-utils",
|
||||||
"tauri-winres",
|
"tauri-winres",
|
||||||
"toml 0.8.2",
|
"toml 0.8.2",
|
||||||
"walkdir 2.4.0",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3263,7 +3243,7 @@ dependencies = [
|
|||||||
"time",
|
"time",
|
||||||
"url",
|
"url",
|
||||||
"uuid",
|
"uuid",
|
||||||
"walkdir 2.4.0",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3290,7 +3270,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"tauri-utils",
|
"tauri-utils",
|
||||||
"toml 0.8.2",
|
"toml 0.8.2",
|
||||||
"walkdir 1.0.7",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3372,7 +3352,7 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
"toml 0.8.2",
|
"toml 0.8.2",
|
||||||
"url",
|
"url",
|
||||||
"walkdir 2.4.0",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3802,24 +3782,13 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "walkdir"
|
|
||||||
version = "1.0.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bb08f9e670fab86099470b97cd2b252d6527f0b3cc1401acdb595ffc9dd288ff"
|
|
||||||
dependencies = [
|
|
||||||
"kernel32-sys",
|
|
||||||
"same-file 0.1.3",
|
|
||||||
"winapi 0.2.8",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "walkdir"
|
name = "walkdir"
|
||||||
version = "2.4.0"
|
version = "2.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
|
checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"same-file 1.0.6",
|
"same-file",
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -4062,12 +4031,6 @@ dependencies = [
|
|||||||
"windows-core",
|
"windows-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi"
|
|
||||||
version = "0.2.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
@ -4078,12 +4041,6 @@ dependencies = [
|
|||||||
"winapi-x86_64-pc-windows-gnu",
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-build"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-i686-pc-windows-gnu"
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@ -4096,7 +4053,7 @@ version = "0.1.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
|
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use super::{get_app, Target};
|
use super::{get_app, Target};
|
||||||
use crate::{
|
use crate::{
|
||||||
helpers::{app_paths::tauri_dir, config::get as get_tauri_config, template::JsonMap},
|
helpers::{config::get as get_tauri_config, template::JsonMap},
|
||||||
interface::{AppInterface, Interface},
|
interface::{AppInterface, Interface},
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
@ -18,17 +18,13 @@ use cargo_mobile2::{
|
|||||||
util::{
|
util::{
|
||||||
self,
|
self,
|
||||||
cli::{Report, TextWrapper},
|
cli::{Report, TextWrapper},
|
||||||
relativize_path,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use handlebars::{
|
use handlebars::{
|
||||||
Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError, RenderErrorReason,
|
Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError, RenderErrorReason,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{env::var_os, path::PathBuf};
|
||||||
env::{current_dir, var, var_os},
|
|
||||||
path::PathBuf,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn command(
|
pub fn command(
|
||||||
target: Target,
|
target: Target,
|
||||||
@ -87,7 +83,6 @@ pub fn exec(
|
|||||||
#[allow(unused_variables)] reinstall_deps: bool,
|
#[allow(unused_variables)] reinstall_deps: bool,
|
||||||
skip_targets_install: bool,
|
skip_targets_install: bool,
|
||||||
) -> Result<App> {
|
) -> Result<App> {
|
||||||
let current_dir = current_dir()?;
|
|
||||||
let tauri_config = get_tauri_config(target.platform_target(), None)?;
|
let tauri_config = get_tauri_config(target.platform_target(), None)?;
|
||||||
|
|
||||||
let tauri_config_guard = tauri_config.lock().unwrap();
|
let tauri_config_guard = tauri_config.lock().unwrap();
|
||||||
@ -97,76 +92,50 @@ pub fn exec(
|
|||||||
|
|
||||||
let (handlebars, mut map) = handlebars(&app);
|
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 args = std::env::args_os();
|
||||||
let mut binary = args
|
|
||||||
|
let (binary, mut build_args) = args
|
||||||
.next()
|
.next()
|
||||||
.map(|bin| {
|
.map(|bin| {
|
||||||
let path = PathBuf::from(&bin);
|
let bin_path = PathBuf::from(&bin);
|
||||||
if path.exists() {
|
let mut build_args = vec!["tauri"];
|
||||||
let absolute_path = util::prefix_path(¤t_dir, path);
|
|
||||||
return relativize_path(absolute_path, &ide_run_cwd).into_os_string();
|
|
||||||
}
|
|
||||||
bin
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|| std::ffi::OsString::from("cargo"));
|
|
||||||
let mut build_args = Vec::new();
|
|
||||||
for arg in args {
|
|
||||||
let path = PathBuf::from(&arg);
|
|
||||||
if path.exists() {
|
|
||||||
let absolute_path = util::prefix_path(¤t_dir, path);
|
|
||||||
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 is_mobile_cmd_arg {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
build_args.push(target.ide_build_script_name().into());
|
|
||||||
|
|
||||||
let binary_path = PathBuf::from(&binary);
|
if let Some(bin_stem) = bin_path.file_stem() {
|
||||||
let bin_stem = binary_path.file_stem().unwrap().to_string_lossy();
|
|
||||||
let r = regex::Regex::new("(nodejs|node)\\-?([1-9]*)*$").unwrap();
|
let r = regex::Regex::new("(nodejs|node)\\-?([1-9]*)*$").unwrap();
|
||||||
if r.is_match(&bin_stem) {
|
if r.is_match(&bin_stem.to_string_lossy()) {
|
||||||
if let Some(npm_execpath) = var_os("npm_execpath").map(PathBuf::from) {
|
if let Some(npm_execpath) = var_os("npm_execpath") {
|
||||||
let manager_stem = npm_execpath.file_stem().unwrap().to_os_string();
|
let manager_stem = PathBuf::from(&npm_execpath)
|
||||||
|
.file_stem()
|
||||||
|
.unwrap()
|
||||||
|
.to_os_string();
|
||||||
let is_npm = manager_stem == "npm-cli";
|
let is_npm = manager_stem == "npm-cli";
|
||||||
let is_npx = manager_stem == "npx-cli";
|
let binary = if is_npm {
|
||||||
binary = if is_npm {
|
|
||||||
"npm".into()
|
"npm".into()
|
||||||
} else if is_npx {
|
} else if manager_stem == "npx-cli" {
|
||||||
"npx".into()
|
"npx".into()
|
||||||
} else {
|
} else {
|
||||||
manager_stem
|
manager_stem
|
||||||
};
|
};
|
||||||
if !(build_args.is_empty() || is_npx) {
|
|
||||||
// remove script path, we'll use `npm_lifecycle_event` instead
|
|
||||||
build_args.remove(0);
|
|
||||||
}
|
|
||||||
if is_npm {
|
if is_npm {
|
||||||
build_args.insert(0, "--".into());
|
build_args.insert(0, "run");
|
||||||
|
build_args.insert(1, "--");
|
||||||
}
|
}
|
||||||
if !is_npx {
|
|
||||||
build_args.insert(0, var("npm_lifecycle_event").unwrap());
|
return (binary, build_args);
|
||||||
}
|
|
||||||
if is_npm {
|
|
||||||
build_args.insert(0, "run".into());
|
|
||||||
}
|
}
|
||||||
|
} else if !cfg!(debug_assertions) && bin_stem == "cargo-tauri" {
|
||||||
|
return (std::ffi::OsString::from("cargo"), build_args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(bin, build_args)
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| (std::ffi::OsString::from("cargo"), vec!["tauri"]));
|
||||||
|
|
||||||
|
build_args.push(target.command_name());
|
||||||
|
build_args.push(target.ide_build_script_name());
|
||||||
|
|
||||||
map.insert("tauri-binary", binary.to_string_lossy());
|
map.insert("tauri-binary", binary.to_string_lossy());
|
||||||
map.insert("tauri-binary-args", &build_args);
|
map.insert("tauri-binary-args", &build_args);
|
||||||
map.insert("tauri-binary-args-str", build_args.join(" "));
|
map.insert("tauri-binary-args-str", build_args.join(" "));
|
||||||
|
Loading…
Reference in New Issue
Block a user