You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rules_ruby: coverage.patch turns binary.cmd.tpl from CRLF to LF and brings back the Windows batch label failures #8753
rules_ruby 0.29.0 ships ruby/private/binary/binary.cmd.tpl with CRLF line endings on purpose (bazel-contrib/rules_ruby#393). cmd.exe looks up call :label targets by byte offset. With LF-only launchers, rb_test randomly failed with The system cannot find the batch label specified - rlocation. Upstream also converts the {rlocation_function} and {env} text it inserts to CRLF.
coverage.patch edits this template. Bazel's patcher reads files with Guava readLines, which drops the \r, and writes them back joined with \n. So the patched template is LF-only. Every Windows .cmd launcher for ruby_binary/ruby_test then mixes LF template lines with the CRLF :rlocation function, which is the layout upstream fixed. This hits every Ruby target on Windows, not only coverage runs.
Where
patches/rules_ruby/coverage.patch:1-15: the hunk on ruby/private/binary/binary.cmd.tpl (@@ -45,8 +45,11 @@).
Bazel 9.3.1 PatchUtil.java:166,170 reads with FileSystemUtils.readLines and writes with writeLinesAs. FileSystemUtils.java:726 joins lines with "\n".
Fix
After the patches run, convert the touched *.cmd.tpl files back to CRLF. One way is a crlf string_list attr on pinned_archive that does rctx.file(p, rctx.read(p).replace("\r\n", "\n").replace("\n", "\r\n")) for each listed path. Set it to ["ruby/private/binary/binary.cmd.tpl"] for rules_ruby.
Add a test that @rules_ruby//ruby/private/binary:binary.cmd.tpl has no bare LF.
Size: S. Risk: low (new opt-in attr; only rules_ruby sets it).
Confirmed at HEAD f404f79. The rules_ruby 0.29.0 tarball (sha c92c2102…) ships binary.cmd.tpl with CRLF on all 54 lines. libs/starlark/repo.bzl:39-40 patches it with rctx.patch, which writes LF back. No other patch touches a .cmd, .bat or .ps1 file.
Chosen approach: add a generic crlf attr to pinned_archive, applied after patches. It can be reused by any later patched Windows script.
Rejected:
Overlay a full CRLF copy through files: it runs before patches and duplicates upstream text.
Use patch_cmds or system patch: not hermetic, and Windows hosts have no patch.
Upstream the coverage hunk only: still blocked on a rules_ruby release. It is a follow-up.
Steps
libs/starlark/repo.bzl: add a public pure helper crlf_text(text) that normalizes to LF and then to CRLF.
libs/starlark/repo.bzl:_pinned_archive_impl, after the patch loop: for each rctx.attr.crlf, fail if the path is missing, then rctx.file(path, crlf_text(rctx.read(path)), executable = False).
Add attr "crlf": attr.string_list(doc = "Paths rewritten with CRLF line endings after patches.").
ruby/toolchain/repos.bzl:65: set crlf = ["ruby/private/binary/binary.cmd.tpl"].
Tests
New libs/starlark/tests/repo_tests.bzl with repo_unit_tests, mode unit, wired in libs/starlark/tests/BUILD.bazel:
"a\nb\r\nc" -> "a\r\nb\r\nc"
"x\r\n" -> "x\r\n"
"" -> ""
ruby/toolchain/metadata_tests.bzl: add an execution-mode starlark_test named rules_ruby_cmd_crlf, declared in ruby/toolchain/BUILD.bazel. Its file_blocks on @rules_ruby//ruby/private/binary:binary.cmd.tpl must contain:
the patched hunk with \r\n, from if "%COVERAGE%" == "1" (\r\n through )\r\n)\r\n
Upstream Windows coverage for rules_ruby is drafted. Nothing is posted upstream yet; it needs owner approval before the issue and PR are opened on bazel-contrib/rules_ruby.
Change: ruby/private/binary/binary.cmd.tpl replaces the "not supported on Windows" block with the hunk from patches/rules_ruby/coverage.patch (0 bare LFs in the worktree; the blob is LF with eol=crlf from upstream .gitattributes, same as before). .github/workflows/ci.yml drops if: matrix.os != 'windows-latest' from "Run coverage" and "Upload coverage report", so the existing //spec:add coverage check (greps SF: in coverage.dat) is the regression test on Windows. The coverage.rb Bundler gate is left for a separate PR.
Draft upstream issue: "Code coverage is not supported on Windows"
bazel coverage of an rb_test on Windows fails: the Windows launcher (ruby/private/binary/binary.cmd.tpl) prints "Code coverage is currently not supported on Windows." and exits 1. The shell launcher already loads the coverage helper through RUBYOPT (added in #348), and generate_rb_binary_script already fills {coverage_helper} and {is_jruby} in the cmd template, so the same can be done on Windows. CI skips the coverage step on windows-latest for this reason. Related: #393.
Assisted by Claude.
Draft upstream PR: "feat: support code coverage on Windows"
Fixes #.
The Windows launcher now resolves the coverage helper with rlocation and prepends -r<helper> to RUBYOPT (backslashes turned into slashes), and sets JRUBY_OPTS=--debug for JRuby, matching binary.sh.tpl. The template stays CRLF.
The CI "Run coverage" and "Upload coverage report" steps now run on Windows too; they check that coverage.dat for //spec:add has an SF: line for lib/gem/add.rb.
This issue has the blocked label but no Blocked on: line in its body. Add one naming the blocking issue (#N), a pull request URL, or the owner action. See CONTRIBUTING.md.
This issue has the blocked label but no Blocked on: line in its body. Add one naming the blocking issue (#N), a pull request URL, or the owner action. See CONTRIBUTING.md.
Activity
TrapsterDK commentedon Nov 6, 2026
Plan
Size: S. Risk: low (new opt-in attr; only rules_ruby sets it).
Confirmed at HEAD f404f79. The rules_ruby 0.29.0 tarball (sha c92c2102…) ships
binary.cmd.tplwith CRLF on all 54 lines.libs/starlark/repo.bzl:39-40patches it withrctx.patch, which writes LF back. No other patch touches a.cmd,.bator.ps1file.Chosen approach: add a generic
crlfattr topinned_archive, applied after patches. It can be reused by any later patched Windows script.Rejected:
files: it runs before patches and duplicates upstream text.patch_cmdsor systempatch: not hermetic, and Windows hosts have nopatch.Steps
libs/starlark/repo.bzl: add a public pure helpercrlf_text(text)that normalizes to LF and then to CRLF.libs/starlark/repo.bzl:_pinned_archive_impl, after the patch loop: for eachrctx.attr.crlf, fail if the path is missing, thenrctx.file(path, crlf_text(rctx.read(path)), executable = False)."crlf": attr.string_list(doc = "Paths rewritten with CRLF line endings after patches.").ruby/toolchain/repos.bzl:65: setcrlf = ["ruby/private/binary/binary.cmd.tpl"].Tests
New
libs/starlark/tests/repo_tests.bzlwithrepo_unit_tests, mode unit, wired inlibs/starlark/tests/BUILD.bazel:"a\nb\r\nc"->"a\r\nb\r\nc""x\r\n"->"x\r\n"""->""ruby/toolchain/metadata_tests.bzl: add an execution-modestarlark_testnamedrules_ruby_cmd_crlf, declared inruby/toolchain/BUILD.bazel. Itsfile_blockson@rules_ruby//ruby/private/binary:binary.cmd.tplmust contain:\r\n, fromif "%COVERAGE%" == "1" (\r\nthrough)\r\n)\r\n{bundler_command} {ruby_binary_name} {binary} {args} %*\r\nThe harness matches bytes exactly (
tools/testing/starlark_harness.rs:evaluate_file).Verify
tools/dx test //libs/starlark/tests:repo_unit //ruby/toolchain:rules_ruby_cmd_crlftools/dx test --affectedtools/dx check --apply --affected, thentools/dx check --affectedNotes
coverage.patchand thecrlfentry can be dropped.Split
TrapsterDK commentedon Nov 7, 2026
Upstream Windows coverage for rules_ruby is drafted. Nothing is posted upstream yet; it needs owner approval before the issue and PR are opened on bazel-contrib/rules_ruby.
Change:
ruby/private/binary/binary.cmd.tplreplaces the "not supported on Windows" block with the hunk frompatches/rules_ruby/coverage.patch(0 bare LFs in the worktree; the blob is LF witheol=crlffrom upstream.gitattributes, same as before)..github/workflows/ci.ymldropsif: matrix.os != 'windows-latest'from "Run coverage" and "Upload coverage report", so the existing//spec:addcoverage check (grepsSF:in coverage.dat) is the regression test on Windows. Thecoverage.rbBundler gate is left for a separate PR.Draft upstream issue: "Code coverage is not supported on Windows"
Draft upstream PR: "feat: support code coverage on Windows"
Review risks to watch in upstream CI: the JRuby Windows leg with
JRUBY_OPTS=--debug, andSF:lines appearing in coverage.dat on Windows.After the upstream PR merges and is released, #9052 bumps rules_ruby and removes the hunk and the
crlfentry.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xut2hzpb4qWNZKpDCrwUz7
TrapsterDK commentedon Nov 7, 2026
Upstream posted:
After it merges and is released, #9052 bumps rules_ruby and removes the coverage hunk and the
crlfentry.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xut2hzpb4qWNZKpDCrwUz7
TrapsterDK commentedon Nov 7, 2026
Status check (2026-11-07): the local fix (crlf attr + ruby_crlf_tests) is on main via #8859. Nothing left for a worker. Remaining:
Labelled blocked. Since the regression is fixed locally, P2 would fit better than P1.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Xut2hzpb4qWNZKpDCrwUz7
github-actions commentedon Nov 7, 2026
This issue has the
blockedlabel but noBlocked on:line in its body. Add one naming the blocking issue (#N), a pull request URL, or the owner action. See CONTRIBUTING.md.TrapsterDK commentedon Nov 9, 2026
Upstream CRLF patch issue bazelbuild/bazel#32510, PR bazelbuild/bazel#32511 (tracked in #8771).
github-actions commentedon Nov 9, 2026
This issue has the
blockedlabel but noBlocked on:line in its body. Add one naming the blocking issue (#N), a pull request URL, or the owner action. See CONTRIBUTING.md.