Skip to content

fix: patch shell polyglot executables for RubyGems overwrite detection - #6

Merged
jdx merged 4 commits into
mainfrom
fix/rubygems-polyglot-detection
Jan 14, 2026
Merged

jdx merged 4 commits into
mainfrom
fix/rubygems-polyglot-detection

Conversation

@jdx

@jdx jdx commented Jan 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Patches shell polyglot executables after installation to fix RubyGems' check_executable_overwrite detection
  • Adds test for gem install ruby-lsp which requires upgrading the bundled rbs gem

Problem

RubyGems' check_executable_overwrite method looks for "This file was generated by RubyGems" comment after the Ruby shebang line. In shell polyglot format (used for portable/relocatable Ruby built with --enable-load-relative), the comment is at the top of the file in the shell section, not after the embedded Ruby shebang at line 13.

This causes gem upgrades to fail with "conflicts with installed executable" errors when trying to upgrade bundled gems that have executables (like rbs).

Example error:

ERROR: Error installing ruby-lsp:
  "rbs" from rbs conflicts with /path/to/ruby/bin/rbs

Root Cause

The detection code in RubyGems:

  1. When LIBRUBY_RELATIVE=yes (portable Ruby), scans for #!/usr/bin/env ruby shebang
  2. Finds it at line 13 in shell polyglot format
  3. Reads next line (blank)
  4. Expects next line to contain "This file was generated by RubyGems"
  5. But line 15 is require 'rubygems' - the comment is at line 3!

Fix

After make install, patch all shell polyglot executables to add the marker comment after the Ruby shebang where RubyGems expects it.

Fixes: jdx/mise#7268

🤖 Generated with Claude Code


Note

Addresses RubyGems executable overwrite detection for portable Ruby builds and validates via targeted tests.

  • After make install, patches shell polyglot bin executables to insert the "This file was generated by RubyGems" marker after the Ruby shebang so check_executable_overwrite works (in jdx-ruby, jdx-ruby-32, jdx-ruby-33, jdx-ruby-34).
  • Extends tests to install openssl and psych to confirm portable headers are present, and installs ruby-lsp to validate upgrades of bundled gems with executables (e.g., rbs).

Written by Cursor Bugbot for commit 47779d1. This will update automatically on new commits. Configure here.

jdx and others added 4 commits January 14, 2026 13:13
RubyGems' check_executable_overwrite looks for "This file was generated
by RubyGems" comment after the Ruby shebang line. However, in shell
polyglot format (used for portable/relocatable Ruby), the comment is at
the top of the file in the shell section, not after the embedded Ruby
shebang.

This causes gem upgrades to fail with "conflicts with installed
executable" errors when trying to upgrade bundled gems that have
executables (like rbs).

The fix patches all shell polyglot executables after installation to
add the marker comment after the Ruby shebang where RubyGems expects it.

Fixes: jdx/mise#7268

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Apply the same fix from jdx-ruby.rb to jdx-ruby-32.rb which is used
for Ruby 3.2.x versions. The previous commit only modified the formula
for Ruby 3.3+ versions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Apply the same fix to jdx-ruby-33.rb and jdx-ruby-34.rb. The CI tests
against Ruby 3.4.1 which uses jdx-ruby-34.rb, so this should now run
the patch code and the ruby-lsp test.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jdx
jdx merged commit 88df0a1 into main Jan 14, 2026
8 checks passed
@jdx
jdx deleted the fix/rubygems-polyglot-detection branch January 14, 2026 21:06
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.

1 participant