Skip to content

Commit 2d31aef

Browse files
authored
fix(cli): ensure gradlew is executable and does not use CRLF (#10751)
* test fix * ensure gradle is executable and does not use CRLF * fix import * add change file * add 0o111 instead
1 parent 58dda44 commit 2d31aef

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

.changes/ensure-gradlew-unix.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"@tauri-apps/cli": patch:bug
4+
---
5+
6+
Ensure gradlew is executable and does not use CRLF so it can be used on UNIX systems.

tooling/cli/src/mobile/mod.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
interface::{AppInterface, AppSettings, DevProcess, Interface, Options as InterfaceOptions},
1111
ConfigValue,
1212
};
13-
#[cfg(target_os = "macos")]
13+
#[cfg(unix)]
1414
use anyhow::Context;
1515
use anyhow::{bail, Result};
1616
use heck::ToSnekCase;
@@ -325,7 +325,10 @@ fn ensure_init(
325325
let java_folder = project_dir
326326
.join("app/src/main/java")
327327
.join(tauri_config_.identifier.replace('.', "/").replace('-', "_"));
328-
if !java_folder.exists() {
328+
if java_folder.exists() {
329+
#[cfg(unix)]
330+
ensure_gradlew(&project_dir)?;
331+
} else {
329332
project_outdated_reasons
330333
.push("you have modified your \"identifier\" in the Tauri configuration");
331334
}
@@ -362,6 +365,31 @@ fn ensure_init(
362365
Ok(())
363366
}
364367

368+
#[cfg(unix)]
369+
fn ensure_gradlew(project_dir: &std::path::Path) -> Result<()> {
370+
use std::os::unix::fs::PermissionsExt;
371+
372+
let gradlew_path = project_dir.join("gradlew");
373+
if let Ok(metadata) = gradlew_path.metadata() {
374+
let mut permissions = metadata.permissions();
375+
let is_executable = permissions.mode() & 0o111 != 0;
376+
if !is_executable {
377+
permissions.set_mode(permissions.mode() | 0o111);
378+
std::fs::set_permissions(&gradlew_path, permissions)
379+
.context("failed to mark gradlew as executable")?;
380+
}
381+
std::fs::write(
382+
&gradlew_path,
383+
std::fs::read_to_string(&gradlew_path)
384+
.context("failed to read gradlew")?
385+
.replace("\r\n", "\n"),
386+
)
387+
.context("failed to replace gradlew CRLF with LF")?;
388+
}
389+
390+
Ok(())
391+
}
392+
365393
fn log_finished(outputs: Vec<PathBuf>, kind: &str) {
366394
if !outputs.is_empty() {
367395
let mut printable_paths = String::new();

0 commit comments

Comments
 (0)