Move remaining OS extensions to prepend

This commit is contained in:
Douglas Eichelberger 2024-09-21 12:24:21 -07:00
parent 7c4f2c19fe
commit eed660e784
28 changed files with 1603 additions and 1526 deletions

View File

@ -177,7 +177,6 @@ class DevelopmentTools
"cpu_family" => Hardware::CPU.family.to_s,
}
end
alias generic_build_system_info build_system_info
end
end

View File

@ -0,0 +1,5 @@
# typed: strict
# module OS::Linux::Cleanup
# include Kernel
# end

View File

@ -1,17 +1,15 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true
require "os/linux/glibc"
class DependencyCollector
undef gcc_dep_if_needed
undef glibc_dep_if_needed
undef init_global_dep_tree_if_needed!
module OS
module Linux
module DependencyCollector
sig { params(related_formula_names: T::Set[String]).returns(T.nilable(Dependency)) }
def gcc_dep_if_needed(related_formula_names)
# gcc is required for libgcc_s.so.1 if glibc or gcc are too old
return unless DevelopmentTools.needs_build_formulae?
return unless ::DevelopmentTools.needs_build_formulae?
return if building_global_dep_tree?
return if related_formula_names.include?(GCC)
return if global_dep_tree[GCC]&.intersect?(related_formula_names)
@ -22,7 +20,7 @@ class DependencyCollector
sig { params(related_formula_names: T::Set[String]).returns(T.nilable(Dependency)) }
def glibc_dep_if_needed(related_formula_names)
return unless DevelopmentTools.needs_libc_formula?
return unless ::DevelopmentTools.needs_libc_formula?
return if building_global_dep_tree?
return if related_formula_names.include?(GLIBC)
return if global_dep_tree[GLIBC]&.intersect?(related_formula_names)
@ -38,7 +36,7 @@ class DependencyCollector
sig { void }
def init_global_dep_tree_if_needed!
return unless DevelopmentTools.needs_build_formulae?
return unless ::DevelopmentTools.needs_build_formulae?
return if building_global_dep_tree?
return unless global_dep_tree.empty?
@ -51,15 +49,15 @@ class DependencyCollector
sig { params(name: String).returns(T.nilable(Formula)) }
def formula_for(name)
@formula_for ||= {}
@formula_for[name] ||= Formula[name]
@formula_for ||= T.let({}, T.nilable(T::Hash[String, Formula]))
@formula_for[name] ||= ::Formula[name]
rescue FormulaUnavailableError
nil
end
sig { params(name: String).returns(T::Array[String]) }
def global_deps_for(name)
@global_deps_for ||= {}
@global_deps_for ||= T.let({}, T.nilable(T::Hash[String, T::Array[String]]))
# Always strip out glibc and gcc from all parts of dependency tree when
# we're calculating their dependency trees. Other parts of Homebrew will
# catch any circular dependencies.
@ -75,8 +73,8 @@ class DependencyCollector
# Use class variables to avoid this expensive logic needing to be done more
# than once.
# rubocop:disable Style/ClassVars
@@global_dep_tree = {}
@@building_global_dep_tree = false
@@global_dep_tree = T.let({}, T::Hash[String, T::Set[String]])
@@building_global_dep_tree = T.let(false, T::Boolean)
sig { returns(T::Hash[String, T::Set[String]]) }
def global_dep_tree
@ -98,4 +96,8 @@ class DependencyCollector
@@building_global_dep_tree.present?
end
# rubocop:enable Style/ClassVars
end
end
end
DependencyCollector.prepend(OS::Linux::DependencyCollector)

View File

@ -1,15 +1,22 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true
class DevelopmentTools
class << self
module OS
module Linux
module DevelopmentTools
extend T::Helpers
requires_ancestor { ::DevelopmentTools }
sig { params(tool: T.any(String, Symbol)).returns(T.nilable(Pathname)) }
def locate(tool)
(@locate ||= {}).fetch(tool) do |key|
@locate[key] = if needs_build_formulae? &&
@locate ||= T.let({}, T.nilable(T::Hash[T.any(String, Symbol), Pathname]))
@locate.fetch(tool) do |key|
@locate[key] = if ::DevelopmentTools.needs_build_formulae? &&
(binutils_path = HOMEBREW_PREFIX/"opt/binutils/bin/#{tool}").executable?
binutils_path
elsif needs_build_formulae? && (glibc_path = HOMEBREW_PREFIX/"opt/glibc/bin/#{tool}").executable?
elsif ::DevelopmentTools.needs_build_formulae? &&
(glibc_path = HOMEBREW_PREFIX/"opt/glibc/bin/#{tool}").executable?
glibc_path
elsif (homebrew_path = HOMEBREW_PREFIX/"bin/#{tool}").executable?
homebrew_path
@ -20,35 +27,38 @@ class DevelopmentTools
end
sig { returns(Symbol) }
def default_compiler
:gcc
end
def default_compiler = :gcc
sig { returns(T::Boolean) }
def needs_libc_formula?
return @needs_libc_formula if defined? @needs_libc_formula
return @needs_libc_formula unless @needs_libc_formula.nil?
@needs_libc_formula = OS::Linux::Glibc.below_ci_version?
@needs_libc_formula = T.let(OS::Linux::Glibc.below_ci_version?, T.nilable(T::Boolean))
@needs_libc_formula = !!@needs_libc_formula
end
sig { returns(T::Boolean) }
def needs_compiler_formula?
return @needs_compiler_formula if defined? @needs_compiler_formula
return @needs_compiler_formula unless @needs_compiler_formula.nil?
gcc = "/usr/bin/gcc"
@needs_compiler_formula = if File.exist?(gcc)
gcc_version(gcc) < OS::LINUX_GCC_CI_VERSION
@needs_compiler_formula = T.let(if File.exist?(gcc)
::DevelopmentTools.gcc_version(gcc) < OS::LINUX_GCC_CI_VERSION
else
true
end
end, T.nilable(T::Boolean))
!!@needs_compiler_formula
end
sig { returns(T::Hash[String, T.nilable(String)]) }
def build_system_info
generic_build_system_info.merge({
super.merge({
"glibc_version" => OS::Linux::Glibc.version.to_s.presence,
"oldest_cpu_family" => Hardware.oldest_cpu.to_s,
})
end
end
end
end
DevelopmentTools.singleton_class.prepend(OS::Linux::DevelopmentTools)

View File

@ -7,10 +7,13 @@ require "hardware"
require "os/linux/glibc"
require "os/linux/kernel"
module Homebrew
module OS
module Linux
module Diagnostic
class Checks
undef fatal_preinstall_checks, supported_configuration_checks
module Checks
extend T::Helpers
requires_ancestor { Homebrew::Diagnostic::Checks }
def fatal_preinstall_checks
%w[
@ -142,7 +145,7 @@ module Homebrew
end
def check_gcc_dependent_linkage
gcc_dependents = Formula.installed.select do |formula|
gcc_dependents = ::Formula.installed.select do |formula|
next false unless formula.tap&.core_tap?
# FIXME: This includes formulae that have no runtime dependency on GCC.
@ -171,4 +174,7 @@ module Homebrew
end
end
end
end
end
Homebrew::Diagnostic::Checks.prepend(OS::Linux::Diagnostic::Checks)

View File

@ -28,7 +28,7 @@ module OS
sig { params(spec: SoftwareSpec).void }
def add_global_deps_to_spec(spec)
return unless DevelopmentTools.needs_build_formulae?
return unless ::DevelopmentTools.needs_build_formulae?
@global_deps ||= begin
dependency_collector = spec.dependency_collector

View File

@ -1,15 +1,12 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true
module Homebrew
class SimulateSystem
class << self
undef os
undef simulating_or_running_on_linux?
undef current_os
module OS
module Linux
module SimulateSystem
sig { returns(T.nilable(Symbol)) }
def os
@os ||= T.let(nil, T.nilable(Symbol))
return :macos if @os.blank? && Homebrew::EnvConfig.simulate_macos_on_linux?
@os
@ -27,3 +24,5 @@ module Homebrew
end
end
end
Homebrew::SimulateSystem.singleton_class.prepend(OS::Linux::SimulateSystem)

View File

@ -8,7 +8,7 @@ module OS
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

View File

@ -1,10 +1,9 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true
class DependencyCollector
undef git_dep_if_needed, subversion_dep_if_needed, cvs_dep_if_needed,
xz_dep_if_needed, unzip_dep_if_needed, bzip2_dep_if_needed
module OS
module Mac
module DependencyCollector
def git_dep_if_needed(tags); end
def subversion_dep_if_needed(tags)
@ -20,4 +19,8 @@ class DependencyCollector
def unzip_dep_if_needed(tags); end
def bzip2_dep_if_needed(tags); end
end
end
end
DependencyCollector.prepend(OS::Mac::DependencyCollector)

View File

@ -1,18 +1,20 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true
require "os/mac/xcode"
class DevelopmentTools
class << self
alias generic_locate locate
undef installed?, default_compiler, curl_handles_most_https_certificates?,
subversion_handles_most_https_certificates?
module OS
module Mac
module DevelopmentTools
extend T::Helpers
requires_ancestor { ::DevelopmentTools }
sig { params(tool: T.any(String, Symbol)).returns(T.nilable(Pathname)) }
def locate(tool)
(@locate ||= {}).fetch(tool) do |key|
@locate[key] = if (located_tool = generic_locate(tool))
@locate ||= T.let({}, T.nilable(T::Hash[T.any(String, Symbol), Pathname]))
@locate.fetch(tool) do |key|
@locate[key] = if (located_tool = super(tool))
located_tool
else
path = Utils.popen_read("/usr/bin/xcrun", "-no-cache", "-find", tool, err: :close).chomp
@ -35,15 +37,15 @@ class DevelopmentTools
end
sig { returns(Version) }
def ld64_version
@ld64_version ||= begin
def self.ld64_version
@ld64_version ||= T.let(begin
json = Utils.popen_read("/usr/bin/ld", "-version_details")
if $CHILD_STATUS.success?
Version.parse(JSON.parse(json)["version"])
else
Version::NULL
end
end
end, T.nilable(Version))
end
sig { returns(T::Boolean) }
@ -80,7 +82,10 @@ class DevelopmentTools
"clt" => MacOS::CLT.version.to_s.presence,
"preferred_perl" => MacOS.preferred_perl_version,
}
generic_build_system_info.merge build_info
super.merge build_info
end
end
end
end
DevelopmentTools.singleton_class.prepend(OS::Mac::DevelopmentTools)

View File

@ -1,7 +1,8 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true
module Homebrew
module OS
module Mac
module Diagnostic
class Volumes
def initialize
@ -41,10 +42,10 @@ module Homebrew
end
end
class Checks
undef fatal_preinstall_checks, fatal_build_from_source_checks,
fatal_setup_build_environment_checks, supported_configuration_checks,
build_from_source_checks
module Checks
extend T::Helpers
requires_ancestor { Homebrew::Diagnostic::Checks }
def fatal_preinstall_checks
checks = %w[
@ -52,7 +53,7 @@ module Homebrew
]
# We need the developer tools for `codesign`.
checks << "check_for_installed_developer_tools" if Hardware::CPU.arm?
checks << "check_for_installed_developer_tools" if ::Hardware::CPU.arm?
checks.freeze
end
@ -91,7 +92,7 @@ module Homebrew
end
def check_for_non_prefixed_findutils
findutils = Formula["findutils"]
findutils = ::Formula["findutils"]
return unless findutils.any_version_installed?
gnubin = %W[#{findutils.opt_libexec}/gnubin #{findutils.libexec}/gnubin]
@ -206,7 +207,7 @@ module Homebrew
<<~EOS
Xcode alone is not sufficient on #{MacOS.version.pretty_name}.
#{DevelopmentTools.installation_instructions}
#{::DevelopmentTools.installation_instructions}
EOS
end
@ -307,7 +308,7 @@ module Homebrew
if gettext&.linked_keg&.directory?
allowlist = ["#{HOMEBREW_CELLAR}/gettext"]
if Hardware::CPU.physical_cpu_arm64?
if ::Hardware::CPU.physical_cpu_arm64?
allowlist += %W[
#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar/gettext
#{HOMEBREW_DEFAULT_PREFIX}/Cellar/gettext
@ -403,7 +404,7 @@ module Homebrew
end
def check_if_supported_sdk_available
return unless DevelopmentTools.installed?
return unless ::DevelopmentTools.installed?
return unless MacOS.sdk_root_needed?
return if MacOS.sdk
@ -464,4 +465,7 @@ module Homebrew
end
end
end
end
end
Homebrew::Diagnostic::Checks.prepend(OS::Mac::Diagnostic::Checks)

View File

@ -37,6 +37,6 @@ module SharedEnvExtension
# This is supported starting Xcode 13, which ships ld64-711.
# https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes
# https://en.wikipedia.org/wiki/Xcode#Xcode_11.0_-_14.x_(since_SwiftUI_framework)_2
DevelopmentTools.ld64_version >= 711
OS::Mac::DevelopmentTools.ld64_version >= 711
end
end

View File

@ -1,8 +1,12 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true
module Stdenv
undef homebrew_extra_pkg_config_paths
module OS
module Mac
module Stdenv
extend T::Helpers
requires_ancestor { ::Stdenv }
sig { returns(T::Array[Pathname]) }
def homebrew_extra_pkg_config_paths
@ -12,7 +16,7 @@ module Stdenv
sig {
params(
formula: T.nilable(Formula),
formula: T.nilable(::Formula),
cc: T.nilable(String),
build_bottle: T.nilable(T::Boolean),
bottle_arch: T.nilable(String),
@ -20,8 +24,8 @@ module Stdenv
debug_symbols: T.nilable(T::Boolean),
).void
}
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
debug_symbols: false)
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil,
testing_formula: false, debug_symbols: false)
generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:,
testing_formula:, debug_symbols:)
@ -114,4 +118,8 @@ module Stdenv
def no_fixup_chains
append "LDFLAGS", "-Wl,-no_fixup_chains" if no_fixup_chains_support?
end
end
end
end
Stdenv.prepend(OS::Mac::Stdenv)

View File

@ -1,29 +1,26 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true
module Superenv
class << self
module OS
module Mac
module Superenv
extend T::Helpers
requires_ancestor { ::Superenv }
module ClassMethods
# The location of Homebrew's shims on macOS.
def shims_path
HOMEBREW_SHIMS_PATH/"mac/super"
end
undef bin
def bin
return unless DevelopmentTools.installed?
return unless ::DevelopmentTools.installed?
shims_path.realpath
end
end
undef homebrew_extra_pkg_config_paths,
homebrew_extra_isystem_paths, homebrew_extra_library_paths,
homebrew_extra_cmake_include_paths,
homebrew_extra_cmake_library_paths,
homebrew_extra_cmake_frameworks_paths,
determine_cccfg
sig { returns(T::Array[Pathname]) }
def homebrew_extra_pkg_config_paths
[Pathname("/usr/lib/pkgconfig"), Pathname("#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}")]
@ -51,7 +48,7 @@ module Superenv
paths = []
if compiler == :llvm_clang
paths << "#{self["HOMEBREW_SDKROOT"]}/usr/lib"
paths << Formula["llvm"].opt_lib.to_s
paths << ::Formula["llvm"].opt_lib.to_s
end
paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"
paths
@ -66,7 +63,9 @@ module Superenv
end
def homebrew_extra_cmake_library_paths
[Pathname("#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries")]
[Pathname(
"#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries",
)]
end
def homebrew_extra_cmake_frameworks_paths
@ -83,8 +82,8 @@ module Superenv
end
# @private
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
debug_symbols: false)
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil,
testing_formula: false, debug_symbols: false)
sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk
is_xcode_sdk = sdk&.source == :xcode
@ -105,7 +104,7 @@ module Superenv
if deps.none? { |d| d.name == "m4" } &&
MacOS.active_developer_dir == MacOS::CLT::PKG_PATH &&
!File.exist?("#{MacOS::CLT::PKG_PATH}/usr/bin/m4") &&
(gm4 = DevelopmentTools.locate("gm4").to_s).present?
(gm4 = ::DevelopmentTools.locate("gm4").to_s).present?
self["M4"] = gm4
end
@ -152,11 +151,13 @@ module Superenv
no_fixup_chains
# Strip build prefixes from linker where supported, for deterministic builds.
append_to_cccfg "o" if DevelopmentTools.ld64_version >= 512
append_to_cccfg "o" if OS::Mac::DevelopmentTools.ld64_version >= 512
# Pass `-ld_classic` whenever the linker is invoked with `-dead_strip_dylibs`
# on `ld` versions that don't properly handle that option.
append_to_cccfg "c" if DevelopmentTools.ld64_version >= "1015.7" && DevelopmentTools.ld64_version <= "1022.1"
if OS::Mac::DevelopmentTools.ld64_version >= "1015.7" && OS::Mac::DevelopmentTools.ld64_version <= "1022.1"
append_to_cccfg "c"
end
end
def no_weak_imports
@ -166,4 +167,9 @@ module Superenv
def no_fixup_chains
append_to_cccfg "f" if no_fixup_chains_support?
end
end
end
end
Superenv.singleton_class.prepend(OS::Mac::Superenv::ClassMethods)
Superenv.prepend(OS::Mac::Superenv)

View File

@ -97,7 +97,7 @@ module FormulaCellarChecks
return unless formula.prefix.directory?
return if formula.tap&.audit_exception(:flat_namespace_allowlist, formula.name)
keg = Keg.new(formula.prefix)
keg = ::Keg.new(formula.prefix)
flat_namespace_files = keg.mach_o_files.reject do |file|
next true unless file.dylib?

View File

@ -10,7 +10,7 @@ module OS
sig { params(formula: Formula).returns(T.nilable(T::Boolean)) }
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?)
end
end

View File

@ -3,10 +3,11 @@
require "macho"
module Hardware
class CPU
class << self
undef type, family, features, sse4?
module OS
module Mac
module Hardware
module CPU
extend T::Helpers
# These methods use info spewed out by sysctl.
# Look in <mach/machine.h> for decoding info.
@ -22,9 +23,9 @@ module Hardware
end
def family
if arm?
if ::Hardware::CPU.arm?
arm_family
elsif intel?
elsif ::Hardware::CPU.intel?
intel_family
else
:dunno
@ -174,4 +175,7 @@ module Hardware
end
end
end
end
end
Hardware::CPU.singleton_class.prepend(OS::Mac::Hardware::CPU)

View File

@ -23,17 +23,17 @@ class Keg
GENERIC_MUST_BE_WRITABLE_DIRECTORIES +
[HOMEBREW_PREFIX/"Frameworks"]
).sort.uniq.freeze
end
undef binary_executable_or_library_files
def binary_executable_or_library_files
mach_o_files
end
module OS
module Mac
module Keg
def binary_executable_or_library_files = mach_o_files
def codesign_patched_binary(file)
return if MacOS.version < :big_sur
unless Hardware::CPU.arm?
unless ::Hardware::CPU.arm?
result = system_command("codesign", args: ["--verify", file], print_stderr: false)
return unless result.stderr.match?(/invalid signature/i)
end
@ -94,8 +94,6 @@ class Keg
end
end
undef prepare_debug_symbols
def prepare_debug_symbols
binary_executable_or_library_files.each do |file|
odebug "Extracting symbols #{file}"
@ -111,8 +109,6 @@ class Keg
end
end
undef consistent_reproducible_symlink_permissions!
# Needed to make symlink permissions consistent on macOS and Linux for
# reproducible bottles.
def consistent_reproducible_symlink_permissions!
@ -120,4 +116,8 @@ class Keg
File.lchmod 0777, file if file.symlink?
end
end
end
end
end
Keg.prepend(OS::Mac::Keg)

View File

@ -1,10 +1,14 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true
class Keg
class << self
undef file_linked_libraries
module OS
module Mac
module Keg
extend T::Helpers
requires_ancestor { ::Keg }
module ClassMethods
def file_linked_libraries(file, string)
# Check dynamic library linkage. Importantly, do not perform for static
# libraries, which will falsely report "linkage" to themselves.
@ -16,8 +20,6 @@ class Keg
end
end
undef relocate_dynamic_linkage
def relocate_dynamic_linkage(relocation)
mach_o_files.each do |file|
file.ensure_writable do
@ -112,10 +114,10 @@ class Keg
# bad_name relative to the lib directory, so that we can skip the more
# expensive recursive search if possible.
def fixed_name(file, bad_name)
if bad_name.start_with? PREFIX_PLACEHOLDER
bad_name.sub(PREFIX_PLACEHOLDER, HOMEBREW_PREFIX)
elsif bad_name.start_with? CELLAR_PLACEHOLDER
bad_name.sub(CELLAR_PLACEHOLDER, HOMEBREW_CELLAR)
if bad_name.start_with? ::Keg::PREFIX_PLACEHOLDER
bad_name.sub(::Keg::PREFIX_PLACEHOLDER, HOMEBREW_PREFIX)
elsif bad_name.start_with? ::Keg::CELLAR_PLACEHOLDER
bad_name.sub(::Keg::CELLAR_PLACEHOLDER, HOMEBREW_CELLAR)
elsif (file.dylib? || file.mach_o_bundle?) && (file.dirname/bad_name).exist?
"@loader_path/#{bad_name}"
elsif file.mach_o_executable? && (lib/bad_name).exist?
@ -209,11 +211,11 @@ class Keg
else
"/usr/bin/perl#{MacOS.preferred_perl_version}"
end
relocation.add_replacement_pair(:perl, PERL_PLACEHOLDER, perl_path)
relocation.add_replacement_pair(:perl, ::Keg::PERL_PLACEHOLDER, perl_path)
if (openjdk = openjdk_dep_name_if_applicable)
openjdk_path = HOMEBREW_PREFIX/"opt"/openjdk/"libexec/openjdk.jdk/Contents/Home"
relocation.add_replacement_pair(:java, JAVA_PLACEHOLDER, openjdk_path.to_s)
relocation.add_replacement_pair(:java, ::Keg::JAVA_PLACEHOLDER, openjdk_path.to_s)
end
relocation
@ -252,4 +254,9 @@ class Keg
filename.start_with?(HOMEBREW_TEMP.to_s) || filename.start_with?(HOMEBREW_TEMP.realpath.to_s)
end
end
end
end
Keg.singleton_class.prepend(OS::Mac::Keg::ClassMethods)
Keg.prepend(OS::Mac::Keg)

View File

@ -9,7 +9,7 @@ module OS
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)
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)

View File

@ -13,7 +13,7 @@ module OS
sig { returns(Symbol) }
def current_os
Homebrew::SimulateSystem.os || MacOS.version.to_sym
::Homebrew::SimulateSystem.os || MacOS.version.to_sym
end
end
end

View File

@ -3,20 +3,26 @@
require "system_command"
module OS
module Mac
module SystemConfig
sig { returns(String) }
def describe_clang
return "N/A" if ::SystemConfig.clang.null?
clang_build_info = ::SystemConfig.clang_build.null? ? "(parse error)" : ::SystemConfig.clang_build
"#{::SystemConfig.clang} build #{clang_build_info}"
end
end
end
end
SystemConfig.prepend(OS::Mac::SystemConfig)
module SystemConfig
class << self
include SystemCommand::Mixin
undef describe_clang
sig { returns(String) }
def describe_clang
return "N/A" if clang.null?
clang_build_info = clang_build.null? ? "(parse error)" : clang_build
"#{clang} build #{clang_build_info}"
end
def xcode
@xcode ||= if MacOS::Xcode.installed?
xcode = MacOS::Xcode.version.to_s

View File

@ -0,0 +1,9 @@
# typed: strict
module Hardware
class CPU
class << self
include OS::Mac::Hardware::CPU
end
end
end

5
Library/Homebrew/keg.rbi Normal file
View File

@ -0,0 +1,5 @@
# typed: strict
class Keg
include OS::Mac::Keg
end

View File

@ -210,7 +210,6 @@ class Keg
# for GNU grep; overridden for BSD grep on OS X
"-lr"
end
alias generic_recursive_fgrep_args recursive_fgrep_args
def egrep_args
grep_bin = "grep"

View File

@ -151,7 +151,7 @@ module OS
# Xcode.prefix is pretty smart, so let's look inside to find the sdk
sdk_prefix = "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs"
# Finally query Xcode itself (this is slow, so check it last)
sdk_platform_path = Utils.popen_read(DevelopmentTools.locate("xcrun"), "--show-sdk-platform-path").chomp
sdk_platform_path = Utils.popen_read(::DevelopmentTools.locate("xcrun"), "--show-sdk-platform-path").chomp
sdk_prefix = File.join(sdk_platform_path, "Developer", "SDKs") unless File.directory? sdk_prefix
sdk_prefix

View File

@ -227,7 +227,7 @@ module OS
sig { returns(String) }
def self.detect_version_from_clang_version
version = DevelopmentTools.clang_version
version = ::DevelopmentTools.clang_version
return "dunno" if version.null?

View File

@ -87,7 +87,7 @@ class AbstractTab
"tap" => nil,
"tap_git_head" => nil,
},
"built_on" => DevelopmentTools.generic_build_system_info,
"built_on" => DevelopmentTools.build_system_info,
}
new(attributes)