development_tools: Convert to Sorbet typed: strict
This commit is contained in:
parent
fdd7fdd2f6
commit
ed4b6d4246
@ -1,4 +1,4 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "version"
|
require "version"
|
||||||
@ -16,7 +16,7 @@ class DevelopmentTools
|
|||||||
# Don't call tools (cc, make, strip, etc.) directly!
|
# Don't call tools (cc, make, strip, etc.) directly!
|
||||||
# Give the name of the binary you look for as a string to this method
|
# Give the name of the binary you look for as a string to this method
|
||||||
# in order to get the full path back as a Pathname.
|
# in order to get the full path back as a Pathname.
|
||||||
(@locate ||= {}).fetch(tool) do |key|
|
(@locate ||= T.let({}, T.nilable(T::Hash[T.untyped, T.untyped]))).fetch(tool) do |key|
|
||||||
@locate[key] = if File.executable?((path = "/usr/bin/#{tool}"))
|
@locate[key] = if File.executable?((path = "/usr/bin/#{tool}"))
|
||||||
Pathname.new path
|
Pathname.new path
|
||||||
# Homebrew GCCs most frequently; much faster to check this before xcrun
|
# Homebrew GCCs most frequently; much faster to check this before xcrun
|
||||||
@ -62,12 +62,13 @@ class DevelopmentTools
|
|||||||
# @api public
|
# @api public
|
||||||
sig { returns(Version) }
|
sig { returns(Version) }
|
||||||
def clang_version
|
def clang_version
|
||||||
@clang_version ||= if (path = locate("clang")) &&
|
@clang_version ||= T.let(
|
||||||
(build_version = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d(?:\.\d)?)/, 1])
|
if (path = locate("clang")) && (bv = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d(?:\.\d)?)/, 1])
|
||||||
Version.new build_version
|
Version.new(bv)
|
||||||
else
|
else
|
||||||
Version::NULL
|
Version::NULL
|
||||||
end
|
end, T.nilable(Version)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the Clang build version.
|
# Get the Clang build version.
|
||||||
@ -75,13 +76,14 @@ class DevelopmentTools
|
|||||||
# @api public
|
# @api public
|
||||||
sig { returns(Version) }
|
sig { returns(Version) }
|
||||||
def clang_build_version
|
def clang_build_version
|
||||||
@clang_build_version ||= if (path = locate("clang")) &&
|
@clang_build_version ||= T.let(
|
||||||
(build_version = `#{path} --version`[
|
if (path = locate("clang")) &&
|
||||||
%r{clang(-| version [^ ]+ \(tags/RELEASE_)(\d{2,})}, 2])
|
(build_version = `#{path} --version`[%r{clang(-| version [^ ]+ \(tags/RELEASE_)(\d{2,})}, 2])
|
||||||
Version.new build_version
|
Version.new(build_version)
|
||||||
else
|
else
|
||||||
Version::NULL
|
Version::NULL
|
||||||
end
|
end, T.nilable(Version)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the LLVM Clang build version.
|
# Get the LLVM Clang build version.
|
||||||
@ -89,15 +91,14 @@ class DevelopmentTools
|
|||||||
# @api public
|
# @api public
|
||||||
sig { returns(Version) }
|
sig { returns(Version) }
|
||||||
def llvm_clang_build_version
|
def llvm_clang_build_version
|
||||||
@llvm_clang_build_version ||= begin
|
@llvm_clang_build_version ||= T.let(begin
|
||||||
path = Formulary.factory("llvm").opt_prefix/"bin/clang"
|
path = Formulary.factory("llvm").opt_prefix/"bin/clang"
|
||||||
if path.executable? &&
|
if path.executable? && (bv = `#{path} --version`[/clang version (\d+\.\d\.\d)/, 1])
|
||||||
(build_version = `#{path} --version`[/clang version (\d+\.\d\.\d)/, 1])
|
Version.new(bv)
|
||||||
Version.new build_version
|
|
||||||
else
|
else
|
||||||
Version::NULL
|
Version::NULL
|
||||||
end
|
end
|
||||||
end
|
end, T.nilable(Version))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the GCC version.
|
# Get the GCC version.
|
||||||
@ -105,12 +106,11 @@ class DevelopmentTools
|
|||||||
# @api internal
|
# @api internal
|
||||||
sig { params(cc: String).returns(Version) }
|
sig { params(cc: String).returns(Version) }
|
||||||
def gcc_version(cc)
|
def gcc_version(cc)
|
||||||
(@gcc_version ||= {}).fetch(cc) do
|
(@gcc_version ||= T.let({}, T.nilable(T::Hash[String, Version]))).fetch(cc) do
|
||||||
path = HOMEBREW_PREFIX/"opt/#{CompilerSelector.preferred_gcc}/bin"/cc
|
path = HOMEBREW_PREFIX/"opt/#{CompilerSelector.preferred_gcc}/bin"/cc
|
||||||
path = locate(cc) unless path.exist?
|
path = locate(cc) unless path.exist?
|
||||||
version = if path &&
|
version = if path && (bv = `#{path} --version`[/gcc(?:(?:-\d+(?:\.\d)?)? \(.+\))? (\d+\.\d\.\d)/, 1])
|
||||||
(build_version = `#{path} --version`[/gcc(?:(?:-\d+(?:\.\d)?)? \(.+\))? (\d+\.\d\.\d)/, 1])
|
Version.new(bv)
|
||||||
Version.new build_version
|
|
||||||
else
|
else
|
||||||
Version::NULL
|
Version::NULL
|
||||||
end
|
end
|
||||||
@ -120,8 +120,8 @@ class DevelopmentTools
|
|||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def clear_version_cache
|
def clear_version_cache
|
||||||
@clang_version = @clang_build_version = nil
|
@clang_version = @clang_build_version = T.let(nil, T.nilable(Version))
|
||||||
@gcc_version = {}
|
@gcc_version = T.let({}, T.nilable(T::Hash[String, Version]))
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user