Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globally silence default gem warnings #18259

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Library/Homebrew/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
require "api/analytics"
require "api/cask"
require "api/formula"
require "warnings"
Warnings.ignore :default_gems do
require "base64" # TODO: Add this to the Gemfile or remove it before moving to Ruby 3.4.
end
require "base64" # TODO: vendor this for Ruby 3.4.

module Homebrew
# Helper functions for using Homebrew's formulae.brew.sh API.
Expand Down
5 changes: 1 addition & 4 deletions Library/Homebrew/dev-cmd/contributions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@

sig { params(totals: T::Hash[String, T::Hash[Symbol, Integer]]).returns(String) }
def generate_csv(totals)
require "warnings"
Warnings.ignore :default_gems do
require "csv"
end
require "csv" # TODO: this will be removed from Ruby 3.4

Check warning on line 127 in Library/Homebrew/dev-cmd/contributions.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/contributions.rb#L127

Added line #L127 was not covered by tests

CSV.generate do |csv|
csv << %w[user repo author committer coauthor review total]
Expand Down
12 changes: 12 additions & 0 deletions Library/Homebrew/standalone/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,15 @@
$LOAD_PATH.unshift "#{HOMEBREW_LIBRARY_PATH}/vendor/bundle/#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/" \
"bundler-#{Homebrew::HOMEBREW_BUNDLER_VERSION}/lib"
$LOAD_PATH.uniq!

# These warnings are nice but often flag problems that are not even our responsibly,
# including in some cases from other Ruby standard library gems.
# We strictly only allow one version of Ruby at a time so future compatibility
# doesn't need to be handled ahead of time.
if defined?(Gem::BUNDLED_GEMS)
[Kernel.singleton_class, Kernel].each do |kernel_class|
next unless kernel_class.respond_to?(:no_warning_require, true)

kernel_class.alias_method :require, :no_warning_require
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this use the Warning gem instead? Feels like a nicer API if possible.

Copy link
Member Author

@Bo98 Bo98 Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already did but it never worked. I got spammed with base64 warnings every time I ran brew tests.

Ruby 3.3.5 also makes it significantly unclearer what needs it. fiddle is an obvious one but it seems that json and irb now need it too despite not being deprecated, because internally they use code that still depends on other deprecated bundled gems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, this approach makes sense then, thanks 👍🏻

end
end
6 changes: 0 additions & 6 deletions Library/Homebrew/warnings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ module Warnings
parser_syntax: [
%r{warning: parser/current is loading parser/ruby\d+, which recognizes},
/warning: \d+\.\d+\.\d+-compliant syntax, but you are running \d+\.\d+\.\d+\./,
# FIXME: https://github.com/errata-ai/vale/issues/818
# <!-- vale off -->
%r{warning: please see https://github\.com/whitequark/parser#compatibility-with-ruby-mri\.},
# <!-- vale on -->
],
default_gems: [
/warning: .+\.rb was loaded from the standard library, .+ default gems since Ruby \d+\.\d+\.\d+\./,
],
}.freeze

Expand Down