summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Arko <andre@arko.net>2010-03-23 15:37:11 -0700
committerAndre Arko <andre@arko.net>2010-03-23 15:57:30 -0700
commit25f1a9e2c864e9c1179a19ec9d856a6c097a7f59 (patch)
tree23e0ecdaddeded302f51c20dceb17f20fab19a69
parente3610450a3e475ce37306172aaa4a9b7a5a59057 (diff)
downloadbundler-25f1a9e2c864e9c1179a19ec9d856a6c097a7f59.tar.gz
Set GEM_HOME and GEM_PATH correctly when locked
-rw-r--r--lib/bundler/environment.rb3
-rw-r--r--lib/bundler/templates/environment.erb18
-rw-r--r--spec/runtime/environment_rb_spec.rb32
3 files changed, 47 insertions, 6 deletions
diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb
index a43bd7319f..872af35a3d 100644
--- a/lib/bundler/environment.rb
+++ b/lib/bundler/environment.rb
@@ -97,9 +97,8 @@ module Bundler
}
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
diff --git a/lib/bundler/templates/environment.erb b/lib/bundler/templates/environment.erb
index 8e4c350947..e7d4af5a7d 100644
--- a/lib/bundler/templates/environment.erb
+++ b/lib/bundler/templates/environment.erb
@@ -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)
diff --git a/spec/runtime/environment_rb_spec.rb b/spec/runtime/environment_rb_spec.rb
index 4097442096..f18c3be2ee 100644
--- a/spec/runtime/environment_rb_spec.rb
+++ b/spec/runtime/environment_rb_spec.rb
@@ -17,6 +17,7 @@ describe "environment.rb file" do
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 @@ describe "environment.rb file" do
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