Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3582 from voxik/fix-rubygems-2.2-compatibility
Browse files Browse the repository at this point in the history
Fix rubygems 2.2+ compatibility
  • Loading branch information
indirect committed Apr 21, 2015
2 parents cd36aa6 + c35a959 commit 0ad473a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
13 changes: 13 additions & 0 deletions lib/bundler/rubygems_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ def preserve_paths
yield
end

def loaded_gem_paths
# RubyGems 2.2+ can put binary extension into dedicated folders,
# therefore use RubyGems facilities to obtain their load paths.
if Gem::Specification.method_defined? :full_require_paths
loaded_gem_paths = Gem.loaded_specs.map {|n, s| s.full_require_paths}
loaded_gem_paths.flatten
else
$LOAD_PATH.select do |p|
Bundler.rubygems.gem_path.any?{|gp| p =~ /^#{Regexp.escape(gp)}/ }
end
end
end

def ui=(obj)
Gem::DefaultUserInteraction.ui = obj
end
Expand Down
9 changes: 6 additions & 3 deletions lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,13 @@ def clean_load_path
# handle 1.9 where system gems are always on the load path
if defined?(::Gem)
me = File.expand_path("../../", __FILE__)
me = /^#{Regexp.escape(me)}/

loaded_gem_paths = Bundler.rubygems.loaded_gem_paths

$LOAD_PATH.reject! do |p|
next if File.expand_path(p) =~ /^#{Regexp.escape(me)}/
p != File.dirname(__FILE__) &&
Bundler.rubygems.gem_path.any?{|gp| p =~ /^#{Regexp.escape(gp)}/ }
next if File.expand_path(p) =~ me
loaded_gem_paths.delete(p)
end
$LOAD_PATH.uniq!
end
Expand Down
33 changes: 33 additions & 0 deletions spec/runtime/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,39 @@
expect(out).to eq("yay")
end

it "should clean $LOAD_PATH properly" do
gem_name = 'very_simple_binary'
full_gem_name = gem_name + '-1.0'
ext_dir = File.join(tmp "extenstions", full_gem_name)

install_gem full_gem_name

install_gemfile <<-G
source "file://#{gem_repo1}"
G

ruby <<-R
if Gem::Specification.method_defined? :extension_dir
s = Gem::Specification.find_by_name '#{gem_name}'
s.extension_dir = '#{ext_dir}'
# Don't build extensions.
s.class.send(:define_method, :build_extensions) { nil }
end
require 'bundler'
gem '#{gem_name}'
puts $LOAD_PATH.count {|path| path =~ /#{gem_name}/} >= 2
Bundler.setup
puts $LOAD_PATH.count {|path| path =~ /#{gem_name}/} == 0
R

expect(out).to eq("true\ntrue")
end

it "stubs out Gem.refresh so it does not reveal system gems" do
system_gems "rack-1.0.0"

Expand Down

0 comments on commit 0ad473a

Please sign in to comment.