Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'origin/env_bunle_refactor' into env_bundle_refactor

Conflicts:
	lib/bundler/bundle.rb
	lib/bundler/templates/environment.erb
  • Loading branch information...
commit 12c740f3d386831560a952bb586482a875445f21 2 parents bccccf9 + 2ae6287
Carlhuda authored
View
13 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
View
26 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
View
16 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
View
7 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)
View
5 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)
View
10 lib/bundler/resolver.rb
@@ -36,7 +36,14 @@ class Resolver
# ==== 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 @@ 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 }
View
8 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] = [] }
View
4 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
View
16 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
View
14 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
View
2  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)
View
3  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
Please sign in to comment.
Something went wrong with that request. Please try again.