summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/gem_tasks.rb3
-rw-r--r--lib/bundler/installer.rb41
-rw-r--r--lib/bundler/installer/standalone.rb48
-rw-r--r--spec/runtime/gem_tasks_spec.rb7
4 files changed, 60 insertions, 39 deletions
diff --git a/lib/bundler/gem_tasks.rb b/lib/bundler/gem_tasks.rb
index 4c8f28c9d6..0ff383bf8b 100644
--- a/lib/bundler/gem_tasks.rb
+++ b/lib/bundler/gem_tasks.rb
@@ -1,2 +1,5 @@
+require "rake/clean"
+CLOBBER.include "pkg"
+
require "bundler/gem_helper"
Bundler::GemHelper.install_tasks
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index 923fbd1faf..1fd0b85dd9 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -2,6 +2,7 @@ require "erb"
require "rubygems/dependency_installer"
require "bundler/worker"
require "bundler/installer/parallel_installer"
+require "bundler/installer/standalone"
module Bundler
class Installer < Environment
@@ -68,7 +69,7 @@ module Bundler
install(options)
lock unless Bundler.settings[:frozen]
- generate_standalone(options[:standalone]) if options[:standalone]
+ Standalone.new(options[:standalone], @definition).generate if options[:standalone]
end
def install_gem_from_spec(spec, standalone = false, worker = 0, force = false)
@@ -209,44 +210,6 @@ module Bundler
end
end
- def generate_standalone(groups)
- standalone_path = Bundler.settings[:path]
- bundler_path = File.join(standalone_path, "bundler")
- SharedHelpers.filesystem_access(bundler_path) do |p|
- FileUtils.mkdir_p(p)
- end
-
- paths = []
-
- if groups.empty?
- specs = @definition.requested_specs
- else
- specs = @definition.specs_for groups.map(&:to_sym)
- end
-
- specs.each do |spec|
- next if spec.name == "bundler"
- next if spec.require_paths.nil? # builtin gems
-
- spec.require_paths.each do |path|
- full_path = Pathname.new(path).absolute? ? path : File.join(spec.full_gem_path, path)
- gem_path = Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path))
- paths << gem_path.to_s.sub("#{Bundler.ruby_version.engine}/#{RbConfig::CONFIG["ruby_version"]}", '#{ruby_engine}/#{ruby_version}')
- end
- end
-
- File.open File.join(bundler_path, "setup.rb"), "w" do |file|
- file.puts "require 'rbconfig'"
- file.puts "# ruby 1.8.7 doesn't define RUBY_ENGINE"
- file.puts "ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'"
- file.puts "ruby_version = RbConfig::CONFIG[\"ruby_version\"]"
- file.puts "path = File.expand_path('..', __FILE__)"
- paths.each do |path|
- file.puts %{$:.unshift "\#{path}/#{path}"}
- end
- end
- end
-
def install_in_parallel(size, standalone, force = false)
ParallelInstaller.call(self, specs, size, standalone, force)
end
diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb
new file mode 100644
index 0000000000..6776dd6200
--- /dev/null
+++ b/lib/bundler/installer/standalone.rb
@@ -0,0 +1,48 @@
+module Bundler
+ class Standalone
+ def initialize(groups, definition)
+ @specs = groups.empty? ? definition.requested_specs : definition.specs_for(groups.map(&:to_sym))
+ end
+
+ def generate
+ SharedHelpers.filesystem_access(bundler_path) do |p|
+ FileUtils.mkdir_p(p)
+ end
+ File.open File.join(bundler_path, "setup.rb"), "w" do |file|
+ file.puts "require 'rbconfig'"
+ file.puts "# ruby 1.8.7 doesn't define RUBY_ENGINE"
+ file.puts "ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'"
+ file.puts "ruby_version = RbConfig::CONFIG[\"ruby_version\"]"
+ file.puts "path = File.expand_path('..', __FILE__)"
+ paths.each do |path|
+ file.puts %{$:.unshift "\#{path}/#{path}"}
+ end
+ end
+ end
+
+ private
+
+ def paths
+ @specs.map do |spec|
+ next if spec.name == "bundler"
+ Array(spec.require_paths).map do |path|
+ gem_path(path, spec).sub(version_dir, '#{ruby_engine}/#{ruby_version}')
+ # This is a static string intentionally. It's interpolated at a later time.
+ end
+ end.flatten
+ end
+
+ def version_dir
+ "#{Bundler.ruby_version.engine}/#{RbConfig::CONFIG["ruby_version"]}"
+ end
+
+ def bundler_path
+ File.join(Bundler.settings[:path], "bundler")
+ end
+
+ def gem_path(path, spec)
+ full_path = Pathname.new(path).absolute? ? path : File.join(spec.full_gem_path, path)
+ Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)).to_s
+ end
+ end
+end
diff --git a/spec/runtime/gem_tasks_spec.rb b/spec/runtime/gem_tasks_spec.rb
index c7641cfe22..1cbc35f7bb 100644
--- a/spec/runtime/gem_tasks_spec.rb
+++ b/spec/runtime/gem_tasks_spec.rb
@@ -25,6 +25,8 @@ describe "require 'bundler/gem_tasks'" do
expect(err).to eq("")
expected_tasks = [
"rake build",
+ "rake clean",
+ "rake clobber",
"rake install",
"rake release[remote]",
]
@@ -32,4 +34,9 @@ describe "require 'bundler/gem_tasks'" do
expect(tasks & expected_tasks).to eq(expected_tasks)
expect(exitstatus).to eq(0) if exitstatus
end
+
+ it "adds 'pkg' to rake/clean's CLOBBER" do
+ require "bundler/gem_tasks"
+ expect(CLOBBER).to include("pkg")
+ end
end