summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsutosh Palai <asupalai@gmail.com>2016-06-30 16:51:18 +0530
committerAsutosh Palai <asupalai@gmail.com>2016-07-03 09:41:58 +0530
commitb9b2600fb900a342a7fff8dcdf9153909b7e983e (patch)
treebe23de517ea4e1929178d98f79b587a440c2f0cc
parent5d76c0d8a5486be272087fd5f0642c263d4df33a (diff)
downloadbundler-b9b2600fb900a342a7fff8dcdf9153909b7e983e.tar.gz
Separated generate_bin into source/path/installer
-rw-r--r--lib/bundler/source/git.rb6
-rw-r--r--lib/bundler/source/path.rb25
-rw-r--r--lib/bundler/source/path/installer.rb50
3 files changed, 42 insertions, 39 deletions
diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb
index 76955ee49e..5344ab694f 100644
--- a/lib/bundler/source/git.rb
+++ b/lib/bundler/source/git.rb
@@ -170,7 +170,7 @@ module Bundler
serialize_gemspecs_in(install_path)
@copied = true
end
- generate_bin(spec)
+ generate_bin(spec, !Bundler.rubygems.spec_missing_extensions?(spec))
requires_checkout? ? spec.post_install_message : nil
end
@@ -223,10 +223,6 @@ module Bundler
private
- def build_extensions(installer)
- super if Bundler.rubygems.spec_missing_extensions?(installer.spec)
- end
-
def serialize_gemspecs_in(destination)
destination = destination.expand_path(Bundler.root) if destination.relative?
Dir["#{destination}/#{@glob}"].each do |spec_path|
diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb
index bbdd30b1e6..cc97f26a15 100644
--- a/lib/bundler/source/path.rb
+++ b/lib/bundler/source/path.rb
@@ -203,13 +203,8 @@ module Bundler
end
end.compact
- SharedHelpers.chdir(gem_dir) do
- installer = Path::Installer.new(spec, :env_shebang => false)
- run_hooks(:pre_install, installer)
- build_extensions(installer) unless disable_extensions
- installer.generate_bin
- run_hooks(:post_install, installer)
- end
+ installer = Path::Installer.new(spec, :env_shebang => false, :disable_extensions => disable_extensions)
+ installer.post_install
rescue Gem::InvalidSpecificationException => e
Bundler.ui.warn "\n#{spec.name} at #{spec.full_gem_path} did not have a valid gemspec.\n" \
"This prevents bundler from installing bins or native extensions, but " \
@@ -224,22 +219,6 @@ module Bundler
Bundler.ui.warn "The validation message from Rubygems was:\n #{e.message}"
end
- def build_extensions(installer)
- installer.build_extensions
- run_hooks(:post_build, installer)
- end
-
- def run_hooks(type, installer)
- hooks_meth = "#{type}_hooks"
- return unless Gem.respond_to?(hooks_meth)
- Gem.send(hooks_meth).each do |hook|
- result = hook.call(installer)
- next unless result == false
- location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
- message = "#{type} hook#{location} failed for #{installer.spec.full_name}"
- raise InstallHookError, message
- end
- end
end
end
end
diff --git a/lib/bundler/source/path/installer.rb b/lib/bundler/source/path/installer.rb
index 0aa27bd564..4fc5c807a5 100644
--- a/lib/bundler/source/path/installer.rb
+++ b/lib/bundler/source/path/installer.rb
@@ -6,13 +6,14 @@ module Bundler
attr_reader :spec
def initialize(spec, options = {})
- @spec = spec
- @gem_dir = Bundler.rubygems.path(spec.full_gem_path)
- @wrappers = true
- @env_shebang = true
- @format_executable = options[:format_executable] || false
- @build_args = options[:build_args] || Bundler.rubygems.build_args
- @gem_bin_dir = "#{Bundler.rubygems.gem_dir}/bin"
+ @spec = spec
+ @gem_dir = Bundler.rubygems.path(spec.full_gem_path)
+ @wrappers = true
+ @env_shebang = true
+ @format_executable = options[:format_executable] || false
+ @build_args = options[:build_args] || Bundler.rubygems.build_args
+ @gem_bin_dir = "#{Bundler.rubygems.gem_dir}/bin"
+ @disable_extentions = options[:disable_extensions]
if Bundler.requires_sudo?
@tmp_dir = Bundler.tmp(spec.full_name).to_s
@@ -22,9 +23,26 @@ module Bundler
end
end
- def generate_bin
- return if spec.executables.nil? || spec.executables.empty?
+ def post_install
+ SharedHelpers.chdir(gem_dir) do
+ run_hooks(:pre_install)
+
+ unless @disable_extentions
+ build_extensions
+ run_hooks(:post_build)
+ end
+
+ generate_bin unless spec.executables.nil? || spec.executables.empty?
+
+ run_hooks(:post_install)
+ end
+ ensure
+ Bundler.rm_rf(@tmp_dir) if Bundler.requires_sudo?
+ end
+
+ private
+ def generate_bin
super
if Bundler.requires_sudo?
@@ -35,8 +53,18 @@ module Bundler
Bundler.sudo "cp -R #{@bin_dir}/#{exe} #{@gem_bin_dir}"
end
end
- ensure
- Bundler.rm_rf(@tmp_dir) if Bundler.requires_sudo?
+ end
+
+ def run_hooks(type)
+ hooks_meth = "#{type}_hooks"
+ return unless Gem.respond_to?(hooks_meth)
+ Gem.send(hooks_meth).each do |hook|
+ result = hook.call(self)
+ next unless result == false
+ location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
+ message = "#{type} hook#{location} failed for #{spec.full_name}"
+ raise InstallHookError, message
+ end
end
end
end