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

Commit

Permalink
Gems from git need their full_gem_path fixed, even when locked
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed Apr 10, 2010
1 parent 2c8d6ae commit 0f97e4f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lib/bundler.rb
Expand Up @@ -20,7 +20,7 @@ module Bundler
autoload :SharedHelpers, 'bundler/shared_helpers'
autoload :SpecSet, 'bundler/spec_set'
autoload :Source, 'bundler/source'
autoload :Specification, 'bundler/specification'
autoload :Specification, 'bundler/shared_helpers'
autoload :UI, 'bundler/ui'

class BundlerError < StandardError
Expand Down
22 changes: 22 additions & 0 deletions lib/bundler/shared_helpers.rb
Expand Up @@ -11,6 +11,28 @@ def requirement
end

module Bundler
class Specification < Gem::Specification
attr_accessor :relative_loaded_from

def self.from_gemspec(gemspec)
spec = allocate
gemspec.instance_variables.each do |ivar|
spec.instance_variable_set(ivar, gemspec.instance_variable_get(ivar))
end
spec
end

def loaded_from
return super unless relative_loaded_from
source.path.join(relative_loaded_from).to_s
end

def full_gem_path
Pathname.new(loaded_from).dirname.expand_path.to_s
end

end

module SharedHelpers
attr_accessor :gem_loaded

Expand Down
23 changes: 0 additions & 23 deletions lib/bundler/specification.rb

This file was deleted.

7 changes: 6 additions & 1 deletion lib/bundler/templates/environment.erb
Expand Up @@ -8,6 +8,7 @@ require 'rubygems'
module Bundler
LOCKED_BY = '<%= Bundler::VERSION %>'
FINGERPRINT = <%= gemfile_fingerprint.inspect %>
HOME = '<%= Bundler.home %>'
AUTOREQUIRES = <%= autorequires_for_groups.inspect %>
SPECS = [
<% specs_for_lock_file.each do |spec| -%>
Expand All @@ -22,7 +23,11 @@ module Bundler
end
spec.loaded_from = hash[:loaded_from]
spec.require_paths = hash[:load_paths]
spec
if spec.loaded_from.include?(HOME)
Bundler::Specification.from_gemspec(spec)
else
spec
end
end

extend SharedHelpers
Expand Down
24 changes: 15 additions & 9 deletions spec/lock/git_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../spec_helper', __FILE__)

describe "bundle lock with git" do
it "doesn't break right after running lock" do
before :each do
build_git "foo"

install_gemfile <<-G
Expand All @@ -10,18 +10,13 @@
G

bundle :lock
end

it "doesn't break right after running lock" do
should_be_installed "foo 1.0.0"
end

it "locks a git source to the current ref" do
build_git "foo"

install_gemfile <<-G
git "#{lib_path('foo-1.0')}"
gem 'foo'
G

bundle :lock
update_git "foo"
bundle :install

Expand All @@ -32,4 +27,15 @@

out.should == "WIN"
end

it "provides correct #full_gem_path" do
rev = revision_for(lib_path("foo-1.0"))
gem_path = "foo-1.0-5b89e78c95d2131a78cc39dab852b6266f4bed9d-#{rev}"
full_gem_path = Bundler.install_path.join(gem_path).to_s

run <<-RUBY
puts Bundler::SPECS.map{|s| s.full_gem_path }
RUBY
out.should == full_gem_path
end
end
12 changes: 6 additions & 6 deletions spec/runtime/load_spec.rb
Expand Up @@ -51,7 +51,7 @@
gem "activesupport", :group => :test
G

ruby <<-R
ruby <<-RUBY
require "bundler"
Bundler.setup :default
Bundler.require :default
Expand All @@ -61,7 +61,7 @@
rescue LoadError
puts "no activesupport"
end
R
RUBY

out.split("\n").should == ["1.0.0", "no activesupport"]
end
Expand All @@ -77,24 +77,24 @@
end

it "loads env.rb instead of the runtime" do
ruby <<-R
ruby <<-RUBY
require 'bundler'
Bundler.load
puts Bundler.instance_eval{ @runtime }
R
RUBY
out.should == "nil"
end

it "does not invoke setup inside env.rb" do
ruby <<-R, :expect_err => true
ruby <<-RUBY, :expect_err => true
require 'bundler'
Bundler.load
if $LOAD_PATH.grep(/rack/i).any?
puts "nooo"
else
puts "hurrah"
end
R
RUBY

out.should == "hurrah"
end
Expand Down

0 comments on commit 0f97e4f

Please sign in to comment.