fix(build): silence Windows mkdir "already exists" noise in build logs (#2753)
Co-authored-by: Joao Manso <X363081@bcpcorp.net> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Carlos Florencio <carlosmflorencio@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# check-make-shells — assert that apps/backend/Makefile's run/dev/start-debug
|
||||
# and deadcode targets expand to the correct per-shell command line, without
|
||||
# running them.
|
||||
# building them.
|
||||
#
|
||||
# The Makefile dispatches on two independent axes:
|
||||
# * EXE suffix — keyed on $(OS): any Windows build (native cmd/PowerShell
|
||||
@@ -19,13 +19,15 @@
|
||||
# without having to run on each. The harness itself is bash (grep, sed), so it
|
||||
# needs a POSIX shell — it runs in the Linux CI job and under Git Bash/WSL
|
||||
# locally, not from native cmd.exe/PowerShell. Covers the Make-target dispatch
|
||||
# that the backend Go CI jobs don't exercise.
|
||||
# that the backend Go CI jobs don't exercise. When cmd.exe is available, the
|
||||
# script also runs an isolated mkdir probe without building any binaries.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
backend_dir="$(cd "$(dirname "$0")/../apps/backend" && pwd)"
|
||||
|
||||
status=0
|
||||
windows_mkdir_recipe=
|
||||
|
||||
# expect <label> <OS> <MSYSTEM> <target> <expected recipe tail>
|
||||
expect() {
|
||||
@@ -51,6 +53,9 @@ expect() {
|
||||
fi
|
||||
if [ "$got" = "$want" ]; then
|
||||
printf 'ok %-16s %-12s %s\n' "$label" "$target" "$got"
|
||||
if [ "$label" = windows-native ] && [ "$target" = build-kandev ]; then
|
||||
windows_mkdir_recipe="$got"
|
||||
fi
|
||||
else
|
||||
printf 'FAIL %-16s %-12s\n want: %s\n got: %s\n' \
|
||||
"$label" "$target" "$want" "$got"
|
||||
@@ -91,6 +96,56 @@ expect git-bash Windows_NT MINGW64 deadcode \
|
||||
'GOTOOLCHAIN=go1.26.0 go run golang.org/x/tools/cmd/deadcode@v0.48.0 -tags fts5 ./...' \
|
||||
'golang.org/x/tools/cmd/deadcode'
|
||||
|
||||
# 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.
|
||||
expect unix '' '' build-kandev 'mkdir -p "bin"' mkdir
|
||||
expect windows-native Windows_NT '' build-kandev 'cmd /c if not exist "bin" mkdir "bin"' mkdir
|
||||
expect git-bash Windows_NT MINGW64 build-kandev 'mkdir -p "bin"' mkdir
|
||||
|
||||
# When cmd.exe is available, execute the captured native-Windows recipe against
|
||||
# a temporary directory. This checks that an existing directory stays quiet.
|
||||
check_native_mkdir_behavior() {
|
||||
local recipe=$1 cmd_bin inner probe_name probe_dir stderr_file first_status
|
||||
if ! cmd_bin=$(command -v cmd.exe 2>/dev/null); then
|
||||
printf 'skip %-16s cmd.exe is not available\n' "native-mkdir"
|
||||
return
|
||||
fi
|
||||
|
||||
probe_name=".make-shell-check-$$"
|
||||
probe_dir="$backend_dir/$probe_name"
|
||||
stderr_file=$(mktemp)
|
||||
inner=${recipe#cmd /c }
|
||||
inner=${inner//bin/$probe_name}
|
||||
|
||||
rm -rf "$probe_dir"
|
||||
first_status=0
|
||||
(cd "$backend_dir" && "$cmd_bin" /c "$inner") 2>"$stderr_file" || first_status=$?
|
||||
if [ "$first_status" -ne 0 ] || [ ! -d "$probe_dir" ] || [ -s "$stderr_file" ]; then
|
||||
printf 'FAIL %-16s first mkdir did not create a quiet directory\n' "native-mkdir"
|
||||
status=1
|
||||
rm -rf "$probe_dir"
|
||||
rm -f "$stderr_file"
|
||||
return
|
||||
fi
|
||||
|
||||
: >"$stderr_file"
|
||||
(cd "$backend_dir" && "$cmd_bin" /c "$inner") 2>"$stderr_file" || true
|
||||
if [ -s "$stderr_file" ]; then
|
||||
printf 'FAIL %-16s existing directory wrote to stderr\n' "native-mkdir"
|
||||
status=1
|
||||
else
|
||||
printf 'ok %-16s existing directory stayed quiet\n' "native-mkdir"
|
||||
fi
|
||||
|
||||
rm -rf "$probe_dir"
|
||||
rm -f "$stderr_file"
|
||||
}
|
||||
|
||||
if [ -n "$windows_mkdir_recipe" ]; then
|
||||
check_native_mkdir_behavior "$windows_mkdir_recipe"
|
||||
fi
|
||||
|
||||
# Static guard: no literal /dev/null inside $(shell ...).
|
||||
#
|
||||
# Unlike a recipe, which only ever runs on a platform its target supports,
|
||||
@@ -122,6 +177,6 @@ else
|
||||
fi
|
||||
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "All Makefile shell-dispatch checks passed (3 shells x 4 targets, plus static guard)."
|
||||
echo "All Makefile shell-dispatch checks passed (run/dev/start-debug/deadcode/build-kandev across 3 shells, plus static guard)."
|
||||
fi
|
||||
exit "$status"
|
||||
|
||||
Reference in New Issue
Block a user