fix: Windows batch file line endings to avoid cmd parsing bug#1222
Conversation
e90e6c4 to
e7c03d2
Compare
|
e7c03d2 to
bd509fd
Compare
fmeum
left a comment
There was a problem hiding this comment.
Wow, that's a subtle bug. Thanks for working on a workaround!
09bbce4 to
fd8897e
Compare
|
Anyone from the maintainers or recent merge authors (e.g., @alexeagle @hofbi) able to review this? |
Windows cmd has a known bug where GOTO/CALL to labels fails when batch files use LF-only line endings and the label crosses a 512-byte boundary during parsing. This causes "cannot find batch label" errors. References: - https://www.dostips.com/forum/viewtopic.php?t=8988 - rocq-prover/rocq#8610 This fix ensures all generated .bat files use CRLF line endings by converting templates and using \r\n in string replacements throughout: - diff_test: template and substitutions, - write_source_file: batch updater scripts, - windows_utils: native launcher scripts. To verify these changes work correctly across platforms, we add a Go binary (`check_newlines`) that validates line endings: - on Windows: verifies scripts have proper CRLF line endings, - otherwise: verifies \n to \r\n replacements don't affect POSIX scripts. Note: we initially considered `sh_test` with PowerShell/batch wrappers, but encountered issues with interpreter dependencies, script portability, and symlink handling across platforms. A single Go binary invoked via `native_test` proved more reliable and maintainable, working consistently across all platforms (no new external dependencies either).
Address review feedback to use `splitlines()` instead of `split("\n")`
and `replace("\n", "\r\n")` which could produce `\r\r\n` if input
already contains `\r\n`.
`splitlines` properly handles all line ending types (`\n`, `\r\n`, `\r`)
and avoids double-escaping issues.
fd8897e to
60a159e
Compare
This upgrade includes a Windows compatibility fix for batch file line endings (bazel-contrib/bazel-lib#1222), which resolves a cmd parsing bug where GOTO/CALL to labels fails when batch files use non CRLF-only line endings and a label crosses a 512-byte boundary: ```diff $ bazel test //deps/openssl3:module_consistency_test [...] ==================== Test output for //deps/openssl3:module_consistency_test: -The system cannot find the batch label specified - compare_files +compare_files +FAIL: files "C:\[...]\bazel-out\[...]\deps\openssl3\openssl3.MODULE.bazel.new" and "C:\[workspace]\deps\openssl3\openssl3.MODULE.bazel" differ. + + +@@//deps/openssl3:openssl3.MODULE.bazel is out of date. To update this file, run: + + bazel run //deps/openssl3:module_consistency +To see differences run: + + diff "C:\[...]\bazel-out\[...]\deps\openssl3\openssl3.MODULE.bazel.new" "C:\[workspace]\deps\openssl3\openssl3.MODULE.bazel" + ================================================================================ ``` Because this now surfaces we'd been generating `*.MODULE.bazel` with OS-specific newlines, the present change fixes it by always issuing UNIX-style newlines: ```sh $ bazel test //deps/openssl3:module_consistency_test [...] //deps/openssl3:module_consistency_test PASSED in 0.4s ``` `bazel_lib` 3.1.1 comes with further improvements, like: - bazel-contrib/bazel-lib#1217 - bazel-contrib/bazel-lib#1220 - bazel-contrib/bazel-lib#1232
### What does this PR do? This upgrade includes a Windows compatibility fix for batch file line endings (bazel-contrib/bazel-lib#1222), which resolves a cmd parsing bug where GOTO/CALL to labels fails when batch files use non CRLF-only line endings and a label crosses a 512-byte boundary: ```diff > bazel test //deps/openssl3:module_consistency_test [...] ==================== Test output for //deps/openssl3:module_consistency_test: -The system cannot find the batch label specified - compare_files +compare_files +FAIL: files "C:\[...]\bazel-out\[...]\deps\openssl3\openssl3.MODULE.bazel.new" and "C:\[workspace]\deps\openssl3\openssl3.MODULE.bazel" differ. + + +@@//deps/openssl3:openssl3.MODULE.bazel is out of date. To update this file, run: + + bazel run //deps/openssl3:module_consistency +To see differences run: + + diff "C:\[...]\bazel-out\[...]\deps\openssl3\openssl3.MODULE.bazel.new" "C:\[workspace]\deps\openssl3\openssl3.MODULE.bazel" + ================================================================================ ``` Because this now surfaces we'd been generating `*.MODULE.bazel` with OS-specific newlines, the present change fixes it by always issuing UNIX-style newlines: ``` > bazel test //deps/openssl3:module_consistency_test [...] //deps/openssl3:module_consistency_test PASSED in 0.4s ``` ### Motivation Keep up to date and better support colleagues working on Windows. ### Describe how you validated your changes Locally for the time being because we still have very limited test coverage due to #44455 being disputed. ### Additional Notes `bazel_lib` 3.1.0/3.1.1 comes with further improvements, like: - bazel-contrib/bazel-lib#1217 - bazel-contrib/bazel-lib#1220 - bazel-contrib/bazel-lib#1232 Co-authored-by: regis.desgroppes <[email protected]>

Windows cmd has a known bug where GOTO/CALL to labels fails when batch files use LF-only line endings and the label crosses a 512-byte boundary during parsing. This causes "cannot find batch label" errors like, for
diff_test:References:
This fix ensures all generated .bat files use CRLF line endings by converting templates and using \r\n in string replacements throughout:
To verify these changes work correctly across platforms, we add a Go binary (
check_newlines) that validates line endings:Note: we initially considered
sh_testwith PowerShell/batch wrappers, but encountered issues with interpreter dependencies, script portability, and symlink handling across platforms.A single Go binary invoked via
native_testproved more reliable and maintainable, working consistently across all platforms (no new external dependencies either).