Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove a little bit of crazy from Definition

  • Loading branch information...
commit 8a4dc7a12e150dae3f0a7e2f6de5a18f899191ac 1 parent cf736cf
Carl Lerche authored
View
5 lib/bundler.rb
@@ -110,11 +110,12 @@ def environment
Bundler::Environment.new(root, definition)
end
- def definition
+ def definition(unlock = nil)
+ @definition = nil if unlock
@definition ||= begin
configure
lockfile = root.join("Gemfile.lock")
- Definition.build(default_gemfile, lockfile)
+ Definition.build(default_gemfile, lockfile, unlock)
end
end
View
8 lib/bundler/cli.rb
@@ -133,13 +133,11 @@ def update(*gems)
if gems.empty? && sources.empty?
# We're doing a full update
FileUtils.rm Bundler.root.join("Gemfile.lock")
- Installer.install Bundler.root, Bundler.definition
else
- Installer.install Bundler.root, Bundler.definition do |i|
- i.unlock_gems gems
- i.unlock_sources sources
- end
+ Bundler.definition(:gems => gems, :sources => sources)
end
+
+ Installer.install Bundler.root, Bundler.definition
end
desc "lock", "Locks the bundle to the current set of dependencies, including all child dependencies."
View
99 lib/bundler/definition.rb
@@ -3,9 +3,10 @@
# TODO: In the 0.10 release, there shouldn't be a locked subclass of Definition
module Bundler
class Definition
- attr_reader :dependencies, :sources, :platforms
+ attr_reader :dependencies, :locked_specs, :platforms
- def self.build(gemfile, lockfile)
+ def self.build(gemfile, lockfile, unlock)
+ unlock ||= {}
gemfile = Pathname.new(gemfile).expand_path
unless gemfile.file?
@@ -15,7 +16,7 @@ def self.build(gemfile, lockfile)
# TODO: move this back into DSL
builder = Dsl.new
builder.instance_eval(File.read(gemfile.to_s), gemfile.to_s, 1)
- builder.to_definition(lockfile)
+ builder.to_definition(lockfile, unlock)
end
=begin
@@ -30,8 +31,8 @@ def self.build(gemfile, lockfile)
specs, then we can try to resolve locally.
=end
- def initialize(lockfile, dependencies, sources)
- @dependencies, @sources, @unlock = dependencies, sources, []
+ def initialize(lockfile, dependencies, sources, unlock)
+ @dependencies, @sources, @unlock = dependencies, sources, unlock
if lockfile && File.exists?(lockfile)
locked = LockfileParser.new(File.read(lockfile))
@@ -49,26 +50,6 @@ def initialize(lockfile, dependencies, sources)
converge
end
- def unlock!(what_to_unlock)
- raise "Specs already loaded" if @specs
-
- # Set the gems to unlock
- @unlock.concat(what_to_unlock[:gems])
- # Find the gems associated with specific sources and unlock them
- what_to_unlock[:sources].each do |source_name|
- source = sources.find { |s| s.name == source_name }
- source.unlock! if source.respond_to?(:unlock!)
-
- # Add all the spec names that are part of the source to unlock
- @unlock.concat @locked_specs.
- select { |s| s.source == source }.
- map { |s| s.name }
-
- # Remove duplicate spec names
- @unlock.uniq!
- end
- end
-
def resolve_remotely!
raise "Specs already loaded" if @specs
@specs = resolve_remote_specs
@@ -80,7 +61,7 @@ def specs
def index
@index ||= Index.build do |idx|
- sources.each do |s|
+ @sources.each do |s|
idx.use s.local_specs
end
end
@@ -88,12 +69,12 @@ def index
def remote_index
@remote_index ||= Index.build do |idx|
- sources.each { |source| idx.use source.specs }
+ @sources.each { |source| idx.use source.specs }
end
end
def no_sources?
- sources.length == 1 && sources.first.remotes.empty?
+ @sources.length == 1 && @sources.first.remotes.empty?
end
def groups
@@ -143,42 +124,27 @@ def to_lock
private
def converge
- common = @locked_sources & @sources
- fresh = @sources - common
- # stale = @locked_sources - common
-
- @sources = common + fresh
+ converge_sources
+ converge_dependencies
+ converge_locked_specs
+ end
- @locked_specs.each do |s|
- if source = @sources.find { |source| s.source == source }
- s.source = source
- else
- @unlock << s.name
- end
+ def converge_sources
+ @sources = (@locked_sources & @sources) | @sources
+ @sources.each do |source|
+ source.unlock! if source.respond_to?(:unlock!) && (@unlock[:sources] || []).include?(source.name)
end
+ end
- @dependencies.each do |dep|
+ def converge_dependencies
+ (@dependencies + @locked_deps).each do |dep|
if dep.source && source = @sources.find { |s| dep.source == s }
- dep.source == source
+ dep.source = source
end
end
end
- def sorted_sources
- sources.sort_by do |s|
- # Place GEM at the top
- [ s.is_a?(Source::Rubygems) ? 1 : 0, s.to_s ]
- end
- end
-
- # We have the dependencies from Gemfile.lock and the dependencies from the
- # Gemfile. Here, we are finding a list of all dependencies that were
- # originally present in the Gemfile that still satisfy the requirements
- # of the dependencies in the Gemfile.lock
- #
- # This allows us to add on the *new* requirements in the Gemfile and make
- # sure that the changes result in a conservative update to the Gemfile.lock.
- def locked_specs
+ def converge_locked_specs
deps = []
@dependencies.each do |dep|
@@ -187,7 +153,15 @@ def locked_specs
end
end
- @locked_specs.for(deps, @unlock)
+ @locked_specs = @locked_specs.for(deps, @unlock[:gems] || [])
+
+ @locked_specs.each do |s|
+ s.source = @sources.find { |source| s.source == source }
+ end
+
+ @locked_specs.delete_if do |s|
+ s.source.nil? || (@unlock[:sources] || []).include?(s.name)
+ end
end
def in_locked_deps?(dep)
@@ -200,6 +174,13 @@ def satisfies_locked_spec?(dep)
@locked_specs.any? { |s| s.satisfies?(dep) }
end
+ def sorted_sources
+ @sources.sort_by do |s|
+ # Place GEM at the top
+ [ s.is_a?(Source::Rubygems) ? 1 : 0, s.to_s ]
+ end
+ end
+
def resolve(type, idx)
source_requirements = {}
dependencies.each do |dep|
@@ -222,9 +203,5 @@ def resolve_remote_specs
rescue #InvalidSpecSet, GemNotFound, PathError
resolve(:specs, remote_index)
end
-
- def ambiguous?(dep)
- dep.requirement.requirements.any? { |op,_| op != '=' }
- end
end
end
View
4 lib/bundler/dsl.rb
@@ -56,10 +56,10 @@ def git(uri, options = {}, source_options = {}, &blk)
source Source::Git.new(_normalize_hash(options).merge("uri" => uri)), source_options, &blk
end
- def to_definition(lockfile)
+ def to_definition(lockfile, unlock)
@sources << @rubygems_source
@sources.uniq!
- Definition.new(lockfile, @dependencies, @sources)
+ Definition.new(lockfile, @dependencies, @sources, unlock)
end
def group(*args, &blk)
View
14 lib/bundler/installer.rb
@@ -4,30 +4,16 @@ module Bundler
class Installer < Environment
def self.install(root, definition, options = {})
installer = new(root, definition)
- yield installer if block_given?
installer.run(options)
installer
end
- def unlock_gems(gem_names)
- @gem_names_to_unlock = gem_names
- end
-
- def unlock_sources(source_names)
- @source_names_to_unlock = source_names
- end
-
def run(options)
if dependencies.empty?
Bundler.ui.warn "The Gemfile specifies no dependencies"
return
end
- # Unlock any requested gems
- @definition.unlock!(
- :gems => @gem_names_to_unlock || [],
- :sources => @source_names_to_unlock || [])
-
# Since we are installing, we can resolve the definition
# using remote specs
@definition.resolve_remotely!
View
7 lib/bundler/spec_set.rb
@@ -31,8 +31,15 @@ def to_a
sorted.dup
end
+ def delete_if(&blk)
+ @lookup = nil
+ @sorted = nil
+ @specs.delete_if(&blk)
+ end
+
def __materialize__
@lookup = nil
+ @sorted = nil
@specs.map! do |s|
next s unless s.is_a?(LazySpecification)
yield s
Please sign in to comment.
Something went wrong with that request. Please try again.