Skip to content

Commit 00241fa

Browse files
authored
fix(cli): append .cmd on the gradle plugin binary on Windows, fix #6502 (#6503)
1 parent c787f74 commit 00241fa

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

.changes/fix-tauri-binary-windows.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
---
5+
6+
Fixes the Android build gradle plugin implementation on Windows.

tooling/cli/src/mobile/init.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ pub fn exec(
121121
let binary_path = PathBuf::from(&binary);
122122
let bin_stem = binary_path.file_stem().unwrap().to_string_lossy();
123123
let r = regex::Regex::new("(nodejs|node)\\-?([1-9]*)*$").unwrap();
124+
let mut is_npm = false;
124125
if r.is_match(&bin_stem) {
125126
if let Some(npm_execpath) = var_os("npm_execpath").map(PathBuf::from) {
127+
is_npm = true;
126128
let manager_stem = npm_execpath.file_stem().unwrap().to_os_string();
127129
binary = if manager_stem == "npm-cli" {
128130
"npm".into()
@@ -142,7 +144,21 @@ pub fn exec(
142144
}
143145
}
144146
}
145-
map.insert("tauri-binary", binary.to_string_lossy());
147+
if is_npm {
148+
map.insert(
149+
"executable",
150+
format!(
151+
r#"if (Os.isFamily(Os.FAMILY_WINDOWS)) {{ """{binary}.cmd""" }} else {{ """{binary}""" }}"#,
152+
binary = binary.to_string_lossy()
153+
),
154+
);
155+
} else {
156+
map.insert(
157+
"executable",
158+
format!(r#""""{}""""#, binary.to_string_lossy()),
159+
);
160+
}
161+
146162
map.insert("tauri-binary-args", &build_args);
147163
map.insert("tauri-binary-args-str", build_args.join(" "));
148164

tooling/cli/src/mobile/ios/xcode_script.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
};
1111

1212
use clap::Parser;
13-
use tauri_mobile::{apple::target::Target, opts::Profile, util};
13+
use tauri_mobile::{apple::target::Target, opts::Profile};
1414

1515
use std::{collections::HashMap, env::var_os, ffi::OsStr, path::PathBuf};
1616

@@ -72,13 +72,7 @@ pub fn command(options: Options) -> Result<()> {
7272
let macos = macos_from_platform(&options.platform);
7373

7474
with_config(None, |_root_conf, config, metadata, cli_options| {
75-
let env = env()?;
76-
// The `PATH` env var Xcode gives us is missing any additions
77-
// made by the user's profile, so we'll manually add cargo's
78-
// `PATH`.
79-
let env = env
80-
.explicit_env_vars(cli_options.vars)
81-
.prepend_to_path(util::home_dir()?.join(".cargo/bin"));
75+
let env = env()?.explicit_env_vars(cli_options.vars);
8276

8377
if !options.sdk_root.is_dir() {
8478
return Err(anyhow::anyhow!(

tooling/cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package {{reverse-domain app.domain}}
22

33
import java.io.File
4+
import org.apache.tools.ant.taskdefs.condition.Os
45
import org.gradle.api.DefaultTask
56
import org.gradle.api.GradleException
67
import org.gradle.api.logging.LogLevel
@@ -26,7 +27,7 @@ open class BuildTask : DefaultTask() {
2627
val release = release ?: throw GradleException("release cannot be null")
2728
project.exec {
2829
workingDir(File(project.projectDir, rootDirRel.path))
29-
executable("""{{ tauri-binary }}""")
30+
executable({{executable}})
3031
args(listOf({{quote-and-join tauri-binary-args}}))
3132
if (project.logger.isEnabled(LogLevel.DEBUG)) {
3233
args("-vv")

0 commit comments

Comments
 (0)