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

Commit

Permalink
Set GEM_HOME and GEM_PATH correctly when locked
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed Mar 23, 2010
1 parent e361045 commit 25f1a9e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
3 changes: 1 addition & 2 deletions lib/bundler/environment.rb
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions lib/bundler/templates/environment.erb
@@ -1,7 +1,7 @@
# DO NOT MODIFY THIS FILE

require 'digest/sha1'
require "rubygems"
require 'rubygems'

<%= shared_helpers %>

Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions spec/runtime/environment_rb_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 25f1a9e

Please sign in to comment.