Skip to content

Commit 4b5d230

Browse files
committed
[GR-16904] Set RbConfig::CONFIG['ruby_version'] to the TruffleRuby version.
PullRequest: truffleruby/928
2 parents c99dbe8 + 4b04786 commit 4b5d230

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Bug fixes:
44

5+
* Set `RbConfig::CONFIG['ruby_version']` to the same value as the TruffleRuby version. This fixes reusing C extensions between different versions of TruffleRuby with Bundler (#1715).
56
* Fixed `Symbol#match` returning `MatchData` (#1706).
67
* Allow `Time#strftime` to be called with binary format strings.
78

lib/truffle/rbconfig.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ module RbConfig
4949
ruby_install_name = 'truffleruby'
5050

5151
ruby_base_name = 'ruby'
52-
ruby_version = Truffle::RUBY_BASE_VERSION
52+
53+
# The full TruffleRuby version, so C extensions from one TruffleRuby version
54+
# are not reused with another TruffleRuby version.
55+
ruby_abi_version = RUBY_ENGINE_VERSION
5356

5457
arch = "#{host_cpu}-#{host_os}"
5558
libs = ''
@@ -96,7 +99,7 @@ module RbConfig
9699
'RUBY_BASE_NAME' => ruby_base_name,
97100
'ruby_install_name' => ruby_install_name,
98101
'RUBY_INSTALL_NAME' => ruby_install_name,
99-
'ruby_version' => ruby_version,
102+
'ruby_version' => ruby_abi_version,
100103
'target_cpu' => host_cpu,
101104
'target_os' => host_os,
102105
}
@@ -160,8 +163,9 @@ module RbConfig
160163
sitedir = \
161164
expanded['sitedir'] = "#{rubylibprefix}/site_ruby"
162165
mkconfig['sitedir'] = '$(rubylibprefix)/site_ruby'
166+
# Must be kept in sync with post.rb
163167
sitelibdir = \
164-
expanded['sitelibdir'] = "#{sitedir}/#{ruby_version}"
168+
expanded['sitelibdir'] = "#{sitedir}/#{ruby_abi_version}"
165169
mkconfig['sitelibdir'] = '$(sitedir)/$(ruby_version)'
166170
expanded['sitearchdir'] = "#{sitelibdir}/#{sitearch}"
167171
mkconfig['sitearchdir'] = '$(sitelibdir)/$(sitearch)'
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
# Empty file to avoid raising a LoadError while loading RubyGems
2-
# Lazy RubyGems also relies on this
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. This
4+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
5+
# redistribute it and/or modify it under the terms of the:
6+
#
7+
# Eclipse Public License version 1.0, or
8+
# GNU General Public License version 2, or
9+
# GNU Lesser General Public License version 2.1.
10+
11+
# Defaults for RubyGems when running on TruffleRuby.
12+
# This file is required by RubyGems when RubyGems is loaded.
13+
14+
module Gem
15+
# The path to the gems shipped with TruffleRuby
16+
def self.default_dir
17+
@default_dir ||= "#{Truffle::Boot.ruby_home or raise 'TruffleRuby home not found'}/lib/ruby/gems/#{Truffle::RUBY_BASE_VERSION}"
18+
end
19+
end

spec/truffle/identity_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
RbConfig::CONFIG['RUBY_INSTALL_NAME'].should == 'truffleruby'
6868
end
6969

70-
it "RbConfig::CONFIG['ruby_version'] matches RUBY_VERSION except with the minor always being zero" do
71-
RbConfig::CONFIG['ruby_version'].should == RUBY_VERSION.sub(/\.(\d+)\z/, '.0')
70+
it "RbConfig::CONFIG['ruby_version'] is the ABI version and matches RUBY_ENGINE_VERSION" do
71+
RbConfig::CONFIG['ruby_version'].should == RUBY_ENGINE_VERSION
7272
end
7373

7474
it "RbConfig::CONFIG['RUBY_BASE_NAME'] is 'ruby'" do

src/main/java/org/truffleruby/language/methods/ExceptionTranslatingNode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.truffleruby.language.methods;
1111

1212
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
13+
import com.oracle.truffle.api.TruffleException;
1314
import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
1415
import com.oracle.truffle.api.frame.VirtualFrame;
1516
import com.oracle.truffle.api.nodes.ControlFlowException;
@@ -238,8 +239,10 @@ private DynamicObject translateThrowable(Throwable throwable) {
238239
throw (AssertionError) throwable;
239240
}
240241

242+
final boolean truffleException = throwable instanceof TruffleException;
243+
241244
if (getContext().getOptions().EXCEPTIONS_PRINT_JAVA
242-
|| getContext().getOptions().EXCEPTIONS_PRINT_UNCAUGHT_JAVA) {
245+
|| (!truffleException && getContext().getOptions().EXCEPTIONS_PRINT_UNCAUGHT_JAVA)) {
243246
throwable.printStackTrace();
244247

245248
if (getContext().getOptions().EXCEPTIONS_PRINT_RUBY_FOR_JAVA) {

src/main/ruby/truffleruby/core/post.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ def p(*a)
102102
ruby_home = Truffle::Boot.ruby_home
103103
if ruby_home
104104
# Does not exist but it's used by rubygems to determine index where to insert gem lib directories, as a result
105-
# paths supplied by -I will stay before gem lib directories.
106-
$LOAD_PATH.push "#{ruby_home}/lib/ruby/site_ruby/#{Truffle::RUBY_BASE_VERSION}"
105+
# paths supplied by -I will stay before gem lib directories. See Gem.load_path_insert_index in rubygems.rb.
106+
# Must be kept in sync with the value of RbConfig::CONFIG['sitelibdir'].
107+
$LOAD_PATH.push "#{ruby_home}/lib/ruby/site_ruby/#{RUBY_ENGINE_VERSION}"
107108

108109
$LOAD_PATH.push "#{ruby_home}/lib/truffle"
109110
$LOAD_PATH.push "#{ruby_home}/lib/mri"

0 commit comments

Comments
 (0)