fix(backend): set LC_ALL=C for CGO Make targets under Git Bash on Windows (#2720)
Co-authored-by: Joao Manso <X363081@bcpcorp.net> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Carlos Florencio <carlosmflorencio@gmail.com>
This commit is contained in:
@@ -86,6 +86,11 @@ expect git-bash Windows_NT MINGW64 start-debug "KANDEV_DEBUG_PPROF_ENABLED=true
|
||||
|
||||
# deadcode — the analyzer is invoked through the same shell-specific env-prefix
|
||||
# mechanism, but its command has no __backend marker, so match its module path.
|
||||
# Git Bash additionally carries the CGO_LOCALE prefix (LC_ALL=C): deadcode compiles
|
||||
# the -tags fts5 cgo packages, and this mingw gcc mis-decodes its own non-ASCII
|
||||
# install path under a UTF-8 locale (see docs/public/windows-support.md). LC_ALL=C
|
||||
# (not LANG=C) is used so it overrides an inherited LC_ALL/LC_CTYPE. Unix and
|
||||
# native cmd stay locale-free.
|
||||
expect unix '' '' deadcode \
|
||||
'GOTOOLCHAIN=go1.26.0 go run golang.org/x/tools/cmd/deadcode@v0.48.0 -tags fts5 ./...' \
|
||||
'golang.org/x/tools/cmd/deadcode'
|
||||
@@ -93,9 +98,23 @@ expect windows-native Windows_NT '' deadcode \
|
||||
'set GOTOOLCHAIN=go1.26.0& go run golang.org/x/tools/cmd/deadcode@v0.48.0 -tags fts5 ./...' \
|
||||
'golang.org/x/tools/cmd/deadcode'
|
||||
expect git-bash Windows_NT MINGW64 deadcode \
|
||||
'GOTOOLCHAIN=go1.26.0 go run golang.org/x/tools/cmd/deadcode@v0.48.0 -tags fts5 ./...' \
|
||||
'LC_ALL=C GOTOOLCHAIN=go1.26.0 go run golang.org/x/tools/cmd/deadcode@v0.48.0 -tags fts5 ./...' \
|
||||
'golang.org/x/tools/cmd/deadcode'
|
||||
|
||||
# test — a second CGO_LOCALE consumer, so the prefix is not proven for deadcode
|
||||
# alone. The `test` recipe is deterministic (no version/timestamp ldflags), so
|
||||
# assert it in full across all three shells: Git Bash carries LC_ALL=C, Unix and
|
||||
# native cmd do not.
|
||||
expect git-bash Windows_NT MINGW64 test \
|
||||
'LC_ALL=C CGO_ENABLED=1 go test -tags fts5 ./...' \
|
||||
'go test -tags fts5'
|
||||
expect unix '' '' test \
|
||||
'CGO_ENABLED=1 go test -tags fts5 ./...' \
|
||||
'go test -tags fts5'
|
||||
expect windows-native Windows_NT '' test \
|
||||
'set CGO_ENABLED=1& go test -tags fts5 ./...' \
|
||||
'go test -tags fts5'
|
||||
|
||||
# mkdir — the Windows branch must check for the directory before calling cmd's
|
||||
# mkdir, so rebuilding over an existing bin/ stays quiet while other errors stay
|
||||
# visible. Unix and Git Bash use idempotent `mkdir -p`, which is silent by design.
|
||||
@@ -176,7 +195,30 @@ else
|
||||
printf 'ok %-16s %s\n' "static" 'no literal /dev/null inside $(shell ...)'
|
||||
fi
|
||||
|
||||
# Static guard: native cgo host builds carry the $(CGO_LOCALE) prefix.
|
||||
#
|
||||
# kandev (-tags fts5) and agentctl both import cgo (go list -deps reports CgoFiles),
|
||||
# so their native `go build` invokes gcc and fails on a non-ASCII toolchain path
|
||||
# under Git Bash unless prefixed with $(CGO_LOCALE) — exactly the miss that first
|
||||
# shipped build-agentctl without it. Cross builds set CGO_ENABLED=0 / GOOS= and do
|
||||
# not invoke gcc, so they are excluded. Extend the cmd list here if another host
|
||||
# binary starts importing cgo.
|
||||
cgo_status=0
|
||||
cgo_unprefixed=$(grep -nE '\$\(GO\) build' "$backend_dir/Makefile" \
|
||||
| grep -E '\./cmd/(kandev|agentctl)$' \
|
||||
| grep -vE 'CGO_LOCALE|GOOS=|\$\(GO_(LINUX|DARWIN)') || cgo_status=$?
|
||||
if [ "$cgo_status" -gt 1 ]; then
|
||||
printf 'FAIL %-16s unable to scan Makefile (grep exit %s)\n' "static-cgo" "$cgo_status"
|
||||
status=1
|
||||
elif [ -n "$cgo_unprefixed" ]; then
|
||||
printf 'FAIL %-16s native cgo build without $(CGO_LOCALE):\n' "static-cgo"
|
||||
printf ' %s\n' "$cgo_unprefixed"
|
||||
status=1
|
||||
else
|
||||
printf 'ok %-16s %s\n' "static-cgo" 'native cgo host builds carry $(CGO_LOCALE)'
|
||||
fi
|
||||
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "All Makefile shell-dispatch checks passed (run/dev/start-debug/deadcode/build-kandev across 3 shells, plus static guard)."
|
||||
echo "All Makefile shell-dispatch checks passed (run/dev/start-debug/deadcode/test/build-kandev across 3 shells, plus static guards)."
|
||||
fi
|
||||
exit "$status"
|
||||
|
||||
Reference in New Issue
Block a user