1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-16 23:33:45 -05:00
Files
pyenv/rbenv.d/exec/gem-rehash/rubygems_plugin.rb
Mislav Marohnić 7b289bcee6 Avoid running rbenv rehash multiple times during bundle install
This is an attempt to work around the fact that Rubygems post_install
hooks may happen multiple times per single `bundle install` and ideally
we want `rbenv rehash` to run only once if new gems have been installed.
However, due to Bundler parallelism using `fork` on platforms that
support it, it's impossible for the child processes to communicate with
the master process to signal it to run `rbenv rehash` in the end.

This hooks into Bundler `install` command and runs `rbenv rehash` after
all gems have finished installing, but only if the install location was
system gems location and not a custom path (such as per-project
`vendor/bundle`).

This is limited because we can't tell whether any gems have been
installed at all, let alone do those gems have executables. However it's
better than having multiple `rbenv rehash` being run in parallel and
outputting confusing error messages as a result.
2015-10-25 17:47:01 +01:00

38 lines
1.1 KiB
Ruby

hook = lambda do |installer|
begin
# Ignore gems that aren't installed in locations that rbenv searches for binstubs
if installer.spec.executables.any? &&
[Gem.default_bindir, Gem.bindir(Gem.user_dir)].include?(installer.bin_dir)
`rbenv rehash`
end
rescue
warn "rbenv: error in gem-rehash (#{$!.class.name}: #{$!.message})"
end
end
if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install)
Bundler::Installer.class_eval do
class << self
alias install_without_rbenv_rehash install
def install(root, definition, options = {})
result = install_without_rbenv_rehash(root, definition, options)
begin
if result && Gem.default_path.include?(Bundler.bundle_path.to_s)
`rbenv rehash`
end
rescue
warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})"
end
result
end
end
end
else
begin
Gem.post_install(&hook)
Gem.post_uninstall(&hook)
rescue
warn "rbenv: error installing gem-rehash hooks (#{$!.class.name}: #{$!.message})"
end
end