Skip to content

Commit e702cd3

Browse files
committed
Use defined?(::TruffleRuby) internally instead of RUBY_ENGINE == 'truffleruby'
* Some tests change RUBY_ENGINE and using RUBY_ENGINE == 'truffleruby' would then no longer choose the path for TruffleRuby in those tests. For instance, RubyGems tests change RUBY_ENGINE. * Make sure that defined?(::TruffleRuby) folds.
1 parent 78eb6cc commit e702cd3

File tree

15 files changed

+27
-25
lines changed

15 files changed

+27
-25
lines changed

lib/mri/erb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ def new_toplevel(vars = nil)
940940
def def_method(mod, methodname, fname='(ERB)')
941941
src = self.src.sub(/^(?!#|$)/) {"def #{methodname}\n"} << "\nend\n"
942942
mod.module_eval do
943-
if RUBY_ENGINE == 'truffleruby'
943+
if defined?(::TruffleRuby)
944944
eval(src, binding, fname)
945945
else
946946
eval(src, binding, fname, -1)

lib/mri/mkmf.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
require 'fileutils'
88
require 'shellwords'
99

10-
if RUBY_ENGINE == 'truffleruby'
10+
if defined?(::TruffleRuby)
1111
# Setup config here as we need to check the clang version
1212
require 'rbconfig-for-mkmf'
1313
# Always use the system libxml/libxslt for Nokogiri on TruffleRuby. This is
@@ -237,7 +237,7 @@ def map_dir(dir, map = nil)
237237
map.inject(dir) {|d, (orig, new)| d.gsub(orig, new)}
238238
end
239239

240-
if RUBY_ENGINE == 'truffleruby'
240+
if defined?(::TruffleRuby)
241241
$extmk = Truffle::Boot.get_option('building-core-cexts') || ENV.key?('MKMF_SET_EXTMK_TO_TRUE')
242242
topdir = RbConfig::CONFIG['prefix'] # the TruffleRuby home
243243
$hdrdir = RbConfig::CONFIG["rubyhdrdir"] # lib/cext/include
@@ -520,7 +520,7 @@ def cc_command(opt="")
520520
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
521521
'arch_hdrdir' => $arch_hdrdir.quote,
522522
'top_srcdir' => $top_srcdir.quote)
523-
if RUBY_ENGINE == 'truffleruby'
523+
if defined?(::TruffleRuby)
524524
# Specify output file (-o) explictly. Clang 3.8 produces conftest.o and 3.9 conftest.bc.
525525
RbConfig::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -o #{CONFTEST}.#{$OBJEXT} -c #{CONFTEST_C}",
526526
conf)
@@ -2165,7 +2165,7 @@ def depend_rules(depend)
21652165
unless suffixes.empty?
21662166
depout.unshift(".SUFFIXES: ." + suffixes.uniq.join(" .") + "\n\n")
21672167
end
2168-
if RUBY_ENGINE == 'truffleruby'
2168+
if defined?(::TruffleRuby)
21692169
# Added dependency on Makefile as we should recompile if the Makefile was re-generated
21702170
if $extconf_h
21712171
depout.unshift("$(OBJS): Makefile $(RUBY_EXTCONF_H)\n\n")
@@ -2527,7 +2527,7 @@ def create_makefile(target, srcprefix = nil)
25272527
if File.exist?(depend)
25282528
mfile.print("###\n", *depend_rules(File.read(depend)))
25292529
else
2530-
if RUBY_ENGINE == 'truffleruby'
2530+
if defined?(::TruffleRuby)
25312531
# Added dependency on Makefile as we should recompile if the Makefile was re-generated
25322532
mfile.print "$(OBJS): $(HDRS) $(ruby_headers) Makefile\n"
25332533
else
@@ -2675,7 +2675,7 @@ def MAIN_DOES_NOTHING(*refs)
26752675
end
26762676
$configure_args["--topdir"] ||= $curdir
26772677

2678-
if RUBY_ENGINE == 'truffleruby'
2678+
if defined?(::TruffleRuby)
26792679
$ruby = arg_config("--ruby", RbConfig.ruby)
26802680
else
26812681
$ruby = arg_config("--ruby", File.join(RbConfig::CONFIG["bindir"], CONFIG["ruby_install_name"]))

lib/mri/net/http.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ def connect
943943

944944
D "opening connection to #{conn_address}:#{conn_port}..."
945945

946-
if RUBY_ENGINE == 'truffleruby'
946+
if defined?(::TruffleRuby)
947947
# We'd rather use :connect_timeout than Timeout, as that starts a thread
948948
begin
949949
s = Socket.tcp(conn_address, conn_port, @local_host, @local_port, connect_timeout: @open_timeout)

lib/mri/rubygems/requirement.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# If we're being loaded after yaml was already required, then
66
# load our yaml + workarounds now.
7-
if RUBY_ENGINE == 'truffleruby'
7+
if defined?(::TruffleRuby)
88
if defined? ::YAML
99
# Truffle: this is conditional because at this point #gem cannot be defined
1010
# (it is defined after loading rubygems/core_ext/kernel_gem which comes

lib/mri/rubygems/test_case.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
109109

110110
extend Gem::Deprecate
111111

112-
if RUBY_ENGINE == 'truffleruby'
112+
if defined?(::TruffleRuby)
113113
# Added to avoid hardcoded paths
114114
TEST_DIR = ENV.fetch('RUBYGEMS_TEST_PATH', File.expand_path('../../../test', __FILE__))
115115
end
@@ -1358,7 +1358,7 @@ def escape_path(*path)
13581358
end
13591359

13601360
@@ruby = rubybin
1361-
if RUBY_ENGINE == 'truffleruby'
1361+
if defined?(::TruffleRuby)
13621362
@@good_rake = "#{rubybin} \"#{TEST_DIR}/rubygems/good_rake.rb\""
13631363
@@bad_rake = "#{rubybin} \"#{TEST_DIR}/rubygems/bad_rake.rb\""
13641364
else
@@ -1553,7 +1553,7 @@ def self.load_cert(cert_name)
15531553

15541554
def self.cert_path(cert_name)
15551555
if 32 == (Time.at(2**32) rescue 32)
1556-
if RUBY_ENGINE == 'truffleruby'
1556+
if defined?(::TruffleRuby)
15571557
cert_file =
15581558
"#{TEST_DIR}/rubygems/#{cert_name}_cert_32.pem"
15591559
else
@@ -1565,7 +1565,7 @@ def self.cert_path(cert_name)
15651565
return cert_file if File.exist? cert_file
15661566
end
15671567

1568-
if RUBY_ENGINE == 'truffleruby'
1568+
if defined?(::TruffleRuby)
15691569
"#{TEST_DIR}/rubygems/#{cert_name}_cert.pem"
15701570
else
15711571
File.expand_path "../../../test/rubygems/#{cert_name}_cert.pem", __FILE__
@@ -1587,7 +1587,7 @@ def self.load_key(key_name, passphrase = nil)
15871587
# Returns the path to the key named +key_name+ from <tt>test/rubygems</tt>
15881588

15891589
def self.key_path(key_name)
1590-
if RUBY_ENGINE == 'truffleruby'
1590+
if defined?(::TruffleRuby)
15911591
"#{TEST_DIR}/rubygems/#{key_name}_key.pem"
15921592
else
15931593
File.expand_path "../../../test/rubygems/#{key_name}_key.pem", __FILE__

lib/mri/uri/generic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def check_host(v)
589589
raise InvalidURIError,
590590
"can not set host with registry or opaque"
591591
else
592-
if RUBY_ENGINE == 'truffleruby'
592+
if defined?(::TruffleRuby)
593593
bad = !parser.regexp[:HOST].match(v)
594594
else
595595
bad = parser.regexp[:HOST] !~ v

lib/mri/webrick/utils.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
require 'io/nonblock'
1414
require 'etc'
1515

16-
if RUBY_ENGINE == 'truffleruby'
16+
if defined?(::TruffleRuby)
1717
require 'timeout'
1818
end
1919

@@ -259,7 +259,7 @@ def terminate
259259
# than +seconds+.
260260
#
261261
# If +seconds+ is zero or nil, simply executes the block
262-
if RUBY_ENGINE == 'truffleruby'
262+
if defined?(::TruffleRuby)
263263
def timeout(seconds, exception=Timeout::Error, &block)
264264
return yield if seconds.nil? or seconds.zero?
265265
Timeout.timeout(seconds, exception, &block)

spec/truffle.mspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class MSpecScript
109109
[/_spec.rb$/, '_tags.txt']
110110
]
111111

112-
if defined?(TruffleRuby) && TruffleRuby.native?
112+
if defined?(::TruffleRuby) && TruffleRuby.native?
113113
# exclude specs tagged with 'aot' and 'graalvm'
114114
set :xtags, (get(:xtags) || []) + ['aot', 'graalvm']
115115
end

src/main/c/openssl/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
require "mkmf"
1515
require File.expand_path('../deprecation', __FILE__)
1616

17-
if RUBY_ENGINE == 'truffleruby'
17+
if defined?(::TruffleRuby)
1818
require 'truffle/openssl-prefix'
1919
dir_config("openssl", ENV["OPENSSL_PREFIX"])
2020
else

test/basictest/runner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exit if defined?(CROSS_COMPILING) and CROSS_COMPILING
44
ruby = ENV["RUBY"]
55
unless ruby
6-
if RUBY_ENGINE == 'truffleruby'
6+
if defined?(::TruffleRuby)
77
require 'rbconfig'
88
ruby = RbConfig.ruby
99
else

0 commit comments

Comments
 (0)