summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-01-04 12:34:52 -0800
committerCarlhuda <carlhuda@engineyard.com>2010-01-04 12:34:52 -0800
commit12c740f3d386831560a952bb586482a875445f21 (patch)
tree2d30f0e472dc6818f09cab0b544dfdb35783b4f4
parentbccccf91226c2f214c83a2e8f874ccffb456abf7 (diff)
parent2ae628748ab50c46b1a032351e623d62d7827de9 (diff)
downloadbundler-12c740f3d386831560a952bb586482a875445f21.tar.gz
Merge remote branch 'origin/env_bunle_refactor' into env_bundle_refactor
Conflicts: lib/bundler/bundle.rb lib/bundler/templates/environment.erb
-rw-r--r--Rakefile13
-rw-r--r--lib/bundler/bundle.rb26
-rw-r--r--lib/bundler/dependency.rb16
-rw-r--r--lib/bundler/environment.rb7
-rw-r--r--lib/bundler/gem_ext.rb5
-rw-r--r--lib/bundler/resolver.rb10
-rw-r--r--lib/bundler/templates/environment.erb8
-rw-r--r--spec/bundler/manifest_file_spec.rb4
-rw-r--r--spec/bundler/manifest_spec.rb16
-rw-r--r--spec/spec_helper.rb14
-rw-r--r--spec/support/builders.rb2
-rw-r--r--spec/support/helpers.rb3
12 files changed, 67 insertions, 57 deletions
diff --git a/Rakefile b/Rakefile
index 5d108b7d79..def5ef3cc0 100644
--- a/Rakefile
+++ b/Rakefile
@@ -37,6 +37,19 @@ else
end
end
+namespace :spec do
+ file "tmp/rg_deps" do
+ repo = File.dirname(__FILE__) + '/tmp/rg_deps'
+ FileUtils.mkdir_p(repo)
+ p repo
+ ENV['GEM_HOME'], ENV['GEM_PATH'] = repo, repo
+ system "gem install builder --no-rdoc --no-ri"
+ end
+
+ desc "Do all setup needed to run the specs"
+ task :setup => "tmp/rg_deps"
+end
+
begin
require 'rake/gempackagetask'
rescue LoadError
diff --git a/lib/bundler/bundle.rb b/lib/bundler/bundle.rb
index 62b8210c02..ae2f306e5a 100644
--- a/lib/bundler/bundle.rb
+++ b/lib/bundler/bundle.rb
@@ -29,18 +29,6 @@ module Bundler
if only_envs = options[:only]
dependencies.reject! { |d| !only_envs.any? {|env| d.in?(env) } }
end
-
- no_bundle = dependencies.map do |dep|
- dep.source == SystemGemSource.instance && dep.name
- end.compact
-
- update = options[:update]
- cached = options[:cached]
-
- options[:rubygems] = @environment.rubygems
- options[:system_gems] = @environment.system_gems
- options[:manifest] = @environment.filename
- options[:no_bundle] = no_bundle
# ==========
# TODO: clean this up
@@ -49,12 +37,6 @@ module Bundler
s.local = options[:cached]
end
- source_requirements = {}
- dependencies = dependencies.map do |dep|
- source_requirements[dep.name] = dep.source if dep.source
- dep.to_gem_dependency
- end
-
# Check to see whether the existing cache meets all the requirements
begin
valid = nil
@@ -68,7 +50,7 @@ module Bundler
# or the user passed --update
if options[:update] || !valid
Bundler.logger.info "Calculating dependencies..."
- bundle = Resolver.resolve(dependencies, [@cache] + sources, source_requirements)
+ bundle = Resolver.resolve(dependencies, [@cache] + sources)
download(bundle, options)
do_install(bundle, options)
valid = bundle
@@ -167,14 +149,14 @@ module Bundler
def download(bundle, options)
bundle.sort_by {|s| s.full_name.downcase }.each do |spec|
- next if options[:no_bundle].include?(spec.name)
+ next if spec.no_bundle?
spec.source.download(spec)
end
end
def do_install(bundle, options)
bundle.each do |spec|
- next if options[:no_bundle].include?(spec.name)
+ next if spec.no_bundle?
spec.loaded_from = @specs_path.join("#{spec.full_name}.gemspec")
# Do nothing if the gem is already expanded
next if @gems_path.join(spec.full_name).directory?
@@ -190,7 +172,7 @@ module Bundler
def generate_bins(bundle, options)
bundle.each do |spec|
- next if options[:no_bundle].include?(spec.name)
+ next if spec.no_bundle?
# HAX -- Generate the bin
bin_dir = @bindir
path = @path
diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb
index d89182fdd8..6899c28e46 100644
--- a/lib/bundler/dependency.rb
+++ b/lib/bundler/dependency.rb
@@ -1,7 +1,7 @@
module Bundler
class InvalidEnvironmentName < StandardError; end
- class Dependency
+ class Dependency < Gem::Dependency
attr_reader :name, :version, :require_as, :only, :except
attr_accessor :source
@@ -10,8 +10,8 @@ module Bundler
options[k.to_s] = v
end
- @name = name
- @version = options["version"] || ">= 0"
+ super(name, options["version"] || ">= 0")
+
@require_as = options["require_as"]
@only = options["only"]
@except = options["except"]
@@ -31,10 +31,6 @@ module Bundler
true
end
- def to_s
- to_gem_dependency.to_s
- end
-
def require_env(environment)
return unless in?(environment)
@@ -51,8 +47,8 @@ module Bundler
@block.call if @block
end
- def to_gem_dependency
- @gem_dep ||= Gem::Dependency.new(name, version)
+ def no_bundle?
+ source == SystemGemSource.instance
end
def ==(o)
@@ -60,5 +56,7 @@ module Bundler
[o.name, o.version, o.require_as, o.only, o.except]
end
+ alias version version_requirements
+
end
end
diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb
index c5c0d5c27c..c43ab5f40a 100644
--- a/lib/bundler/environment.rb
+++ b/lib/bundler/environment.rb
@@ -70,6 +70,9 @@ module Bundler
@gem_dependencies ||= dependencies.map { |d| d.to_gem_dependency }
end
+ alias rubygems? rubygems
+ alias system_gems? system_gems
+
private
def default_sources
@@ -83,9 +86,9 @@ module Bundler
def load_paths_for_specs(specs, options)
load_paths = []
specs.each do |spec|
- next if options[:no_bundle].include?(spec.name)
+ next if spec.no_bundle?
full_gem_path = Pathname.new(spec.full_gem_path)
-
+
load_paths << load_path_for(full_gem_path, spec.bindir) if spec.bindir
spec.require_paths.each do |path|
load_paths << load_path_for(full_gem_path, path)
diff --git a/lib/bundler/gem_ext.rb b/lib/bundler/gem_ext.rb
index c43c90a8ea..707f582608 100644
--- a/lib/bundler/gem_ext.rb
+++ b/lib/bundler/gem_ext.rb
@@ -11,8 +11,9 @@ module Gem
end
class Specification
- attr_accessor :source
- attr_accessor :location
+ attr_accessor :source, :location, :no_bundle
+
+ alias no_bundle? no_bundle
remove_method(:specification_version) if method_defined?(:specification_version)
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 2ad9cc2c2f..7c3ba77938 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -36,7 +36,14 @@ module Bundler
# ==== Returns
# <GemBundle>,nil:: If the list of dependencies can be resolved, a
# collection of gemspecs is returned. Otherwise, nil is returned.
- def self.resolve(requirements, sources, source_requirements = {})
+ def self.resolve(requirements, sources)
+ source_requirements = {}
+
+ requirements.each do |r|
+ next unless r.source
+ source_requirements[r.name] = r.source
+ end
+
resolver = new(sources, source_requirements)
result = catch(:success) do
resolver.resolve(requirements, {})
@@ -54,6 +61,7 @@ module Bundler
# a smaller index in the array.
ordered = []
result.values.each do |spec1|
+ spec1.no_bundle = true if source_requirements[spec1.name] == SystemGemSource.instance
index = nil
place = ordered.detect do |spec2|
spec1.dependencies.any? { |d| d.name == spec2.name }
diff --git a/lib/bundler/templates/environment.erb b/lib/bundler/templates/environment.erb
index 4edacacc14..0a25eb0253 100644
--- a/lib/bundler/templates/environment.erb
+++ b/lib/bundler/templates/environment.erb
@@ -3,7 +3,7 @@ module Bundler
file = File.expand_path(__FILE__)
dir = File.dirname(file)
-<% unless options[:system_gems] -%>
+<% unless system_gems? -%>
ENV["GEM_HOME"] = dir
ENV["GEM_PATH"] = dir
@@ -25,12 +25,12 @@ module Bundler
@gemfile = "#{dir}/<%= filename %>"
-<% if options[:rubygems] -%>
+<% if rubygems? -%>
require "rubygems" unless respond_to?(:gem) # 1.9 already has RubyGems loaded
@bundled_specs = {}
<% specs.each do |spec| -%>
-<% if options[:no_bundle].include?(spec.name) -%>
+<% if spec.no_bundle? -%>
gem "<%= spec.name %>", "<%= spec.version %>"
<% else -%>
<% path = spec_file_for(spec) -%>
@@ -108,7 +108,7 @@ module Bundler
end
end
-<% if options[:rubygems] -%>
+<% if rubygems? -%>
module Gem
@loaded_stacks = Hash.new { |h,k| h[k] = [] }
diff --git a/spec/bundler/manifest_file_spec.rb b/spec/bundler/manifest_file_spec.rb
index 45c20df6fc..8b3d43702c 100644
--- a/spec/bundler/manifest_file_spec.rb
+++ b/spec/bundler/manifest_file_spec.rb
@@ -41,10 +41,10 @@ describe "Bundler::Environment" do
end
it "sets the default bundle path to vendor/gems" do
- @manifest.gem_path.should_not exist
+ @manifest.gem_path.join('environment.rb').should_not exist
goto :app
bundle
- @manifest.gem_path.should exist
+ @manifest.gem_path.join('environment.rb').should exist
end
it "allows setting the bundle path in the manifest file" do
diff --git a/spec/bundler/manifest_spec.rb b/spec/bundler/manifest_spec.rb
index e57646cbec..2f50e6e6b7 100644
--- a/spec/bundler/manifest_spec.rb
+++ b/spec/bundler/manifest_spec.rb
@@ -104,14 +104,16 @@ describe "Bundler::Environment" do
describe "runtime" do
it "is able to work system gems" do
- install_manifest <<-Gemfile
- clear_sources
- source "file://#{gem_repo1}"
- gem "rack"
- Gemfile
+ system_gems "rake-0.8.7" do
+ install_manifest <<-Gemfile
+ clear_sources
+ source "file://#{gem_repo1}"
+ gem "rack"
+ Gemfile
- out = run_in_context "require 'rake' ; puts Rake"
- out.should == "Rake"
+ out = run_in_context "require 'rake' ; puts RAKE"
+ out.should == "0.8.7"
+ end
end
it "it does not work with system gems if system gems have been disabled" do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 89c1c79103..5ec2d19d6f 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,21 +1,23 @@
$:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
+
require "pp"
require "rubygems"
require "bundler"
require "spec"
require "rbconfig"
+Gem.clear_paths
+
+root = File.expand_path("../..", __FILE__)
+FileUtils.rm_rf("#{root}/tmp/repos")
+`rake -f #{root}/Rakefile spec:setup`
+ENV['GEM_HOME'], ENV['GEM_PATH'] = "#{root}/tmp/rg_deps", "#{root}/tmp/rg_deps"
+
Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |file|
require file
end
-tmpdir = File.expand_path('../../tmp', __FILE__)
-FileUtils.mkdir_p(tmpdir) unless File.exist?(tmpdir)
-Dir["#{tmpdir}/*"].each do |file|
- FileUtils.rm_rf file
-end
-
Spec::Runner.configure do |config|
config.include Spec::Builders
config.include Spec::Matchers
diff --git a/spec/support/builders.rb b/spec/support/builders.rb
index d46e2c11fe..a45dddb135 100644
--- a/spec/support/builders.rb
+++ b/spec/support/builders.rb
@@ -125,7 +125,7 @@ module Spec
end
def build_dep(name, requirements = Gem::Requirement.default, type = :runtime)
- Gem::Dependency.new(name, requirements, type)
+ Bundler::Dependency.new(name, :version => requirements)
end
def build_lib(name, *args, &blk)
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index d1e072c7e7..3fd866738e 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -118,7 +118,8 @@ module Spec
def reset!
Dir["#{tmp_path}/*"].each do |file|
- FileUtils.rm_rf(file) unless File.basename(file) == "repos"
+ next if %w(repos rg_deps).include?(File.basename(file))
+ FileUtils.rm_rf(file)
end
FileUtils.mkdir_p(tmp_path)
end