Skip to content

Commit

Permalink
jruby support
Browse files Browse the repository at this point in the history
  • Loading branch information
ahorek committed Oct 1, 2021
1 parent f2618fa commit 59221f9
Show file tree
Hide file tree
Showing 8 changed files with 652 additions and 33 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
push:
pull_request:
schedule:
- cron: '15 9 * * *'

jobs:
host:
name: ${{ matrix.os }} ${{ matrix.ruby }}
if: ${{ github.repository == 'ruby/cgi' || github.event_name != 'schedule' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- ubuntu-18.04
- macos-11
- macos-10.15
- windows-latest
ruby:
- '3.0'
- 2.7
- 2.6
- debug
include:
- { os: ubuntu-20.04, ruby: head, ignore-pkg-error: true }
- { os: windows-latest, ruby: mingw, ignore-pkg-error: true }
- { os: windows-latest, ruby: mswin, ignore-pkg-error: true }
- { os: ubuntu-20.04, ruby: jruby }
- { os: ubuntu-20.04, ruby: jruby-head, ignore-pkg-error: true }
exclude:
- { os: windows-latest, ruby: debug }

steps:
- uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # 'bundle install' and cache

- run: bundle exec rake compile

- run: bundle exec rake build

- run: bundle exec rake test

- name: Integration test
run: bundle exec rake check
continue-on-error: ${{ matrix.ignore-pkg-error || (matrix.ruby == 'debug') }}
22 changes: 0 additions & 22 deletions .github/workflows/test.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/spec/reports/
/tmp/
/Gemfile.lock
*.jar
*.bundle
*.so
*.dll
69 changes: 61 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,73 @@
require "bundler/gem_tasks"
require "rake/testtask"

require 'rake/javaextensiontask'
Rake::JavaExtensionTask.new("escape") do |ext|
ext.source_version = '1.8'
ext.target_version = '1.8'
ext.ext_dir = 'ext/java'
ext.lib_dir = 'lib/cgi'

task :build => :compile
end

unless RUBY_ENGINE == 'jruby'
require 'rake/extensiontask'
Rake::ExtensionTask.new("cgi/escape")
end

Rake::TestTask.new(:test) do |t|
t.libs << "test/lib"
t.libs.concat ["test/lib", "lib"]
t.libs << "ext/java/org/jruby/ext/cgi/escape/lib" if RUBY_ENGINE == 'jruby'
t.ruby_opts << "-rhelper"
t.test_files = FileList['test/**/test_*.rb']
end

require 'rake/extensiontask'
Rake::ExtensionTask.new("cgi/escape")

task :sync_tool do
require 'fileutils'
FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
cp "../ruby/tool/lib/envutil.rb", "./test/lib"
cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
end

task :check do
Bundler.with_unbundled_env do
spec = Gem::Specification::load("cgi.gemspec")
version = spec.version.to_s

gem = "pkg/cgi-#{version}#{"-java" if RUBY_ENGINE == "jruby"}.gem"
File.size?(gem) or abort "gem not built!"

sh "gem", "install", gem

require_relative "test/lib/envutil"

_, _, status = EnvUtil.invoke_ruby([], <<~EOS)
version = #{version.dump}
gem "cgi", version
loaded_version = Gem.loaded_specs["cgi"].version.to_s
if loaded_version == version
puts "cgi \#{loaded_version} is loaded."
else
abort "cgi \#{loaded_version} is loaded instead of \#{version}!"
end
require "cgi/escape"
string = "&<>"
actual = CGI.escape(string)
expected = "%26%3C%3E"
puts "CGI.escape(\#{string.dump}) = \#{actual.dump}"
if actual != expected
abort "no! expected to be \#{expected.dump}!"
end
EOS

if status.success?
puts "check succeeded!"
else
warn "check failed!"
exit status.exitstatus
end
end
end

task :default => :test
17 changes: 14 additions & 3 deletions cgi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ Gem::Specification.new do |spec|
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage

spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = []

spec.files = [
"LICENSE.txt",
"README.md",
*Dir["lib{.rb,/**/*.rb}", "bin/*"] ]

spec.require_paths = ["lib"]

if Gem::Platform === spec.platform and spec.platform =~ 'java' or RUBY_ENGINE == 'jruby'
spec.platform = 'java'
spec.require_paths << "ext/java/org/jruby/ext/cgi/escape/lib"
spec.files += Dir["ext/java/**/*.{rb}", "lib/cgi/escape.jar"]
else
spec.files += Dir["ext/cgi/**/*.{rb,c,h,sh}", "ext/cgi/escape/depend", "lib/cgi/escape.so"]
end
end
Loading

0 comments on commit 59221f9

Please sign in to comment.