Files
brew/Library/Homebrew/test/support/helper/cmd/brew-verify-undefined.rb
T
Mike McQuaid 0c2baca69e ignorable: replace callcc with Fiber
- Ruby 4.0's `continuation` warns `callcc is obsolete; use Fiber
  instead` whenever it is required, which happens on every `brew`
  command that loads a formula from source.
- Run `Ignorable.hook_raise` blocks in a `Fiber`: `raise` now pauses
  at the raise site and asks an `on_ignorable` callback whether to
  resume (`:ignore`) or raise there as usual, replacing the rescue
  plus continuation jump and `Ignorable::ExceptionMixin#ignore`.
- `Debrew` menus and `Formulary` `ignore_errors` decisions now happen
  before the stack unwinds, so `ensure` blocks only run when an
  exception is actually raised.
- Only require `ignorable` when `Formulary` uses `ignore_errors` and
  drop the obsolete `brew verify-undefined` `Warnings` guard.

Fixes https://github.com/Homebrew/brew/issues/23384
2026-08-01 14:28:57 +01:00

122 lines
2.8 KiB
Ruby
Executable File

# typed: strict
# frozen_string_literal: true
require "cli/parser"
require "utils/output"
UNDEFINED_CONSTANTS = %w[
AbstractDownloadStrategy
Addressable
Base64
CacheStore
Cask::Cask
Cask::CaskLoader
Completions
Concurrent
CSV
Formula
Formulary
GitRepository
Homebrew::API
Homebrew::Manpages
Homebrew::Settings
JSONSchemer
Kramdown
MachO
Metafiles
MethodSource
Minitest
Nokogiri
OS::Mac::Version
PatchELF
Plist
Pry
ProgressBar
PyCall
REXML
Red
Redcarpet
RSpec
RuboCop
RubyProf
StackProf
Spoom
Tap
Tapioca
UnpackStrategy
Utils::Analytics
Utils::Backtrace
Utils::Bottles
Utils::Curl
Utils::Fork
Utils::Git
Utils::GitHub
Utils::Link
Utils::Svn
Uri
Vernier
Warnings
YARD
].freeze
UNDEFINED_CONSTANTS_AFTER_REQUIRE = T.let({
"api" => %w[Base64 Concurrent Homebrew::DownloadQueue Plist],
"cask/artifact/pkg" => %w[Plist],
"dev-cmd/formula-analytics" => %w[InfluxDBClient3 PyCall],
"downloadable" => %w[Concurrent],
"extend/os/mac/extend/pathname" => %w[MachO],
"formula_cellar_checks" => %w[Plist],
"keg" => %w[MachO],
"livecheck/livecheck" => %w[Addressable],
"os/mac/xcode" => %w[Plist],
"service" => %w[Plist],
"services/cli" => %w[Plist],
}.freeze, T::Hash[String, T::Array[String]])
module Homebrew
module Cmd
class VerifyUndefined < AbstractCommand
sig { override.void }
def run; end
end
end
end
parser = Homebrew::CLI::Parser.new(Homebrew::Cmd::VerifyUndefined) do
usage_banner <<~EOS
`verify-undefined`
Verifies that the following constants have not been defined
at startup to make sure that startup times stay consistent.
Constants:
#{UNDEFINED_CONSTANTS.join("\n")}
EOS
end
parser.parse
UNDEFINED_CONSTANTS.each do |constant_name|
# The constant name is iterated from the list above.
# rubocop:disable Sorbet/ConstantsFromStrings
Object.const_get(constant_name)
# rubocop:enable Sorbet/ConstantsFromStrings
Utils::Output.ofail "#{constant_name} should not be defined at startup"
rescue NameError
# We expect this to error as it should not be defined.
end
UNDEFINED_CONSTANTS_AFTER_REQUIRE.each do |require_path, constant_names|
require require_path
constant_names.each do |constant_name|
# The constant name is iterated from the list above.
# rubocop:disable Sorbet/ConstantsFromStrings
Object.const_get(constant_name)
# rubocop:enable Sorbet/ConstantsFromStrings
Utils::Output.ofail "#{constant_name} should not be defined after requiring #{require_path}"
rescue NameError
# We expect this to error as it should not be defined.
end
end