Skip to content

Commit 799052d

Browse files
amatsudanobu
andcommitted
Install a stub file in binary gems only
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
1 parent df242e7 commit 799052d

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if RUBY_PLATFORM =~ /java/
2929
else
3030
require 'rake/extensiontask'
3131
spec = Gem::Specification.load("psych.gemspec")
32+
spec.require_paths.insert(0, *%w[stub])
3233
Rake::ExtensionTask.new("psych", spec) do |ext|
3334
ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
3435
ext.cross_compile = true

lib/psych.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# frozen_string_literal: true
22
require 'psych/versions'
3-
case RUBY_ENGINE
4-
when 'jruby'
5-
require 'psych_jars'
6-
if JRuby::Util.respond_to?(:load_ext)
7-
JRuby::Util.load_ext('org.jruby.ext.psych.PsychLibrary')
3+
4+
unless caller_locations(1, 1)[0].absolute_path == File.expand_path('../stub/psych.rb', __dir__)
5+
case RUBY_ENGINE
6+
when 'jruby'
7+
require 'psych_jars'
8+
if JRuby::Util.respond_to?(:load_ext)
9+
JRuby::Util.load_ext('org.jruby.ext.psych.PsychLibrary')
10+
else
11+
require 'java'; require 'jruby'
12+
org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false)
13+
end
814
else
9-
require 'java'; require 'jruby'
10-
org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false)
11-
end
12-
else
13-
begin
14-
require "#{RUBY_VERSION[/\d+\.\d+/]}/psych.so"
15-
rescue LoadError
1615
require 'psych.so'
1716
end
1817
end
18+
1919
require 'psych/nodes'
2020
require 'psych/streaming'
2121
require 'psych/visitors'

psych.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ DESCRIPTION
4141
"lib/psych/set.rb", "lib/psych/stream.rb", "lib/psych/streaming.rb", "lib/psych/syntax_error.rb",
4242
"lib/psych/tree_builder.rb", "lib/psych/versions.rb", "lib/psych/visitors.rb","lib/psych/visitors/depth_first.rb",
4343
"lib/psych/visitors/emitter.rb", "lib/psych/visitors/json_tree.rb", "lib/psych/visitors/to_ruby.rb",
44-
"lib/psych/visitors/visitor.rb", "lib/psych/visitors/yaml_tree.rb", "lib/psych/y.rb", "psych.gemspec"
44+
"lib/psych/visitors/visitor.rb", "lib/psych/visitors/yaml_tree.rb", "lib/psych/y.rb", "psych.gemspec",
45+
"stub/psych.rb"
4546
]
4647

4748
s.rdoc_options = ["--main", "README.md"]

stub/psych.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "#{RUBY_VERSION[/\d+\.\d+/]}/psych.so"
2+
require_relative '../lib/psych'

0 commit comments

Comments
 (0)