Skip to content

rules_ruby: coverage.patch turns binary.cmd.tpl from CRLF to LF and brings back the Windows batch label failures #8753

Open

Description

@TrapsterDK

Problem

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 @@).
  • ruby/toolchain/repos.bzl:65-74: pinned_archive(name = "rules_ruby", patches = [..., coverage.patch]).
  • libs/starlark/repo.bzl:39-40: rctx.patch(patch, strip = 1).
  • 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.

Blocked on: #9052, #8771

Activity

  1. added
    P1Bugs in existing features
    model:sonnetAgent lane: scoped change with stated design, Sonnet
    trackingParent issue split into sub-issues
    on Nov 6, 2026
  2. TrapsterDK commented on Nov 6, 2026

    @TrapsterDK
    CollaboratorAuthor

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

    1. libs/starlark/repo.bzl: add a public pure helper crlf_text(text) that normalizes to LF and then to CRLF.
    2. 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).
    3. Add attr "crlf": attr.string_list(doc = "Paths rewritten with CRLF line endings after patches.").
    4. 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
      • {bundler_command} {ruby_binary_name} {binary} {args} %*\r\n

      The 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_crlf
    • tools/dx test --affected
    • tools/dx check --apply --affected, then tools/dx check --affected

    Notes

    Split

  3. TrapsterDK commented on Nov 7, 2026

    @TrapsterDK
    CollaboratorAuthor

    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.

    Follows up on #348. Related: #393.

    Assisted by Claude.

    Review risks to watch in upstream CI: the JRuby Windows leg with JRUBY_OPTS=--debug, and SF: 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 crlf entry.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Xut2hzpb4qWNZKpDCrwUz7

  4. TrapsterDK commented on Nov 7, 2026

    @TrapsterDK
    CollaboratorAuthor

    Upstream posted:

    After it merges and is released, #9052 bumps rules_ruby and removes the coverage hunk and the crlf entry.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Xut2hzpb4qWNZKpDCrwUz7

  5. added
    blockedWaiting on upstream or a design decision
    and removed
    blockedWaiting on upstream or a design decision
    on Nov 7, 2026
  6. TrapsterDK commented on Nov 7, 2026

    @TrapsterDK
    CollaboratorAuthor

    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

  7. github-actions commented on Nov 7, 2026

    @github-actions
    Contributor

    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.

  8. TrapsterDK commented on Nov 9, 2026

    @TrapsterDK
    CollaboratorAuthor

    Upstream CRLF patch issue bazelbuild/bazel#32510, PR bazelbuild/bazel#32511 (tracked in #8771).

  9. github-actions commented on Nov 9, 2026

    @github-actions
    Contributor

    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.

  10. added
    P2Improve and finish existing features
    and removed
    P1Bugs in existing features
    on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Improve and finish existing featuresblockedWaiting on upstream or a design decisionmodel:sonnetAgent lane: scoped change with stated design, SonnettrackingParent issue split into sub-issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions