Repository navigation
fix(cli/mobile): normalize gradlew CRLF on Windows hosts too - #16017
Legend-Master merged 11 commits into
Conversation
ensure_gradlew was gated behind #[cfg(unix)], so the CRLF-to-LF normalization only ran on unix hosts. The CRLF rewrite itself is platform-neutral: a CRLF gradlew breaks sh ./gradlew on every host, including Git-Bash on Windows. Split the function so the unix-only exec-bit fix stays gated while the LF rewrite runs everywhere. This unblocks Windows hosts that previously failed at the gradlew invocation with "'gradlew' is not recognized as an internal or external command" when gradlew carried CRLF endings.
OCR review: the unconditional rewrite churned the file's mtime on every tauri android dev/build even when it was already LF, and could fail on read-only or AV-locked files. Gate the write on the CRLF check.
Hoist gradlew_path above the cfg(unix) block and downgrade CRLF normalization failures to warnings: on Windows the CLI invokes gradlew.bat, so a locked or read-only gradlew must not abort builds that would otherwise succeed. Read failures are logged at debug level.
Package Changes Through 6f227cbThere are 14 changes which include tauri-cli with minor, @tauri-apps/cli with minor, tauri with minor, tauri-build with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, @tauri-apps/api with minor, tauri-bundler with minor, tauri-macos-sign with minor, tauri-codegen with minor, tauri-macros with minor, tauri-plugin with minor, tauri-driver with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
Legend-Master
left a comment
There was a problem hiding this comment.
Thanks! Just a few nitpicks and we can get this merged.
| // The CRLF→LF rewrite is platform-neutral: a CRLF gradlew breaks `sh | ||
| // ./gradlew` on every host (including Git-Bash on Windows), and bash | ||
| // scripts must always use LF. Best effort: only rewrite when a CRLF is | ||
| // actually present, and warn instead of failing so a locked or read-only | ||
| // file cannot abort builds that would otherwise succeed. | ||
| match std::fs::read_to_string(&gradlew_path) { | ||
| Ok(contents) => { | ||
| if contents.contains("\r\n") { | ||
| if let Err(error) = std::fs::write(&gradlew_path, contents.replace("\r\n", "\n")) { | ||
| log::warn!("failed to normalize gradlew CRLF line endings: {error}"); | ||
| } | ||
| } | ||
| } | ||
| Err(error) => log::debug!("failed to read gradlew for CRLF normalization: {error}"), | ||
| } |
There was a problem hiding this comment.
Preserve the old fs_context at least on unix platforms.
| // The CRLF→LF rewrite is platform-neutral: a CRLF gradlew breaks `sh | ||
| // ./gradlew` on every host (including Git-Bash on Windows), and bash | ||
| // scripts must always use LF. Best effort: only rewrite when a CRLF is | ||
| // actually present, and warn instead of failing so a locked or read-only | ||
| // file cannot abort builds that would otherwise succeed. |
There was a problem hiding this comment.
Remove LLM marks, just say why do it on all platforms, and link this PR.
On unix a gradlew that cannot be rewritten will fail the build anyway with a cryptic sh error, so restore the previous fs_context errors there; on Windows the CLI invokes gradlew.bat, so failures only warn. Also reword the comment to plainly state why the rewrite runs on all platforms and reference this PR.
|
Both addressed in adaa8b2: unix failures now propagate with the original fs_context messages again (only Windows warns, since the CLI invokes gradlew.bat there), and the comment now plainly states why the rewrite runs on all platforms with a link back to this PR. |
Summary
ensure_gradlew— which rewrites CRLF to LF in the Androidgradlewwrapper — is gated behind
#[cfg(unix)], both at the call site inensure_initand on the function itself. On Windows hosts thenormalization silently never runs, so a
gradlewwith CRLF endingsbreaks
sh ./gradlewinvocations from Git-Bash/WSL with/usr/bin/env: ‘sh\r’: No such file or directory.This splits the function so the platform-neutral LF rewrite runs on
every host, while the unix exec-bit fix remains gated.
Why this matters
A CRLF
gradlewbreaks everysh-based invocation. Windows userscloning a project whose committed
gradlewcarries CRLF (or checkingout with
core.autocrlf=true) hit this on the firsttauri android build. The normalization is cheap, platform-neutral,and the function already existed — it just never ran off-unix.
Changes
#[cfg(unix)]gate on theensure_gradlewcall site sothe CRLF rewrite runs on all hosts;
#[cfg(unix)](exec bits are a unix permission concept);Verification
On a Windows host:
gradlewin a project'sgen/android, rantauri android build, and confirmed the file was rewritten to LFduring
ensure_init;PS
Adds a change file under .changes as per the contribution guidelines.