aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-04-20 17:51:12 -0700
committerCarlhuda <carlhuda@engineyard.com>2010-04-20 17:51:12 -0700
commitba579f4a3e525fdd78d89531291450b26a009b07 (patch)
treecd0a51cbbfb2bb6038535d52c2702fb5e60845fa
parent4bfff00e3bfc24c92c2a4e24ed08ad4e40942db2 (diff)
downloadbundler-ba579f4a3e525fdd78d89531291450b26a009b07.tar.gz
Remove temporary flex stuff
-rw-r--r--lib/bundler.rb15
-rw-r--r--lib/bundler/cli.rb35
-rw-r--r--lib/bundler/definition.rb129
-rw-r--r--lib/bundler/dsl.rb9
-rw-r--r--lib/bundler/environment.rb45
-rw-r--r--lib/bundler/flex/definition.rb61
-rw-r--r--lib/bundler/flex/environments.rb57
-rw-r--r--lib/bundler/flex/lockfile_parser.rb82
-rw-r--r--lib/bundler/installer.rb4
-rw-r--r--lib/bundler/lockfile_parser.rb79
-rw-r--r--spec/install/gems/flex_spec.rb3
-rw-r--r--spec/support/helpers.rb6
-rw-r--r--spec/unit/parser_spec.rb2
13 files changed, 150 insertions, 377 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 37b42855..d88b7847 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -11,10 +11,10 @@ module Bundler
autoload :Dependency, 'bundler/dependency'
autoload :Dsl, 'bundler/dsl'
autoload :Environment, 'bundler/environment'
- autoload :Flex, 'bundler/flex'
autoload :Index, 'bundler/index'
autoload :Installer, 'bundler/installer'
autoload :LazySpecification, 'bundler/lazy_specification'
+ autoload :LockfileParser, 'bundler/lockfile_parser'
autoload :RemoteSpecification, 'bundler/remote_specification'
autoload :Resolver, 'bundler/resolver'
autoload :Runtime, 'bundler/runtime'
@@ -116,18 +116,7 @@ module Bundler
def definition
configure
lockfile = root.join("Gemfile.lock")
- if lockfile.exist?
- Definition.from_lock(lockfile)
- else
- Definition.from_gemfile(default_gemfile)
- end
- end
-
- # TODO: obvious
- def flexdef
- configure
- lockfile = root.join("Gemfile.lock")
- Flex::Definition.build(default_gemfile, lockfile)
+ Definition.build(default_gemfile, lockfile)
end
def home
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index e5b30d3f..7cfeef56 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -69,7 +69,6 @@ module Bundler
desc "install", "Install the current environment to the system"
method_option "without", :type => :array, :banner => "Exclude gems that are part of the specified named group."
- method_option "relock", :type => :boolean, :banner => "Unlock, install the gems, and relock."
method_option "disable-shared-gems", :type => :boolean, :banner => "Do not use any shared gems, such as the system gem repository."
method_option "gemfile", :type => :string, :banner => "Use the specified gemfile instead of Gemfile"
def install(path = nil)
@@ -83,15 +82,7 @@ module Bundler
Bundler.settings[:disable_shared_gems] = '1' if options["disable-shared-gems"] || path
Bundler.settings.without = opts[:without]
- remove_lockfiles if options[:relock]
-
- begin
- Installer.install(Bundler.root, Bundler.definition, opts)
- rescue GemfileChanged
- raise GemfileChanged, "You changed your Gemfile after locking. Please run `bundle install --relock`."
- end
-
- lock if options[:relock] || options[:flex]
+ Installer.install(Bundler.root, Bundler.definition, opts)
cache if Bundler.root.join("vendor/cache").exist?
rescue GemNotFound => e
if Bundler.definition.sources.empty?
@@ -100,30 +91,6 @@ module Bundler
raise e
end
- desc "flex_install", "Temporary command for the 0.10 install as it is being built"
- method_option "without", :type => :array, :banner => "Exclude gems that are part of the specified named group."
- method_option "disable-shared-gems", :type => :boolean, :banner => "Do not use any shared gems, such as the system gem repository."
- method_option "gemfile", :type => :string, :banner => "Use the specified gemfile instead of Gemfile"
- def flex_install(path = nil)
- opts = options.dup
- opts[:without] ||= []
- opts[:without].map! { |g| g.to_sym }
-
- # Can't use Bundler.settings for this because settings needs gemfile.dirname
- ENV['BUNDLE_GEMFILE'] = opts[:gemfile] if opts[:gemfile]
- Bundler.settings[:path] = path if path
- Bundler.settings[:disable_shared_gems] = '1' if options["disable-shared-gems"] || path
- Bundler.settings.without = opts[:without]
-
- Flex::Installer.install(Bundler.root, Bundler.flexdef, opts)
- cache if Bundler.root.join("vendor/cache").exist?
- rescue GemNotFound => e
- if Bundler.flexdef.sources.empty?
- Bundler.ui.warn "Your Gemfile doesn't have any sources. You can add one with a line like 'source :gemcutter'"
- end
- raise e
- end
-
desc "lock", "Locks the bundle to the current set of dependencies, including all child dependencies."
def lock
if locked?
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 2aa86847..eb23042d 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -3,124 +3,59 @@ require "digest/sha1"
# TODO: In the 0.10 release, there shouldn't be a locked subclass of Definition
module Bundler
class Definition
- def self.from_gemfile(gemfile)
+ attr_reader :dependencies, :sources, :locked_specs
+
+ def self.build(gemfile, lockfile)
gemfile = Pathname.new(gemfile).expand_path
unless gemfile.file?
raise GemfileNotFound, "#{gemfile} not found"
end
- Dsl.evaluate(gemfile)
+ # 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)
end
- def self.from_lock(lockfile, check = true)
- return nil unless lockfile.exist?
-
- locked_definition = Locked.new(YAML.load_file(lockfile))
+ def initialize(lockfile, dependencies, sources)
+ @dependencies, @sources = dependencies, sources
- if check
- hash = Digest::SHA1.hexdigest(File.read("#{Bundler.root}/Gemfile"))
- unless locked_definition.hash == hash
- raise GemfileChanged, "You changed your Gemfile after locking. Please relock using `bundle lock`"
- end
+ if lockfile && File.exists?(lockfile)
+ locked = LockfileParser.new(File.read(lockfile))
+ @locked_deps = locked.dependencies
+ @locked_specs = SpecSet.new(locked.specs)
+ else
+ @locked_deps = []
+ @locked_specs = SpecSet.new([])
end
-
- locked_definition
end
- def self.flexdef(gemfile, lockfile)
- Flex.new(from_gemfile(gemfile), from_lock(lockfile, false))
- end
-
- attr_reader :dependencies, :sources
-
- alias resolved_dependencies dependencies
-
- def initialize(dependencies, sources)
- @dependencies = dependencies
- @sources = sources
+ # TODO: OMG LOL
+ def resolved_dependencies
+ locked_specs_as_deps + dependencies
end
def groups
dependencies.map { |d| d.groups }.flatten.uniq
end
- class Flex
- def initialize(gemfile, lockfile)
- @gemfile = gemfile
- @lockfile = lockfile
- end
-
- def dependencies
- @gemfile.dependencies
- 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_as_deps
+ deps = @dependencies & @locked_deps
- def sources
- @gemfile.sources
+ @dependencies.each do |dep|
+ next if deps.include?(dep)
+ deps << dep if @locked_specs.any? { |s| s.satisfies?(dep) }
end
- def groups
- dependencies.map { |d| d.groups }.flatten.uniq
- end
-
- def resolved_dependencies
- @resolved_dependencies ||= begin
- if @lockfile
- # Build a list of gems that have been removed from the gemfile
- # but are still listed in the lockfile
- removed_deps = @lockfile.dependencies.select do |d|
- dependencies.all? { |d2| d2.name != d.name }
- end
-
- # Take the lockfile, remove the gems that are in the previously
- # built list of removed gems, and keep what's left over
- new_deps = @lockfile.resolved_dependencies.reject do |d|
- removed_deps.any? { |d2| d.name == d2.name }
- end
-
- # Add gems that have been added to the gemfile
- dependencies.each do |d|
- next if new_deps.any? {|new_dep| new_dep.name == d.name }
- new_deps << d
- end
-
- new_deps
- else
- dependencies
- end
- end
- end
- end
-
- class Locked < Definition
- def initialize(details)
- @details = details
- end
-
- def hash
- @details["hash"]
- end
-
- def sources
- @sources ||= @details["sources"].map do |args|
- name, options = args.to_a.flatten
- Bundler::Source.const_get(name).new(options)
- end
- end
-
- def resolved_dependencies
- @resolved_dependencies ||= @details["specs"].map do |args|
- name, details = args.to_a.flatten
- details["source"] = sources[details["source"]] if details.include?("source")
- Bundler::Dependency.new(name, details.delete("version"), details)
- end
- end
-
- def dependencies
- @dependencies ||= @details["dependencies"].map do |opts|
- Bundler::Dependency.new(opts.delete("name"), opts.delete("version"), opts)
- end
- end
+ @locked_specs.for(deps).map { |s| Gem::Dependency.new(s.name, s.version) }
end
end
end
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index 6de9acce..21646611 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -51,13 +51,8 @@ module Bundler
source Source::Git.new(_normalize_hash(options).merge("uri" => uri)), source_options, &blk
end
- def to_definition
- Definition.new(@dependencies, @sources)
- end
-
- # TODO: obvious
- def to_flex_definition(lockfile)
- Flex::Definition.new(lockfile, @dependencies, @sources)
+ def to_definition(lockfile)
+ Definition.new(lockfile, @dependencies, @sources)
end
def group(*args, &blk)
diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb
index c635a897..9e4e14eb 100644
--- a/lib/bundler/environment.rb
+++ b/lib/bundler/environment.rb
@@ -102,7 +102,7 @@ module Bundler
end
def gemfile_fingerprint
- Digest::SHA1.hexdigest(File.read("#{root}/Gemfile"))
+ Digest::SHA1.hexdigest(File.read(Bundler.default_gemfile))
end
def specs_for_lock_file
@@ -124,29 +124,42 @@ module Bundler
end
def write_yml_lock
- yml = details.to_yaml
File.open("#{root}/Gemfile.lock", 'w') do |f|
- f.puts yml
+ f.puts details
end
end
def details
- details = {}
- details["hash"] = gemfile_fingerprint
- details["sources"] = sources.map { |s| { s.class.name.split("::").last => s.options} }
-
- details["specs"] = specs.map do |s|
- options = {"version" => s.version.to_s}
- options["source"] = sources.index(s.source) if sources.include?(s.source)
- { s.name => options }
+ output = ""
+
+ pinned_sources = dependencies.map {|d| d.source }
+ all_sources = @definition.sources.map {|s| s }
+
+ specified_sources = all_sources - pinned_sources
+
+ unless specified_sources.empty?
+ output << "sources:\n"
+
+ specified_sources.each do |source|
+ output << " #{source.to_lock}\n"
+ end
+ output << "\n"
end
- details["dependencies"] = @definition.dependencies.map do |d|
- info = {"version" => d.requirement.to_s, "group" => d.groups, "name" => d.name}
- info.merge!("require" => d.autorequire) if d.autorequire
- info
+ unless @definition.dependencies.empty?
+ output << "dependencies:\n"
+ @definition.dependencies.sort_by {|d| d.name }.each do |dependency|
+ output << dependency.to_lock
+ end
+ output << "\n"
+ end
+
+ output << "specs:\n"
+ specs.sort_by {|s| s.name }.each do |spec|
+ output << spec.to_lock
end
- details
+
+ output
end
def autorequires_for_groups(*groups)
diff --git a/lib/bundler/flex/definition.rb b/lib/bundler/flex/definition.rb
deleted file mode 100644
index 76fa8df4..00000000
--- a/lib/bundler/flex/definition.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-# TODO: In the 0.10 release, there shouldn't be a locked subclass of Definition
-module Bundler
- module Flex
- class Definition
- attr_reader :dependencies, :sources, :locked_specs
-
- def self.build(gemfile, lockfile)
- gemfile = Pathname.new(gemfile).expand_path
-
- unless gemfile.file?
- raise GemfileNotFound, "#{gemfile} not found"
- end
-
- # TODO: move this back into DSL
- builder = Dsl.new
- builder.instance_eval(File.read(gemfile.to_s), gemfile.to_s, 1)
- builder.to_flex_definition(lockfile)
- end
-
- def initialize(lockfile, dependencies, sources)
- @dependencies, @sources = dependencies, sources
-
- if lockfile && File.exists?(lockfile)
- locked = LockfileParser.new(File.read(lockfile))
- @locked_deps = locked.dependencies
- @locked_specs = SpecSet.new(locked.specs)
- else
- @locked_deps = []
- @locked_specs = SpecSet.new([])
- end
- end
-
- # TODO: OMG LOL
- def resolved_dependencies
- locked_specs_as_deps + dependencies
- end
-
- def groups
- dependencies.map { |d| d.groups }.flatten.uniq
- 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_as_deps
- deps = @dependencies & @locked_deps
-
- @dependencies.each do |dep|
- next if deps.include?(dep)
- deps << dep if @locked_specs.any? { |s| s.satisfies?(dep) }
- end
-
- @locked_specs.for(deps).map { |s| Gem::Dependency.new(s.name, s.version) }
- end
- end
- end
-end \ No newline at end of file
diff --git a/lib/bundler/flex/environments.rb b/lib/bundler/flex/environments.rb
deleted file mode 100644
index b3cb8f0b..00000000
--- a/lib/bundler/flex/environments.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-module Bundler
- module Flex
- module Environment
- def write_yml_lock
- File.open("#{root}/Gemfile.lock", 'w') do |f|
- f.puts details
- end
- end
-
- def details
- output = ""
-
- pinned_sources = dependencies.map {|d| d.source }
- all_sources = @definition.sources.map {|s| s }
-
- specified_sources = all_sources - pinned_sources
-
- unless specified_sources.empty?
- output << "sources:\n"
-
- specified_sources.each do |source|
- output << " #{source.to_lock}\n"
- end
- output << "\n"
- end
-
- unless @definition.dependencies.empty?
- output << "dependencies:\n"
- @definition.dependencies.sort_by {|d| d.name }.each do |dependency|
- output << dependency.to_lock
- end
- output << "\n"
- end
-
- output << "specs:\n"
- specs.sort_by {|s| s.name }.each do |spec|
- output << spec.to_lock
- end
-
- output
- end
- end
-
- class Installer < Bundler::Installer
- include Environment
-
- def run(*)
- super
- lock
- end
- end
-
- class Runtime < Bundler::Runtime
- include Environment
- end
- end
-end \ No newline at end of file
diff --git a/lib/bundler/flex/lockfile_parser.rb b/lib/bundler/flex/lockfile_parser.rb
deleted file mode 100644
index c04521ae..00000000
--- a/lib/bundler/flex/lockfile_parser.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-require "strscan"
-
-module Bundler
- module Flex
- class LockfileParser
- attr_reader :sources, :dependencies, :specs
-
- # Do stuff
- def initialize(lockfile)
- @sources = []
- @dependencies = []
- @specs = []
-
- lockfile.split(/\n+/).each do |line|
- case line
- when "sources:"
- @state = :source
- when "dependencies:"
- @state = :dependencies
- when "specs:"
- @state = :specs
- else
- send("parse_#{@state}", line)
- end
- end
- end
-
- private
-
- TYPES = {
- "git" => Bundler::Source::Git,
- "gem" => Bundler::Source::Rubygems,
- "path" => Bundler::Source::Path
- }
-
- def parse_source(line)
- @sources << parse_source_line(line)
- end
-
- def parse_source_line(line)
- type, source, option_line = line.match(/^\s+(\w+): ([^\s]*?)(?: (.*))?$/).captures
- options = extract_options(option_line)
- TYPES[type].from_lock(source, options)
- end
-
- NAME_VERSION = '(?! )(.*?)(?: \((.*)\))?:?'
-
- def parse_dependencies(line)
- if line =~ %r{^ {2}#{NAME_VERSION}$}
- name, version = $1, $2
-
- @current = Bundler::Dependency.new(name, version)
- @dependencies << @current
- else
- @current.source = parse_source_line(line)
- end
- end
-
- def parse_specs(line)
- if line =~ %r{^ {2}#{NAME_VERSION}$}
- @current = LazySpecification.new($1, $2)
- @specs << @current
- else
- line =~ %r{^ {4}#{NAME_VERSION}$}
- @current.dependencies << Gem::Dependency.new($1, $2)
- end
- end
-
- def extract_options(line)
- options = {}
- return options unless line
-
- line.scan(/(\w+):"((?:|.*?[^\\])(?:\\\\)*)" ?/) do |k,v|
- options[k] = v
- end
-
- options
- end
-
- end
- end
-end \ No newline at end of file
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index 08c939b4..bfd41487 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -36,9 +36,7 @@ module Bundler
spec.source.install(spec)
end
- if locked?
- write_rb_lock
- end
+ lock
Bundler.ui.confirm "Your bundle is complete! Use `bundle show gemname` to see where a bundled gem is installed."
end
diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb
new file mode 100644
index 00000000..572791d8
--- /dev/null
+++ b/lib/bundler/lockfile_parser.rb
@@ -0,0 +1,79 @@
+require "strscan"
+
+module Bundler
+ class LockfileParser
+ attr_reader :sources, :dependencies, :specs
+
+ # Do stuff
+ def initialize(lockfile)
+ @sources = []
+ @dependencies = []
+ @specs = []
+
+ lockfile.split(/\n+/).each do |line|
+ case line
+ when "sources:"
+ @state = :source
+ when "dependencies:"
+ @state = :dependencies
+ when "specs:"
+ @state = :specs
+ else
+ send("parse_#{@state}", line)
+ end
+ end
+ end
+
+ private
+
+ TYPES = {
+ "git" => Bundler::Source::Git,
+ "gem" => Bundler::Source::Rubygems,
+ "path" => Bundler::Source::Path
+ }
+
+ def parse_source(line)
+ @sources << parse_source_line(line)
+ end
+
+ def parse_source_line(line)
+ type, source, option_line = line.match(/^\s+(\w+): ([^\s]*?)(?: (.*))?$/).captures
+ options = extract_options(option_line)
+ TYPES[type].from_lock(source, options)
+ end
+
+ NAME_VERSION = '(?! )(.*?)(?: \((.*)\))?:?'
+
+ def parse_dependencies(line)
+ if line =~ %r{^ {2}#{NAME_VERSION}$}
+ name, version = $1, $2
+
+ @current = Bundler::Dependency.new(name, version)
+ @dependencies << @current
+ else
+ @current.source = parse_source_line(line)
+ end
+ end
+
+ def parse_specs(line)
+ if line =~ %r{^ {2}#{NAME_VERSION}$}
+ @current = LazySpecification.new($1, $2)
+ @specs << @current
+ else
+ line =~ %r{^ {4}#{NAME_VERSION}$}
+ @current.dependencies << Gem::Dependency.new($1, $2)
+ end
+ end
+
+ def extract_options(line)
+ options = {}
+ return options unless line
+
+ line.scan(/(\w+):"((?:|.*?[^\\])(?:\\\\)*)" ?/) do |k,v|
+ options[k] = v
+ end
+
+ options
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/install/gems/flex_spec.rb b/spec/install/gems/flex_spec.rb
index ac2e51fb..effeff5d 100644
--- a/spec/install/gems/flex_spec.rb
+++ b/spec/install/gems/flex_spec.rb
@@ -25,7 +25,7 @@ describe "bundle flex_install" do
gem 'rack', '1.0'
G
- bundle :flex_install
+ bundle :install
should_be_installed "rack 1.0.0"
should_be_locked
end
@@ -118,6 +118,7 @@ describe "bundle flex_install" do
end
it "rebuilds env.rb correctly" do
+ pending
build_repo2
flex_install_gemfile <<-G
source "file://#{gem_repo2}"
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index ce9df3be..b5df5c04 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -119,11 +119,7 @@ module Spec
bundle :install, opts
end
- def flex_install_gemfile(*args)
- gemfile(*args)
- opts = args.last.is_a?(Hash) ? args.last : {}
- bundle :flex_install, opts
- end
+ alias flex_install_gemfile install_gemfile
def install_gems(*gems)
gems.each do |g|
diff --git a/spec/unit/parser_spec.rb b/spec/unit/parser_spec.rb
index ef9332d0..6efd0a2c 100644
--- a/spec/unit/parser_spec.rb
+++ b/spec/unit/parser_spec.rb
@@ -12,7 +12,7 @@ describe "lockfile parser" do
def locked
lockfile = File.read(bundled_app('Gemfile.lock'))
- Bundler::Flex::LockfileParser.new(lockfile)
+ Bundler::LockfileParser.new(lockfile)
end
it "has the source in it" do