Commit graph

92 commits

Author SHA1 Message Date
David Rodríguez
4cbfd87e5a [rubygems/rubygems] Allow disabling RubyGems require decorations
Currently Bundler needs to do cumbersome operations to revert custom
RubyGems require on a `bundler/setup` context. This causes issues when
third party gems also monkeypatch require, since Bundler will also undo
those decorations.

This commit allows it to use the simpler approach of properly telling
RubyGems that it needs to default to built-in require without any extra
magic.

1df5009e14

Co-authored-by: Xavier Noria <fxn@hashref.com>
2023-01-31 10:49:08 +09:00
Nobuyoshi Nakada
89546dce21 [rubygems/rubygems] [DOC] Remove internal document about Kernel monkey patch
https://bugs.ruby-lang.org/issues/19285

1e22219ed4
2023-01-08 08:09:34 +00:00
Nobuyoshi Nakada
55aa1a206c [rubygems/rubygems] LoadError#path on the caught exception does not need to protect
a31f5d1a18
2023-01-08 08:09:34 +00:00
Nobuyoshi Nakada
1a1b653c9c [rubygems/rubygems] Let RDoc parse the doc of Kernel#require
Since RDoc does not parse string literals as documents, `eval` the
entire file instead of embedding in a here-document.
On the contrary, as `gem_original_require` alias is an implementation
detail but not for users, it should not be documented.

cad4cf16cf
2023-01-08 08:09:33 +00:00
Hiroshi SHIBATA
bbe56a6437 Merge RubyGems/Bundler master
from bfb0ae6977
2022-12-12 10:49:43 +09:00
Thomas E. Enebo
420bdba139 [rubygems/rubygems] Allow upcoming JRuby to pass keywords for Kernel#warn
jruby-head (which will be JRuby 9.4.0.0) can now properly process
the keywords to Kernel#warn.  I cannot think of any capability based
test for this so I constrained it using a version guard.  Only JRuby
will ever hit the version guard.

cd468c7e0f
2022-10-22 08:01:24 +00:00
Hiroshi SHIBATA
44264b4fee Merge rubygems/bundler HEAD.
Pick from dfbb5a3811
2022-08-09 12:05:19 +09:00
Takuya Noguchi
d7ffd3fea4
RubyGems: Enable Style/StringLiterals cop
Signed-off-by: Takuya Noguchi <takninnovationresearch@gmail.com>
2022-07-22 12:07:23 +09:00
David Rodríguez
12a5fa408b Sync RubyGems & Bundler with upstream repo 2022-06-24 10:52:02 +09:00
Hiroshi SHIBATA
c082c6eb7c Sync RubyGems and Bundler with upstream 2021-07-07 15:31:52 +09:00
David Rodríguez
53468cc111 Sync latest development version of bundler & rubygems 2021-03-08 13:47:35 +09:00
Hiroshi SHIBATA
4aca77edde Merge prepare version of RubyGems 3.2.0 2020-12-08 17:30:02 +09:00
Hiroshi SHIBATA
b717f73402
Revert "Manually merged from https://github.com/rubygems/rubygems/pull/2636"
31a6eaabc1 is obsoleted with
  https://github.com/rubygems/rubygems/pull/3820
2020-09-23 22:01:44 +09:00
Hiroshi SHIBATA
31a6eaabc1
Manually merged from https://github.com/rubygems/rubygems/pull/2636
Enable Style/EmptyLinesAroundClassBody rubocop cop.
2020-09-23 21:02:56 +09:00
Jeremy Evans
1a935606b5 [rubygems/rubygems] Fix Kernel#warn override to handle backtrace location with nil path
It's very unlikely to hit this case, but it is possible, as
Thread::Backtrace::Location#path can return nil if the location is
a cfunc with no previous iseq.  See location_path in vm_backtrace.c
in Ruby.

511935645a
2020-07-31 21:07:19 +09:00
Benoit Daloze
331fe6a88f [rubygems/rubygems] Ignore internal frames in RubyGems' Kernel#warn
* See https://github.com/oracle/truffleruby/issues/2046
* `<internal:` is a common prefix also used by core Ruby files in CRuby.
* test_no_kernel_require_in_*warn_with_uplevel already test this.
* Unfortunately just skipping `<internal:` in the Ruby implementation
  is not enough, because RubyGems' #warn would not skip the
  `<internal:` require (TruffleRuby defines #require in Ruby),
  and the Ruby implementation's #warn would not skip
  RubyGems's #require. The #caller_locations(0) look like this:

  warnee.rb:1:in `<top (required)>' # where #warn is called
  <internal:core> core/kernel.rb:234:in `gem_original_require' # not skipped by RubyGems' warn, skipped by the Ruby impl
  rubygems/core_ext/kernel_require.rb:54:in `require' # not skipped by the Ruby impl's warn, what would be shown without this fix
  warn.rb:1:in `<main>' # what would be correct

  warn.rb is
  require "warnee"
  warnee.rb is
  puts caller_locations(0), nil
  warn "oops", uplevel: 1

7c838f7419
2020-07-31 21:07:19 +09:00
David Rodríguez
a89665b7b1 Enforce no empty lines around class body in rubygems
To normalize the code style with `bundler`.
2020-07-31 21:07:19 +09:00
David Rodríguez
955f1837a1 Use space inside block braces everywhere
To make rubygems code style consistent with bundler.
2020-06-15 21:20:37 +09:00
Yuki Nishijima
77ba8a1d61 [rubygems/rubygems] Use LoadError#path to figure out the argument passed to 'require'
5995394ec4
2020-06-05 07:32:42 +09:00
David Rodríguez
b9d431a7b1 [rubygems/rubygems] Remove direct reference to PR
The code is quite different now, so I think the link might be even
confusing. If you want to know more, use git history.

db872c7a18
2020-06-05 07:32:42 +09:00
David Rodríguez
f0f138aa5d [rubygems/rubygems] Fix $LOADED_FEATURES cache sometimes not respected
In the cases where the initial manually `-I` path resolution succeeded,
we were passing a full path to the original require effectively skipping
the `$LOADED_FEATURES` cache. With this change, we _only_ do the
resolution when a matching requirable path is found in a default gem. In
that case, we skip activation of the default gem if we detect that the
required file will be picked up for a `-I` path.

22ad5717c3
2020-06-05 07:32:42 +09:00
David Rodríguez
07dca5c02c [rubygems/rubygems] Extract a local outside the loop
da1492e9d7
2020-06-05 07:32:42 +09:00
David Rodríguez
5aa5aad48a [rubygems/rubygems] Refactor Gem.load_path_insert_index
ae95885dff
2020-06-05 07:32:42 +09:00
David Rodríguez
a18e81d797 [rubygems/rubygems] Fix performance regression in require
Our check for `-I` paths should not go through all activated gems.

00d98eb8a3
2020-06-05 07:32:42 +09:00
David Rodríguez
1039c32de6 [rubygems/rubygems] Simplify nested require exceptions
7fbef2f0e3
2020-05-08 14:13:29 +09:00
David Rodríguez
96064e6f1c
Sync rubygems with current master (#2889) 2020-03-24 15:39:24 +09:00
Hiroshi SHIBATA
8c67080381
Revert "[rubygems/rubygems] Fix require issue with file extension priority"
This reverts commit d767da428c.

  It fails with spec/ruby/core/kernel/require_spec.rb:5
2020-02-06 22:07:39 +09:00
David Rodríguez
d767da428c
[rubygems/rubygems] Fix require issue with file extension priority
If `require "a"` is run when two folders have been specified in the -I
option including a "a.rb" file and a "a.so" file respectively, the ruby
spec says that the ".rb" file should always be preferred. However, the
logic we added in 6b81076d9
to make the -I option always beat default gems does not respect this
spec, creating a difference from the original ruby-core's require.

[the ruby spec says]: d80a6e2b22/core/kernel/shared/require.rb (L234-L246)

b3944384f4
2020-02-06 21:57:18 +09:00
Nobuyoshi Nakada
eb512c5a95
warn should be a global function 2019-12-13 21:38:50 +09:00
Hiroshi SHIBATA
82cc2843a9
Prepare to release RubyGems 3.1.0 final version. 2019-12-13 20:19:33 +09:00
Kazuhiro NISHIYAMA
d336db6568
Fix a typo 2019-11-13 15:04:49 +09:00
Hiroshi SHIBATA
f36a53d038
Only enabled mon_owned condition with Ruby 2.5+ 2019-11-12 19:36:41 +09:00
Koichi Sasada
fef4370b40 check more. 2019-11-12 10:07:45 +09:00
Koichi Sasada
4a30fabfcf Monitor owner state check correctly.
Monitor can be owned at the beginning of this method.
2019-11-12 09:37:34 +09:00
Yusuke Endoh
2407e89725 Revert "Use untaint for File.symlink in kernel_require.rb"
This reverts commit d9978ce5d3.

Untaint was tentatively restored due to test failures.  But now, the
failed tests have been removed, so we can revert the tentative fix.
2019-11-12 08:39:38 +09:00
Hiroshi SHIBATA
d9978ce5d3
Use untaint for File.symlink in kernel_require.rb
Partly reverted 7d463e360b
2019-11-12 08:03:26 +09:00
Koichi Sasada
b8d242d221 release RUBYGEMS_ACTIVATION_MONITOR correctly.
`File.symlink? safe_lp` can raise SecurityError and raising an
exception can leave RUBYGEMS_ACTIVATION_MONITOR locking. This
patch release it correctly.
2019-11-12 04:33:28 +09:00
Koichi Sasada
4be1e84d78 more messages 2019-11-12 04:13:54 +09:00
Koichi Sasada
a815053a3e check monitor is owning for debug 2019-11-12 04:03:33 +09:00
Hiroshi SHIBATA
f1f27da6c4
Revert "Try to revert the test failure with Ruby CI"
This reverts commit 8b27c23b5d.
2019-11-11 21:49:21 +09:00
Hiroshi SHIBATA
8b27c23b5d
Try to revert the test failure with Ruby CI
20191111T093005Z.fail.html.gz
2019-11-11 20:19:29 +09:00
Hiroshi SHIBATA
7d463e360b Merge RubyGems 3.1.0.pre3
* Fix gem pristine not accounting for user installed gems. Pull request
    #2914 by Luis Sagastume.
  * Refactor keyword argument test for Ruby 2.7. Pull request #2947 by
    SHIBATA Hiroshi.
  * Fix errors at frozen Gem::Version. Pull request #2949 by Nobuyoshi
    Nakada.
  * Remove taint usage on Ruby 2.7+. Pull request #2951 by Jeremy Evans.
  * Check Manifest.txt is up to date. Pull request #2953 by David Rodríguez.
  * Clarify symlink conditionals in tests. Pull request #2962 by David
    Rodríguez.
  * Update command line parsing to work under ps. Pull request #2966 by
    David Rodríguez.
  * Properly test `Gem::Specifications.stub_for`. Pull request #2970 by
    David Rodríguez.
  * Fix Gem::LOADED_SPECS_MUTEX handling for recursive locking. Pull request
    #2985 by MSP-Greg.
2019-11-11 16:59:49 +09:00
David Rodríguez
f48655d04d Remove unneeded exec bits from some files
I noticed that some files in rubygems were executable, and I could think
of no reason why they should be.

In general, I think ruby files should never have the executable bit set
unless they include a shebang, so I run the following command over the
whole repo:

```bash
find . -name '*.rb' -type f -executable -exec bash -c 'grep -L "^#!" $1 || chmod -x $1' _ {} \;
```
2019-11-09 21:36:30 +09:00
David Rodríguez
a2af473018
[rubygems/rubygems] Make sure our modifications to kernel.warn work
And test the fix we're adding.

6f86637b98
2019-09-26 17:48:01 +09:00
David Rodríguez
54839f0173
[rubygems/rubygems] Fix jruby build
cc255b774a
2019-09-26 17:48:01 +09:00
David Rodríguez
4f87a1583d
[rubygems/rubygems] Introduce default prerelease requirement
506c5bce49
2019-09-26 17:48:01 +09:00
Jeremy Evans
80b5a0ff2a
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.

This makes the following changes to : handling.

* Treats as **kw, prompting keyword argument separation warnings
  if called with a positional hash.

* Do not look for an option hash if empty keywords are provided.
  For backwards compatibility, treat an empty keyword splat as a empty
  mandatory positional hash argument, but emit a a warning, as this
  behavior will be removed in Ruby 3.  The argument number check
  needs to be moved lower so it can correctly handle an empty
  positional argument being added.

* If the last argument is nil and it is necessary to treat it as an option
  hash in order to make sure all arguments are processed, continue to
  treat the last argument as the option hash. Emit a warning in this case,
  as this behavior will be removed in Ruby 3.

* If splitting the keyword hash into two hashes, issue a warning, as we
  will not be splitting hashes in Ruby 3.

* If the keyword argument is required to fill a mandatory positional
  argument, continue to do so, but emit a warning as this behavior will
  be going away in Ruby 3.

* If keyword arguments are provided and the last argument is not a hash,
  that indicates something wrong. This can happen if a cfunc is calling
  rb_scan_args multiple times, and providing arguments that were not
  passed to it from Ruby.  Callers need to switch to the new
  rb_scan_args_kw function, which allows passing of whether keywords
  were provided.

This commit fixes all warnings caused by the changes above.

It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used.  If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.

In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby.  The last argument may or may not be a hash,
so we can't set keyword argument mode.  However, if it is a
hash, we don't want to warn when treating it as keywords.

In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args.  Also, make
sure not to pass nil in place of an option hash.

Work around Kernel#warn warnings due to problems in the Rubygems
override of the method.  There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.

Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 11:18:49 -07:00
Hiroshi SHIBATA
221ba9b66c
Revert "`Gem.load_path_insert_index always returns non-nil index after Ruby 1.9"
This reverts commit 260ef51a73.

  This broke the stable versions of Ruby like 2.4 and 2.5
2019-08-17 17:01:23 +09:00
Hiroshi SHIBATA
d041c6cebb
Added comments for extended require by RubyGems 2019-08-17 15:12:46 +09:00
Hiroshi SHIBATA
260ef51a73
`Gem.load_path_insert_index always returns non-nil index after Ruby 1.9 2019-08-17 15:12:46 +09:00