mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #20152 from Homebrew/extend-os-class-methods
Fix handling of class methods in `extend/os`
This commit is contained in:
commit
44dcb58f9e
@ -57,6 +57,11 @@ class DevelopmentTools
|
|||||||
:clang
|
:clang
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Version) }
|
||||||
|
def ld64_version
|
||||||
|
Version::NULL
|
||||||
|
end
|
||||||
|
|
||||||
# Get the Clang version.
|
# Get the Clang version.
|
||||||
#
|
#
|
||||||
# @api public
|
# @api public
|
||||||
|
@ -5,18 +5,20 @@ module OS
|
|||||||
module Linux
|
module Linux
|
||||||
module Cask
|
module Cask
|
||||||
module Quarantine
|
module Quarantine
|
||||||
|
module ClassMethods
|
||||||
extend T::Helpers
|
extend T::Helpers
|
||||||
|
|
||||||
requires_ancestor { ::Cask::Quarantine }
|
requires_ancestor { ::Cask::Quarantine }
|
||||||
|
|
||||||
sig { returns(Symbol) }
|
sig { returns(Symbol) }
|
||||||
def self.check_quarantine_support = :linux
|
def check_quarantine_support = :linux
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def self.available? = false
|
def available? = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Cask::Quarantine.prepend(OS::Linux::Cask::Quarantine)
|
Cask::Quarantine.singleton_class.prepend(OS::Linux::Cask::Quarantine::ClassMethods)
|
||||||
|
@ -1,9 +1,21 @@
|
|||||||
# typed: strict
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class CompilerSelector
|
module OS
|
||||||
|
module Linux
|
||||||
|
module CompilerSelector
|
||||||
|
module ClassMethods
|
||||||
|
extend T::Helpers
|
||||||
|
|
||||||
|
requires_ancestor { T.class_of(::CompilerSelector) }
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def self.preferred_gcc
|
def preferred_gcc
|
||||||
OS::LINUX_PREFERRED_GCC_COMPILER_FORMULA
|
OS::LINUX_PREFERRED_GCC_COMPILER_FORMULA
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
CompilerSelector.singleton_class.prepend(OS::Linux::CompilerSelector::ClassMethods)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
module OS
|
module OS
|
||||||
module Linux
|
module Linux
|
||||||
module DevelopmentTools
|
module DevelopmentTools
|
||||||
|
module ClassMethods
|
||||||
extend T::Helpers
|
extend T::Helpers
|
||||||
|
|
||||||
requires_ancestor { ::DevelopmentTools }
|
requires_ancestor { ::DevelopmentTools }
|
||||||
@ -67,6 +68,7 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
DevelopmentTools.singleton_class.prepend(OS::Linux::DevelopmentTools)
|
DevelopmentTools.singleton_class.prepend(OS::Linux::DevelopmentTools::ClassMethods)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
module OS
|
module OS
|
||||||
module Linux
|
module Linux
|
||||||
module SimulateSystem
|
module SimulateSystem
|
||||||
|
module ClassMethods
|
||||||
sig { returns(T.nilable(Symbol)) }
|
sig { returns(T.nilable(Symbol)) }
|
||||||
def os
|
def os
|
||||||
@os ||= T.let(nil, T.nilable(Symbol))
|
@os ||= T.let(nil, T.nilable(Symbol))
|
||||||
@ -23,6 +24,7 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Homebrew::SimulateSystem.singleton_class.prepend(OS::Linux::SimulateSystem)
|
Homebrew::SimulateSystem.singleton_class.prepend(OS::Linux::SimulateSystem::ClassMethods)
|
||||||
|
@ -51,7 +51,7 @@ module OS
|
|||||||
out.puts "Host glibc: #{host_glibc_version}"
|
out.puts "Host glibc: #{host_glibc_version}"
|
||||||
out.puts "#{::DevelopmentTools.host_gcc_path}: #{host_gcc_version}"
|
out.puts "#{::DevelopmentTools.host_gcc_path}: #{host_gcc_version}"
|
||||||
out.puts "/usr/bin/ruby: #{host_ruby_version}" if RUBY_PATH != HOST_RUBY_PATH
|
out.puts "/usr/bin/ruby: #{host_ruby_version}" if RUBY_PATH != HOST_RUBY_PATH
|
||||||
["glibc", CompilerSelector.preferred_gcc, OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA, "xorg"].each do |f|
|
["glibc", ::CompilerSelector.preferred_gcc, OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA, "xorg"].each do |f|
|
||||||
out.puts "#{f}: #{formula_linked_version(f)}"
|
out.puts "#{f}: #{formula_linked_version(f)}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,7 @@ require "os/mac/xcode"
|
|||||||
module OS
|
module OS
|
||||||
module Mac
|
module Mac
|
||||||
module DevelopmentTools
|
module DevelopmentTools
|
||||||
|
module ClassMethods
|
||||||
extend T::Helpers
|
extend T::Helpers
|
||||||
|
|
||||||
requires_ancestor { ::DevelopmentTools }
|
requires_ancestor { ::DevelopmentTools }
|
||||||
@ -37,7 +38,7 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(Version) }
|
sig { returns(Version) }
|
||||||
def self.ld64_version
|
def ld64_version
|
||||||
@ld64_version ||= T.let(begin
|
@ld64_version ||= T.let(begin
|
||||||
json = Utils.popen_read("/usr/bin/ld", "-version_details")
|
json = Utils.popen_read("/usr/bin/ld", "-version_details")
|
||||||
if $CHILD_STATUS.success?
|
if $CHILD_STATUS.success?
|
||||||
@ -86,6 +87,7 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
DevelopmentTools.singleton_class.prepend(OS::Mac::DevelopmentTools)
|
DevelopmentTools.singleton_class.prepend(OS::Mac::DevelopmentTools::ClassMethods)
|
||||||
|
@ -145,7 +145,7 @@ module OS
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
oclp_support_tier = Hardware::CPU.features.include?(:pclmulqdq) ? 2 : 3
|
oclp_support_tier = ::Hardware::CPU.features.include?(:pclmulqdq) ? 2 : 3
|
||||||
|
|
||||||
<<~EOS
|
<<~EOS
|
||||||
You have booted macOS using OpenCore Legacy Patcher.
|
You have booted macOS using OpenCore Legacy Patcher.
|
||||||
|
@ -41,7 +41,7 @@ module OS
|
|||||||
# This is supported starting Xcode 13, which ships ld64-711.
|
# This is supported starting Xcode 13, which ships ld64-711.
|
||||||
# https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes
|
# 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
|
# https://en.wikipedia.org/wiki/Xcode#Xcode_11.0_-_14.x_(since_SwiftUI_framework)_2
|
||||||
OS::Mac::DevelopmentTools.ld64_version >= 711
|
::DevelopmentTools.ld64_version >= 711
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -149,11 +149,11 @@ module OS
|
|||||||
no_fixup_chains
|
no_fixup_chains
|
||||||
|
|
||||||
# Strip build prefixes from linker where supported, for deterministic builds.
|
# Strip build prefixes from linker where supported, for deterministic builds.
|
||||||
append_to_cccfg "o" if OS::Mac::DevelopmentTools.ld64_version >= 512
|
append_to_cccfg "o" if ::DevelopmentTools.ld64_version >= 512
|
||||||
|
|
||||||
# Pass `-ld_classic` whenever the linker is invoked with `-dead_strip_dylibs`
|
# Pass `-ld_classic` whenever the linker is invoked with `-dead_strip_dylibs`
|
||||||
# on `ld` versions that don't properly handle that option.
|
# on `ld` versions that don't properly handle that option.
|
||||||
return unless OS::Mac::DevelopmentTools.ld64_version.between?("1015.7", "1022.1")
|
return unless ::DevelopmentTools.ld64_version.between?("1015.7", "1022.1")
|
||||||
|
|
||||||
append_to_cccfg "c"
|
append_to_cccfg "c"
|
||||||
end
|
end
|
||||||
|
@ -7,6 +7,7 @@ module OS
|
|||||||
module Mac
|
module Mac
|
||||||
module Hardware
|
module Hardware
|
||||||
module CPU
|
module CPU
|
||||||
|
module ClassMethods
|
||||||
extend T::Helpers
|
extend T::Helpers
|
||||||
|
|
||||||
# These methods use info spewed out by sysctl.
|
# These methods use info spewed out by sysctl.
|
||||||
@ -40,7 +41,7 @@ module OS
|
|||||||
::Hardware::CPU.sysctl_bool("sysctl.proc_translated")
|
::Hardware::CPU.sysctl_bool("sysctl.proc_translated")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.features
|
def features
|
||||||
@features ||= ::Hardware::CPU.sysctl_n(
|
@features ||= ::Hardware::CPU.sysctl_n(
|
||||||
"machdep.cpu.features",
|
"machdep.cpu.features",
|
||||||
"machdep.cpu.extfeatures",
|
"machdep.cpu.extfeatures",
|
||||||
@ -54,9 +55,10 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Hardware::CPU.singleton_class.prepend(OS::Mac::Hardware::CPU)
|
Hardware::CPU.singleton_class.prepend(OS::Mac::Hardware::CPU::ClassMethods)
|
||||||
|
|
||||||
module Hardware
|
module Hardware
|
||||||
class CPU
|
class CPU
|
||||||
|
@ -1,13 +1,26 @@
|
|||||||
# typed: strict
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Language
|
module OS
|
||||||
|
module Mac
|
||||||
|
module Language
|
||||||
module Java
|
module Java
|
||||||
def self.java_home(version = nil)
|
module ClassMethods
|
||||||
|
extend T::Helpers
|
||||||
|
|
||||||
|
requires_ancestor { T.class_of(::Language::Java) }
|
||||||
|
|
||||||
|
sig { params(version: T.nilable(String)).returns(T.nilable(Pathname)) }
|
||||||
|
def java_home(version = nil)
|
||||||
openjdk = find_openjdk_formula(version)
|
openjdk = find_openjdk_formula(version)
|
||||||
return unless openjdk
|
return unless openjdk
|
||||||
|
|
||||||
openjdk.opt_libexec/"openjdk.jdk/Contents/Home"
|
openjdk.opt_libexec/"openjdk.jdk/Contents/Home"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Language::Java.singleton_class.prepend(OS::Mac::Language::Java::ClassMethods)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
module OS
|
module OS
|
||||||
module Mac
|
module Mac
|
||||||
module Readall
|
module Readall
|
||||||
|
module ClassMethods
|
||||||
extend T::Helpers
|
extend T::Helpers
|
||||||
|
|
||||||
requires_ancestor { Kernel }
|
requires_ancestor { Kernel }
|
||||||
@ -42,6 +43,7 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Readall.singleton_class.prepend(OS::Mac::Readall)
|
Readall.singleton_class.prepend(OS::Mac::Readall::ClassMethods)
|
||||||
|
@ -1,9 +1,21 @@
|
|||||||
# typed: strict
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Sandbox
|
module OS
|
||||||
|
module Mac
|
||||||
|
module Sandbox
|
||||||
|
module ClassMethods
|
||||||
|
extend T::Helpers
|
||||||
|
|
||||||
|
requires_ancestor { T.class_of(::Sandbox) }
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def self.available?
|
def available?
|
||||||
File.executable?(SANDBOX_EXEC)
|
File.executable?(::Sandbox::SANDBOX_EXEC)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Sandbox.singleton_class.prepend(OS::Mac::Sandbox::ClassMethods)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
module OS
|
module OS
|
||||||
module Mac
|
module Mac
|
||||||
module SimulateSystem
|
module SimulateSystem
|
||||||
|
module ClassMethods
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def simulating_or_running_on_macos?
|
def simulating_or_running_on_macos?
|
||||||
return true if Homebrew::SimulateSystem.os.blank?
|
return true if Homebrew::SimulateSystem.os.blank?
|
||||||
@ -17,6 +18,7 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Homebrew::SimulateSystem.singleton_class.prepend(OS::Mac::SimulateSystem)
|
Homebrew::SimulateSystem.singleton_class.prepend(OS::Mac::SimulateSystem::ClassMethods)
|
||||||
|
@ -7,6 +7,7 @@ module OS
|
|||||||
module Mac
|
module Mac
|
||||||
# Wrapper around UNIXSocket to allow > 104 characters on macOS.
|
# Wrapper around UNIXSocket to allow > 104 characters on macOS.
|
||||||
module UNIXSocketExt
|
module UNIXSocketExt
|
||||||
|
module ClassMethods
|
||||||
extend T::Helpers
|
extend T::Helpers
|
||||||
|
|
||||||
requires_ancestor { Kernel }
|
requires_ancestor { Kernel }
|
||||||
@ -25,6 +26,7 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Utils::UNIXSocketExt.singleton_class.prepend(OS::Mac::UNIXSocketExt)
|
Utils::UNIXSocketExt.singleton_class.prepend(OS::Mac::UNIXSocketExt::ClassMethods)
|
||||||
|
@ -10,7 +10,6 @@ require "utils/fork"
|
|||||||
# Helper class for running a sub-process inside of a sandboxed environment.
|
# Helper class for running a sub-process inside of a sandboxed environment.
|
||||||
class Sandbox
|
class Sandbox
|
||||||
SANDBOX_EXEC = "/usr/bin/sandbox-exec"
|
SANDBOX_EXEC = "/usr/bin/sandbox-exec"
|
||||||
private_constant :SANDBOX_EXEC
|
|
||||||
|
|
||||||
# This is defined in the macOS SDK but Ruby unfortunately does not expose it.
|
# This is defined in the macOS SDK but Ruby unfortunately does not expose it.
|
||||||
# This value can be found by compiling a C program that prints TIOCSCTTY.
|
# This value can be found by compiling a C program that prints TIOCSCTTY.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user