Skip to content

Commit

Permalink
Merge pull request #611 from jaggederest/fix_register_default_spec
Browse files Browse the repository at this point in the history
Fix logic of register_default_spec

Issue #611 is needed for #612 which will sort the files list for packagers.

By fixing the issue now this method should not need to change as much.
  • Loading branch information
drbrain committed Aug 26, 2013
2 parents 4a1c6e6 + 8d4fc02 commit effc037
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1048,16 +1048,14 @@ class << self
#

def register_default_spec(spec)
new_format, prefix_pattern = nil
new_format = Gem.default_gems_use_full_paths? || spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }

spec.files.each do |file|
if new_format == nil
new_format = spec.require_paths.any? {|path| file.start_with? path}

prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")
prefix_pattern = /^(#{prefix_group})/
end
if new_format
prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")
prefix_pattern = /^(#{prefix_group})/
end

spec.files.each do |file|
if new_format
file = file.sub(prefix_pattern, "")
next unless $~
Expand Down
7 changes: 7 additions & 0 deletions lib/rubygems/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,11 @@ def self.default_key_path
def self.default_cert_path
File.join Gem.user_home, ".gem", "gem-public_cert.pem"
end

##
# Whether to expect full paths in default gems - true for non-MRI
# ruby implementations
def self.default_gems_use_full_paths?
ruby_engine != 'ruby'
end
end
22 changes: 22 additions & 0 deletions test/rubygems/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,28 @@ def test_register_default_spec
assert_equal nil, Gem.find_unresolved_default_spec("README")
end

def test_default_gems_use_full_paths
begin
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, 'ruby'
refute Gem.default_gems_use_full_paths?
ensure
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, engine
end

begin
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, 'jruby'
assert Gem.default_gems_use_full_paths?
ensure
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, engine
end
end

def with_plugin(path)
test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}",
@@project_dir)
Expand Down

0 comments on commit effc037

Please sign in to comment.