Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Bundler.flexdef, move locking into Environment, and lock from fle…

…x_install
  • Loading branch information...
commit ab5b1fc4a9ccd572f5f0bb40aa77abbfb33f3414 1 parent eb819fb
Carlhuda authored
View
7 lib/bundler.rb
@@ -98,6 +98,13 @@ def definition
end
end
+ # TODO: obvious
+ def flexdef
+ configure
+ lockfile = root.join("Gemfile.lock")
+ Definition.flexdef(default_gemfile, lockfile)
+ end
+
def home
bundle_path.join("bundler")
end
View
4 lib/bundler/cli.rb
@@ -112,9 +112,7 @@ def flex_install(path = nil)
Bundler.settings[:disable_shared_gems] = '1' if options["disable-shared-gems"] || path
Bundler.settings.without = opts[:without]
- Installer.install(Bundler.root, Bundler.definition, opts)
-
- lock
+ Installer.install(Bundler.root, Bundler.flexdef, opts).lock
cache if Bundler.root.join("vendor/cache").exist?
rescue GemNotFound => e
if Bundler.definition.sources.empty?
View
25 lib/bundler/definition.rb
@@ -1,5 +1,6 @@
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)
@@ -12,17 +13,33 @@ def self.from_gemfile(gemfile)
Dsl.evaluate(gemfile)
end
- def self.from_lock(lockfile)
+ def self.from_lock(lockfile, check = true)
locked_definition = Locked.new(YAML.load_file(lockfile))
- hash = Digest::SHA1.hexdigest(File.read("#{Bundler.root}/Gemfile"))
- unless locked_definition.hash == hash
- raise GemfileError, "You changed your Gemfile after locking. Please relock using `bundle lock`"
+ if check
+ hash = Digest::SHA1.hexdigest(File.read("#{Bundler.root}/Gemfile"))
+ unless locked_definition.hash == hash
+ raise GemfileError, "You changed your Gemfile after locking. Please relock using `bundle lock`"
+ end
end
locked_definition
end
+ def self.flexdef(gemfile, lockfile)
+ target = from_gemfile(gemfile)
+ return target unless lockfile.exist?
+
+ current = from_lock(lockfile, false)
+
+ target.dependencies.each do |td|
+ next if current.resolved_dependencies.any? { |cd| td.name == cd.name }
+ current.resolved_dependencies << td
+ end
+
+ current
+ end
+
attr_reader :dependencies, :sources
alias resolved_dependencies dependencies
View
39 lib/bundler/environment.rb
@@ -36,6 +36,15 @@ def resolved_dependencies
@definition.resolved_dependencies
end
+ def lock
+ Bundler.ui.info("The bundle is already locked, relocking.") if locked?
+ sources.each { |s| s.lock if s.respond_to?(:lock) }
+ FileUtils.mkdir_p("#{root}/.bundle")
+ write_yml_lock
+ write_rb_lock
+ Bundler.ui.confirm("The bundle is now locked. Use `bundle show` to list the gems in the environment.")
+ end
+
private
def sources
@@ -110,6 +119,36 @@ def specs_for_lock_file
end
end
+ def load_paths
+ specs.map { |s| s.load_paths }.flatten
+ end
+
+ def write_yml_lock
+ yml = details.to_yaml
+ File.open("#{root}/Gemfile.lock", 'w') do |f|
+ f.puts yml
+ 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 }
+ 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
+ end
+ details
+ end
+
def autorequires_for_groups(*groups)
groups.map! { |g| g.to_sym }
groups = groups.any? ? groups : (@definition.groups - Bundler.settings.without)
View
4 lib/bundler/installer.rb
@@ -3,7 +3,9 @@
module Bundler
class Installer < Environment
def self.install(root, definition, options)
- new(root, definition).run(options)
+ installer = new(root, definition)
+ installer.run(options)
+ installer
end
def run(options)
View
38 lib/bundler/runtime.rb
@@ -54,15 +54,6 @@ def require(*groups)
end
end
- def lock
- Bundler.ui.info("The bundle is already locked, relocking.") if locked?
- sources.each { |s| s.lock if s.respond_to?(:lock) }
- FileUtils.mkdir_p("#{root}/.bundle")
- write_yml_lock
- write_rb_lock
- Bundler.ui.confirm("The bundle is now locked. Use `bundle show` to list the gems in the environment.")
- end
-
def dependencies_for(*groups)
if groups.empty?
dependencies
@@ -91,34 +82,5 @@ def cache
private
- def load_paths
- specs.map { |s| s.load_paths }.flatten
- end
-
- def write_yml_lock
- yml = details.to_yaml
- File.open("#{root}/Gemfile.lock", 'w') do |f|
- f.puts yml
- 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 }
- 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
- end
- details
- end
end
end
View
19 spec/install/gems/flex_spec.rb
@@ -11,6 +11,25 @@
should_be_locked
end
+ it "allows install even when the lockfile is invalid" do
+ flex_install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem 'rack'
+ G
+
+ should_be_installed "rack 1.0.0"
+ should_be_locked
+
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem 'rack', '1.0'
+ G
+
+ bundle :flex_install
+ should_be_installed "rack 1.0.0"
+ should_be_locked
+ end
+
it "does awesome" do
pending
build_repo2
Please sign in to comment.
Something went wrong with that request. Please try again.