Permalink
Browse files

Respect different ruby platforms and versions. Rub lotion on brittle …

…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...
1 parent 5ab2189 commit 6fba8ef89f7344c1d2773f6394ed7f547f5b3d92 @jeremy jeremy committed Jan 1, 2010
View
@@ -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 = {})
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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}"}
@@ -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|
@@ -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)
@@ -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
@@ -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
@@ -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
@@ -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__)
View
@@ -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"
@@ -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
@@ -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"
@@ -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"
@@ -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
@@ -308,7 +312,7 @@
Gemfile
m.install
- build_manifest <<-Gemfile
+ m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
gem "rack"
@@ -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
@@ -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"
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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"
@@ -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
@@ -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
View
@@ -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
@@ -121,4 +122,4 @@ def reset!
FileUtils.mkdir_p(tmp_path)
end
end
-end
+end
Oops, something went wrong.

0 comments on commit 6fba8ef

Please sign in to comment.