Skip to content

Conversation

@rdesgroppes
Copy link
Contributor

@rdesgroppes rdesgroppes commented Dec 19, 2025

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:

The system cannot find the batch label specified - compare_files

References:

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).

@rdesgroppes rdesgroppes changed the title Fix Windows batch file line endings to avoid cmd.exe parsing bug Fix Windows batch file line endings to avoid cmd parsing bug Dec 19, 2025
@rdesgroppes rdesgroppes changed the title Fix Windows batch file line endings to avoid cmd parsing bug fix: Windows batch file line endings to avoid cmd parsing bug Dec 19, 2025
@rdesgroppes rdesgroppes force-pushed the fix-diff-test-line-endings-on-windows branch from e90e6c4 to e7c03d2 Compare December 19, 2025 23:44
@aspect-workflows
Copy link

aspect-workflows bot commented Dec 19, 2025

Bazel 8 (Test)

4 test targets passed

Targets
//lib/tests/copy_to_directory:case_22_test [k8-fastbuild]                                                 115ms
//lib/tests/copy_to_directory_bin_action:test [k8-fastbuild]                                              102ms
//lib/tests/write_source_files:write_source_file_script_newlines_test [k8-fastbuild]                      85ms
//lib/tests/write_source_files:write_source_file_test_script_newlines_test [k8-fastbuild]                 80ms

Total test execution time was 382ms. 131 tests (97.0%) were fully cached saving 42s.


Bazel 9 (Test)

4 test targets passed

Targets
//lib/tests/copy_to_directory:case_22_test [k8-fastbuild]                                                 130ms
//lib/tests/copy_to_directory_bin_action:test [k8-fastbuild]                                              77ms
//lib/tests/write_source_files:write_source_file_script_newlines_test [k8-fastbuild]                      124ms
//lib/tests/write_source_files:write_source_file_test_script_newlines_test [k8-fastbuild]                 121ms

Total test execution time was 452ms. 131 tests (97.0%) were fully cached saving 25s.


Bazel 7 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 23ms.


Bazel 8 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 23ms.


Bazel 9 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Bazel 7 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 20ms.


Bazel 8 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 21ms.


Bazel 9 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 33ms.


Bazel 7 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 309ms.


Bazel 8 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 295ms.


Bazel 9 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 263ms.


Bazel 7 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 204ms.


Bazel 8 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 260ms.


Bazel 9 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 271ms.


Bazel 7 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 20ms.


Bazel 8 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 21ms.


Bazel 9 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 33ms.


Bazel 7 (Test)

e2e/smoke

All tests were cache hits

4 tests (100.0%) were fully cached saving 415ms.


Bazel 8 (Test)

e2e/smoke

All tests were cache hits

4 tests (100.0%) were fully cached saving 636ms.


Bazel 9 (Test)

e2e/smoke

All tests were cache hits

4 tests (100.0%) were fully cached saving 732ms.


Bazel 7 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 30ms.


Bazel 8 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 28ms.


Bazel 9 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 35ms.

@rdesgroppes rdesgroppes force-pushed the fix-diff-test-line-endings-on-windows branch from e7c03d2 to bd509fd Compare December 19, 2025 23:47
Copy link
Member

@fmeum fmeum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that's a subtle bug. Thanks for working on a workaround!

@rdesgroppes rdesgroppes force-pushed the fix-diff-test-line-endings-on-windows branch 6 times, most recently from 09bbce4 to fd8897e Compare January 6, 2026 16:59
@rdesgroppes rdesgroppes marked this pull request as ready for review January 6, 2026 17:08
@rdesgroppes rdesgroppes requested a review from fmeum January 6, 2026 17:09
@rdesgroppes
Copy link
Contributor Author

Anyone from the maintainers or recent merge authors (e.g., @alexeagle @hofbi) able to review this?

Copy link
Contributor

@tokup tokup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice - thanks

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.
@rdesgroppes rdesgroppes force-pushed the fix-diff-test-line-endings-on-windows branch from fd8897e to 60a159e Compare January 12, 2026 12:03
@rdesgroppes rdesgroppes requested a review from tokup January 12, 2026 12:07
@fmeum fmeum enabled auto-merge (squash) January 13, 2026 16:05
@fmeum fmeum merged commit 8a8fcd6 into bazel-contrib:main Jan 13, 2026
20 checks passed
@rdesgroppes rdesgroppes deleted the fix-diff-test-line-endings-on-windows branch January 13, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants