Skip to content

Commit

Permalink
fix(cli): ensure gradlew is executable and does not use CRLF (#10751)
Browse files Browse the repository at this point in the history
* test fix

* ensure gradle is executable and does not use CRLF

* fix import

* add change file

* add 0o111 instead
  • Loading branch information
lucasfernog authored Aug 23, 2024
1 parent 58dda44 commit 2d31aef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/ensure-gradlew-unix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:bug
"@tauri-apps/cli": patch:bug
---

Ensure gradlew is executable and does not use CRLF so it can be used on UNIX systems.
32 changes: 30 additions & 2 deletions tooling/cli/src/mobile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
interface::{AppInterface, AppSettings, DevProcess, Interface, Options as InterfaceOptions},
ConfigValue,
};
#[cfg(target_os = "macos")]
#[cfg(unix)]
use anyhow::Context;
use anyhow::{bail, Result};
use heck::ToSnekCase;
Expand Down Expand Up @@ -325,7 +325,10 @@ fn ensure_init(
let java_folder = project_dir
.join("app/src/main/java")
.join(tauri_config_.identifier.replace('.', "/").replace('-', "_"));
if !java_folder.exists() {
if java_folder.exists() {
#[cfg(unix)]
ensure_gradlew(&project_dir)?;
} else {
project_outdated_reasons
.push("you have modified your \"identifier\" in the Tauri configuration");
}
Expand Down Expand Up @@ -362,6 +365,31 @@ fn ensure_init(
Ok(())
}

#[cfg(unix)]
fn ensure_gradlew(project_dir: &std::path::Path) -> Result<()> {
use std::os::unix::fs::PermissionsExt;

let gradlew_path = project_dir.join("gradlew");
if let Ok(metadata) = gradlew_path.metadata() {
let mut permissions = metadata.permissions();
let is_executable = permissions.mode() & 0o111 != 0;
if !is_executable {
permissions.set_mode(permissions.mode() | 0o111);
std::fs::set_permissions(&gradlew_path, permissions)
.context("failed to mark gradlew as executable")?;
}
std::fs::write(
&gradlew_path,
std::fs::read_to_string(&gradlew_path)
.context("failed to read gradlew")?
.replace("\r\n", "\n"),
)
.context("failed to replace gradlew CRLF with LF")?;
}

Ok(())
}

fn log_finished(outputs: Vec<PathBuf>, kind: &str) {
if !outputs.is_empty() {
let mut printable_paths = String::new();
Expand Down

0 comments on commit 2d31aef

Please sign in to comment.