Commit graph

103 commits

Author SHA1 Message Date
Hiroshi SHIBATA
65a0f46880 Warn to use tsort for Ruby 3.6 that will be released at 2026 2025-07-10 16:48:16 +09:00
Joshua Young
8bf13f2605 Reduce allocations in Gem::BUNDLED_GEMS.warning? 2025-07-02 11:28:23 +09:00
Nobuyoshi Nakada
dc74f9cb36
Make uplevel suitable as the option to Kernel#warn
Make Gem::BUNDLED_GEMS.uplevel returns `nil` if `require` frame is not
found, for the simplicity.
2025-06-28 22:27:30 +09:00
Nobuyoshi Nakada
baa0500140
Use symbols as level instead of strings 2025-06-28 22:24:20 +09:00
Hiroshi SHIBATA
b47a04eb91 Refactor bundled condition 2025-04-10 17:29:39 +09:00
Hiroshi SHIBATA
598b0e8b72 The current force_activate always fails without Gemfile 2025-04-10 17:29:39 +09:00
Hiroshi SHIBATA
938db05361 Removed the warning targets for Ruby 3.1 because 3.1 is already EOL 2025-04-02 10:52:26 +09:00
David Rodríguez
c83370671b Improve bundled gems warning messages
Currently evenn if the require actually fails, they suggest that the
file was actually loaded, which is confusing. I reworded them to reduce
this confusion.
2025-02-06 13:07:55 +09:00
David Rodríguez
03a0c4e079 Rename "gem" to "name"
The name "gem" could be confused with RubyGems activation method.
2025-02-06 13:07:55 +09:00
David Rodríguez
433f4e30b3 Simplify bundled gems warnings implementation
Most of the stuff is not actually necessary.
2025-02-06 13:07:55 +09:00
David Rodríguez
68bb6ceeaf Remove unnecessary SINCE_FAST_PATH constant
If anything, I think this may be causing some false positives.
2025-02-06 13:07:55 +09:00
Hiroshi SHIBATA
be1d0fcdb0 Added force_activate feature again 2025-01-24 15:46:46 +09:00
Hiroshi SHIBATA
68095ffc16 irb and reline are now bundled gems, we don't need to skip workaround for them 2025-01-24 15:46:46 +09:00
Hiroshi SHIBATA
4a02a72ca5 Dont't use stub constants like LIBDIR in bundled_gems.rb 2025-01-08 11:55:39 +09:00
David Rodríguez
42026ec3da Fix bundled gems warning for sub feature locations 2024-12-24 12:07:54 +09:00
David Rodríguez
3cbfd21916 Fix code location in bundled gems warnings 2024-12-23 16:01:30 +09:00
David Rodríguez
a51b5660dc Find uplevel for bundled gems warnings just once 2024-12-23 16:01:30 +09:00
Stan Lo
ff8570b005 Fix LoadError's linking issue
Original issue: https://github.com/ruby/rdoc/issues/1128

The problem is caused by the `# :stopdoc:` directive in `bundled_gems.rb`,
which's scope covers the redefinition of `LoadError`.

Since the goal of `# :stopdoc:` is to hide the documentation of `Gem::BUNDLED_GEMS`,
we can use `# :nodoc:` on it instead.
2024-12-12 16:43:25 -05:00
Hiroshi SHIBATA
24889e44f7 Rename environment name to more descriptive 2024-11-27 16:45:10 +09:00
Hiroshi SHIBATA
b45f7a54af Find .ext/common path from LOAD_PATH for out-of-place build 2024-11-15 14:04:19 +09:00
Hiroshi SHIBATA
52e867268e Port test_warn_sub_feature.rb to RSpec example 2024-11-15 14:04:19 +09:00
Hiroshi SHIBATA
c5637f940a fiddle provide sub-feature like fiddle/import 2024-11-15 14:04:19 +09:00
Hiroshi SHIBATA
11265baed9 Use environmental variable for bundled_gems_spec.rb 2024-11-15 08:16:03 +09:00
Hiroshi SHIBATA
b44272fcb4 Port test_warn_bundled_gems.rb to RSpec example 2024-11-15 08:16:03 +09:00
Hiroshi SHIBATA
441069c093 We can't handle optional dependency without new API of Rubygems.
I don't want to make bundled_gems.rb more complex and complicate.

Revert "Fixed warning condition with LoadError"

This reverts commit 3a9e48b9a4.

Revert "Only warn fiddle as optional dependency"

This reverts commit ff3f61556f.

Revert "Only `warn` about bundled gems when require succeeds"

This reverts commit a70adce1ce.
2024-11-13 13:47:36 +09:00
Hiroshi SHIBATA
8cd36a6dab
Don't warn the bundled gems that are migrated at Ruby 3.0.
We should stop warnings at some point. I decided to that period EOL-ed versions.
ex. In 2024, Ruby 3.0 is EOL. we removed webrick, rexml, rss from warning targets.
2024-09-30 18:53:21 +09:00
Hiroshi SHIBATA
3a9e48b9a4
Fixed warning condition with LoadError 2024-09-30 11:35:59 +09:00
Hiroshi SHIBATA
ff3f61556f
Only warn fiddle as optional dependency 2024-09-27 18:39:05 +09:00
David Rodríguez
a70adce1ce Only warn about bundled gems when require succeeds 2024-09-27 17:03:45 +09:00
Hiroshi SHIBATA
3146cbbbc4
Dont't warn reline called from irb, reline is already declared at irb gemspec 2024-09-13 13:19:31 +09:00
Hiroshi SHIBATA
0e7b6e348f Merge GH-11492 2024-09-06 14:45:17 +09:00
Hiroshi SHIBATA
e43d701f09 Warn irb, reline for Ruby 3.5 2024-09-06 14:45:17 +09:00
Hiroshi SHIBATA
71c14c8889 Don't show script name when bundle exec and call ruby script directly. 2024-08-21 16:48:35 +09:00
Hiroshi SHIBATA
c97dc7739e Skip to show script name with using ruby -r option 2024-08-21 16:48:35 +09:00
Hiroshi SHIBATA
5fedf1c3ac Show correct script name with sub-feature case 2024-08-21 16:48:35 +09:00
Kentaro Takeyama
2a933609e7 Delete unnecessary rubocop disable comment 2024-08-15 17:16:25 +09:00
Hiroshi SHIBATA
7e0910a82c
We should use uplevel:2 in another case.
Like the following scenario with bootsnap, that frames are same or smaller than frame_to_skip(=3).

---
"/Users/hsbt/.local/share/rbenv/versions/3.3-dev/lib/ruby/3.3.0/bundled_gems.rb:69:in `block (2 levels) in replace_require'"
"/Users/hsbt/.local/share/gem/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'"
"test_warn_bootsnap.rb:11:in `<main>'"
---
2024-08-08 16:20:22 +09:00
Jean Boussier
7594a292b1
lib/bundled_gems.rb: more reliable caller detection
The `2` skipped frames went out of sync and now it should be `3`.

Rather than just update the offset, we can implement a way that
is adaptative as long as all require decorators are also called require.

Also we should compute the corresponding `uplevel` otherwise the
warning will still point decorators.

Co-authored-by: "Hiroshi SHIBATA" <hsbt@ruby-lang.org>
2024-08-08 15:50:26 +09:00
Hiroshi SHIBATA
fa443699af
Partly reverted 09638741ba
This change didn't work with Ruby 3.3.

We should revert this to test bundled_gems.rb with Ruby 3.3.
2024-08-08 13:24:27 +09:00
David Rodríguez
5258e8b1cd Make sure to always use the right warn 2024-08-05 12:16:49 +08:00
Jean Boussier
34adc07372 Document the reasoning behind the fix for [Bug #20641] 2024-07-22 18:07:18 +02:00
Jean Boussier
82aee1a946 bundled_gems.rb: Add a fast path
[Bug #20641] `Gem::BUNDLED_GEMS.warning?` adds a lot of extra
work on top of `require`. When the call end up atually loading code
the overhead is somewhat marginal.

However it's not uncommon for code to go some late `require` in some
paths, so it's expected that calling `require` with something already
required is somewhat fast, and `bundled_gems.rb` breaks this assumption.

To avoid this, we can have a fast path that in most case allow to
short-circuit all the heavy computations. If we extract the feature
basename and it doesn't match any of the bundled gems we care about
we can return very early.

With this change `require 'date'` is now only 1.33x slower on Ruby
3.3.3, than it was on Ruby 3.2.2, whereas before this change it
was at least 100x slower.
2024-07-22 10:33:07 +02:00
Hiroshi SHIBATA
d7e558e3c4
Mark to warn logger as bundled gems for Ruby 3.5 2024-06-05 17:26:50 +09:00
Hiroshi SHIBATA
10ecdeb466
Mark to warn fiddle as bundled gems for Ruby 3.5 2024-06-05 08:35:33 +09:00
Hiroshi SHIBATA
8ff5458c2e
EXACT list is mostly same as SINCE list on bundled gems. 2024-06-04 18:30:39 +09:00
Hiroshi SHIBATA
f365bef0c7
Warn to use win32ole without Gemfile for Ruby 3.5 2024-06-04 18:30:39 +09:00
Hiroshi SHIBATA
fb6cfb413d
Mark rdoc as bundled gems at Ruby 3.5 2024-05-09 17:39:57 +09:00
Eugene Kenny
67dd9af17e [Bug #20450] Remove rubyarchdir from bootsnap paths 2024-04-25 13:29:28 +09:00
Nobuyoshi Nakada
09638741ba [Feature #20335] Thread.each_caller_location arguments
Accecpt the same arguments as `caller` and `caller_locations`.
2024-04-17 18:47:07 +09:00
Masataka Pocke Kuwabara
76914d474d Fix error when default gem is loaded from -r option
This patch fixes an error when a default gem that will be migrated to
a bundled gem is loaded from `-r` option.

Problem
===

`bundle exec ruby -rostruct -e ''` unexpectedly raises the following error:

```console
$ ruby -v
ruby 3.4.0dev (2024-04-08T02:39:00Z master 6f7e8e278f) [arm64-darwin21]
$ bundle init && bundle install
$ bundle exec ruby -rostruct -e ''
/Users/kuwabara.masataka/.rbenv/versions/trunk/lib/ruby/3.4.0+0/bundled_gems.rb:111:in 'Gem::BUNDLED_GEMS.warning?': undefined method 'find' for nil (NoMethodError)

      caller = caller_locations(3, 3).find {|c| c&.absolute_path}
                                     ^^^^^
        from /Users/kuwabara.masataka/.rbenv/versions/trunk/lib/ruby/3.4.0+0/bundled_gems.rb:75:in 'block (2 levels) in Kernel#replace_require'
```

Solution
===

This patch uses a safe navigation operator to fix this problem. By this
change, the command will show the warning message correctly.

```console
$ bundle exec ruby -rostruct -e ''
warning: ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec.
```
2024-04-08 15:48:26 +09:00