Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge remote branch 'origin/env_bunle_refactor' into env_bundle_refactor
Browse files Browse the repository at this point in the history
Conflicts:
	lib/bundler/bundle.rb
	lib/bundler/templates/environment.erb
  • Loading branch information
Carlhuda committed Jan 4, 2010
2 parents bccccf9 + 2ae6287 commit 12c740f
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 57 deletions.
13 changes: 13 additions & 0 deletions Rakefile
Expand Up @@ -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
Expand Down
26 changes: 4 additions & 22 deletions lib/bundler/bundle.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -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
Expand Down
16 changes: 7 additions & 9 deletions 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

Expand All @@ -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"]
Expand All @@ -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)

Expand All @@ -51,14 +47,16 @@ 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)
[name, version, require_as, only, except] ==
[o.name, o.version, o.require_as, o.only, o.except]
end

alias version version_requirements

end
end
7 changes: 5 additions & 2 deletions lib/bundler/environment.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/bundler/gem_ext.rb
Expand Up @@ -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)

Expand Down
10 changes: 9 additions & 1 deletion lib/bundler/resolver.rb
Expand Up @@ -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, {})
Expand All @@ -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 }
Expand Down
8 changes: 4 additions & 4 deletions lib/bundler/templates/environment.erb
Expand Up @@ -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

Expand All @@ -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) -%>
Expand Down Expand Up @@ -108,7 +108,7 @@ module Bundler
end
end

<% if options[:rubygems] -%>
<% if rubygems? -%>
module Gem
@loaded_stacks = Hash.new { |h,k| h[k] = [] }

Expand Down
4 changes: 2 additions & 2 deletions spec/bundler/manifest_file_spec.rb
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions spec/bundler/manifest_spec.rb
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion spec/support/builders.rb
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion spec/support/helpers.rb
Expand Up @@ -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
Expand Down

0 comments on commit 12c740f

Please sign in to comment.