Module: OS::Linux::SystemConfig::ClassMethods Private

Includes:
SystemCommand::Mixin
Defined in:
extend/os/linux/system_config.rb

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.

Constant Summary collapse

HOST_RUBY_PATH =

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

"/usr/bin/ruby"

Instance Method Summary collapse

Methods included from SystemCommand::Mixin

#system_command, #system_command!

Instance Method Details

#config_sectionsArray<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:



127
128
129
# File 'extend/os/linux/system_config.rb', line 127

def config_sections
  super + [:linux_config]
end

#formula_linked_version(formula) ⇒ String, PkgVersion

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.

Parameters:

Returns:



43
44
45
46
47
48
49
# File 'extend/os/linux/system_config.rb', line 43

def formula_linked_version(formula)
  return "N/A" if Homebrew::EnvConfig.no_install_from_api? && !CoreTap.instance.installed?

  Formulary.factory(formula).any_installed_version || "N/A"
rescue FormulaUnavailableError
  "N/A"
end

#host_gcc_versionString

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:



35
36
37
38
39
40
# File 'extend/os/linux/system_config.rb', line 35

def host_gcc_version
  gcc = ::DevelopmentTools.host_gcc_path
  return "N/A" unless gcc.executable?

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

#host_glibc_versionString, 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:



19
20
21
22
23
24
# File 'extend/os/linux/system_config.rb', line 19

def host_glibc_version
  version = OS::Linux::Glibc.system_version
  return "N/A" if version.null?

  version
end

#host_libstdcxx_versionString, 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:



27
28
29
30
31
32
# File 'extend/os/linux/system_config.rb', line 27

def host_libstdcxx_version
  version = OS::Linux::Libstdcxx.system_version
  return "N/A" if version.null?

  version
end

#host_ruby_versionString

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:



52
53
54
55
56
57
# File 'extend/os/linux/system_config.rb', line 52

def host_ruby_version
  out, _, status = system_command(HOST_RUBY_PATH, args: ["-e", "puts RUBY_VERSION"], print_stderr: false).to_a
  return "N/A" unless status.success?

  out
end

#linux_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)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'extend/os/linux/system_config.rb', line 108

def linux_config(out = $stdout)
  out.puts "Kernel: #{Utils.safe_popen_read("uname", "-mors").chomp}"
  out.puts "Landlock ABI: #{::Sandbox::Landlock.kernel_abi_version || "N/A"}"
  out.puts "OS: #{OS::Linux.os_version}"
  if OS.wsl?
    out.puts "WSL: #{OS::Linux.wsl_version}"
    windows = windows_version
    out.puts "Windows: #{windows}" if windows
  end
  out.puts "Host glibc: #{host_glibc_version}"
  out.puts "Host libstdc++: #{host_libstdcxx_version}"
  out.puts "#{::DevelopmentTools.host_gcc_path}: #{host_gcc_version}"
  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|
    out.puts "#{f}: #{formula_linked_version(f)}"
  end
end

#windows_registry_values(cmd) ⇒ Hash{String => 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.

Parameters:

Returns:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'extend/os/linux/system_config.rb', line 90

def windows_registry_values(cmd)
  output = Utils.popen_read(cmd, "/d", "/c", "reg", "query",
                            "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
                            err: :close)

  output.each_line.with_object({}) do |line, values|
    match = line.delete("\r").match(/^\s*(\S+)\s+REG_\S+\s+(.+?)\s*$/)
    next if match.nil?

    key = match[1]
    value = match[2]
    next if key.nil? || value.nil?

    values[key] = value.start_with?("0x") ? value.to_i(16).to_s : value
  end
end

#windows_registry_version(cmd) ⇒ 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.

Parameters:

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'extend/os/linux/system_config.rb', line 74

def windows_registry_version(cmd)
  values = windows_registry_values(cmd)
  product_name = values["ProductName"]
  build = values["CurrentBuildNumber"]
  return if product_name.blank? || build.blank?

  product_name = product_name.sub(/\AWindows 10\b/, "Windows 11") if build.to_i >= 22_000
  build += ".#{values["UBR"]}" if values["UBR"].present?

  version = values["DisplayVersion"] || values["ReleaseId"]
  return "#{product_name} [#{build}]" if version.blank?

  "#{product_name} (#{version}) [#{build}]"
end

#windows_versionString?

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
63
64
65
66
67
68
69
70
71
# File 'extend/os/linux/system_config.rb', line 60

def windows_version
  return unless OS.wsl?

  cmd = Kernel.which("cmd.exe", ORIGINAL_PATHS) || ::Pathname.new("/mnt/c/Windows/System32/cmd.exe")
  return unless cmd.executable?

  windows_registry_version(cmd) || Utils.popen_read(cmd, "/d", "/c", "ver", err: :close)
                                        .delete("\r")
                                        .lines
                                        .map(&:strip)
                                        .find { |line| line.start_with?("Microsoft Windows") }
end