Merge pull request #20526 from Homebrew/typed-strict

Miscellaneous `typed: strict`
This commit is contained in:
Mike McQuaid 2025-08-21 06:34:47 +00:00 committed by GitHub
commit ae76de7859
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 12 deletions

View File

@ -276,7 +276,7 @@ module Homebrew
puts
new_major_version, new_minor_version, new_patch_version = new_tag.split(".").map(&:to_i)
old_major_version, old_minor_version = old_tag.split(".")[0, 2].map(&:to_i) if old_tag.present?
old_major_version, old_minor_version = T.must(old_tag.split(".")[0, 2]).map(&:to_i) if old_tag.present?
if old_tag.blank? || new_major_version > old_major_version || new_minor_version > old_minor_version
puts <<~EOS
The #{new_major_version}.#{new_minor_version}.0 release notes are available on the Homebrew Blog:

View File

@ -83,10 +83,10 @@ module OS
return if !MacOS.sdk_root_needed? && sdk&.source != :xcode
Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks)
sdk = sdk.path
sdk = T.must(sdk).path
# Extra setup to support Xcode 4.3+ without CLT.
self["SDKROOT"] = sdk
self["SDKROOT"] = sdk.to_s
# Tell clang/gcc where system include's are:
append_path "CPATH", "#{sdk}/usr/include"
# The -isysroot is needed, too, because of the Frameworks

View File

@ -88,7 +88,7 @@ module OS
if is_xcode_sdk || MacOS.sdk_root_needed?
Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks)
self["HOMEBREW_SDKROOT"] = sdk.path if sdk
self["HOMEBREW_SDKROOT"] = sdk.path.to_s if sdk
end
self["HOMEBREW_DEVELOPER_DIR"] = if is_xcode_sdk

View File

@ -28,7 +28,7 @@ module OS
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 << "-DCMAKE_OSX_SYSROOT=#{T.must(MacOS.sdk_for_formula(self)).path}" if MacOS.sdk_root_needed?
args
end

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true
module OS
@ -9,6 +9,7 @@ module OS
sig { returns(Version) }
def system_version
@system_version ||= T.let(nil, T.nilable(Version))
@system_version ||= begin
version = Utils.popen_read("/usr/bin/ldd", "--version")[/ (\d+\.\d+)/, 1]
if version
@ -21,6 +22,7 @@ module OS
sig { returns(Version) }
def version
@version ||= T.let(nil, T.nilable(Version))
@version ||= begin
version = Utils.popen_read(HOMEBREW_PREFIX/"opt/glibc/bin/ldd", "--version")[/ (\d+\.\d+)/, 1]
if version

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true
require "macos_version"
@ -20,7 +20,7 @@ module OS
# Provide MacOS alias for backwards compatibility and nicer APIs.
::MacOS = OS::Mac
VERSION = ENV.fetch("HOMEBREW_MACOS_VERSION").chomp.freeze
VERSION = T.let(ENV.fetch("HOMEBREW_MACOS_VERSION").chomp.freeze, String)
private_constant :VERSION
# This can be compared to numerics, strings, or symbols
@ -29,7 +29,7 @@ module OS
# @api internal
sig { returns(MacOSVersion) }
def self.version
@version ||= full_version.strip_patch
@version ||= T.let(full_version.strip_patch, T.nilable(MacOSVersion))
end
# This can be compared to numerics, strings, or symbols
@ -38,6 +38,7 @@ module OS
# @api internal
sig { returns(MacOSVersion) }
def self.full_version
@full_version ||= T.let(nil, T.nilable(MacOSVersion))
@full_version ||= if (fake_macos = ENV.fetch("HOMEBREW_FAKE_MACOS", nil)) # for Portable Ruby building
MacOSVersion.new(fake_macos)
else
@ -71,6 +72,7 @@ module OS
sig { returns(T::Array[String]) }
def self.languages
@languages ||= T.let(nil, T.nilable(T::Array[String]))
return @languages if @languages
os_langs = Utils.popen_read("defaults", "read", "-g", "AppleLanguages")
@ -83,13 +85,17 @@ module OS
@languages = os_langs
end
sig { returns(T.nilable(String)) }
def self.language
languages.first
end
sig { returns(String) }
def self.active_developer_dir
@active_developer_dir ||= Utils.popen_read("/usr/bin/xcode-select", "-print-path").strip
@active_developer_dir ||= T.let(
Utils.popen_read("/usr/bin/xcode-select", "-print-path").strip,
T.nilable(String),
)
end
sig { returns(T::Boolean) }
@ -114,6 +120,7 @@ module OS
# If no specific SDK is requested, the SDK matching the OS version is returned,
# if available. Otherwise, the latest SDK is returned.
sig { returns(T.any(CLTSDKLocator, XcodeSDKLocator)) }
def self.sdk_locator
if CLT.installed? && CLT.provides_sdk?
CLT.sdk_locator
@ -122,10 +129,18 @@ module OS
end
end
sig { params(version: T.nilable(MacOSVersion)).returns(T.nilable(SDK)) }
def self.sdk(version = nil)
sdk_locator.sdk_if_applicable(version)
end
sig {
params(
formula: Formula,
version: T.nilable(MacOSVersion),
check_only_runtime_requirements: T::Boolean,
).returns(T.nilable(SDK))
}
def self.sdk_for_formula(formula, version = nil, check_only_runtime_requirements: false)
# If the formula requires Xcode, don't return the CLT SDK
# If check_only_runtime_requirements is true, don't necessarily return the
@ -141,11 +156,13 @@ module OS
end
# Returns the path to an SDK or nil, following the rules set by {sdk}.
sig { params(version: T.nilable(MacOSVersion)).returns(T.nilable(Pathname)) }
def self.sdk_path(version = nil)
s = sdk(version)
s&.path
end
sig { params(version: T.nilable(MacOSVersion)).returns(T.nilable(Pathname)) }
def self.sdk_path_if_needed(version = nil)
# Prefer CLT SDK when both Xcode and the CLT are installed.
# Expected results:
@ -165,6 +182,7 @@ module OS
# - {https://github.com/Homebrew/legacy-homebrew/issues/13}
# - {https://github.com/Homebrew/legacy-homebrew/issues/41}
# - {https://github.com/Homebrew/legacy-homebrew/issues/48}
sig { returns(T::Array[Pathname]) }
def self.macports_or_fink
paths = []
@ -209,12 +227,15 @@ module OS
sig { params(ids: String).returns(T::Array[String]) }
def self.mdfind(*ids)
@mdfind ||= T.let(nil, T.nilable(T::Hash[T::Array[String], String]))
(@mdfind ||= {}).fetch(ids) do
@mdfind[ids] = Utils.popen_read("/usr/bin/mdfind", mdfind_query(*ids)).split("\n")
end
end
sig { params(id: String).returns(String) }
def self.pkgutil_info(id)
@pkginfo ||= T.let(nil, T.nilable(T::Hash[String, String]))
(@pkginfo ||= {}).fetch(id) do |key|
@pkginfo[key] = Utils.popen_read("/usr/sbin/pkgutil", "--pkg-info", key).strip
end

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true
require "services/formula_wrapper"
@ -24,6 +24,7 @@ module Homebrew
end
# List all available services with status, user, and path to the file.
sig { returns(T::Array[T::Hash[Symbol, T.anything]]) }
def self.services_list
available_services.map(&:to_hash)
end

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true
require "utils/popen"
@ -6,6 +6,10 @@ require "utils/popen"
module Homebrew
# Helper functions for reading and writing settings.
module Settings
sig {
params(setting: T.any(String, Symbol), repo: Pathname)
.returns(T.nilable(String))
}
def self.read(setting, repo: HOMEBREW_REPOSITORY)
return unless (repo/".git/config").exist?
@ -16,6 +20,7 @@ module Homebrew
value
end
sig { params(setting: T.any(String, Symbol), value: T.any(String, T::Boolean), repo: Pathname).void }
def self.write(setting, value, repo: HOMEBREW_REPOSITORY)
return unless (repo/".git/config").exist?
@ -26,6 +31,7 @@ module Homebrew
Kernel.system("git", "-C", repo.to_s, "config", "--replace-all", "homebrew.#{setting}", value, exception: true)
end
sig { params(setting: T.any(String, Symbol), repo: Pathname).void }
def self.delete(setting, repo: HOMEBREW_REPOSITORY)
return unless (repo/".git/config").exist?