Use top-level OS instead

This commit is contained in:
Douglas Eichelberger 2024-09-18 15:33:49 -07:00
parent bb80f063dc
commit 61985bc7f3
20 changed files with 215 additions and 251 deletions

View File

@ -60,7 +60,7 @@ module Homebrew
return false if Homebrew::EnvConfig.no_verify_attestations? return false if Homebrew::EnvConfig.no_verify_attestations?
return true if Homebrew::EnvConfig.verify_attestations? return true if Homebrew::EnvConfig.verify_attestations?
return false if ENV.fetch("CI", false) 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. # Always check credentials last to avoid unnecessary credential extraction.
(Homebrew::EnvConfig.developer? || Homebrew::EnvConfig.devcmdrun?) && GitHub::API.credentials.present? (Homebrew::EnvConfig.developer? || Homebrew::EnvConfig.devcmdrun?) && GitHub::API.credentials.present?

View File

@ -394,10 +394,10 @@ module Homebrew
# On Linux, GCC installation can be moved so long as the whole directory tree is moved together: # 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. # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed.
when Version.formula_optionally_versioned_regex(:gcc) 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. # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451.
when Version.formula_optionally_versioned_regex(:binutils) when Version.formula_optionally_versioned_regex(:binutils)
%r{#{cellar_regex}/binutils} if ::OS.linux? %r{#{cellar_regex}/binutils} if OS.linux?
end end
# rubocop:enable Homebrew/MoveToExtendOS # rubocop:enable Homebrew/MoveToExtendOS

View File

@ -116,12 +116,12 @@ module Homebrew
# TODO: Refactor and move to extend/os # TODO: Refactor and move to extend/os
# rubocop:disable Homebrew/MoveToExtendOS # rubocop:disable Homebrew/MoveToExtendOS
unless ::OS.mac? unless OS.mac?
bundle_args << "--tag" << "~needs_macos" << "--tag" << "~cask" bundle_args << "--tag" << "~needs_macos" << "--tag" << "~cask"
files = files.grep_v(%r{^test/(os/mac|cask)(/.*|_spec\.rb)$}) files = files.grep_v(%r{^test/(os/mac|cask)(/.*|_spec\.rb)$})
end end
unless ::OS.linux? unless OS.linux?
bundle_args << "--tag" << "~needs_linux" bundle_args << "--tag" << "~needs_linux"
files = files.grep_v(%r{^test/os/linux(/.*|_spec\.rb)$}) files = files.grep_v(%r{^test/os/linux(/.*|_spec\.rb)$})
end end

View File

@ -1,7 +1,6 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module Linux module Linux
module Cleanup module Cleanup
@ -26,6 +25,5 @@ module Homebrew
end end
end end
end end
end
Homebrew::Cleanup.prepend(Homebrew::OS::Linux::Cleanup) Homebrew::Cleanup.prepend(OS::Linux::Cleanup)

View File

@ -1,7 +1,6 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module Linux module Linux
module CLI module CLI
@ -28,6 +27,5 @@ module Homebrew
end end
end end
end end
end
Homebrew::CLI::Parser.prepend(Homebrew::OS::Linux::CLI::Parser) Homebrew::CLI::Parser.prepend(OS::Linux::CLI::Parser)

View File

@ -95,11 +95,11 @@ module Homebrew
end end
def check_glibc_minimum_version def check_glibc_minimum_version
return unless ::OS::Linux::Glibc.below_minimum_version? return unless OS::Linux::Glibc.below_minimum_version?
<<~EOS <<~EOS
Your system glibc #{::OS::Linux::Glibc.system_version} is too old. Your system glibc #{OS::Linux::Glibc.system_version} is too old.
We only support glibc #{::OS::Linux::Glibc.minimum_version} or later. We only support glibc #{OS::Linux::Glibc.minimum_version} or later.
#{please_create_pull_requests} #{please_create_pull_requests}
We recommend updating to a newer version via your distribution's We recommend updating to a newer version via your distribution's
package manager, upgrading your distribution to the latest version, package manager, upgrading your distribution to the latest version,
@ -108,11 +108,11 @@ module Homebrew
end end
def check_kernel_minimum_version def check_kernel_minimum_version
return unless ::OS::Linux::Kernel.below_minimum_version? return unless OS::Linux::Kernel.below_minimum_version?
<<~EOS <<~EOS
Your Linux kernel #{::OS.kernel_version} is too old. Your Linux kernel #{OS.kernel_version} is too old.
We only support kernel #{::OS::Linux::Kernel.minimum_version} or later. We only support kernel #{OS::Linux::Kernel.minimum_version} or later.
You will be unable to use binary packages (bottles). You will be unable to use binary packages (bottles).
#{please_create_pull_requests} #{please_create_pull_requests}
We recommend updating to a newer version via your distribution's We recommend updating to a newer version via your distribution's

View File

@ -1,7 +1,6 @@
# typed: true # rubocop:disable Sorbet/StrictSigil # typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module Linux module Linux
module Formula module Formula
@ -53,6 +52,5 @@ module Homebrew
end end
end end
end end
end
Formula.prepend(Homebrew::OS::Linux::Formula) Formula.prepend(OS::Linux::Formula)

View File

@ -78,7 +78,7 @@ module Homebrew
private_class_method :symlink_ld_so private_class_method :symlink_ld_so
def self.setup_preferred_gcc_libs 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? glibc_installed = (HOMEBREW_PREFIX/"opt/glibc/bin/ld.so").readable?
return unless gcc_opt_prefix.readable? return unless gcc_opt_prefix.readable?

View File

@ -1,9 +1,8 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module MacOS module Mac
module Cleaner module Cleaner
private private
@ -14,6 +13,5 @@ module Homebrew
end end
end end
end end
end
Cleaner.prepend(Homebrew::OS::MacOS::Cleaner) Cleaner.prepend(OS::Mac::Cleaner)

View File

@ -1,9 +1,8 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module MacOS module Mac
module Cleanup module Cleanup
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def use_system_ruby? def use_system_ruby?
@ -14,6 +13,5 @@ module Homebrew
end end
end end
end end
end
Homebrew::Cleanup.prepend(Homebrew::OS::MacOS::Cleanup) Homebrew::Cleanup.prepend(OS::Mac::Cleanup)

View File

@ -1,14 +1,13 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module MacOS module Mac
module DevCmd module DevCmd
module Bottle module Bottle
sig { returns(T::Array[String]) } sig { returns(T::Array[String]) }
def tar_args def tar_args
if ::MacOS.version >= :catalina if MacOS.version >= :catalina
["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze ["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze
else else
[].freeze [].freeze
@ -23,6 +22,5 @@ module Homebrew
end end
end end
end end
end
Homebrew::DevCmd::Bottle.prepend(Homebrew::OS::MacOS::DevCmd::Bottle) Homebrew::DevCmd::Bottle.prepend(OS::Mac::DevCmd::Bottle)

View File

@ -110,9 +110,9 @@ module Homebrew
return if ENV["HOMEBREW_INTEGRATION_TEST"] return if ENV["HOMEBREW_INTEGRATION_TEST"]
who = +"We" who = +"We"
what = if ::OS::Mac.version.prerelease? what = if OS::Mac.version.prerelease?
"pre-release version" "pre-release version"
elsif ::OS::Mac.version.outdated_release? elsif OS::Mac.version.outdated_release?
who << " (and Apple)" who << " (and Apple)"
"old version" "old version"
end end
@ -149,7 +149,7 @@ module Homebrew
#{MacOS::Xcode.update_instructions} #{MacOS::Xcode.update_instructions}
EOS EOS
if ::OS::Mac.version.prerelease? if OS::Mac.version.prerelease?
current_path = Utils.popen_read("/usr/bin/xcode-select", "-p") current_path = Utils.popen_read("/usr/bin/xcode-select", "-p")
message += <<~EOS message += <<~EOS
If #{MacOS::Xcode.latest_version} is installed, you may need to: If #{MacOS::Xcode.latest_version} is installed, you may need to:

View File

@ -1,9 +1,8 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module MacOS module Mac
module Formula module Formula
extend T::Helpers extend T::Helpers
@ -26,16 +25,15 @@ module Homebrew
# Avoid false positives for clock_gettime support on 10.11. # Avoid false positives for clock_gettime support on 10.11.
# CMake cache entries for other weak symbols may be added here as needed. # 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" 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. # 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 << "-DCMAKE_OSX_SYSROOT=#{MacOS.sdk_for_formula(self).path}" if MacOS.sdk_root_needed?
args args
end end
end end
end end
end end
end
Formula.prepend(Homebrew::OS::MacOS::Formula) Formula.prepend(OS::Mac::Formula)

View File

@ -1,9 +1,8 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module MacOS module Mac
module FormulaInstaller module FormulaInstaller
extend T::Helpers extend T::Helpers
@ -11,12 +10,11 @@ module Homebrew
sig { params(formula: Formula).returns(T.nilable(T::Boolean)) } sig { params(formula: Formula).returns(T.nilable(T::Boolean)) }
def fresh_install?(formula) def fresh_install?(formula)
!Homebrew::EnvConfig.developer? && !::OS::Mac.version.outdated_release? && !Homebrew::EnvConfig.developer? && !OS::Mac.version.outdated_release? &&
(!installed_as_dependency? || !formula.any_version_installed?) (!installed_as_dependency? || !formula.any_version_installed?)
end end
end end
end end
end end
end
FormulaInstaller.prepend(Homebrew::OS::MacOS::FormulaInstaller) FormulaInstaller.prepend(OS::Mac::FormulaInstaller)

View File

@ -1,20 +1,18 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module MacOS module Mac
module LinkageChecker module LinkageChecker
private private
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def system_libraries_exist_in_cache? 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. # In macOS Big Sur and later, system libraries do not exist on-disk and instead exist in a cache.
::MacOS.version >= :big_sur MacOS.version >= :big_sur
end
end end
end end
end end
end end
LinkageChecker.prepend(Homebrew::OS::MacOS::LinkageChecker) LinkageChecker.prepend(OS::Mac::LinkageChecker)

View File

@ -1,9 +1,8 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module MacOS module Mac
module Readall module Readall
extend T::Helpers extend T::Helpers
@ -16,7 +15,7 @@ module Homebrew
current_macos_version = if os_name.is_a?(Symbol) current_macos_version = if os_name.is_a?(Symbol)
MacOSVersion.from_symbol(os_name) MacOSVersion.from_symbol(os_name)
else else
::MacOS.version MacOS.version
end end
success = T.let(true, T::Boolean) success = T.let(true, T::Boolean)
@ -43,6 +42,5 @@ module Homebrew
end end
end end
end end
end
Readall.singleton_class.prepend(Homebrew::OS::MacOS::Readall) Readall.singleton_class.prepend(OS::Mac::Readall)

View File

@ -1,9 +1,8 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew
module OS module OS
module MacOS module Mac
module SimulateSystem module SimulateSystem
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def simulating_or_running_on_macos? def simulating_or_running_on_macos?
@ -13,11 +12,10 @@ module Homebrew
sig { returns(Symbol) } sig { returns(Symbol) }
def current_os def current_os
Homebrew::SimulateSystem.os || ::MacOS.version.to_sym Homebrew::SimulateSystem.os || MacOS.version.to_sym
end
end end
end end
end end
end end
Homebrew::SimulateSystem.singleton_class.prepend(Homebrew::OS::MacOS::SimulateSystem) Homebrew::SimulateSystem.singleton_class.prepend(OS::Mac::SimulateSystem)

View File

@ -504,9 +504,9 @@ module Homebrew
return unless @core_tap return unless @core_tap
return if formula.name != "glibc" return if formula.name != "glibc"
# Also allow LINUX_GLIBC_NEXT_CI_VERSION for when we're upgrading. # 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, " \ "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." "which allows them to use our Linux bottles, which were compiled against system glibc on CI."
end end

View File

@ -9,7 +9,7 @@ module RuboCop
MSG = "Move `OS.linux?` and `OS.mac?` calls to `extend/os`." MSG = "Move `OS.linux?` and `OS.mac?` calls to `extend/os`."
def_node_matcher :os_check?, <<~PATTERN def_node_matcher :os_check?, <<~PATTERN
(send (const {nil? cbase} :OS) {:mac? | :linux?}) (send (const nil? :OS) {:mac? | :linux?})
PATTERN PATTERN
def on_send(node) def on_send(node)

View File

@ -18,18 +18,4 @@ RSpec.describe RuboCop::Cop::Homebrew::MoveToExtendOS do
^^^^^^^ Homebrew/MoveToExtendOS: Move `OS.linux?` and `OS.mac?` calls to `extend/os`. ^^^^^^^ Homebrew/MoveToExtendOS: Move `OS.linux?` and `OS.mac?` calls to `extend/os`.
RUBY RUBY
end 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 end