build: enforce LF on build inputs via .gitattributes; drop sed CR-stripping

npm/build.sh stripped CRs from configure and every scripts/ file before each
WASM build.  Its purpose was purely to survive a Windows checkout with
core.autocrlf=true (which rewrites LF->CRLF, and bash/make then reject CRLF) --
not reproducible packaging.  No tracked build input is CRLF today
(`git ls-files --eol` shows only the incidental appimage/rsc/magic.svg), so it
never fired on a normal checkout, and it mutated the source tree to do it.

Add .gitattributes `eol=lf` for configure, scripts/**, *.sh, *.mak, *.mak.in
and Makefile.in.  Attributes override core.autocrlf, so git always checks these
out as LF regardless of platform -- the authoritative fix -- and the source tree
is never rewritten by the build.  Remove sed_strip_cr and its call sites.

Verified: git check-attr reports eol=lf for configure/scripts/*/*.sh/rules.mak/
Makefile.in; build.sh parses cleanly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Darryl L. Miles 2026-07-23 15:31:18 +00:00 committed by R. Timothy Edwards
parent 25fa181200
commit 92d13c9894
2 changed files with 13 additions and 14 deletions

11
.gitattributes vendored
View File

@ -6,3 +6,14 @@
Makefile filter=header
*.gds diff=gds
# Keep build/shell scripts and makefiles LF even when checked out on Windows
# (git core.autocrlf=true), or the shell and make reject CRLF. .gitattributes
# overrides core.autocrlf, so this is the authoritative fix and the WASM build
# (npm/build.sh) no longer needs to strip CRs from the source tree.
/configure text eol=lf
/scripts/** text eol=lf
*.sh text eol=lf
*.mak text eol=lf
*.mak.in text eol=lf
Makefile.in text eol=lf

View File

@ -84,16 +84,6 @@ ncpu() {
fi
}
# Portable in-place sed (BSD sed on macOS disagrees with GNU on -i).
# Uses redirect-back instead of mv so the file's mode bits are preserved
# (configure must stay executable across build.sh invocations).
sed_strip_cr() {
local file=$1 tmp
tmp=$(mktemp)
# Only write back when a CR was actually stripped, so a clean LF checkout is
# left untouched (no mtime bump that could perturb a coexisting native build).
sed 's/\r//' "$file" > "$tmp" && { cmp -s "$tmp" "$file" || cat "$tmp" > "$file"; } && rm "$tmp"
}
if [ $OPT_RELEASE -eq 1 ]; then
EXTRA_CFLAGS="-O2"
@ -171,10 +161,8 @@ build_variant() {
rm -rf "$build_dir"
mkdir -p "$build_dir"
# Strip Windows CRLF line endings on the configure inputs (in the source tree,
# read by configure; no-op on Linux-native files).
sed_strip_cr "$REPO_ROOT/configure"
find "$REPO_ROOT/scripts/" -type f -print0 | while IFS= read -r -d '' f; do sed_strip_cr "$f"; done
# configure and scripts/ are kept LF by .gitattributes (eol=lf), so no CRLF
# stripping is needed here even on a Windows checkout with core.autocrlf=true.
cd "$build_dir"