Permalink
Browse files

Set GEM_HOME and GEM_PATH correctly when locked

  • Loading branch information...
indirect committed Mar 23, 2010
1 parent e361045 commit 25f1a9e2c864e9c1179a19ec9d856a6c097a7f59
Showing with 47 additions and 6 deletions.
  1. +1 −2 lib/bundler/environment.rb
  2. +14 −4 lib/bundler/templates/environment.erb
  3. +32 −0 spec/runtime/environment_rb_spec.rb
@@ -97,9 +97,8 @@ def specs_for_lock_file
}
if s.respond_to?(:relative_loaded_from) && s.relative_loaded_from
hash[:virtual_spec] = s.to_ruby
- else
- hash[:loaded_from] = s.loaded_from.to_s
end
+ hash[:loaded_from] = s.loaded_from.to_s
hash
end
end
@@ -1,7 +1,7 @@
# DO NOT MODIFY THIS FILE
require 'digest/sha1'
-require "rubygems"
+require 'rubygems'
<%= shared_helpers %>
@@ -14,11 +14,11 @@ module Bundler
<%= spec.inspect %>,
<% end -%>
].map do |hash|
- if hash[:loaded_from]
+ if hash[:virtual_spec]
+ spec = eval(hash[:virtual_spec], binding, "<virtual spec for '#{hash[:name]}'>")
+ else
dir = File.dirname(hash[:loaded_from])
spec = Dir.chdir(dir){ eval(File.read(hash[:loaded_from]), binding, hash[:loaded_from]) }
- else
- spec = eval(hash[:virtual_spec], binding, "<virtual spec for '#{hash[:name]}'>")
end
spec.loaded_from = hash[:loaded_from]
spec.require_paths = hash[:load_paths]
@@ -27,6 +27,15 @@ module Bundler
extend SharedHelpers
+ def self.configure_gem_path_and_home(specs)
+ # Fix paths, so that Gem.source_index and such will work
+ paths = specs.map{|s| s.installation_path }
+ paths.flatten!; paths.compact!; paths.uniq!; paths.reject!{|p| p.empty? }
+ ENV['GEM_PATH'] = paths.join(File::PATH_SEPARATOR)
+ ENV['GEM_HOME'] = paths.first
+ Gem.clear_paths
+ end
+
def self.match_fingerprint
print = Digest::SHA1.hexdigest(File.read(File.expand_path('../../Gemfile', __FILE__)))
unless print == FINGERPRINT
@@ -38,6 +47,7 @@ module Bundler
match_fingerprint
clean_load_path
cripple_rubygems(SPECS)
+ configure_gem_path_and_home(SPECS)
SPECS.each do |spec|
Gem.loaded_specs[spec.name] = spec
$LOAD_PATH.unshift(*spec.require_paths)
@@ -17,6 +17,7 @@
it "works with gems from git that don't have gemspecs" do
run <<-R, :lite_runtime => true
+ `open '.bundle/environment.rb'`
require 'no-gemspec'
puts NOGEMSPEC
R
@@ -73,6 +74,37 @@
out.should == "rack is not part of the bundle. Add it to Gemfile."
end
+
+ it "sets GEM_HOME appropriately" do
+ run "puts ENV['GEM_HOME']", :lite_runtime => true
+ out.should == default_bundle_path.to_s
+ end
+
+ it "sets GEM_PATH appropriately" do
+ run "puts Gem.path", :lite_runtime => true
+ out.should == default_bundle_path.to_s
+ end
+ end
+
+ describe "with system gems in the bundle" do
+ before :each do
+ system_gems "rack-1.0.0"
+
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack", "1.0.0"
+ gem "activesupport", "2.3.5"
+ G
+
+ bundle :lock
+ end
+
+ it "sets GEM_PATH appropriately" do
+ run "puts Gem.path", :lite_runtime => true
+ paths = out.split("\n")
+ paths.should include(system_gem_path.to_s)
+ paths.should include(default_bundle_path.to_s)
+ end
end
describe "with a gemspec that requires other files" do

0 comments on commit 25f1a9e

Please sign in to comment.