From 07da4aa7a691e010a9a740c11fb27f92db9fa795 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Thu, 5 Sep 2024 17:59:26 -0700 Subject: [PATCH 1/6] Stop suppressing undef errors --- Library/Homebrew/sorbet/config | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/sorbet/config b/Library/Homebrew/sorbet/config index cd1ae82b7cfab..a55c8dfed4c73 100644 --- a/Library/Homebrew/sorbet/config +++ b/Library/Homebrew/sorbet/config @@ -6,5 +6,4 @@ --ignore=/test/.gem --ignore=Formula --ignore=Casks ---suppress-error-code=3008 --suppress-error-code=7019 From 27e951c408d9b7d64551ddb084f49473ebf30dc1 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Thu, 5 Sep 2024 19:56:32 -0700 Subject: [PATCH 2/6] Replace undef with prepended modules --- Library/Homebrew/cli/args.rb | 3 - Library/Homebrew/extend/os/linux/cleanup.rb | 8 ++- Library/Homebrew/extend/os/linux/formula.rb | 12 ++-- Library/Homebrew/extend/os/linux/parser.rb | 13 ++-- Library/Homebrew/extend/os/mac/cleaner.rb | 6 +- Library/Homebrew/extend/os/mac/cleanup.rb | 6 +- .../Homebrew/extend/os/mac/dev-cmd/bottle.rb | 8 +-- Library/Homebrew/extend/os/mac/formula.rb | 9 ++- .../extend/os/mac/formula_installer.rb | 8 ++- .../Homebrew/extend/os/mac/linkage_checker.rb | 6 +- Library/Homebrew/extend/os/mac/readall.rb | 61 ++++++++++--------- .../Homebrew/extend/os/mac/simulate_system.rb | 23 +++---- 12 files changed, 87 insertions(+), 76 deletions(-) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index 709a84e77f1f7..648cd3aa71c76 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -19,9 +19,6 @@ class Args < OpenStruct sig { returns(T::Array[String]) } attr_reader :options_only, :flags_only - # undefine tap to allow --tap argument - undef tap - sig { void } def initialize require "cli/named_args" diff --git a/Library/Homebrew/extend/os/linux/cleanup.rb b/Library/Homebrew/extend/os/linux/cleanup.rb index b6cd428fe88d6..deb231b31865d 100644 --- a/Library/Homebrew/extend/os/linux/cleanup.rb +++ b/Library/Homebrew/extend/os/linux/cleanup.rb @@ -2,8 +2,10 @@ # frozen_string_literal: true module Homebrew - class Cleanup - undef use_system_ruby? + module CleanupLinux + extend T::Helpers + + requires_ancestor { Cleanup } sig { returns(T::Boolean) } def use_system_ruby? @@ -21,3 +23,5 @@ def use_system_ruby? end end end + +Homebrew::Cleanup.prepend(Homebrew::CleanupLinux) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index a6914a1f02c54..2d6250f816f16 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -1,12 +1,10 @@ # typed: true # rubocop:disable Sorbet/StrictSigil # frozen_string_literal: true -class Formula - undef shared_library - undef loader_path - undef deuniversalize_machos - undef add_global_deps_to_spec - undef valid_platform? +module FormulaLinux + extend T::Helpers + + requires_ancestor { Formula } sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) } def shared_library(name, version = nil) @@ -50,3 +48,5 @@ def valid_platform? requirements.none?(MacOSRequirement) end end + +Formula.prepend(FormulaLinux) diff --git a/Library/Homebrew/extend/os/linux/parser.rb b/Library/Homebrew/extend/os/linux/parser.rb index 7d81e2dddc867..37f8481e18865 100644 --- a/Library/Homebrew/extend/os/linux/parser.rb +++ b/Library/Homebrew/extend/os/linux/parser.rb @@ -1,16 +1,19 @@ -# typed: strict +# typed: true # rubocop:todo Sorbet/StrictSigil # frozen_string_literal: true module Homebrew module CLI - class Parser - undef set_default_options - undef validate_options + module ParserLinux + extend T::Helpers + requires_ancestor { Homebrew::CLI::Parser } + + sig { void } def set_default_options @args["formula?"] = true if @args.respond_to?(:formula?) end + sig { void } def validate_options return unless @args.respond_to?(:cask?) return unless @args.cask? @@ -22,3 +25,5 @@ def validate_options end end end + +Homebrew::CLI::Parser.prepend(Homebrew::CLI::ParserLinux) diff --git a/Library/Homebrew/extend/os/mac/cleaner.rb b/Library/Homebrew/extend/os/mac/cleaner.rb index 460169c996214..23cdfbf947ff4 100644 --- a/Library/Homebrew/extend/os/mac/cleaner.rb +++ b/Library/Homebrew/extend/os/mac/cleaner.rb @@ -1,13 +1,13 @@ # typed: strict # frozen_string_literal: true -class Cleaner +module CleanerMac private - undef executable_path? - sig { params(path: Pathname).returns(T::Boolean) } def executable_path?(path) path.mach_o_executable? || path.text_executable? end end + +Cleaner.prepend(CleanerMac) diff --git a/Library/Homebrew/extend/os/mac/cleanup.rb b/Library/Homebrew/extend/os/mac/cleanup.rb index 3565e162b4f4b..8c07923e0952f 100644 --- a/Library/Homebrew/extend/os/mac/cleanup.rb +++ b/Library/Homebrew/extend/os/mac/cleanup.rb @@ -2,9 +2,7 @@ # frozen_string_literal: true module Homebrew - class Cleanup - undef use_system_ruby? - + module CleanupMac sig { returns(T::Boolean) } def use_system_ruby? return false if Homebrew::EnvConfig.force_vendor_ruby? @@ -13,3 +11,5 @@ def use_system_ruby? end end end + +Homebrew::Cleanup.prepend(Homebrew::CleanupMac) diff --git a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb index 26d96cc1ceb63..1c3ad6a7f9492 100644 --- a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb +++ b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb @@ -3,9 +3,7 @@ module Homebrew module DevCmd - class Bottle < AbstractCommand - undef tar_args - + module BottleMac sig { returns(T::Array[String]) } def tar_args if MacOS.version >= :catalina @@ -15,8 +13,6 @@ def tar_args end end - undef gnu_tar - sig { params(gnu_tar_formula: Formula).returns(String) } def gnu_tar(gnu_tar_formula) "#{gnu_tar_formula.opt_bin}/gtar" @@ -24,3 +20,5 @@ def gnu_tar(gnu_tar_formula) end end end + +Homebrew::DevCmd::Bottle.prepend(Homebrew::DevCmd::BottleMac) diff --git a/Library/Homebrew/extend/os/mac/formula.rb b/Library/Homebrew/extend/os/mac/formula.rb index c32a41d9e34c8..0aedbc9cab65c 100644 --- a/Library/Homebrew/extend/os/mac/formula.rb +++ b/Library/Homebrew/extend/os/mac/formula.rb @@ -1,9 +1,10 @@ # typed: strict # frozen_string_literal: true -class Formula - undef valid_platform? - undef std_cmake_args +module FormulaMac + extend T::Helpers + + requires_ancestor { Formula } sig { returns(T::Boolean) } def valid_platform? @@ -31,3 +32,5 @@ def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework args end end + +Formula.prepend(FormulaMac) diff --git a/Library/Homebrew/extend/os/mac/formula_installer.rb b/Library/Homebrew/extend/os/mac/formula_installer.rb index 89115c871d052..fe825f722111f 100644 --- a/Library/Homebrew/extend/os/mac/formula_installer.rb +++ b/Library/Homebrew/extend/os/mac/formula_installer.rb @@ -1,8 +1,10 @@ # typed: strict # frozen_string_literal: true -class FormulaInstaller - undef fresh_install? +module FormulaInstallerMac + extend T::Helpers + + requires_ancestor { FormulaInstaller } sig { params(formula: Formula).returns(T.nilable(T::Boolean)) } def fresh_install?(formula) @@ -10,3 +12,5 @@ def fresh_install?(formula) (!installed_as_dependency? || !formula.any_version_installed?) end end + +FormulaInstaller.prepend(FormulaInstallerMac) diff --git a/Library/Homebrew/extend/os/mac/linkage_checker.rb b/Library/Homebrew/extend/os/mac/linkage_checker.rb index b48d2b90d325a..1171257479bc0 100644 --- a/Library/Homebrew/extend/os/mac/linkage_checker.rb +++ b/Library/Homebrew/extend/os/mac/linkage_checker.rb @@ -1,9 +1,7 @@ # typed: strict # frozen_string_literal: true -class LinkageChecker - undef system_libraries_exist_in_cache? - +module LinkageCheckerMac private sig { returns(T::Boolean) } @@ -12,3 +10,5 @@ def system_libraries_exist_in_cache? MacOS.version >= :big_sur end end + +LinkageChecker.prepend(LinkageCheckerMac) diff --git a/Library/Homebrew/extend/os/mac/readall.rb b/Library/Homebrew/extend/os/mac/readall.rb index 6957c2b086c36..15a78a78fe215 100644 --- a/Library/Homebrew/extend/os/mac/readall.rb +++ b/Library/Homebrew/extend/os/mac/readall.rb @@ -1,39 +1,42 @@ # typed: strict # frozen_string_literal: true -module Readall - class << self - undef valid_casks? +module ReadallMac + extend T::Helpers - def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type) - return true if os_name == :linux + requires_ancestor { Kernel } - current_macos_version = if os_name.is_a?(Symbol) - MacOSVersion.from_symbol(os_name) - else - MacOS.version - end + sig { params(tap: Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) } + def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type) + return true if os_name == :linux + + current_macos_version = if os_name.is_a?(Symbol) + MacOSVersion.from_symbol(os_name) + else + MacOS.version + end - success = T.let(true, T::Boolean) - tap.cask_files.each do |file| - cask = Cask::CaskLoader.load(file) - - # Fine to have missing URLs for unsupported macOS - macos_req = cask.depends_on.macos - next if macos_req&.version && Array(macos_req.version).none? do |macos_version| - current_macos_version.compare(macos_req.comparator, macos_version) - end - - raise "Missing URL" if cask.url.nil? - rescue Interrupt - raise - rescue Exception => e # rubocop:disable Lint/RescueException - os_and_arch = "macOS #{current_macos_version} on #{arch}" - onoe "Invalid cask (#{os_and_arch}): #{file}" - $stderr.puts e - success = false + success = T.let(true, T::Boolean) + tap.cask_files.each do |file| + cask = Cask::CaskLoader.load(file) + + # Fine to have missing URLs for unsupported macOS + macos_req = cask.depends_on.macos + next if macos_req&.version && Array(macos_req.version).none? do |macos_version| + current_macos_version.compare(macos_req.comparator, macos_version) end - success + + raise "Missing URL" if cask.url.nil? + rescue Interrupt + raise + rescue Exception => e # rubocop:disable Lint/RescueException + os_and_arch = "macOS #{current_macos_version} on #{arch}" + onoe "Invalid cask (#{os_and_arch}): #{file}" + $stderr.puts e + success = false end + success end end + +Readall.singleton_class.prepend(ReadallMac) diff --git a/Library/Homebrew/extend/os/mac/simulate_system.rb b/Library/Homebrew/extend/os/mac/simulate_system.rb index 95bc2ef9ae58b..aacc2692026ba 100644 --- a/Library/Homebrew/extend/os/mac/simulate_system.rb +++ b/Library/Homebrew/extend/os/mac/simulate_system.rb @@ -2,20 +2,17 @@ # frozen_string_literal: true module Homebrew - class SimulateSystem - class << self - undef simulating_or_running_on_macos? - undef current_os - - sig { returns(T::Boolean) } - def simulating_or_running_on_macos? - os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(os) - end + module SimulateSystemMac + sig { returns(T::Boolean) } + def simulating_or_running_on_macos? + SimulateSystem.os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(SimulateSystem.os) + end - sig { returns(Symbol) } - def current_os - os || MacOS.version.to_sym - end + sig { returns(Symbol) } + def current_os + SimulateSystem.os || MacOS.version.to_sym end end end + +Homebrew::SimulateSystem.singleton_class.prepend(Homebrew::SimulateSystemMac) From 7cd329c116e418c4597f4702a6ec73a81131b20f Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 10 Sep 2024 19:12:15 -0700 Subject: [PATCH 3/6] Makes args readable --- Library/Homebrew/cli/parser.rb | 3 +++ Library/Homebrew/extend/os/linux/parser.rb | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 79db0ede47a37..af8bec643791d 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -24,6 +24,9 @@ class Parser }.freeze, T::Hash[Symbol, String]) private_constant :ArgType, :HIDDEN_DESC_PLACEHOLDER, :SYMBOL_TO_USAGE_MAPPING + sig { returns(Args) } + attr_reader :args + sig { returns(Args::OptionsType) } attr_reader :processed_options diff --git a/Library/Homebrew/extend/os/linux/parser.rb b/Library/Homebrew/extend/os/linux/parser.rb index 37f8481e18865..7573d9e22f891 100644 --- a/Library/Homebrew/extend/os/linux/parser.rb +++ b/Library/Homebrew/extend/os/linux/parser.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true module Homebrew @@ -10,13 +10,13 @@ module ParserLinux sig { void } def set_default_options - @args["formula?"] = true if @args.respond_to?(:formula?) + args["formula?"] = true if args.respond_to?(:formula?) end sig { void } def validate_options - return unless @args.respond_to?(:cask?) - return unless @args.cask? + return unless args.respond_to?(:cask?) + return unless args.cask? # NOTE: We don't raise an error here because we don't want # to print the help page or a stack trace. From bb80f063dc9a4f91afd54bb80228546f128daac1 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Fri, 13 Sep 2024 12:22:52 -0700 Subject: [PATCH 4/6] Fix namespacing --- Library/Homebrew/attestation.rb | 2 +- Library/Homebrew/dev-cmd/bottle.rb | 4 +- Library/Homebrew/dev-cmd/tests.rb | 4 +- Library/Homebrew/extend/os/linux/cleanup.rb | 32 ++++--- .../Homebrew/extend/os/linux/cli/parser.rb | 33 +++++++ .../Homebrew/extend/os/linux/diagnostic.rb | 12 +-- Library/Homebrew/extend/os/linux/formula.rb | 96 ++++++++++--------- Library/Homebrew/extend/os/linux/install.rb | 2 +- Library/Homebrew/extend/os/linux/parser.rb | 29 ------ Library/Homebrew/extend/os/mac/cleaner.rb | 18 ++-- Library/Homebrew/extend/os/mac/cleanup.rb | 16 ++-- .../Homebrew/extend/os/mac/dev-cmd/bottle.rb | 32 ++++--- Library/Homebrew/extend/os/mac/diagnostic.rb | 6 +- Library/Homebrew/extend/os/mac/formula.rb | 65 +++++++------ .../extend/os/mac/formula_installer.rb | 22 +++-- .../Homebrew/extend/os/mac/linkage_checker.rb | 20 ++-- Library/Homebrew/extend/os/mac/readall.rb | 74 +++++++------- .../Homebrew/extend/os/mac/simulate_system.rb | 23 +++-- Library/Homebrew/extend/os/parser.rb | 2 +- Library/Homebrew/formula_auditor.rb | 4 +- .../Homebrew/rubocops/move_to_extend_os.rb | 2 +- .../test/rubocops/move_to_extend_os_spec.rb | 14 +++ 22 files changed, 291 insertions(+), 221 deletions(-) create mode 100644 Library/Homebrew/extend/os/linux/cli/parser.rb delete mode 100644 Library/Homebrew/extend/os/linux/parser.rb diff --git a/Library/Homebrew/attestation.rb b/Library/Homebrew/attestation.rb index 853643465fa30..f568a495ded36 100644 --- a/Library/Homebrew/attestation.rb +++ b/Library/Homebrew/attestation.rb @@ -60,7 +60,7 @@ def self.enabled? return false if Homebrew::EnvConfig.no_verify_attestations? return true if Homebrew::EnvConfig.verify_attestations? return false if ENV.fetch("CI", false) - return false if OS.unsupported_configuration? + return false if ::OS.unsupported_configuration? # Always check credentials last to avoid unnecessary credential extraction. (Homebrew::EnvConfig.developer? || Homebrew::EnvConfig.devcmdrun?) && GitHub::API.credentials.present? diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index b0c914ae01d39..5ce69ba9fde07 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -394,10 +394,10 @@ def formula_ignores(formula) # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. when Version.formula_optionally_versioned_regex(:gcc) - Regexp.union(%r{#{cellar_regex}/gcc}, %r{#{prefix_regex}/opt/gcc}) if OS.linux? + Regexp.union(%r{#{cellar_regex}/gcc}, %r{#{prefix_regex}/opt/gcc}) if ::OS.linux? # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. when Version.formula_optionally_versioned_regex(:binutils) - %r{#{cellar_regex}/binutils} if OS.linux? + %r{#{cellar_regex}/binutils} if ::OS.linux? end # rubocop:enable Homebrew/MoveToExtendOS diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index b45df9ac942d7..ec64bdde394ba 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -116,12 +116,12 @@ def run # TODO: Refactor and move to extend/os # rubocop:disable Homebrew/MoveToExtendOS - unless OS.mac? + unless ::OS.mac? bundle_args << "--tag" << "~needs_macos" << "--tag" << "~cask" files = files.grep_v(%r{^test/(os/mac|cask)(/.*|_spec\.rb)$}) end - unless OS.linux? + unless ::OS.linux? bundle_args << "--tag" << "~needs_linux" files = files.grep_v(%r{^test/os/linux(/.*|_spec\.rb)$}) end diff --git a/Library/Homebrew/extend/os/linux/cleanup.rb b/Library/Homebrew/extend/os/linux/cleanup.rb index deb231b31865d..15a7e0b0ecac6 100644 --- a/Library/Homebrew/extend/os/linux/cleanup.rb +++ b/Library/Homebrew/extend/os/linux/cleanup.rb @@ -2,26 +2,30 @@ # frozen_string_literal: true module Homebrew - module CleanupLinux - extend T::Helpers + module OS + module Linux + module Cleanup + extend T::Helpers - requires_ancestor { Cleanup } + requires_ancestor { Homebrew::Cleanup } - sig { returns(T::Boolean) } - def use_system_ruby? - return false if Homebrew::EnvConfig.force_vendor_ruby? + sig { returns(T::Boolean) } + def use_system_ruby? + return false if Homebrew::EnvConfig.force_vendor_ruby? - rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact - system_ruby = Pathname.new("/usr/bin/ruby") - rubies << system_ruby if system_ruby.exist? + rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact + system_ruby = Pathname.new("/usr/bin/ruby") + rubies << system_ruby if system_ruby.exist? - check_ruby_version = HOMEBREW_LIBRARY_PATH/"utils/ruby_check_version_script.rb" - rubies.uniq.any? do |ruby| - quiet_system ruby, "--enable-frozen-string-literal", "--disable=gems,did_you_mean,rubyopt", - check_ruby_version, RUBY_VERSION + check_ruby_version = HOMEBREW_LIBRARY_PATH/"utils/ruby_check_version_script.rb" + rubies.uniq.any? do |ruby| + quiet_system ruby, "--enable-frozen-string-literal", "--disable=gems,did_you_mean,rubyopt", + check_ruby_version, RUBY_VERSION + end + end end end end end -Homebrew::Cleanup.prepend(Homebrew::CleanupLinux) +Homebrew::Cleanup.prepend(Homebrew::OS::Linux::Cleanup) diff --git a/Library/Homebrew/extend/os/linux/cli/parser.rb b/Library/Homebrew/extend/os/linux/cli/parser.rb new file mode 100644 index 0000000000000..091ad48920ff7 --- /dev/null +++ b/Library/Homebrew/extend/os/linux/cli/parser.rb @@ -0,0 +1,33 @@ +# typed: strict +# frozen_string_literal: true + +module Homebrew + module OS + module Linux + module CLI + module Parser + extend T::Helpers + + requires_ancestor { Homebrew::CLI::Parser } + + sig { void } + def set_default_options + args["formula?"] = true if args.respond_to?(:formula?) + end + + sig { void } + def validate_options + return unless args.respond_to?(:cask?) + return unless args.cask? + + # NOTE: We don't raise an error here because we don't want + # to print the help page or a stack trace. + odie "Invalid `--cask` usage: Casks do not work on Linux" + end + end + end + end + end +end + +Homebrew::CLI::Parser.prepend(Homebrew::OS::Linux::CLI::Parser) diff --git a/Library/Homebrew/extend/os/linux/diagnostic.rb b/Library/Homebrew/extend/os/linux/diagnostic.rb index c3c665cb20a8c..84d8ee6167972 100644 --- a/Library/Homebrew/extend/os/linux/diagnostic.rb +++ b/Library/Homebrew/extend/os/linux/diagnostic.rb @@ -95,11 +95,11 @@ def check_supported_architecture end def check_glibc_minimum_version - return unless OS::Linux::Glibc.below_minimum_version? + return unless ::OS::Linux::Glibc.below_minimum_version? <<~EOS - Your system glibc #{OS::Linux::Glibc.system_version} is too old. - We only support glibc #{OS::Linux::Glibc.minimum_version} or later. + Your system glibc #{::OS::Linux::Glibc.system_version} is too old. + We only support glibc #{::OS::Linux::Glibc.minimum_version} or later. #{please_create_pull_requests} We recommend updating to a newer version via your distribution's package manager, upgrading your distribution to the latest version, @@ -108,11 +108,11 @@ def check_glibc_minimum_version end def check_kernel_minimum_version - return unless OS::Linux::Kernel.below_minimum_version? + return unless ::OS::Linux::Kernel.below_minimum_version? <<~EOS - Your Linux kernel #{OS.kernel_version} is too old. - We only support kernel #{OS::Linux::Kernel.minimum_version} or later. + Your Linux kernel #{::OS.kernel_version} is too old. + We only support kernel #{::OS::Linux::Kernel.minimum_version} or later. You will be unable to use binary packages (bottles). #{please_create_pull_requests} We recommend updating to a newer version via your distribution's diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index 2d6250f816f16..e71b1e7df109f 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -1,52 +1,58 @@ # typed: true # rubocop:disable Sorbet/StrictSigil # frozen_string_literal: true -module FormulaLinux - extend T::Helpers - - requires_ancestor { Formula } - - sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) } - def shared_library(name, version = nil) - suffix = if version == "*" || (name == "*" && version.blank?) - "{,.*}" - elsif version.present? - ".#{version}" +module Homebrew + module OS + module Linux + module Formula + extend T::Helpers + + requires_ancestor { ::Formula } + + sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) } + def shared_library(name, version = nil) + suffix = if version == "*" || (name == "*" && version.blank?) + "{,.*}" + elsif version.present? + ".#{version}" + end + "#{name}.so#{suffix}" + end + + sig { returns(String) } + def loader_path + "$ORIGIN" + end + + sig { params(targets: T.nilable(T.any(Pathname, String))).void } + def deuniversalize_machos(*targets); end + + sig { params(spec: SoftwareSpec).void } + def add_global_deps_to_spec(spec) + return unless DevelopmentTools.needs_build_formulae? + + @global_deps ||= begin + dependency_collector = spec.dependency_collector + related_formula_names = Set.new([ + name, + *aliases, + *versioned_formulae_names, + ]) + [ + dependency_collector.gcc_dep_if_needed(related_formula_names), + dependency_collector.glibc_dep_if_needed(related_formula_names), + ].compact.freeze + end + @global_deps.each { |dep| spec.dependency_collector.add(dep) } + end + + sig { returns(T::Boolean) } + def valid_platform? + requirements.none?(MacOSRequirement) + end + end end - "#{name}.so#{suffix}" - end - - sig { returns(String) } - def loader_path - "$ORIGIN" - end - - sig { params(targets: T.nilable(T.any(Pathname, String))).void } - def deuniversalize_machos(*targets); end - - sig { params(spec: SoftwareSpec).void } - def add_global_deps_to_spec(spec) - return unless DevelopmentTools.needs_build_formulae? - - @global_deps ||= begin - dependency_collector = spec.dependency_collector - related_formula_names = Set.new([ - name, - *aliases, - *versioned_formulae_names, - ]) - [ - dependency_collector.gcc_dep_if_needed(related_formula_names), - dependency_collector.glibc_dep_if_needed(related_formula_names), - ].compact.freeze - end - @global_deps.each { |dep| spec.dependency_collector.add(dep) } - end - - sig { returns(T::Boolean) } - def valid_platform? - requirements.none?(MacOSRequirement) end end -Formula.prepend(FormulaLinux) +Formula.prepend(Homebrew::OS::Linux::Formula) diff --git a/Library/Homebrew/extend/os/linux/install.rb b/Library/Homebrew/extend/os/linux/install.rb index ab4a4901466bd..2ce522d91cd66 100644 --- a/Library/Homebrew/extend/os/linux/install.rb +++ b/Library/Homebrew/extend/os/linux/install.rb @@ -78,7 +78,7 @@ def self.symlink_ld_so private_class_method :symlink_ld_so def self.setup_preferred_gcc_libs - gcc_opt_prefix = HOMEBREW_PREFIX/"opt/#{OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA}" + gcc_opt_prefix = HOMEBREW_PREFIX/"opt/#{::OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA}" glibc_installed = (HOMEBREW_PREFIX/"opt/glibc/bin/ld.so").readable? return unless gcc_opt_prefix.readable? diff --git a/Library/Homebrew/extend/os/linux/parser.rb b/Library/Homebrew/extend/os/linux/parser.rb deleted file mode 100644 index 7573d9e22f891..0000000000000 --- a/Library/Homebrew/extend/os/linux/parser.rb +++ /dev/null @@ -1,29 +0,0 @@ -# typed: strict -# frozen_string_literal: true - -module Homebrew - module CLI - module ParserLinux - extend T::Helpers - - requires_ancestor { Homebrew::CLI::Parser } - - sig { void } - def set_default_options - args["formula?"] = true if args.respond_to?(:formula?) - end - - sig { void } - def validate_options - return unless args.respond_to?(:cask?) - return unless args.cask? - - # NOTE: We don't raise an error here because we don't want - # to print the help page or a stack trace. - odie "Invalid `--cask` usage: Casks do not work on Linux" - end - end - end -end - -Homebrew::CLI::Parser.prepend(Homebrew::CLI::ParserLinux) diff --git a/Library/Homebrew/extend/os/mac/cleaner.rb b/Library/Homebrew/extend/os/mac/cleaner.rb index 23cdfbf947ff4..ece95188cc884 100644 --- a/Library/Homebrew/extend/os/mac/cleaner.rb +++ b/Library/Homebrew/extend/os/mac/cleaner.rb @@ -1,13 +1,19 @@ # typed: strict # frozen_string_literal: true -module CleanerMac - private +module Homebrew + module OS + module MacOS + module Cleaner + private - sig { params(path: Pathname).returns(T::Boolean) } - def executable_path?(path) - path.mach_o_executable? || path.text_executable? + sig { params(path: Pathname).returns(T::Boolean) } + def executable_path?(path) + path.mach_o_executable? || path.text_executable? + end + end + end end end -Cleaner.prepend(CleanerMac) +Cleaner.prepend(Homebrew::OS::MacOS::Cleaner) diff --git a/Library/Homebrew/extend/os/mac/cleanup.rb b/Library/Homebrew/extend/os/mac/cleanup.rb index 8c07923e0952f..75d32bea15904 100644 --- a/Library/Homebrew/extend/os/mac/cleanup.rb +++ b/Library/Homebrew/extend/os/mac/cleanup.rb @@ -2,14 +2,18 @@ # frozen_string_literal: true module Homebrew - module CleanupMac - sig { returns(T::Boolean) } - def use_system_ruby? - return false if Homebrew::EnvConfig.force_vendor_ruby? + module OS + module MacOS + module Cleanup + sig { returns(T::Boolean) } + def use_system_ruby? + return false if Homebrew::EnvConfig.force_vendor_ruby? - Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present? + Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present? + end + end end end end -Homebrew::Cleanup.prepend(Homebrew::CleanupMac) +Homebrew::Cleanup.prepend(Homebrew::OS::MacOS::Cleanup) diff --git a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb index 1c3ad6a7f9492..c7ebdc5e4469e 100644 --- a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb +++ b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb @@ -2,23 +2,27 @@ # frozen_string_literal: true module Homebrew - module DevCmd - module BottleMac - sig { returns(T::Array[String]) } - def tar_args - if MacOS.version >= :catalina - ["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze - else - [].freeze - end - end + module OS + module MacOS + module DevCmd + module Bottle + sig { returns(T::Array[String]) } + def tar_args + if ::MacOS.version >= :catalina + ["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze + else + [].freeze + end + end - sig { params(gnu_tar_formula: Formula).returns(String) } - def gnu_tar(gnu_tar_formula) - "#{gnu_tar_formula.opt_bin}/gtar" + sig { params(gnu_tar_formula: Formula).returns(String) } + def gnu_tar(gnu_tar_formula) + "#{gnu_tar_formula.opt_bin}/gtar" + end + end end end end end -Homebrew::DevCmd::Bottle.prepend(Homebrew::DevCmd::BottleMac) +Homebrew::DevCmd::Bottle.prepend(Homebrew::OS::MacOS::DevCmd::Bottle) diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index fa714f68ec56e..86fe60c347af6 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -110,9 +110,9 @@ def check_for_unsupported_macos return if ENV["HOMEBREW_INTEGRATION_TEST"] who = +"We" - what = if OS::Mac.version.prerelease? + what = if ::OS::Mac.version.prerelease? "pre-release version" - elsif OS::Mac.version.outdated_release? + elsif ::OS::Mac.version.outdated_release? who << " (and Apple)" "old version" end @@ -149,7 +149,7 @@ def check_xcode_up_to_date #{MacOS::Xcode.update_instructions} EOS - if OS::Mac.version.prerelease? + if ::OS::Mac.version.prerelease? current_path = Utils.popen_read("/usr/bin/xcode-select", "-p") message += <<~EOS If #{MacOS::Xcode.latest_version} is installed, you may need to: diff --git a/Library/Homebrew/extend/os/mac/formula.rb b/Library/Homebrew/extend/os/mac/formula.rb index 0aedbc9cab65c..7cfd0a88f9a74 100644 --- a/Library/Homebrew/extend/os/mac/formula.rb +++ b/Library/Homebrew/extend/os/mac/formula.rb @@ -1,36 +1,41 @@ # typed: strict # frozen_string_literal: true -module FormulaMac - extend T::Helpers - - requires_ancestor { Formula } - - sig { returns(T::Boolean) } - def valid_platform? - requirements.none?(LinuxRequirement) - end - - sig { - params( - install_prefix: T.any(String, Pathname), - install_libdir: T.any(String, Pathname), - find_framework: String, - ).returns(T::Array[String]) - } - def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework: "LAST") - args = generic_std_cmake_args(install_prefix:, install_libdir:, - find_framework:) - - # Avoid false positives for clock_gettime support on 10.11. - # CMake cache entries for other weak symbols may be added here as needed. - args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0" if MacOS.version == "10.11" && MacOS::Xcode.version >= "8.0" - - # Ensure CMake is using the same SDK we are using. - args << "-DCMAKE_OSX_SYSROOT=#{MacOS.sdk_for_formula(self).path}" if MacOS.sdk_root_needed? - - args +module Homebrew + module OS + module MacOS + module Formula + extend T::Helpers + + requires_ancestor { ::Formula } + + sig { returns(T::Boolean) } + def valid_platform? + requirements.none?(LinuxRequirement) + end + + sig { + params( + install_prefix: T.any(String, Pathname), + install_libdir: T.any(String, Pathname), + find_framework: String, + ).returns(T::Array[String]) + } + def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework: "LAST") + args = generic_std_cmake_args(install_prefix:, install_libdir:, find_framework:) + + # Avoid false positives for clock_gettime support on 10.11. + # CMake cache entries for other weak symbols may be added here as needed. + args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0" if ::MacOS.version == "10.11" && ::MacOS::Xcode.version >= "8.0" + + # Ensure CMake is using the same SDK we are using. + args << "-DCMAKE_OSX_SYSROOT=#{::MacOS.sdk_for_formula(self).path}" if ::MacOS.sdk_root_needed? + + args + end + end + end end end -Formula.prepend(FormulaMac) +Formula.prepend(Homebrew::OS::MacOS::Formula) diff --git a/Library/Homebrew/extend/os/mac/formula_installer.rb b/Library/Homebrew/extend/os/mac/formula_installer.rb index fe825f722111f..b601cbad93bc5 100644 --- a/Library/Homebrew/extend/os/mac/formula_installer.rb +++ b/Library/Homebrew/extend/os/mac/formula_installer.rb @@ -1,16 +1,22 @@ # typed: strict # frozen_string_literal: true -module FormulaInstallerMac - extend T::Helpers +module Homebrew + module OS + module MacOS + module FormulaInstaller + extend T::Helpers - requires_ancestor { FormulaInstaller } + requires_ancestor { ::FormulaInstaller } - sig { params(formula: Formula).returns(T.nilable(T::Boolean)) } - def fresh_install?(formula) - !Homebrew::EnvConfig.developer? && !OS::Mac.version.outdated_release? && - (!installed_as_dependency? || !formula.any_version_installed?) + sig { params(formula: Formula).returns(T.nilable(T::Boolean)) } + def fresh_install?(formula) + !Homebrew::EnvConfig.developer? && !::OS::Mac.version.outdated_release? && + (!installed_as_dependency? || !formula.any_version_installed?) + end + end + end end end -FormulaInstaller.prepend(FormulaInstallerMac) +FormulaInstaller.prepend(Homebrew::OS::MacOS::FormulaInstaller) diff --git a/Library/Homebrew/extend/os/mac/linkage_checker.rb b/Library/Homebrew/extend/os/mac/linkage_checker.rb index 1171257479bc0..6a63b0aefc0d8 100644 --- a/Library/Homebrew/extend/os/mac/linkage_checker.rb +++ b/Library/Homebrew/extend/os/mac/linkage_checker.rb @@ -1,14 +1,20 @@ # typed: strict # frozen_string_literal: true -module LinkageCheckerMac - private +module Homebrew + module OS + module MacOS + module LinkageChecker + private - sig { returns(T::Boolean) } - def system_libraries_exist_in_cache? - # In macOS Big Sur and later, system libraries do not exist on-disk and instead exist in a cache. - MacOS.version >= :big_sur + sig { returns(T::Boolean) } + def system_libraries_exist_in_cache? + # In macOS Big Sur and later, system libraries do not exist on-disk and instead exist in a cache. + ::MacOS.version >= :big_sur + end + end + end end end -LinkageChecker.prepend(LinkageCheckerMac) +LinkageChecker.prepend(Homebrew::OS::MacOS::LinkageChecker) diff --git a/Library/Homebrew/extend/os/mac/readall.rb b/Library/Homebrew/extend/os/mac/readall.rb index 15a78a78fe215..008c036bd7985 100644 --- a/Library/Homebrew/extend/os/mac/readall.rb +++ b/Library/Homebrew/extend/os/mac/readall.rb @@ -1,42 +1,48 @@ # typed: strict # frozen_string_literal: true -module ReadallMac - extend T::Helpers - - requires_ancestor { Kernel } - - sig { params(tap: Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) } - def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type) - return true if os_name == :linux - - current_macos_version = if os_name.is_a?(Symbol) - MacOSVersion.from_symbol(os_name) - else - MacOS.version - end - - success = T.let(true, T::Boolean) - tap.cask_files.each do |file| - cask = Cask::CaskLoader.load(file) - - # Fine to have missing URLs for unsupported macOS - macos_req = cask.depends_on.macos - next if macos_req&.version && Array(macos_req.version).none? do |macos_version| - current_macos_version.compare(macos_req.comparator, macos_version) +module Homebrew + module OS + module MacOS + module Readall + extend T::Helpers + + requires_ancestor { Kernel } + + sig { params(tap: Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) } + def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type) + return true if os_name == :linux + + current_macos_version = if os_name.is_a?(Symbol) + MacOSVersion.from_symbol(os_name) + else + ::MacOS.version + end + + success = T.let(true, T::Boolean) + tap.cask_files.each do |file| + cask = Cask::CaskLoader.load(file) + + # Fine to have missing URLs for unsupported macOS + macos_req = cask.depends_on.macos + next if macos_req&.version && Array(macos_req.version).none? do |macos_version| + current_macos_version.compare(macos_req.comparator, macos_version) + end + + raise "Missing URL" if cask.url.nil? + rescue Interrupt + raise + rescue Exception => e # rubocop:disable Lint/RescueException + os_and_arch = "macOS #{current_macos_version} on #{arch}" + onoe "Invalid cask (#{os_and_arch}): #{file}" + $stderr.puts e + success = false + end + success + end end - - raise "Missing URL" if cask.url.nil? - rescue Interrupt - raise - rescue Exception => e # rubocop:disable Lint/RescueException - os_and_arch = "macOS #{current_macos_version} on #{arch}" - onoe "Invalid cask (#{os_and_arch}): #{file}" - $stderr.puts e - success = false end - success end end -Readall.singleton_class.prepend(ReadallMac) +Readall.singleton_class.prepend(Homebrew::OS::MacOS::Readall) diff --git a/Library/Homebrew/extend/os/mac/simulate_system.rb b/Library/Homebrew/extend/os/mac/simulate_system.rb index aacc2692026ba..ac63e8568f1d6 100644 --- a/Library/Homebrew/extend/os/mac/simulate_system.rb +++ b/Library/Homebrew/extend/os/mac/simulate_system.rb @@ -2,17 +2,22 @@ # frozen_string_literal: true module Homebrew - module SimulateSystemMac - sig { returns(T::Boolean) } - def simulating_or_running_on_macos? - SimulateSystem.os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(SimulateSystem.os) - end + module OS + module MacOS + module SimulateSystem + sig { returns(T::Boolean) } + def simulating_or_running_on_macos? + Homebrew::SimulateSystem.os.blank? || [:macos, + *MacOSVersion::SYMBOLS.keys].include?(Homebrew::SimulateSystem.os) + end - sig { returns(Symbol) } - def current_os - SimulateSystem.os || MacOS.version.to_sym + sig { returns(Symbol) } + def current_os + Homebrew::SimulateSystem.os || ::MacOS.version.to_sym + end + end end end end -Homebrew::SimulateSystem.singleton_class.prepend(Homebrew::SimulateSystemMac) +Homebrew::SimulateSystem.singleton_class.prepend(Homebrew::OS::MacOS::SimulateSystem) diff --git a/Library/Homebrew/extend/os/parser.rb b/Library/Homebrew/extend/os/parser.rb index eb84af9d0abce..fcf79902524d1 100644 --- a/Library/Homebrew/extend/os/parser.rb +++ b/Library/Homebrew/extend/os/parser.rb @@ -1,4 +1,4 @@ # typed: strict # frozen_string_literal: true -require "extend/os/linux/parser" if OS.linux? +require "extend/os/linux/cli/parser" if OS.linux? diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index c19909e2f9199..e3132f98e47ab 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -504,9 +504,9 @@ def audit_glibc return unless @core_tap return if formula.name != "glibc" # Also allow LINUX_GLIBC_NEXT_CI_VERSION for when we're upgrading. - return if [OS::LINUX_GLIBC_CI_VERSION, OS::LINUX_GLIBC_NEXT_CI_VERSION].include?(formula.version.to_s) + return if [::OS::LINUX_GLIBC_CI_VERSION, ::OS::LINUX_GLIBC_NEXT_CI_VERSION].include?(formula.version.to_s) - problem "The glibc version must be #{OS::LINUX_GLIBC_CI_VERSION}, as needed by our CI on Linux. " \ + problem "The glibc version must be #{::OS::LINUX_GLIBC_CI_VERSION}, as needed by our CI on Linux. " \ "The glibc formula is for users who have a system glibc with a lower version, " \ "which allows them to use our Linux bottles, which were compiled against system glibc on CI." end diff --git a/Library/Homebrew/rubocops/move_to_extend_os.rb b/Library/Homebrew/rubocops/move_to_extend_os.rb index 00aa8742c661c..30457528e1976 100644 --- a/Library/Homebrew/rubocops/move_to_extend_os.rb +++ b/Library/Homebrew/rubocops/move_to_extend_os.rb @@ -9,7 +9,7 @@ class MoveToExtendOS < Base MSG = "Move `OS.linux?` and `OS.mac?` calls to `extend/os`." def_node_matcher :os_check?, <<~PATTERN - (send (const nil? :OS) {:mac? | :linux?}) + (send (const {nil? cbase} :OS) {:mac? | :linux?}) PATTERN def on_send(node) diff --git a/Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb b/Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb index a20b0d949e149..5d1e434c2b4d1 100644 --- a/Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb +++ b/Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb @@ -18,4 +18,18 @@ ^^^^^^^ Homebrew/MoveToExtendOS: Move `OS.linux?` and `OS.mac?` calls to `extend/os`. RUBY end + + it "registers an offense when using `::OS.linux?`" do + expect_offense(<<~RUBY) + ::OS.linux? + ^^^^^^^^^^^ Homebrew/MoveToExtendOS: Move `OS.linux?` and `OS.mac?` calls to `extend/os`. + RUBY + end + + it "registers an offense when using `::OS.mac?`" do + expect_offense(<<~RUBY) + ::OS.mac? + ^^^^^^^^^ Homebrew/MoveToExtendOS: Move `OS.linux?` and `OS.mac?` calls to `extend/os`. + RUBY + end end From 61985bc7f3d0b6de8e6542b802b4c50fd354cfc9 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Wed, 18 Sep 2024 15:33:49 -0700 Subject: [PATCH 5/6] Use top-level OS instead --- Library/Homebrew/attestation.rb | 2 +- Library/Homebrew/dev-cmd/bottle.rb | 4 +- Library/Homebrew/dev-cmd/tests.rb | 4 +- Library/Homebrew/extend/os/linux/cleanup.rb | 34 ++++--- .../Homebrew/extend/os/linux/cli/parser.rb | 38 ++++---- .../Homebrew/extend/os/linux/diagnostic.rb | 12 +-- Library/Homebrew/extend/os/linux/formula.rb | 88 +++++++++---------- Library/Homebrew/extend/os/linux/install.rb | 2 +- Library/Homebrew/extend/os/mac/cleaner.rb | 18 ++-- Library/Homebrew/extend/os/mac/cleanup.rb | 18 ++-- .../Homebrew/extend/os/mac/dev-cmd/bottle.rb | 32 ++++--- Library/Homebrew/extend/os/mac/diagnostic.rb | 6 +- Library/Homebrew/extend/os/mac/formula.rb | 64 +++++++------- .../extend/os/mac/formula_installer.rb | 22 +++-- .../Homebrew/extend/os/mac/linkage_checker.rb | 20 ++--- Library/Homebrew/extend/os/mac/readall.rb | 72 ++++++++------- .../Homebrew/extend/os/mac/simulate_system.rb | 26 +++--- Library/Homebrew/formula_auditor.rb | 4 +- .../Homebrew/rubocops/move_to_extend_os.rb | 2 +- .../test/rubocops/move_to_extend_os_spec.rb | 14 --- 20 files changed, 223 insertions(+), 259 deletions(-) diff --git a/Library/Homebrew/attestation.rb b/Library/Homebrew/attestation.rb index f568a495ded36..853643465fa30 100644 --- a/Library/Homebrew/attestation.rb +++ b/Library/Homebrew/attestation.rb @@ -60,7 +60,7 @@ def self.enabled? return false if Homebrew::EnvConfig.no_verify_attestations? return true if Homebrew::EnvConfig.verify_attestations? return false if ENV.fetch("CI", false) - return false if ::OS.unsupported_configuration? + return false if OS.unsupported_configuration? # Always check credentials last to avoid unnecessary credential extraction. (Homebrew::EnvConfig.developer? || Homebrew::EnvConfig.devcmdrun?) && GitHub::API.credentials.present? diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 5ce69ba9fde07..b0c914ae01d39 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -394,10 +394,10 @@ def formula_ignores(formula) # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. when Version.formula_optionally_versioned_regex(:gcc) - Regexp.union(%r{#{cellar_regex}/gcc}, %r{#{prefix_regex}/opt/gcc}) if ::OS.linux? + Regexp.union(%r{#{cellar_regex}/gcc}, %r{#{prefix_regex}/opt/gcc}) if OS.linux? # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. when Version.formula_optionally_versioned_regex(:binutils) - %r{#{cellar_regex}/binutils} if ::OS.linux? + %r{#{cellar_regex}/binutils} if OS.linux? end # rubocop:enable Homebrew/MoveToExtendOS diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index ec64bdde394ba..b45df9ac942d7 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -116,12 +116,12 @@ def run # TODO: Refactor and move to extend/os # rubocop:disable Homebrew/MoveToExtendOS - unless ::OS.mac? + unless OS.mac? bundle_args << "--tag" << "~needs_macos" << "--tag" << "~cask" files = files.grep_v(%r{^test/(os/mac|cask)(/.*|_spec\.rb)$}) end - unless ::OS.linux? + unless OS.linux? bundle_args << "--tag" << "~needs_linux" files = files.grep_v(%r{^test/os/linux(/.*|_spec\.rb)$}) end diff --git a/Library/Homebrew/extend/os/linux/cleanup.rb b/Library/Homebrew/extend/os/linux/cleanup.rb index 15a7e0b0ecac6..be63e0e558298 100644 --- a/Library/Homebrew/extend/os/linux/cleanup.rb +++ b/Library/Homebrew/extend/os/linux/cleanup.rb @@ -1,31 +1,29 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module OS - module Linux - module Cleanup - extend T::Helpers +module OS + module Linux + module Cleanup + extend T::Helpers - requires_ancestor { Homebrew::Cleanup } + requires_ancestor { Homebrew::Cleanup } - sig { returns(T::Boolean) } - def use_system_ruby? - return false if Homebrew::EnvConfig.force_vendor_ruby? + sig { returns(T::Boolean) } + def use_system_ruby? + return false if Homebrew::EnvConfig.force_vendor_ruby? - rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact - system_ruby = Pathname.new("/usr/bin/ruby") - rubies << system_ruby if system_ruby.exist? + rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact + system_ruby = Pathname.new("/usr/bin/ruby") + rubies << system_ruby if system_ruby.exist? - check_ruby_version = HOMEBREW_LIBRARY_PATH/"utils/ruby_check_version_script.rb" - rubies.uniq.any? do |ruby| - quiet_system ruby, "--enable-frozen-string-literal", "--disable=gems,did_you_mean,rubyopt", - check_ruby_version, RUBY_VERSION - end + check_ruby_version = HOMEBREW_LIBRARY_PATH/"utils/ruby_check_version_script.rb" + rubies.uniq.any? do |ruby| + quiet_system ruby, "--enable-frozen-string-literal", "--disable=gems,did_you_mean,rubyopt", + check_ruby_version, RUBY_VERSION end end end end end -Homebrew::Cleanup.prepend(Homebrew::OS::Linux::Cleanup) +Homebrew::Cleanup.prepend(OS::Linux::Cleanup) diff --git a/Library/Homebrew/extend/os/linux/cli/parser.rb b/Library/Homebrew/extend/os/linux/cli/parser.rb index 091ad48920ff7..e5fd59e146cb9 100644 --- a/Library/Homebrew/extend/os/linux/cli/parser.rb +++ b/Library/Homebrew/extend/os/linux/cli/parser.rb @@ -1,33 +1,31 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module OS - module Linux - module CLI - module Parser - extend T::Helpers +module OS + module Linux + module CLI + module Parser + extend T::Helpers - requires_ancestor { Homebrew::CLI::Parser } + requires_ancestor { Homebrew::CLI::Parser } - sig { void } - def set_default_options - args["formula?"] = true if args.respond_to?(:formula?) - end + sig { void } + def set_default_options + args["formula?"] = true if args.respond_to?(:formula?) + end - sig { void } - def validate_options - return unless args.respond_to?(:cask?) - return unless args.cask? + sig { void } + def validate_options + return unless args.respond_to?(:cask?) + return unless args.cask? - # NOTE: We don't raise an error here because we don't want - # to print the help page or a stack trace. - odie "Invalid `--cask` usage: Casks do not work on Linux" - end + # NOTE: We don't raise an error here because we don't want + # to print the help page or a stack trace. + odie "Invalid `--cask` usage: Casks do not work on Linux" end end end end end -Homebrew::CLI::Parser.prepend(Homebrew::OS::Linux::CLI::Parser) +Homebrew::CLI::Parser.prepend(OS::Linux::CLI::Parser) diff --git a/Library/Homebrew/extend/os/linux/diagnostic.rb b/Library/Homebrew/extend/os/linux/diagnostic.rb index 84d8ee6167972..c3c665cb20a8c 100644 --- a/Library/Homebrew/extend/os/linux/diagnostic.rb +++ b/Library/Homebrew/extend/os/linux/diagnostic.rb @@ -95,11 +95,11 @@ def check_supported_architecture end def check_glibc_minimum_version - return unless ::OS::Linux::Glibc.below_minimum_version? + return unless OS::Linux::Glibc.below_minimum_version? <<~EOS - Your system glibc #{::OS::Linux::Glibc.system_version} is too old. - We only support glibc #{::OS::Linux::Glibc.minimum_version} or later. + Your system glibc #{OS::Linux::Glibc.system_version} is too old. + We only support glibc #{OS::Linux::Glibc.minimum_version} or later. #{please_create_pull_requests} We recommend updating to a newer version via your distribution's package manager, upgrading your distribution to the latest version, @@ -108,11 +108,11 @@ def check_glibc_minimum_version end def check_kernel_minimum_version - return unless ::OS::Linux::Kernel.below_minimum_version? + return unless OS::Linux::Kernel.below_minimum_version? <<~EOS - Your Linux kernel #{::OS.kernel_version} is too old. - We only support kernel #{::OS::Linux::Kernel.minimum_version} or later. + Your Linux kernel #{OS.kernel_version} is too old. + We only support kernel #{OS::Linux::Kernel.minimum_version} or later. You will be unable to use binary packages (bottles). #{please_create_pull_requests} We recommend updating to a newer version via your distribution's diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index e71b1e7df109f..4af57d02c9eef 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -1,58 +1,56 @@ # typed: true # rubocop:disable Sorbet/StrictSigil # frozen_string_literal: true -module Homebrew - module OS - module Linux - module Formula - extend T::Helpers - - requires_ancestor { ::Formula } - - sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) } - def shared_library(name, version = nil) - suffix = if version == "*" || (name == "*" && version.blank?) - "{,.*}" - elsif version.present? - ".#{version}" - end - "#{name}.so#{suffix}" +module OS + module Linux + module Formula + extend T::Helpers + + requires_ancestor { ::Formula } + + sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) } + def shared_library(name, version = nil) + suffix = if version == "*" || (name == "*" && version.blank?) + "{,.*}" + elsif version.present? + ".#{version}" end + "#{name}.so#{suffix}" + end - sig { returns(String) } - def loader_path - "$ORIGIN" - end + sig { returns(String) } + def loader_path + "$ORIGIN" + end - sig { params(targets: T.nilable(T.any(Pathname, String))).void } - def deuniversalize_machos(*targets); end - - sig { params(spec: SoftwareSpec).void } - def add_global_deps_to_spec(spec) - return unless DevelopmentTools.needs_build_formulae? - - @global_deps ||= begin - dependency_collector = spec.dependency_collector - related_formula_names = Set.new([ - name, - *aliases, - *versioned_formulae_names, - ]) - [ - dependency_collector.gcc_dep_if_needed(related_formula_names), - dependency_collector.glibc_dep_if_needed(related_formula_names), - ].compact.freeze - end - @global_deps.each { |dep| spec.dependency_collector.add(dep) } + sig { params(targets: T.nilable(T.any(Pathname, String))).void } + def deuniversalize_machos(*targets); end + + sig { params(spec: SoftwareSpec).void } + def add_global_deps_to_spec(spec) + return unless DevelopmentTools.needs_build_formulae? + + @global_deps ||= begin + dependency_collector = spec.dependency_collector + related_formula_names = Set.new([ + name, + *aliases, + *versioned_formulae_names, + ]) + [ + dependency_collector.gcc_dep_if_needed(related_formula_names), + dependency_collector.glibc_dep_if_needed(related_formula_names), + ].compact.freeze end + @global_deps.each { |dep| spec.dependency_collector.add(dep) } + end - sig { returns(T::Boolean) } - def valid_platform? - requirements.none?(MacOSRequirement) - end + sig { returns(T::Boolean) } + def valid_platform? + requirements.none?(MacOSRequirement) end end end end -Formula.prepend(Homebrew::OS::Linux::Formula) +Formula.prepend(OS::Linux::Formula) diff --git a/Library/Homebrew/extend/os/linux/install.rb b/Library/Homebrew/extend/os/linux/install.rb index 2ce522d91cd66..ab4a4901466bd 100644 --- a/Library/Homebrew/extend/os/linux/install.rb +++ b/Library/Homebrew/extend/os/linux/install.rb @@ -78,7 +78,7 @@ def self.symlink_ld_so private_class_method :symlink_ld_so def self.setup_preferred_gcc_libs - gcc_opt_prefix = HOMEBREW_PREFIX/"opt/#{::OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA}" + gcc_opt_prefix = HOMEBREW_PREFIX/"opt/#{OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA}" glibc_installed = (HOMEBREW_PREFIX/"opt/glibc/bin/ld.so").readable? return unless gcc_opt_prefix.readable? diff --git a/Library/Homebrew/extend/os/mac/cleaner.rb b/Library/Homebrew/extend/os/mac/cleaner.rb index ece95188cc884..303500fa5e1f6 100644 --- a/Library/Homebrew/extend/os/mac/cleaner.rb +++ b/Library/Homebrew/extend/os/mac/cleaner.rb @@ -1,19 +1,17 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module OS - module MacOS - module Cleaner - private +module OS + module Mac + module Cleaner + private - sig { params(path: Pathname).returns(T::Boolean) } - def executable_path?(path) - path.mach_o_executable? || path.text_executable? - end + sig { params(path: Pathname).returns(T::Boolean) } + def executable_path?(path) + path.mach_o_executable? || path.text_executable? end end end end -Cleaner.prepend(Homebrew::OS::MacOS::Cleaner) +Cleaner.prepend(OS::Mac::Cleaner) diff --git a/Library/Homebrew/extend/os/mac/cleanup.rb b/Library/Homebrew/extend/os/mac/cleanup.rb index 75d32bea15904..08b4ec01454d2 100644 --- a/Library/Homebrew/extend/os/mac/cleanup.rb +++ b/Library/Homebrew/extend/os/mac/cleanup.rb @@ -1,19 +1,17 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module OS - module MacOS - module Cleanup - sig { returns(T::Boolean) } - def use_system_ruby? - return false if Homebrew::EnvConfig.force_vendor_ruby? +module OS + module Mac + module Cleanup + sig { returns(T::Boolean) } + def use_system_ruby? + return false if Homebrew::EnvConfig.force_vendor_ruby? - Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present? - end + Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present? end end end end -Homebrew::Cleanup.prepend(Homebrew::OS::MacOS::Cleanup) +Homebrew::Cleanup.prepend(OS::Mac::Cleanup) diff --git a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb index c7ebdc5e4469e..9d07b436956cd 100644 --- a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb +++ b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb @@ -1,28 +1,26 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module OS - module MacOS - module DevCmd - module Bottle - sig { returns(T::Array[String]) } - def tar_args - if ::MacOS.version >= :catalina - ["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze - else - [].freeze - end +module OS + module Mac + module DevCmd + module Bottle + sig { returns(T::Array[String]) } + def tar_args + if MacOS.version >= :catalina + ["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze + else + [].freeze end + end - sig { params(gnu_tar_formula: Formula).returns(String) } - def gnu_tar(gnu_tar_formula) - "#{gnu_tar_formula.opt_bin}/gtar" - end + sig { params(gnu_tar_formula: Formula).returns(String) } + def gnu_tar(gnu_tar_formula) + "#{gnu_tar_formula.opt_bin}/gtar" end end end end end -Homebrew::DevCmd::Bottle.prepend(Homebrew::OS::MacOS::DevCmd::Bottle) +Homebrew::DevCmd::Bottle.prepend(OS::Mac::DevCmd::Bottle) diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index 86fe60c347af6..fa714f68ec56e 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -110,9 +110,9 @@ def check_for_unsupported_macos return if ENV["HOMEBREW_INTEGRATION_TEST"] who = +"We" - what = if ::OS::Mac.version.prerelease? + what = if OS::Mac.version.prerelease? "pre-release version" - elsif ::OS::Mac.version.outdated_release? + elsif OS::Mac.version.outdated_release? who << " (and Apple)" "old version" end @@ -149,7 +149,7 @@ def check_xcode_up_to_date #{MacOS::Xcode.update_instructions} EOS - if ::OS::Mac.version.prerelease? + if OS::Mac.version.prerelease? current_path = Utils.popen_read("/usr/bin/xcode-select", "-p") message += <<~EOS If #{MacOS::Xcode.latest_version} is installed, you may need to: diff --git a/Library/Homebrew/extend/os/mac/formula.rb b/Library/Homebrew/extend/os/mac/formula.rb index 7cfd0a88f9a74..4731717dfe475 100644 --- a/Library/Homebrew/extend/os/mac/formula.rb +++ b/Library/Homebrew/extend/os/mac/formula.rb @@ -1,41 +1,39 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module OS - module MacOS - module Formula - extend T::Helpers - - requires_ancestor { ::Formula } - - sig { returns(T::Boolean) } - def valid_platform? - requirements.none?(LinuxRequirement) - end - - sig { - params( - install_prefix: T.any(String, Pathname), - install_libdir: T.any(String, Pathname), - find_framework: String, - ).returns(T::Array[String]) - } - def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework: "LAST") - args = generic_std_cmake_args(install_prefix:, install_libdir:, find_framework:) - - # Avoid false positives for clock_gettime support on 10.11. - # CMake cache entries for other weak symbols may be added here as needed. - args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0" if ::MacOS.version == "10.11" && ::MacOS::Xcode.version >= "8.0" - - # Ensure CMake is using the same SDK we are using. - args << "-DCMAKE_OSX_SYSROOT=#{::MacOS.sdk_for_formula(self).path}" if ::MacOS.sdk_root_needed? - - args - end +module OS + module Mac + module Formula + extend T::Helpers + + requires_ancestor { ::Formula } + + sig { returns(T::Boolean) } + def valid_platform? + requirements.none?(LinuxRequirement) + end + + sig { + params( + install_prefix: T.any(String, Pathname), + install_libdir: T.any(String, Pathname), + find_framework: String, + ).returns(T::Array[String]) + } + def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework: "LAST") + args = generic_std_cmake_args(install_prefix:, install_libdir:, find_framework:) + + # Avoid false positives for clock_gettime support on 10.11. + # CMake cache entries for other weak symbols may be added here as needed. + args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0" if MacOS.version == "10.11" && MacOS::Xcode.version >= "8.0" + + # Ensure CMake is using the same SDK we are using. + args << "-DCMAKE_OSX_SYSROOT=#{MacOS.sdk_for_formula(self).path}" if MacOS.sdk_root_needed? + + args end end end end -Formula.prepend(Homebrew::OS::MacOS::Formula) +Formula.prepend(OS::Mac::Formula) diff --git a/Library/Homebrew/extend/os/mac/formula_installer.rb b/Library/Homebrew/extend/os/mac/formula_installer.rb index b601cbad93bc5..a817d924fb061 100644 --- a/Library/Homebrew/extend/os/mac/formula_installer.rb +++ b/Library/Homebrew/extend/os/mac/formula_installer.rb @@ -1,22 +1,20 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module OS - module MacOS - module FormulaInstaller - extend T::Helpers +module OS + module Mac + module FormulaInstaller + extend T::Helpers - requires_ancestor { ::FormulaInstaller } + requires_ancestor { ::FormulaInstaller } - sig { params(formula: Formula).returns(T.nilable(T::Boolean)) } - def fresh_install?(formula) - !Homebrew::EnvConfig.developer? && !::OS::Mac.version.outdated_release? && - (!installed_as_dependency? || !formula.any_version_installed?) - end + sig { params(formula: Formula).returns(T.nilable(T::Boolean)) } + def fresh_install?(formula) + !Homebrew::EnvConfig.developer? && !OS::Mac.version.outdated_release? && + (!installed_as_dependency? || !formula.any_version_installed?) end end end end -FormulaInstaller.prepend(Homebrew::OS::MacOS::FormulaInstaller) +FormulaInstaller.prepend(OS::Mac::FormulaInstaller) diff --git a/Library/Homebrew/extend/os/mac/linkage_checker.rb b/Library/Homebrew/extend/os/mac/linkage_checker.rb index 6a63b0aefc0d8..b82af034b2121 100644 --- a/Library/Homebrew/extend/os/mac/linkage_checker.rb +++ b/Library/Homebrew/extend/os/mac/linkage_checker.rb @@ -1,20 +1,18 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module OS - module MacOS - module LinkageChecker - private +module OS + module Mac + module LinkageChecker + private - sig { returns(T::Boolean) } - def system_libraries_exist_in_cache? - # In macOS Big Sur and later, system libraries do not exist on-disk and instead exist in a cache. - ::MacOS.version >= :big_sur - end + sig { returns(T::Boolean) } + def system_libraries_exist_in_cache? + # In macOS Big Sur and later, system libraries do not exist on-disk and instead exist in a cache. + MacOS.version >= :big_sur end end end end -LinkageChecker.prepend(Homebrew::OS::MacOS::LinkageChecker) +LinkageChecker.prepend(OS::Mac::LinkageChecker) diff --git a/Library/Homebrew/extend/os/mac/readall.rb b/Library/Homebrew/extend/os/mac/readall.rb index 008c036bd7985..4ad0cd1a05f2f 100644 --- a/Library/Homebrew/extend/os/mac/readall.rb +++ b/Library/Homebrew/extend/os/mac/readall.rb @@ -1,48 +1,46 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module OS - module MacOS - module Readall - extend T::Helpers - - requires_ancestor { Kernel } - - sig { params(tap: Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) } - def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type) - return true if os_name == :linux - - current_macos_version = if os_name.is_a?(Symbol) - MacOSVersion.from_symbol(os_name) - else - ::MacOS.version - end +module OS + module Mac + module Readall + extend T::Helpers + + requires_ancestor { Kernel } - success = T.let(true, T::Boolean) - tap.cask_files.each do |file| - cask = Cask::CaskLoader.load(file) - - # Fine to have missing URLs for unsupported macOS - macos_req = cask.depends_on.macos - next if macos_req&.version && Array(macos_req.version).none? do |macos_version| - current_macos_version.compare(macos_req.comparator, macos_version) - end - - raise "Missing URL" if cask.url.nil? - rescue Interrupt - raise - rescue Exception => e # rubocop:disable Lint/RescueException - os_and_arch = "macOS #{current_macos_version} on #{arch}" - onoe "Invalid cask (#{os_and_arch}): #{file}" - $stderr.puts e - success = false + sig { params(tap: Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) } + def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type) + return true if os_name == :linux + + current_macos_version = if os_name.is_a?(Symbol) + MacOSVersion.from_symbol(os_name) + else + MacOS.version + end + + success = T.let(true, T::Boolean) + tap.cask_files.each do |file| + cask = Cask::CaskLoader.load(file) + + # Fine to have missing URLs for unsupported macOS + macos_req = cask.depends_on.macos + next if macos_req&.version && Array(macos_req.version).none? do |macos_version| + current_macos_version.compare(macos_req.comparator, macos_version) end - success + + raise "Missing URL" if cask.url.nil? + rescue Interrupt + raise + rescue Exception => e # rubocop:disable Lint/RescueException + os_and_arch = "macOS #{current_macos_version} on #{arch}" + onoe "Invalid cask (#{os_and_arch}): #{file}" + $stderr.puts e + success = false end + success end end end end -Readall.singleton_class.prepend(Homebrew::OS::MacOS::Readall) +Readall.singleton_class.prepend(OS::Mac::Readall) diff --git a/Library/Homebrew/extend/os/mac/simulate_system.rb b/Library/Homebrew/extend/os/mac/simulate_system.rb index ac63e8568f1d6..f027eb0b883c6 100644 --- a/Library/Homebrew/extend/os/mac/simulate_system.rb +++ b/Library/Homebrew/extend/os/mac/simulate_system.rb @@ -1,23 +1,21 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module OS - module MacOS - module SimulateSystem - sig { returns(T::Boolean) } - def simulating_or_running_on_macos? - Homebrew::SimulateSystem.os.blank? || [:macos, - *MacOSVersion::SYMBOLS.keys].include?(Homebrew::SimulateSystem.os) - end +module OS + module Mac + module SimulateSystem + sig { returns(T::Boolean) } + def simulating_or_running_on_macos? + Homebrew::SimulateSystem.os.blank? || [:macos, + *MacOSVersion::SYMBOLS.keys].include?(Homebrew::SimulateSystem.os) + end - sig { returns(Symbol) } - def current_os - Homebrew::SimulateSystem.os || ::MacOS.version.to_sym - end + sig { returns(Symbol) } + def current_os + Homebrew::SimulateSystem.os || MacOS.version.to_sym end end end end -Homebrew::SimulateSystem.singleton_class.prepend(Homebrew::OS::MacOS::SimulateSystem) +Homebrew::SimulateSystem.singleton_class.prepend(OS::Mac::SimulateSystem) diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index e3132f98e47ab..c19909e2f9199 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -504,9 +504,9 @@ def audit_glibc return unless @core_tap return if formula.name != "glibc" # Also allow LINUX_GLIBC_NEXT_CI_VERSION for when we're upgrading. - return if [::OS::LINUX_GLIBC_CI_VERSION, ::OS::LINUX_GLIBC_NEXT_CI_VERSION].include?(formula.version.to_s) + return if [OS::LINUX_GLIBC_CI_VERSION, OS::LINUX_GLIBC_NEXT_CI_VERSION].include?(formula.version.to_s) - problem "The glibc version must be #{::OS::LINUX_GLIBC_CI_VERSION}, as needed by our CI on Linux. " \ + problem "The glibc version must be #{OS::LINUX_GLIBC_CI_VERSION}, as needed by our CI on Linux. " \ "The glibc formula is for users who have a system glibc with a lower version, " \ "which allows them to use our Linux bottles, which were compiled against system glibc on CI." end diff --git a/Library/Homebrew/rubocops/move_to_extend_os.rb b/Library/Homebrew/rubocops/move_to_extend_os.rb index 30457528e1976..00aa8742c661c 100644 --- a/Library/Homebrew/rubocops/move_to_extend_os.rb +++ b/Library/Homebrew/rubocops/move_to_extend_os.rb @@ -9,7 +9,7 @@ class MoveToExtendOS < Base MSG = "Move `OS.linux?` and `OS.mac?` calls to `extend/os`." def_node_matcher :os_check?, <<~PATTERN - (send (const {nil? cbase} :OS) {:mac? | :linux?}) + (send (const nil? :OS) {:mac? | :linux?}) PATTERN def on_send(node) diff --git a/Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb b/Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb index 5d1e434c2b4d1..a20b0d949e149 100644 --- a/Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb +++ b/Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb @@ -18,18 +18,4 @@ ^^^^^^^ Homebrew/MoveToExtendOS: Move `OS.linux?` and `OS.mac?` calls to `extend/os`. RUBY end - - it "registers an offense when using `::OS.linux?`" do - expect_offense(<<~RUBY) - ::OS.linux? - ^^^^^^^^^^^ Homebrew/MoveToExtendOS: Move `OS.linux?` and `OS.mac?` calls to `extend/os`. - RUBY - end - - it "registers an offense when using `::OS.mac?`" do - expect_offense(<<~RUBY) - ::OS.mac? - ^^^^^^^^^ Homebrew/MoveToExtendOS: Move `OS.linux?` and `OS.mac?` calls to `extend/os`. - RUBY - end end From 125ced9cf8b59e3dbf66bcc1b1147b7603ddea62 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Thu, 19 Sep 2024 10:43:05 -0700 Subject: [PATCH 6/6] Fix formatting --- Library/Homebrew/extend/os/mac/simulate_system.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/simulate_system.rb b/Library/Homebrew/extend/os/mac/simulate_system.rb index f027eb0b883c6..cba78f44e98f0 100644 --- a/Library/Homebrew/extend/os/mac/simulate_system.rb +++ b/Library/Homebrew/extend/os/mac/simulate_system.rb @@ -6,8 +6,9 @@ module Mac module SimulateSystem sig { returns(T::Boolean) } def simulating_or_running_on_macos? - Homebrew::SimulateSystem.os.blank? || [:macos, - *MacOSVersion::SYMBOLS.keys].include?(Homebrew::SimulateSystem.os) + return true if Homebrew::SimulateSystem.os.blank? + + [:macos, *MacOSVersion::SYMBOLS.keys].include?(Homebrew::SimulateSystem.os) end sig { returns(Symbol) }