Skip to content

Commit

Permalink
Respect different ruby platforms and versions. Rub lotion on brittle …
Browse files Browse the repository at this point in the history
…tests.

Conflicts:

	lib/bundler/bundle.rb
	lib/bundler/environment.rb
	spec/bundler/cli_spec.rb
	spec/bundler/installer_spec.rb
	spec/bundler/manifest_file_spec.rb
  • Loading branch information
jeremy committed Jan 2, 2010
1 parent 5ab2189 commit 6fba8ef
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 59 deletions.
45 changes: 27 additions & 18 deletions lib/bundler/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ class Bundle
def initialize(path, bindir)
FileUtils.mkdir_p(path)

@path = Pathname.new(path)
@path = Pathname.new(path)
@bindir = Pathname.new(bindir)

@cache = GemDirectorySource.new(:location => @path.join("cache"))
@cache_path = @path.join('cache')
@cache = GemDirectorySource.new(:location => @cache_path)

@specs_path = @path.join('specifications')
@gems_path = @path.join('gems')
end

def install(dependencies, sources, options = {})
Expand Down Expand Up @@ -51,10 +55,10 @@ def install(dependencies, sources, options = {})
end

def cache(*gemfiles)
FileUtils.mkdir_p(@path.join("cache"))
FileUtils.mkdir_p(@cache_path)
gemfiles.each do |gemfile|
Bundler.logger.info "Caching: #{File.basename(gemfile)}"
FileUtils.cp(gemfile, @path.join("cache"))
FileUtils.cp(gemfile, @cache_path)
end
end

Expand All @@ -70,7 +74,7 @@ def prune(dependencies, sources)
specs.each do |spec|
unless bundle.any? { |s| s.name == spec.name && s.version == spec.version }
Bundler.logger.info "Pruning #{spec.name} (#{spec.version}) from the cache"
FileUtils.rm @path.join("cache", "#{spec.full_name}.gem")
FileUtils.rm @cache_path.join("#{spec.full_name}.gem")
end
end
end
Expand All @@ -85,8 +89,8 @@ def outdated_gems
end

def source_index
index = Gem::SourceIndex.from_gems_in(@path.join("specifications"))
index.each { |n, spec| spec.loaded_from = @path.join("specifications", "#{spec.full_name}.gemspec") }
index = Gem::SourceIndex.from_gems_in(@specs_path)
index.each { |n, spec| spec.loaded_from = @specs_path.join("#{spec.full_name}.gemspec") }
index
end

Expand All @@ -110,9 +114,9 @@ def download(bundle, options)
def do_install(bundle, options)
bundle.each do |spec|
next if options[:no_bundle].include?(spec.name)
spec.loaded_from = @path.join("specifications", "#{spec.full_name}.gemspec")
spec.loaded_from = @specs_path.join("#{spec.full_name}.gemspec")
# Do nothing if the gem is already expanded
next if @path.join("gems", spec.full_name).directory?
next if @gems_path.join(spec.full_name).directory?

case spec.source
when GemSource, GemDirectorySource, SystemGemSource
Expand All @@ -129,11 +133,12 @@ def generate_bins(bundle, options)
# HAX -- Generate the bin
bin_dir = @bindir
path = @path
gems_path = @gems_path
installer = Gem::Installer.allocate
installer.instance_eval do
@spec = spec
@bin_dir = bin_dir
@gem_dir = path.join("gems", "#{spec.full_name}")
@gem_dir = gems_path.join(spec.full_name)
@gem_home = path
@wrappers = true
@format_executable = false
Expand All @@ -146,7 +151,7 @@ def generate_bins(bundle, options)
def expand_gemfile(spec, options)
Bundler.logger.info "Installing #{spec.name} (#{spec.version})"

gemfile = @path.join("cache", "#{spec.full_name}.gem").to_s
gemfile = @cache_path.join("#{spec.full_name}.gem").to_s

if build_args = options[:build_options] && options[:build_options][spec.name]
Gem::Command.build_args = build_args.map {|k,v| "--with-#{k}=#{v}"}
Expand All @@ -169,12 +174,12 @@ def expand_gemfile(spec, options)

def expand_vendored_gem(spec, options)
add_spec(spec)
FileUtils.mkdir_p(@path.join("gems"))
File.symlink(spec.location, @path.join("gems", spec.full_name))
FileUtils.mkdir_p(@gems_path)
File.symlink(spec.location, @gems_path.join(spec.full_name))
end

def add_spec(spec)
destination = path.join('specifications')
destination = @specs_path
destination.mkdir unless destination.exist?

File.open(destination.join("#{spec.full_name}.gemspec"), 'w') do |f|
Expand Down Expand Up @@ -203,8 +208,8 @@ def cleanup(valid, options)
end

def cleanup_spec(spec)
FileUtils.rm_rf(@path.join("specifications", "#{spec.full_name}.gemspec"))
FileUtils.rm_rf(@path.join("gems", spec.full_name))
FileUtils.rm_rf(@specs_path.join("#{spec.full_name}.gemspec"))
FileUtils.rm_rf(@gems_path.join(spec.full_name))
end

def expand(options)
Expand All @@ -214,12 +219,16 @@ def expand(options)
end

def configure(specs, options)
FileUtils.mkdir_p(path)
generate_environment(specs, options)
generate_environment_picker
end

def generate_environment(specs, options)
FileUtils.mkdir_p(path)
def generate_environment_picker
FileUtils.cp("#{File.dirname(__FILE__)}/templates/environment_picker.erb", path.join("../../environment.rb"))
end

def generate_environment(specs, options)
load_paths = load_paths_for_specs(specs, options)
bindir = @bindir.relative_path_from(path).to_s
filename = options[:manifest].relative_path_from(path).to_s
Expand Down
6 changes: 5 additions & 1 deletion lib/bundler/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Environment
attr_accessor :rubygems, :system_gems
attr_writer :gem_path, :bindir

def self.default_gem_path(root)
Pathname.new("#{root}/vendor/gems/#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}")
end

def initialize(filename)
@filename = filename
@default_sources = default_sources
Expand Down Expand Up @@ -114,7 +118,7 @@ def root
end

def gem_path
@gem_path ||= root.join("vendor", "gems")
@gem_path ||= self.class.default_gem_path(root)
end

def bindir
Expand Down
4 changes: 4 additions & 0 deletions lib/bundler/templates/environment_picker.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'rbconfig'
engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
version = Config::CONFIG['ruby_version']
require File.expand_path("../#{engine}/#{version}/environment", __FILE__)
30 changes: 17 additions & 13 deletions spec/bundler/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

describe "it working" do
before :each do
build_manifest <<-Gemfile
@manifest = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
gem "rake"
Expand All @@ -72,8 +72,8 @@

it "caches and installs rake" do
gems = %w(rake-0.8.7 activesupport-2.3.2 rack-1.0.0)
bundled_app("vendor", "gems").should have_cached_gems(*gems)
bundled_app("vendor", "gems").should have_installed_gems(*gems)
@manifest.gem_path.should have_cached_gems(*gems)
@manifest.gem_path.should have_installed_gems(*gems)
end

it "creates a default environment file with the appropriate load paths" do
Expand All @@ -87,6 +87,10 @@
out.should == "0.8.7 - 2.3.2 - 1.0.0"
end

it "creates a platform-independent environment picker" do
@manifest.gem_path.join('../../environment.rb').file?.should == true
end

it "creates valid executables in ./bin" do
app_root do
`bin/rake`.should == "0.8.7\n"
Expand Down Expand Up @@ -231,7 +235,7 @@

describe "it working without rubygems" do
before(:each) do
build_manifest <<-Gemfile
@manifest = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
gem "rake"
Expand Down Expand Up @@ -267,17 +271,17 @@

it "stubs out Gem.dir" do
out = run_in_context "puts Gem.dir"
out.should == "#{bundled_app}/vendor/gems"
out.should == @manifest.gem_path.to_s
end

it "stubs out Gem.default_dir" do
out = run_in_context "puts Gem.default_dir"
out.should == "#{bundled_app}/vendor/gems"
out.should == @manifest.gem_path.to_s
end

it "stubs out Gem.path" do
out = run_in_context "puts Gem.path"
out.should == "#{bundled_app}/vendor/gems"
out.should == @manifest.gem_path.to_s
end
end

Expand Down Expand Up @@ -308,7 +312,7 @@
Gemfile
m.install

build_manifest <<-Gemfile
m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
gem "rack"
Expand All @@ -317,8 +321,8 @@
Dir.chdir(bundled_app) do
gem_command :bundle, "--update"
end
bundled_app("vendor", "gems").should include_cached_gems("rack-1.0.0")
bundled_app("vendor", "gems").should have_installed_gems("rack-1.0.0")
m.gem_path.should include_cached_gems("rack-1.0.0")
m.gem_path.should have_installed_gems("rack-1.0.0")
end
end

Expand Down Expand Up @@ -418,7 +422,7 @@
end

it "adds a gem directory to the cache" do
build_manifest <<-Gemfile
m = build_manifest <<-Gemfile
clear_sources
gem "rack"
gem "activesupport"
Expand All @@ -431,8 +435,8 @@
%w(actionmailer-2.3.2 activerecord-2.3.2 rake-0.8.7 rack-0.9.1 rack-1.0.0).each do |gemfile|
out.should include("Caching: #{gemfile}.gem")
end
tmp_gem_path.should include_cached_gems("rack-1.0.0", "activesupport-2.3.2")
tmp_gem_path.should have_installed_gems("rack-1.0.0", "activesupport-2.3.2")
m.gem_path.should include_cached_gems("rack-1.0.0", "activesupport-2.3.2")
m.gem_path.should have_installed_gems("rack-1.0.0", "activesupport-2.3.2")
end
end

Expand Down
31 changes: 17 additions & 14 deletions spec/bundler/installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,27 @@ def setup
it "creates the bundle directory if it does not exist" do
setup
@manifest.install
bundled_app("vendor", "gems").should have_cached_gems(*@gems)
@manifest.gem_path.should have_cached_gems(*@gems)
end

it "uses the bundle directory if it is empty" do
bundled_app("vendor", "gems").mkdir_p
bundled_path.mkdir_p
setup
@manifest.install
bundled_app("vendor", "gems").should have_cached_gems(*@gems)
@manifest.gem_path.should have_cached_gems(*@gems)
end

it "uses the bundle directory if it is a valid gem repo" do
%w(cache doc gems specifications).each { |dir| bundled_app("vendor", "gems", dir).mkdir_p }
bundled_app("vendor", "gems", "environment.rb").touch
%w(cache doc specifications).each { |dir| bundled_path.join(dir).mkdir_p }
bundled_path.join('gems').mkdir_p
bundled_path.join('environment.rb').touch
setup
@manifest.install
bundled_app("vendor", "gems").should have_cached_gems(*@gems)
@manifest.gem_path.should have_cached_gems(*@gems)
end

it "does not use the bundle directory if it is not a valid gem repo" do
bundled_app("vendor", "gems", "fail").touch_p
bundled_path.join('fail').touch_p
lambda {
setup
@manifest.install
Expand Down Expand Up @@ -71,14 +72,16 @@ def setup
end

it "does not modify any .gemspec files that are to be installed if a directory of the same name exists" do
dir = bundled_app("gems", "rails-2.3.2")
spec = bundled_app("specifications", "rails-2.3.2.gemspec")
dir = bundled_path.join("gems", "rails-2.3.2")
spec = bundled_path.join("specifications", "rails-2.3.2.gemspec")
bin = dir.join("bin", "rails")

dir.mkdir_p
spec.touch_p
bin.touch_p

setup
lambda { @manifest.install }.should_not change { [dir.mtime, spec.mtime] }
lambda { @manifest.install }.should_not change { [dir.mtime, spec.mtime, bin.mtime] }
end

it "keeps bin files for already installed gems" do
Expand Down Expand Up @@ -111,15 +114,15 @@ def setup
setup
@manifest.install
@gems.each do |name|
bundled_app("vendor", "gems", "gems", name).should be_directory
@manifest.gem_path.join('gems', name).should be_directory
end
end

it "creates a specification for each gem" do
setup
@manifest.install
@gems.each do |name|
bundled_app("vendor", "gems", "specifications", "#{name}.gemspec").should be_file
@manifest.gem_path.join("specifications/#{name}.gemspec").should be_file
end
end

Expand All @@ -130,8 +133,8 @@ def setup
gem "very-simple-prerelease", "1.0.pre"
Gemfile
m.install
bundled_app("vendor", "gems").should have_cached_gem("very-simple-prerelease-1.0.pre")
bundled_app("vendor", "gems").should have_installed_gem("very-simple-prerelease-1.0.pre")
m.gem_path.should have_cached_gem("very-simple-prerelease-1.0.pre")
m.gem_path.should have_installed_gem("very-simple-prerelease-1.0.pre")
end

it "outputs a logger message for each gem that is installed" do
Expand Down
8 changes: 4 additions & 4 deletions spec/bundler/manifest_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
describe "Bundler::Environment" do

before :each do
simple_manifest
@manifest = simple_manifest
end

def simple_manifest(extra = nil)
build_manifest_file <<-Gemfile
build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
gem "rack"
Expand Down Expand Up @@ -41,10 +41,10 @@ def works
end

it "sets the default bundle path to vendor/gems" do
bundled_app("vendor/gems").should_not exist
@manifest.gem_path.should_not exist
goto :app
bundle
bundled_app("vendor/gems").should exist
@manifest.gem_path.should exist
end

it "allows setting the bundle path in the manifest file" do
Expand Down
4 changes: 2 additions & 2 deletions spec/bundler/manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
rake-0.8.7 actionpack-2.3.2
activeresource-2.3.2 rails-2.3.2)

tmp_gem_path.should have_cached_gems(*gems)
tmp_gem_path.should have_installed_gems(*gems)
bundled_path.should have_cached_gems(*gems)
bundled_path.should have_installed_gems(*gems)
end

it "skips fetching the source index if all gems are present" do
Expand Down
5 changes: 3 additions & 2 deletions spec/support/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Spec
module Helpers
def run_in_context(cmd)
env = bundled_app("vendor", "gems", "environment")
env = bundled_path.join('environment.rb')
raise "Missing environment.rb" unless env.file?
ruby "-r #{env}", cmd
end

Expand Down Expand Up @@ -121,4 +122,4 @@ def reset!
FileUtils.mkdir_p(tmp_path)
end
end
end
end
Loading

0 comments on commit 6fba8ef

Please sign in to comment.