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/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/cleanup.rb b/Library/Homebrew/extend/os/linux/cleanup.rb index b6cd428fe88d6..be63e0e558298 100644 --- a/Library/Homebrew/extend/os/linux/cleanup.rb +++ b/Library/Homebrew/extend/os/linux/cleanup.rb @@ -1,23 +1,29 @@ # typed: strict # frozen_string_literal: true -module Homebrew - class Cleanup - undef use_system_ruby? +module OS + module Linux + module Cleanup + extend T::Helpers - sig { returns(T::Boolean) } - def use_system_ruby? - return false if Homebrew::EnvConfig.force_vendor_ruby? + requires_ancestor { Homebrew::Cleanup } - rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact - system_ruby = Pathname.new("/usr/bin/ruby") - rubies << system_ruby if system_ruby.exist? + sig { returns(T::Boolean) } + def use_system_ruby? + return false if Homebrew::EnvConfig.force_vendor_ruby? - 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 + 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 end end end end + +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 new file mode 100644 index 0000000000000..e5fd59e146cb9 --- /dev/null +++ b/Library/Homebrew/extend/os/linux/cli/parser.rb @@ -0,0 +1,31 @@ +# typed: strict +# frozen_string_literal: true + +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 + +Homebrew::CLI::Parser.prepend(OS::Linux::CLI::Parser) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index a6914a1f02c54..4af57d02c9eef 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -1,52 +1,56 @@ # 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? - - 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 +module OS + module Linux + module Formula + extend T::Helpers - sig { returns(String) } - def loader_path - "$ORIGIN" - end + requires_ancestor { ::Formula } - 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 { 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(T::Boolean) } - def valid_platform? - requirements.none?(MacOSRequirement) + 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 end + +Formula.prepend(OS::Linux::Formula) diff --git a/Library/Homebrew/extend/os/linux/parser.rb b/Library/Homebrew/extend/os/linux/parser.rb deleted file mode 100644 index 7d81e2dddc867..0000000000000 --- a/Library/Homebrew/extend/os/linux/parser.rb +++ /dev/null @@ -1,24 +0,0 @@ -# typed: strict -# frozen_string_literal: true - -module Homebrew - module CLI - class Parser - undef set_default_options - undef validate_options - - def set_default_options - @args["formula?"] = true if @args.respond_to?(:formula?) - end - - 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 diff --git a/Library/Homebrew/extend/os/mac/cleaner.rb b/Library/Homebrew/extend/os/mac/cleaner.rb index 460169c996214..303500fa5e1f6 100644 --- a/Library/Homebrew/extend/os/mac/cleaner.rb +++ b/Library/Homebrew/extend/os/mac/cleaner.rb @@ -1,13 +1,17 @@ # typed: strict # frozen_string_literal: true -class Cleaner - private +module OS + module Mac + module Cleaner + private - undef executable_path? - - 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 + +Cleaner.prepend(OS::Mac::Cleaner) diff --git a/Library/Homebrew/extend/os/mac/cleanup.rb b/Library/Homebrew/extend/os/mac/cleanup.rb index 3565e162b4f4b..08b4ec01454d2 100644 --- a/Library/Homebrew/extend/os/mac/cleanup.rb +++ b/Library/Homebrew/extend/os/mac/cleanup.rb @@ -1,15 +1,17 @@ # typed: strict # frozen_string_literal: true -module Homebrew - class Cleanup - undef use_system_ruby? +module OS + module Mac + module 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? - - Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present? + Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present? + end end end end + +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 26d96cc1ceb63..9d07b436956cd 100644 --- a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb +++ b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb @@ -1,26 +1,26 @@ # typed: strict # frozen_string_literal: true -module Homebrew - module DevCmd - class Bottle < AbstractCommand - undef tar_args - - sig { returns(T::Array[String]) } - def tar_args - if MacOS.version >= :catalina - ["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze - else - [].freeze +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 - end - - undef gnu_tar - 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 + +Homebrew::DevCmd::Bottle.prepend(OS::Mac::DevCmd::Bottle) diff --git a/Library/Homebrew/extend/os/mac/formula.rb b/Library/Homebrew/extend/os/mac/formula.rb index c32a41d9e34c8..4731717dfe475 100644 --- a/Library/Homebrew/extend/os/mac/formula.rb +++ b/Library/Homebrew/extend/os/mac/formula.rb @@ -1,33 +1,39 @@ # typed: strict # frozen_string_literal: true -class Formula - undef valid_platform? - undef std_cmake_args +module OS + module Mac + module Formula + extend T::Helpers - sig { returns(T::Boolean) } - def valid_platform? - requirements.none?(LinuxRequirement) - end + 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:) - 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 + # 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(OS::Mac::Formula) diff --git a/Library/Homebrew/extend/os/mac/formula_installer.rb b/Library/Homebrew/extend/os/mac/formula_installer.rb index 89115c871d052..a817d924fb061 100644 --- a/Library/Homebrew/extend/os/mac/formula_installer.rb +++ b/Library/Homebrew/extend/os/mac/formula_installer.rb @@ -1,12 +1,20 @@ # typed: strict # frozen_string_literal: true -class FormulaInstaller - undef fresh_install? +module OS + module Mac + module FormulaInstaller + extend T::Helpers - 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?) + 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 + end end end + +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 b48d2b90d325a..b82af034b2121 100644 --- a/Library/Homebrew/extend/os/mac/linkage_checker.rb +++ b/Library/Homebrew/extend/os/mac/linkage_checker.rb @@ -1,14 +1,18 @@ # typed: strict # frozen_string_literal: true -class LinkageChecker - undef system_libraries_exist_in_cache? +module OS + module Mac + module LinkageChecker + private - 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 + +LinkageChecker.prepend(OS::Mac::LinkageChecker) diff --git a/Library/Homebrew/extend/os/mac/readall.rb b/Library/Homebrew/extend/os/mac/readall.rb index 6957c2b086c36..4ad0cd1a05f2f 100644 --- a/Library/Homebrew/extend/os/mac/readall.rb +++ b/Library/Homebrew/extend/os/mac/readall.rb @@ -1,39 +1,46 @@ # typed: strict # frozen_string_literal: true -module Readall - class << self - undef valid_casks? +module OS + module Mac + module Readall + 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 - - success = T.let(true, T::Boolean) - tap.cask_files.each do |file| - cask = Cask::CaskLoader.load(file) + 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 - # 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) + current_macos_version = if os_name.is_a?(Symbol) + MacOSVersion.from_symbol(os_name) + else + 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 + + 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 - success end end end + +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 95bc2ef9ae58b..cba78f44e98f0 100644 --- a/Library/Homebrew/extend/os/mac/simulate_system.rb +++ b/Library/Homebrew/extend/os/mac/simulate_system.rb @@ -1,21 +1,22 @@ # typed: strict # frozen_string_literal: true -module Homebrew - class SimulateSystem - class << self - undef simulating_or_running_on_macos? - undef current_os - +module OS + module Mac + module SimulateSystem sig { returns(T::Boolean) } def simulating_or_running_on_macos? - os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(os) + return true if Homebrew::SimulateSystem.os.blank? + + [:macos, *MacOSVersion::SYMBOLS.keys].include?(Homebrew::SimulateSystem.os) end sig { returns(Symbol) } def current_os - os || MacOS.version.to_sym + Homebrew::SimulateSystem.os || MacOS.version.to_sym end end end end + +Homebrew::SimulateSystem.singleton_class.prepend(OS::Mac::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/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