Skip to content

Commit

Permalink
fix(cli/android): fallback to ${program}.cmd (#6576)
Browse files Browse the repository at this point in the history
* fix(cli/android): fallback to `${program}.cmd`

* cleanup [skip ci]

* revert variable to tauri-binary [skip ci]

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
  • Loading branch information
amrbashir and lucasfernog authored Mar 29, 2023
1 parent 6e3e4c2 commit 39df2c9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changes/pnpm-android.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'cli.rs': 'patch'
---

Fix `tauri anroid build/dev` crashing when used with standalone `pnpm` executable on Windows.
16 changes: 0 additions & 16 deletions tooling/cli/src/mobile/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ pub fn exec(
let binary_path = PathBuf::from(&binary);
let bin_stem = binary_path.file_stem().unwrap().to_string_lossy();
let r = regex::Regex::new("(nodejs|node)\\-?([1-9]*)*$").unwrap();
let mut is_npm = false;
if r.is_match(&bin_stem) {
if let Some(npm_execpath) = var_os("npm_execpath").map(PathBuf::from) {
is_npm = true;
let manager_stem = npm_execpath.file_stem().unwrap().to_os_string();
binary = if manager_stem == "npm-cli" {
"npm".into()
Expand All @@ -144,20 +142,6 @@ pub fn exec(
}
}
}
if is_npm {
map.insert(
"executable",
format!(
r#"if (Os.isFamily(Os.FAMILY_WINDOWS)) {{ """{binary}.cmd""" }} else {{ """{binary}""" }}"#,
binary = binary.to_string_lossy()
),
);
} else {
map.insert(
"executable",
format!(r#""""{}""""#, binary.to_string_lossy()),
);
}

map.insert("tauri-binary", binary.to_string_lossy());
map.insert("tauri-binary-args", &build_args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,28 @@ open class BuildTask : DefaultTask() {

@TaskAction
fun build() {
val executable = """{{tauri-binary}}""";
try {
runTauriCli(executable)
} catch (e: Exception){
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
runTauriCli("$executable.cmd")
} else {
throw e;
}
}
}

fun runTauriCli(executable: String) {
val rootDirRel = rootDirRel ?: throw GradleException("rootDirRel cannot be null")
val target = target ?: throw GradleException("target cannot be null")
val release = release ?: throw GradleException("release cannot be null")
val args = listOf({{quote-and-join tauri-binary-args}});

project.exec {
workingDir(File(project.projectDir, rootDirRel.path))
executable({{executable}})
args(listOf({{quote-and-join tauri-binary-args}}))
executable(executable)
args(args)
if (project.logger.isEnabled(LogLevel.DEBUG)) {
args("-vv")
} else if (project.logger.isEnabled(LogLevel.INFO)) {
Expand All @@ -40,5 +55,4 @@ open class BuildTask : DefaultTask() {
args(listOf("--target", target))
}.assertNormalExitValue()
}
}

}

0 comments on commit 39df2c9

Please sign in to comment.