diff --git a/Rakefile b/Rakefile index 5d108b7d79e..def5ef3cc0a 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 62b8210c028..ae2f306e5ab 100644 --- a/lib/bundler/bundle.rb +++ b/lib/bundler/bundle.rb @@ -29,18 +29,6 @@ def install(options = {}) 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 @@ def install(options = {}) 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 @@ def install(options = {}) # 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 @@ def only_local(sources) 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 @@ def do_install(bundle, options) 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 d89182fdd8f..6899c28e464 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 @@ def initialize(name, options = {}, &block) 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 @@ def in?(environment) true end - def to_s - to_gem_dependency.to_s - end - def require_env(environment) return unless in?(environment) @@ -51,8 +47,8 @@ def require_env(environment) @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 @@ def ==(o) [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 c5c0d5c27c7..c43ab5f40a4 100644 --- a/lib/bundler/environment.rb +++ b/lib/bundler/environment.rb @@ -70,6 +70,9 @@ def gem_dependencies @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 @@ def repository 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 c43c90a8ea7..707f582608d 100644 --- a/lib/bundler/gem_ext.rb +++ b/lib/bundler/gem_ext.rb @@ -11,8 +11,9 @@ def app_script_text(bin_file_name) 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 2ad9cc2c2fa..7c3ba779383 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -36,7 +36,14 @@ class Resolver # ==== Returns # ,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 @@ def self.resolve(requirements, sources, source_requirements = {}) # 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 4edacacc143..0a25eb0253d 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 45c20df6fc1..8b3d43702c1 100644 --- a/spec/bundler/manifest_file_spec.rb +++ b/spec/bundler/manifest_file_spec.rb @@ -41,10 +41,10 @@ def works 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 e57646cbecb..2f50e6e6b71 100644 --- a/spec/bundler/manifest_spec.rb +++ b/spec/bundler/manifest_spec.rb @@ -104,14 +104,16 @@ 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 89c1c791038..5ec2d19d6fb 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 d46e2c11fe9..a45dddb1352 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -125,7 +125,7 @@ def build_spec(name, version, platform = nil, &block) 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 d1e072c7e76..3fd866738e8 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -118,7 +118,8 @@ def system_gems(*gems) 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