Module: SystemConfig Private

Extended by:
SystemCommand::Mixin
Defined in:
system_config.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper module for querying information about the system configuration.

Class Method Summary collapse

Methods included from SystemCommand::Mixin

command_sandbox, system_command, system_command!

Class Method Details

.branch ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



55
56
57
# File 'system_config.rb', line 55

def branch
  homebrew_head_info[2] || "(none)"
end

.clang ⇒ Version

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



24
25
26
27
28
29
30
# File 'system_config.rb', line 24

def clang
  @clang ||= if DevelopmentTools.installed?
    DevelopmentTools.clang_version
  else
    Version::NULL
  end
end

.clang_build ⇒ Version

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



33
34
35
36
37
38
39
# File 'system_config.rb', line 33

def clang_build
  @clang_build ||= if DevelopmentTools.installed?
    DevelopmentTools.clang_build_version
  else
    Version::NULL
  end
end

.config_sections ⇒ Array<Symbol>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



231
232
233
# File 'system_config.rb', line 231

def config_sections
  [:homebrew_config, :core_tap_config, :homebrew_env_config, :hardware_config, :host_software_config]
end

.core_tap_config(out = $stdout) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • out (File, StringIO, IO) (defaults to: $stdout)


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'system_config.rb', line 159

def core_tap_config(out = $stdout)
  dump_tap_config(CoreTap.instance, out)
  dump_tap_config(CoreCaskTap.instance, out)
  return if Homebrew::EnvConfig.no_install_from_api?

  threshold = OS.third_party_homebrew&.api_delay_hours
  return unless threshold

  delay_hours = Homebrew::API.cached_packages_delay_hours
  return if delay_hours.nil? || delay_hours < threshold

  out.puts <<~EOS
    Package metadata was #{delay_hours} hours old at the last API refresh.
    A proxy or mirror may be delaying updates. A cooldown this long can leave
    your system exposed for #{delay_hours} more hours after Homebrew publishes a zero-day fix
    for an installed package.
  EOS
end

.describe_clang ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



75
76
77
78
79
80
81
82
83
# File 'system_config.rb', line 75

def describe_clang
  return "N/A" if clang.null?

  if clang_build.null?
    clang.to_s
  else
    "#{clang} build #{clang_build}"
  end
end

.describe_curl ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



113
114
115
116
117
118
119
120
121
122
# File 'system_config.rb', line 113

def describe_curl
  out = system_command(Utils::Curl.curl_executable, args: ["--version"], verbose: false).stdout

  match_data = /^curl (?<curl_version>[\d.]+)/.match(out)
  if match_data
    "#{match_data[:curl_version]} => #{Utils::Curl.curl_path}"
  else
    "N/A"
  end
end

.describe_git ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



106
107
108
109
110
# File 'system_config.rb', line 106

def describe_git
  return "N/A" unless Utils::Git.available?

  "#{Utils::Git.version} => #{Utils::Git.path}"
end

.describe_homebrew_ruby ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



86
87
88
# File 'system_config.rb', line 86

def describe_homebrew_ruby
  "#{RUBY_VERSION} => #{RUBY_PATH}"
end

.dump_tap_config(tap, out = $stdout) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • tap (Tap)
  • out (File, StringIO, IO) (defaults to: $stdout)


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'system_config.rb', line 125

def dump_tap_config(tap, out = $stdout)
  tap_name = case tap
  when CoreTap
    "Core tap"
  when CoreCaskTap
    "Core cask tap"
  else
    raise ArgumentError, "Unknown tap: #{tap}"
  end

  if tap.installed?
    out.puts "#{tap_name} origin: #{tap.remote}" if tap.remote != tap.default_remote
    head, last_commit, branch = tap.git_repository.head_info
    display_head = head || "(none)"
    out.puts "#{tap_name} HEAD: #{display_head}"
    display_commit = last_commit || "never"
    out.puts "#{tap_name} last commit: #{display_commit}"
    default_branches = %w[main master].freeze
    if default_branches.exclude?(branch)
      display_branch = branch || "(none)"
      out.puts "#{tap_name} branch: #{display_branch}"
    end
  end

  json_file = Homebrew::API::Internal.cached_packages_json_file_path
  if json_file.exist?
    modified_at = json_file.mtime.utc.strftime("%d %b %H:%M UTC")
    out.puts "#{tap_name} JSON: #{modified_at}"
  elsif !tap.installed?
    out.puts "#{tap_name}: N/A"
  end
end

.dump_verbose_config(out = $stdout) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • out (File, StringIO, IO) (defaults to: $stdout)


236
237
238
239
240
241
242
243
244
245
# File 'system_config.rb', line 236

def dump_verbose_config(out = $stdout)
  # Most sections shell out for their values (Git, compilers, curl,
  # etc.), so render them concurrently and print them in order.
  sections = Utils.parallel_map(config_sections) do |section|
    io = StringIO.new
    public_send(section, io)
    io.string
  end
  sections.each { |section| out.print section }
end

.hardware ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



91
92
93
94
95
# File 'system_config.rb', line 91

def hardware
  return if Hardware::CPU.type == :dunno

  "CPU: #{Hardware.cores_as_words}-core #{Hardware::CPU.bits}-bit #{Hardware::CPU.family}"
end

.hardware_config(out = $stdout) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • out (File, StringIO, IO) (defaults to: $stdout)


225
226
227
228
# File 'system_config.rb', line 225

def hardware_config(out = $stdout)
  hardware = self.hardware
  out.puts hardware if hardware
end

.head ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



60
61
62
# File 'system_config.rb', line 60

def head
  homebrew_head_info[0] || "(none)"
end

.homebrew_config(out = $stdout) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • out (File, StringIO, IO) (defaults to: $stdout)


179
180
181
182
183
184
185
# File 'system_config.rb', line 179

def homebrew_config(out = $stdout)
  out.puts "HOMEBREW_VERSION: #{HOMEBREW_VERSION}"
  out.puts "ORIGIN: #{origin}"
  out.puts "HEAD: #{head}"
  out.puts "Last commit: #{last_commit}"
  out.puts "Branch: #{branch}"
end

.homebrew_env_config(out = $stdout) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • out (File, StringIO, IO) (defaults to: $stdout)


188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'system_config.rb', line 188

def homebrew_env_config(out = $stdout)
  out.puts "HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}"
  repository = HOMEBREW_REPOSITORY
  cellar = HOMEBREW_CELLAR
  out.puts "HOMEBREW_REPOSITORY: #{repository}" if repository.to_s != Homebrew::DEFAULT_REPOSITORY.to_s
  out.puts "HOMEBREW_CELLAR: #{cellar}" if cellar.to_s != Homebrew::DEFAULT_CELLAR.to_s

  Homebrew::EnvConfig.non_default_variables.each do |env|
    env_symbol = env.to_sym
    hash = Homebrew::EnvConfig::ENVS.fetch(env_symbol)
    value = Homebrew::EnvConfig.public_send(Homebrew::EnvConfig.env_method_name(env_symbol, hash))

    if hash[:boolean]
      setting = value ? "set" : "false"
      out.puts "#{env}: #{setting}"
      next
    end

    next unless value

    if ENV.sensitive?(env)
      out.puts "#{env}: set"
    else
      out.puts "#{env}: #{value}"
    end
  end
  out.puts "Homebrew Ruby: #{describe_homebrew_ruby}"
end

.homebrew_head_info ⇒ Array<([String, nil], [String, nil], [String, nil])>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



47
48
49
50
51
52
# File 'system_config.rb', line 47

def homebrew_head_info
  @homebrew_head_info ||= T.let(
    homebrew_repo.head_info,
    T.nilable([T.nilable(String), T.nilable(String), T.nilable(String)]),
  )
end

.homebrew_repo ⇒ GitRepository

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



42
43
44
# File 'system_config.rb', line 42

def homebrew_repo
  GitRepository.new(HOMEBREW_REPOSITORY)
end

.host_software_config(out = $stdout) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • out (File, StringIO, IO) (defaults to: $stdout)


218
219
220
221
222
# File 'system_config.rb', line 218

def host_software_config(out = $stdout)
  out.puts "Clang: #{describe_clang}"
  out.puts "Git: #{describe_git}"
  out.puts "Curl: #{describe_curl}"
end

.initialize ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



18
19
20
21
# File 'system_config.rb', line 18

def initialize
  @clang = T.let(nil, T.nilable(Version))
  @clang_build = T.let(nil, T.nilable(Version))
end

.kernel ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



98
99
100
# File 'system_config.rb', line 98

def kernel
  Utils.popen_read_text("uname", "-m", err: :err).chomp
end

.last_commit ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



65
66
67
# File 'system_config.rb', line 65

def last_commit
  homebrew_head_info[1] || "never"
end

.origin ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



70
71
72
# File 'system_config.rb', line 70

def origin
  homebrew_repo.origin_url || "(none)"
end

.windows_version ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



103
# File 'system_config.rb', line 103

def windows_version; end