From 4830cf5823955af6b2353c37e87d3224389e533b Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 29 May 2023 13:53:49 +0200 Subject: [PATCH] Add TruffleRuby support and add it in CI --- .github/workflows/test.yml | 3 ++- Rakefile | 4 ++-- ext/cgi/escape/extconf.rb | 6 +++++- lib/cgi/util.rb | 9 ++++++--- test/cgi/test_cgi_util.rb | 4 ++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff12376..ea2d4f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,6 @@ jobs: ruby-versions: uses: ruby/actions/.github/workflows/ruby_versions.yml@master with: - engine: cruby-jruby min_version: 2.5 test: needs: ruby-versions @@ -22,6 +21,8 @@ jobs: - { os: windows-latest, ruby: jruby } - { os: macos-latest, ruby: jruby-head } - { os: windows-latest, ruby: jruby-head } + - { os: windows-latest, ruby: truffleruby } + - { os: windows-latest, ruby: truffleruby-head } include: - { os: windows-latest, ruby: mingw } - { os: windows-latest, ruby: mswin } diff --git a/Rakefile b/Rakefile index 77dd3cd..9262a89 100644 --- a/Rakefile +++ b/Rakefile @@ -11,7 +11,7 @@ Rake::JavaExtensionTask.new("escape") do |ext| task :build => :compile end -unless RUBY_ENGINE == 'jruby' +if RUBY_ENGINE == 'ruby' require 'rake/extensiontask' extask = Rake::ExtensionTask.new("cgi/escape") do |x| x.lib_dir.sub!(%r[(?=/|\z)], "/#{RUBY_VERSION}/#{x.platform}") @@ -22,7 +22,7 @@ Rake::TestTask.new(:test) do |t| t.libs << "test/lib" if RUBY_ENGINE == 'jruby' t.libs << "ext/java/org/jruby/ext/cgi/escape/lib" - else + elsif RUBY_ENGINE == 'ruby' t.libs << "lib/#{RUBY_VERSION}/#{extask.platform}" end t.ruby_opts << "-rhelper" diff --git a/ext/cgi/escape/extconf.rb b/ext/cgi/escape/extconf.rb index 16e8ff2..73acd89 100644 --- a/ext/cgi/escape/extconf.rb +++ b/ext/cgi/escape/extconf.rb @@ -1,3 +1,7 @@ require 'mkmf' -create_makefile 'cgi/escape' +if RUBY_ENGINE == 'truffleruby' + File.write("Makefile", dummy_makefile($srcdir).join("")) +else + create_makefile 'cgi/escape' +end diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb index 5a5c77a..5f33589 100644 --- a/lib/cgi/util.rb +++ b/lib/cgi/util.rb @@ -90,9 +90,12 @@ def escapeHTML(string) end end - begin - require 'cgi/escape' - rescue LoadError + # TruffleRuby runs the pure-Ruby variant faster, do not use the C extension there + unless RUBY_ENGINE == 'truffleruby' + begin + require 'cgi/escape' + rescue LoadError + end end # Unescape a string that has been HTML-escaped diff --git a/test/cgi/test_cgi_util.rb b/test/cgi/test_cgi_util.rb index a3be193..b3a46a1 100644 --- a/test/cgi/test_cgi_util.rb +++ b/test/cgi/test_cgi_util.rb @@ -262,7 +262,7 @@ def setup remove_method :escapeHTML alias _unescapeHTML unescapeHTML remove_method :unescapeHTML - end + end if defined?(CGI::Escape) end def teardown @@ -271,7 +271,7 @@ def teardown remove_method :_escapeHTML alias unescapeHTML _unescapeHTML remove_method :_unescapeHTML - end + end if defined?(CGI::Escape) end def test_cgi_escapeHTML_with_invalid_byte_sequence