diff options
author | Carl Lerche <carllerche@mac.com> | 2010-03-10 21:10:25 -0800 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-03-10 21:10:25 -0800 |
commit | 0d5e87b89617fabb175ed8d0b54bee764b454f2c (patch) | |
tree | 1c0871afb63ccdb9d65cb58aa82bd9ad1c570fcc | |
parent | ea42c17846477ac542b31a72457c78a0646f3c0d (diff) | |
download | bundler-0d5e87b89617fabb175ed8d0b54bee764b454f2c.tar.gz |
Move writing the ruby lock to Environment
-rw-r--r-- | lib/bundler/cli.rb | 3 | ||||
-rw-r--r-- | lib/bundler/environment.rb | 71 | ||||
-rw-r--r-- | lib/bundler/installer.rb | 4 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 69 | ||||
-rw-r--r-- | lib/bundler/source.rb | 3 |
5 files changed, 78 insertions, 72 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 968b345b6b..0a7bf99891 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -68,9 +68,6 @@ module Bundler remove_lockfiles if options[:relock] Installer.install(Bundler.root, Bundler.definition, opts) - # Ensures that .bundle/environment.rb exists - # TODO: Figure out a less hackish way to do this - Bundler.load lock if options[:relock] end diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb index 59970f16c3..3602f12dd1 100644 --- a/lib/bundler/environment.rb +++ b/lib/bundler/environment.rb @@ -28,6 +28,13 @@ module Bundler end end + def specs_for(*groups) + groups = @definition.groups if groups.empty? + groups -= Bundler.settings.without + groups.map! { |g| g.to_sym } + specs.select { |s| (s.groups & groups).any? } + end + def group_specs(specs) dependencies.each do |d| spec = specs.find { |s| s.name == d.name } @@ -44,5 +51,69 @@ module Bundler group_spec(specs, spec, groups) end end + + # ==== Locking + + def locked? + File.exist?("#{root}/Gemfile.lock") + end + + def write_rb_lock + shared_helpers = File.read(File.expand_path("../shared_helpers.rb", __FILE__)) + template = File.read(File.expand_path("../templates/environment.erb", __FILE__)) + erb = ERB.new(template, nil, '-') + FileUtils.mkdir_p(rb_lock_file.dirname) + File.open(rb_lock_file, 'w') do |f| + f.puts erb.result(binding) + end + end + + def rb_lock_file + root.join(".bundle/environment.rb") + end + + def gemfile_fingerprint + Digest::SHA1.hexdigest(File.read("#{root}/Gemfile")) + end + + def specs_for_lock_file + specs_for.map do |s| + hash = {} + hash[:loaded_from] = s.loaded_from.to_s + hash[:load_paths] = s.load_paths + hash + end + end + + def autorequires_for_groups(*groups) + groups.map! { |g| g.to_sym } + autorequires = Hash.new { |h,k| h[k] = [] } + + ordered_deps = [] + specs_for(*groups).each do |g| + dep = @definition.dependencies.find{|d| d.name == g.name } + ordered_deps << dep if dep && !ordered_deps.include?(dep) + end + + ordered_deps.each do |dep| + dep.groups.each do |group| + # If there is no autorequire, then rescue from + # autorequiring the gems name + if dep.autorequire + dep.autorequire.each do |file| + autorequires[group] << [file, true] + end + else + autorequires[group] << [dep.name, false] + end + end + end + + if groups.empty? + autorequires + else + groups.inject({}) { |h,g| h[g] = autorequires[g]; h } + end + end end end diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 20c512e9dd..13ff9d8deb 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -33,6 +33,10 @@ module Bundler Bundler.ui.info "" end + if locked? + write_rb_lock + end + Bundler.ui.confirm "Your bundle is complete!" end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 90395c188b..e5de8b3968 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -67,10 +67,6 @@ module Bundler Bundler.ui.info("The bundle is now locked. Use `bundle show` to list the gems in the environment.") end - def locked? - File.exist?("#{root}/Gemfile.lock") || File.exist?("#{root}/.bundle/environment.rb") - end - def dependencies_for(*groups) if groups.empty? dependencies @@ -79,13 +75,6 @@ module Bundler end end - def specs_for(*groups) - groups = @definition.groups if groups.empty? - groups -= Bundler.settings.without - groups.map! { |g| g.to_sym } - specs.select { |s| (s.groups & groups).any? } - end - def specs @specs ||= begin source_requirements = {} @@ -126,20 +115,6 @@ module Bundler specs.map { |s| s.load_paths }.flatten end - def rb_lock_file - root.join(".bundle/environment.rb") - end - - def write_rb_lock - shared_helpers = File.read(File.expand_path("../shared_helpers.rb", __FILE__)) - template = File.read(File.expand_path("../templates/environment.erb", __FILE__)) - erb = ERB.new(template, nil, '-') - FileUtils.mkdir_p(rb_lock_file.dirname) - File.open(rb_lock_file, 'w') do |f| - f.puts erb.result(binding) - end - end - def write_yml_lock yml = details.to_yaml File.open("#{root}/Gemfile.lock", 'w') do |f| @@ -165,49 +140,5 @@ module Bundler end details end - - def gemfile_fingerprint - Digest::SHA1.hexdigest(File.read("#{root}/Gemfile")) - end - - def specs_for_lock_file - specs_for.map do |s| - hash = {} - hash[:loaded_from] = s.loaded_from.to_s - hash[:load_paths] = s.load_paths - hash - end - end - - def autorequires_for_groups(*groups) - groups.map! { |g| g.to_sym } - autorequires = Hash.new { |h,k| h[k] = [] } - - ordered_deps = [] - specs_for(*groups).each do |g| - dep = @definition.dependencies.find{|d| d.name == g.name } - ordered_deps << dep if dep && !ordered_deps.include?(dep) - end - - ordered_deps.each do |dep| - dep.groups.each do |group| - # If there is no autorequire, then rescue from - # autorequiring the gems name - if dep.autorequire - dep.autorequire.each do |file| - autorequires[group] << [file, true] - end - else - autorequires[group] << [dep.name, false] - end - end - end - - if groups.empty? - autorequires - else - groups.inject({}) { |h,g| h[g] = autorequires[g]; h } - end - end end end diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 55f7399afc..baf6065dd3 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -40,6 +40,8 @@ module Bundler :bin_dir => "#{Gem.dir}/bin" installer.install + + spec.loaded_from = "#{Gem.dir}/specifications/#{spec.full_name}.gemspec" end private @@ -131,6 +133,7 @@ module Bundler :bin_dir => "#{Gem.dir}/bin" installer.install + spec.loaded_from = "#{Gem.dir}/specifications/#{spec.full_name}.gemspec" end end |