Commit graph

8 commits

Author SHA1 Message Date
benmelz
325abac17d
Move gem-rehash monkey patch (#1541)
The `rubygems_plugin.rb` file doesn't get loaded until after `Bundler::Installer.install` is called, so target `Bundler::Installer#install` to fix invocation order issues.

Co-authored-by: Mislav Marohnić <git@mislav.net>
2023-12-09 21:14:40 +01:00
Mislav Marohnić
d2d3012f17
Restore Rubygems warning for user-installed gems 2022-10-07 13:02:18 +02:00
Mislav Marohnić
959968c46d
Support GEM_HOME, add limited support for user-installed gems (#1436)
The rehash process will now discover executables in additional locations:
- `~/.gem/ruby/<version>/bin/*`
- `$GEM_HOME/bin`

The `rbenv which` (and thus `rbenv exec`) command will also search these locations when looking up a command. This enables shims to dispatch calls to executables added by `gem install --user-install`.

Note that this support is limited:
- It will only work with C Ruby, as it's difficult to guess the `~/.gem/<engine>/<version>` directory for other Rubies without actually loading Ruby;
- It will only work for RBENV_VERSION values in the format `X.Y.Z` and not "system".
2022-09-26 02:57:15 +02:00
Roman Sandler
d508822f9a Make sure the alias statement only executes if there is not already an alias in place 2015-10-27 10:53:51 +01:00
Mislav Marohnić
2b0f16757a Only rehash if bundle install actually created new executables
This avoids running `rbenv rehash` after installing libraries that don't
have executables, or after a no-op `bundle install` that didn't install
anything.
2015-10-25 18:31:50 +01:00
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
Mislav Marohnić
7e0e85bdda Avoid JRuby warning during rehash Rubygems plugin
As it seems, JRuby 1.7 complains on stderr every time you invoke `system`:

    warning: executable? does not in this environment and will return a dummy value

It doesn't seem to complain when backtics are used. It's safe to use
backticks here because `rbenv rehash` doesn't output anything on stdout,
and the exit status of the command is irrelevant.
2014-10-19 18:06:09 +02:00
Mislav Marohnić
67f429c41d Bring automatic gem-rehash functionality to rbenv core
This bakes in the functionality of rbenv-gem-rehash plugin.

The Rubygems hook is improved:

- It will not rehash for gems installed in locations that rbenv otherwise
  doesn't search for binstubs; for instance in case of
  `bundle --path vendor/bundle`.
- It rescues exceptions and makes them non-lethal by warning on stderr.
2014-10-19 14:35:43 +02:00