Skip to content

Commit d47a45b

Browse files
authored
Merge pull request #21124 from Homebrew/system_config_strict_type
system_config: `typed: strict`
2 parents 922fd1d + cbcb105 commit d47a45b

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

Library/Homebrew/extend/os/linux/system_config.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# typed: true # rubocop:todo Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
require "compilers"
@@ -14,27 +14,31 @@ module ClassMethods
1414

1515
HOST_RUBY_PATH = "/usr/bin/ruby"
1616

17+
sig { returns(T.any(String, Version)) }
1718
def host_glibc_version
1819
version = OS::Linux::Glibc.system_version
1920
return "N/A" if version.null?
2021

2122
version
2223
end
2324

25+
sig { returns(T.any(String, Version)) }
2426
def host_libstdcxx_version
2527
version = OS::Linux::Libstdcxx.system_version
2628
return "N/A" if version.null?
2729

2830
version
2931
end
3032

33+
sig { returns(String) }
3134
def host_gcc_version
3235
gcc = ::DevelopmentTools.host_gcc_path
3336
return "N/A" unless gcc.executable?
3437

35-
Utils.popen_read(gcc, "--version")[/ (\d+\.\d+\.\d+)/, 1]
38+
Utils.popen_read(gcc, "--version")[/ (\d+\.\d+\.\d+)/, 1] || "N/A"
3639
end
3740

41+
sig { params(formula: T.any(Pathname, String)).returns(T.any(String, PkgVersion)) }
3842
def formula_linked_version(formula)
3943
return "N/A" if Homebrew::EnvConfig.no_install_from_api? && !CoreTap.instance.installed?
4044

@@ -43,13 +47,15 @@ def formula_linked_version(formula)
4347
"N/A"
4448
end
4549

50+
sig { returns(String) }
4651
def host_ruby_version
4752
out, _, status = system_command(HOST_RUBY_PATH, args: ["-e", "puts RUBY_VERSION"], print_stderr: false).to_a
4853
return "N/A" unless status.success?
4954

5055
out
5156
end
5257

58+
sig { params(out: T.any(File, StringIO, IO)).void }
5359
def dump_verbose_config(out = $stdout)
5460
kernel = Utils.safe_popen_read("uname", "-mors").chomp
5561
super

Library/Homebrew/extend/os/mac/system_config.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# typed: true # rubocop:disable Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
require "system_command"
@@ -11,6 +11,12 @@ module ClassMethods
1111

1212
requires_ancestor { T.class_of(::SystemConfig) }
1313

14+
sig { void }
15+
def initialize
16+
@xcode = T.let(nil, T.nilable(String))
17+
@clt = T.let(nil, T.nilable(Version))
18+
end
19+
1420
sig { returns(String) }
1521
def describe_clang
1622
return "N/A" if ::SystemConfig.clang.null?
@@ -19,6 +25,7 @@ def describe_clang
1925
"#{::SystemConfig.clang} build #{clang_build_info}"
2026
end
2127

28+
sig { returns(T.nilable(String)) }
2229
def xcode
2330
@xcode ||= if MacOS::Xcode.installed?
2431
xcode = MacOS::Xcode.version.to_s
@@ -27,15 +34,18 @@ def xcode
2734
end
2835
end
2936

37+
sig { returns(T.nilable(Version)) }
3038
def clt
3139
@clt ||= MacOS::CLT.version if MacOS::CLT.installed?
3240
end
3341

42+
sig { params(out: T.any(File, StringIO, IO)).void }
3443
def core_tap_config(out = $stdout)
3544
dump_tap_config(CoreTap.instance, out)
3645
dump_tap_config(CoreCaskTap.instance, out)
3746
end
3847

48+
sig { params(out: T.any(File, StringIO, IO)).void }
3949
def dump_verbose_config(out = $stdout)
4050
super
4151
out.puts "macOS: #{MacOS.full_version}-#{kernel}"

Library/Homebrew/system_config.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# typed: true # rubocop:todo Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
require "hardware"
@@ -13,6 +13,13 @@ module SystemConfig
1313
class << self
1414
include SystemCommand::Mixin
1515

16+
sig { void }
17+
def initialize
18+
@clang = T.let(nil, T.nilable(Version))
19+
@clang_build = T.let(nil, T.nilable(Version))
20+
end
21+
22+
sig { returns(Version) }
1623
def clang
1724
@clang ||= if DevelopmentTools.installed?
1825
DevelopmentTools.clang_version
@@ -21,6 +28,7 @@ def clang
2128
end
2229
end
2330

31+
sig { returns(Version) }
2432
def clang_build
2533
@clang_build ||= if DevelopmentTools.installed?
2634
DevelopmentTools.clang_build_version
@@ -65,12 +73,13 @@ def describe_clang
6573
end
6674
end
6775

76+
sig { params(path: T.nilable(Pathname)).returns(String) }
6877
def describe_path(path)
6978
return "N/A" if path.nil?
7079

7180
realpath = path.realpath
7281
if realpath == path
73-
path
82+
path.to_s
7483
else
7584
"#{path} => #{realpath}"
7685
end
@@ -112,6 +121,7 @@ def describe_curl
112121
end
113122
end
114123

124+
sig { params(tap: Tap, out: T.any(File, StringIO, IO)).void }
115125
def dump_tap_config(tap, out = $stdout)
116126
case tap
117127
when CoreTap
@@ -140,10 +150,12 @@ def dump_tap_config(tap, out = $stdout)
140150
end
141151
end
142152

153+
sig { params(out: T.any(File, StringIO, IO)).void }
143154
def core_tap_config(out = $stdout)
144155
dump_tap_config(CoreTap.instance, out)
145156
end
146157

158+
sig { params(out: T.any(File, StringIO, IO)).void }
147159
def homebrew_config(out = $stdout)
148160
out.puts "HOMEBREW_VERSION: #{HOMEBREW_VERSION}"
149161
out.puts "ORIGIN: #{origin}"
@@ -152,6 +164,7 @@ def homebrew_config(out = $stdout)
152164
out.puts "Branch: #{branch}"
153165
end
154166

167+
sig { params(out: T.any(File, StringIO, IO)).void }
155168
def homebrew_env_config(out = $stdout)
156169
out.puts "HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}"
157170
{
@@ -183,12 +196,14 @@ def homebrew_env_config(out = $stdout)
183196
out.puts "Homebrew Ruby: #{describe_homebrew_ruby}"
184197
end
185198

199+
sig { params(out: T.any(File, StringIO, IO)).void }
186200
def host_software_config(out = $stdout)
187201
out.puts "Clang: #{describe_clang}"
188202
out.puts "Git: #{describe_git}"
189203
out.puts "Curl: #{describe_curl}"
190204
end
191205

206+
sig { params(out: T.any(File, StringIO, IO)).void }
192207
def dump_verbose_config(out = $stdout)
193208
homebrew_config(out)
194209
core_tap_config(out)

0 commit comments

Comments
 (0)