Skip to content

Commit 4797365

Browse files
committed
Fix kernel_require.rb packed at wrong path when rubygems-update is installed
When rubygems-update is installed (e.g. via asdf on Linux/macOS), rubygems.rb lives in site_ruby rather than rubylibdir. Since rubygems.rb uses require_relative to load kernel_require.rb, both files must reside in the same directory tree. Previously kernel_require.rb was always located from rubylibdir, causing a path mismatch at runtime: rubygems.rb in site_ruby could not find kernel_require.rb. Fix by preferring the directory of the actually-loaded rubygems.rb from $LOADED_FEATURES, falling back to rubylibdir for standard Ruby installations (including RubyInstaller on Windows).
1 parent ac57eed commit 4797365

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lib/ocran/direction.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,25 @@ def normalized_features
100100
# Since https://github.com/rubygems/rubygems/commit/cad4cf16cf8fcc637d9da643ef97cf0be2ed63cb
101101
# rubygems/core_ext/kernel_require.rb is loaded via IO.read+eval rather than require,
102102
# so it never appears in $LOADED_FEATURES and must be added manually.
103-
# Use RbConfig::CONFIG["rubylibdir"] directly so the path is always correct,
104-
# regardless of Ruby version or platform path separator conventions.
103+
# We check multiple candidate locations because the layout varies by Ruby setup:
104+
# - Standard Ruby (including RubyInstaller on Windows): rubygems.rb lives in rubylibdir
105+
# - Ruby with rubygems-update (e.g. asdf on Linux/macOS): rubygems.rb lives in site_ruby
106+
# kernel_require.rb must be packed alongside the rubygems.rb that was actually loaded,
107+
# because rubygems.rb uses require_relative to load it.
105108
kernel_require_rel = "rubygems/core_ext/kernel_require.rb"
106109
unless features.any? { |f| f.to_posix.end_with?(kernel_require_rel) }
107-
kernel_require_path = Pathname(RbConfig::CONFIG["rubylibdir"]) / kernel_require_rel
108-
features.push(kernel_require_path) if kernel_require_path.exist?
110+
# Prefer the location alongside the actually-loaded rubygems.rb, fall back to rubylibdir
111+
rubygems_feature = features.find { |f| f.to_posix.end_with?("/rubygems.rb") }
112+
candidate_dirs = []
113+
candidate_dirs << rubygems_feature.dirname if rubygems_feature
114+
candidate_dirs << Pathname(RbConfig::CONFIG["rubylibdir"])
115+
candidate_dirs.each do |base_dir|
116+
kernel_require_path = base_dir / kernel_require_rel
117+
if kernel_require_path.exist?
118+
features.push(kernel_require_path)
119+
break
120+
end
121+
end
109122
end
110123

111124
# Convert all relative paths to absolute paths before building.

test/test_ocra.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,6 @@ def test_glimmer_libui
10771077
# zlib1.dll in archdir. Without them the SxS activation context fails with
10781078
# error 14001 at runtime. Verifies that compress/decompress round-trips work.
10791079
def test_zlib
1080-
skip "SxS manifest test is Windows-only" unless Gem.win_platform?
10811080
with_fixture 'zlib' do
10821081
assert system("ruby", ocran, "zlib.rb", *DefaultArgs)
10831082
assert File.exist?(exe_name("zlib"))

0 commit comments

Comments
 (0)