Merge pull request #18093 from Homebrew/no-include-kernel

This commit is contained in:
Mike McQuaid 2024-08-20 09:08:16 +01:00 committed by GitHub
commit c2713f84be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 108 additions and 112 deletions

View File

@ -134,7 +134,7 @@ module Homebrew
next next
end end
Migrator.migrate_if_needed(formula, force: args.force?) Migrator.migrate_if_needed(formula, force: args.force?)
Homebrew.reinstall_formula( Homebrew::Reinstall.reinstall_formula(
formula, formula,
flags: args.flags_only, flags: args.flags_only,
installed_on_request: args.named.present?, installed_on_request: args.named.present?,

View File

@ -1,5 +0,0 @@
# typed: strict
module Homebrew
include Kernel
end

View File

@ -6,9 +6,8 @@ require "development_tools"
require "messages" require "messages"
module Homebrew module Homebrew
module_function module Reinstall
def self.reinstall_formula(
def reinstall_formula(
formula, formula,
flags:, flags:,
installed_on_request: false, installed_on_request: false,
@ -79,7 +78,7 @@ module Homebrew
end end
end end
def backup(keg) def self.backup(keg)
keg.unlink keg.unlink
begin begin
keg.rename backup_path(keg) keg.rename backup_path(keg)
@ -90,8 +89,9 @@ module Homebrew
EOS EOS
end end
end end
private_class_method :backup
def restore_backup(keg, keg_was_linked, verbose:) def self.restore_backup(keg, keg_was_linked, verbose:)
path = backup_path(keg) path = backup_path(keg)
return unless path.directory? return unless path.directory?
@ -101,8 +101,11 @@ module Homebrew
path.rename keg path.rename keg
keg.link(verbose:) if keg_was_linked keg.link(verbose:) if keg_was_linked
end end
private_class_method :restore_backup
def backup_path(path) def self.backup_path(path)
Pathname.new "#{path}.reinstall" Pathname.new "#{path}.reinstall"
end end
private_class_method :backup_path
end
end end

View File

@ -409,7 +409,7 @@ module Homebrew
return if dry_run return if dry_run
reinstallable_broken_dependents.each do |formula| reinstallable_broken_dependents.each do |formula|
Homebrew.reinstall_formula( Reinstall.reinstall_formula(
formula, formula,
flags:, flags:,
force_bottle:, force_bottle:,

View File

@ -30,19 +30,17 @@ module Homebrew
).freeze ).freeze
private_constant :VENDOR_VERSION_FILE private_constant :VENDOR_VERSION_FILE
module_function def self.gemfile
def gemfile
File.join(ENV.fetch("HOMEBREW_LIBRARY"), "Homebrew", "Gemfile") File.join(ENV.fetch("HOMEBREW_LIBRARY"), "Homebrew", "Gemfile")
end end
private_class_method :gemfile private_class_method :gemfile
def bundler_definition def self.bundler_definition
@bundler_definition ||= Bundler::Definition.build(Bundler.default_gemfile, Bundler.default_lockfile, false) @bundler_definition ||= Bundler::Definition.build(Bundler.default_gemfile, Bundler.default_lockfile, false)
end end
private_class_method :bundler_definition private_class_method :bundler_definition
def valid_gem_groups def self.valid_gem_groups
install_bundler! install_bundler!
require "bundler" require "bundler"
@ -54,11 +52,11 @@ module Homebrew
end end
end end
def ruby_bindir def self.ruby_bindir
"#{RbConfig::CONFIG["prefix"]}/bin" "#{RbConfig::CONFIG["prefix"]}/bin"
end end
def ohai_if_defined(message) def self.ohai_if_defined(message)
if defined?(ohai) if defined?(ohai)
$stderr.ohai message $stderr.ohai message
else else
@ -66,7 +64,7 @@ module Homebrew
end end
end end
def opoo_if_defined(message) def self.opoo_if_defined(message)
if defined?(opoo) if defined?(opoo)
$stderr.opoo message $stderr.opoo message
else else
@ -74,7 +72,7 @@ module Homebrew
end end
end end
def odie_if_defined(message) def self.odie_if_defined(message)
if defined?(odie) if defined?(odie)
odie message odie message
else else
@ -83,7 +81,7 @@ module Homebrew
end end
end end
def setup_gem_environment!(setup_path: true) def self.setup_gem_environment!(setup_path: true)
require "rubygems" require "rubygems"
raise "RubyGems too old!" if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.2.0") raise "RubyGems too old!" if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.2.0")
@ -114,7 +112,7 @@ module Homebrew
ENV["GEM_PATH"] = gem_home ENV["GEM_PATH"] = gem_home
end end
def install_gem!(name, version: nil, setup_gem_environment: true) def self.install_gem!(name, version: nil, setup_gem_environment: true)
setup_gem_environment! if setup_gem_environment setup_gem_environment! if setup_gem_environment
specs = Gem::Specification.find_all_by_name(name, version) specs = Gem::Specification.find_all_by_name(name, version)
@ -141,7 +139,7 @@ module Homebrew
odie_if_defined "failed to install the '#{name}' gem." odie_if_defined "failed to install the '#{name}' gem."
end end
def install_gem_setup_path!(name, version: nil, executable: name, setup_gem_environment: true) def self.install_gem_setup_path!(name, version: nil, executable: name, setup_gem_environment: true)
install_gem!(name, version:, setup_gem_environment:) install_gem!(name, version:, setup_gem_environment:)
return if find_in_path(executable) return if find_in_path(executable)
@ -151,14 +149,14 @@ module Homebrew
EOS EOS
end end
def find_in_path(executable) def self.find_in_path(executable)
ENV.fetch("PATH").split(":").find do |path| ENV.fetch("PATH").split(":").find do |path|
File.executable?(File.join(path, executable)) File.executable?(File.join(path, executable))
end end
end end
private_class_method :find_in_path private_class_method :find_in_path
def install_bundler! def self.install_bundler!
old_bundler_version = ENV.fetch("BUNDLER_VERSION", nil) old_bundler_version = ENV.fetch("BUNDLER_VERSION", nil)
setup_gem_environment! setup_gem_environment!
@ -174,7 +172,7 @@ module Homebrew
ENV["BUNDLER_VERSION"] = old_bundler_version ENV["BUNDLER_VERSION"] = old_bundler_version
end end
def user_gem_groups def self.user_gem_groups
@user_gem_groups ||= if GEM_GROUPS_FILE.exist? @user_gem_groups ||= if GEM_GROUPS_FILE.exist?
GEM_GROUPS_FILE.readlines(chomp: true) GEM_GROUPS_FILE.readlines(chomp: true)
else else
@ -183,7 +181,7 @@ module Homebrew
end end
private_class_method :user_gem_groups private_class_method :user_gem_groups
def write_user_gem_groups(groups) def self.write_user_gem_groups(groups)
return if @user_gem_groups == groups && GEM_GROUPS_FILE.exist? return if @user_gem_groups == groups && GEM_GROUPS_FILE.exist?
# Write the file atomically, in case we're working parallel # Write the file atomically, in case we're working parallel
@ -206,12 +204,12 @@ module Homebrew
end end
private_class_method :write_user_gem_groups private_class_method :write_user_gem_groups
def forget_user_gem_groups! def self.forget_user_gem_groups!
GEM_GROUPS_FILE.truncate(0) if GEM_GROUPS_FILE.exist? GEM_GROUPS_FILE.truncate(0) if GEM_GROUPS_FILE.exist?
@user_gem_groups = [] @user_gem_groups = []
end end
def user_vendor_version def self.user_vendor_version
@user_vendor_version ||= if VENDOR_VERSION_FILE.exist? @user_vendor_version ||= if VENDOR_VERSION_FILE.exist?
VENDOR_VERSION_FILE.read.to_i VENDOR_VERSION_FILE.read.to_i
else else
@ -220,7 +218,7 @@ module Homebrew
end end
private_class_method :user_vendor_version private_class_method :user_vendor_version
def install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups: []) def self.install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups: [])
old_path = ENV.fetch("PATH", nil) old_path = ENV.fetch("PATH", nil)
old_gem_path = ENV.fetch("GEM_PATH", nil) old_gem_path = ENV.fetch("GEM_PATH", nil)
old_gem_home = ENV.fetch("GEM_HOME", nil) old_gem_home = ENV.fetch("GEM_HOME", nil)