Module: OS::Mac Private
- Extended by:
- Utils::Output::Mixin
- Defined in:
- os/mac.rb,
extend/os/mac/keg.rb,
extend/os/mac/tap.rb,
extend/os/mac/cleaner.rb,
extend/os/mac/cleanup.rb,
extend/os/mac/formula.rb,
extend/os/mac/readall.rb,
extend/os/mac/sandbox.rb,
extend/os/mac/cask/dsl.rb,
extend/os/mac/hardware.rb,
extend/os/mac/reinstall.rb,
extend/os/mac/diagnostic.rb,
extend/os/mac/hardware/cpu.rb,
extend/os/mac/keg_relocate.rb,
extend/os/mac/utils/socket.rb,
extend/os/mac/bundle/bundle.rb,
extend/os/mac/dev-cmd/tests.rb,
extend/os/mac/language/java.rb,
extend/os/mac/system_config.rb,
extend/os/mac/utils/bottles.rb,
extend/os/mac/bundle/skipper.rb,
extend/os/mac/dev-cmd/bottle.rb,
extend/os/mac/extend/ENV/std.rb,
extend/os/mac/extend/pathname.rb,
extend/os/mac/linkage_checker.rb,
extend/os/mac/missing_formula.rb,
extend/os/mac/simulate_system.rb,
extend/os/mac/extend/ENV/super.rb,
extend/os/mac/development_tools.rb,
extend/os/mac/extend/ENV/shared.rb,
extend/os/mac/formula_installer.rb,
extend/os/mac/cask/artifact/moved.rb,
extend/os/mac/dependency_collector.rb,
extend/os/mac/formula_cellar_checks.rb,
extend/os/mac/cask/artifact/symlinked.rb,
extend/os/mac/cask/artifact/abstract_uninstall.rb,
cask/macos.rb,
os/mac/sdk.rb,
os/mac/xcode.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 system information on macOS.
Defined Under Namespace
Modules: Bottles, Bundle, CLT, Cask, Cleaner, Cleanup, DependencyCollector, DevCmd, DevelopmentTools, Diagnostic, Formula, FormulaCellarChecks, FormulaInstaller, Hardware, Keg, Language, LinkageChecker, MissingFormula, Pathname, Readall, Reinstall, Sandbox, SharedEnvExtension, SimulateSystem, Stdenv, Superenv, SystemConfig, Tap, UNIXSocketExt, Xcode Classes: CLTSDKLocator, SDK, XcodeSDKLocator
Class Method Summary collapse
- .active_developer_dir ⇒ String private
- .app_with_bundle_id(*ids) ⇒ ::Pathname? private
-
.full_version ⇒ MacOSVersion
internal
This can be compared to numerics, strings, or symbols using the standard Ruby Comparable methods.
- .full_version=(version) ⇒ void private
- .language ⇒ String? private
- .languages ⇒ Array<String> private
- .latest_sdk_version ⇒ ::Version private
-
.macports_or_fink ⇒ Array<Pathname>
private
See these issues for some history:.
- .mdfind(*ids) ⇒ Array<String> private
- .mdfind_query(*ids) ⇒ String private
- .pkgutil_info(id) ⇒ String private
- .preferred_perl_version ⇒ String private
-
.sdk(version = nil) ⇒ SDK?
private
If a specific SDK is requested:.
-
.sdk_for_formula(formula, version = nil, check_only_runtime_requirements: false) ⇒ SDK?
Returns the path to the SDK needed based on the formula's requirements.
- .sdk_locator ⇒ CLTSDKLocator, XcodeSDKLocator private
-
.sdk_path(version = nil) ⇒ ::Pathname?
Returns the path to an SDK or nil, following the rules set by Mac.sdk.
-
.sdk_path_if_needed(version = nil) ⇒ ::Pathname?
Prefer CLT SDK when both Xcode and the CLT are installed.
- .sdk_root_needed? ⇒ Boolean private
- .system_dir?(dir) ⇒ Boolean private
- .undeletable?(path) ⇒ Boolean private
-
.version ⇒ MacOSVersion
internal
This can be compared to numerics, strings, or symbols using the standard Ruby Comparable methods.
Methods included from Utils::Output::Mixin
odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, pretty_duration, pretty_installed, pretty_outdated, pretty_uninstalled
Class Method Details
.active_developer_dir ⇒ 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.
98 99 100 101 102 103 |
# File 'os/mac.rb', line 98 def self.active_developer_dir @active_developer_dir ||= T.let( Utils.popen_read("/usr/bin/xcode-select", "-print-path").strip, T.nilable(String), ) end |
.app_with_bundle_id(*ids) ⇒ ::Pathname?
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.
214 215 216 217 218 219 220 221 222 223 224 |
# File 'os/mac.rb', line 214 def self.app_with_bundle_id(*ids) require "bundle_version" paths = mdfind(*ids).filter_map do |bundle_path| ::Pathname.new(bundle_path) if bundle_path.exclude?("/Backups.backupdb/") end return paths.first unless paths.all? { |bp| (bp/"Contents/Info.plist").exist? } # Prefer newest one, if we can find it. paths.max_by { |bundle_path| Homebrew::BundleVersion.from_info_plist(bundle_path/"Contents/Info.plist") } end |
.full_version ⇒ MacOSVersion
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This can be compared to numerics, strings, or symbols using the standard Ruby Comparable methods.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'os/mac.rb', line 41 def self.full_version @full_version ||= T.let(nil, T.nilable(MacOSVersion)) # HOMEBREW_FAKE_MACOS is set system-wide in the macOS 11-arm64-cross image # for building a macOS 11 Portable Ruby on macOS 12 # odisabled: remove support for Big Sur September (or later) 2027 @full_version ||= if (fake_macos = ENV.fetch("HOMEBREW_FAKE_MACOS", nil)) MacOSVersion.new(fake_macos) else MacOSVersion.new(VERSION) end end |
.full_version=(version) ⇒ 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.
54 55 56 57 |
# File 'os/mac.rb', line 54 def self.full_version=(version) @full_version = MacOSVersion.new(version.chomp) @version = nil end |
.language ⇒ 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.
93 94 95 |
# File 'os/mac.rb', line 93 def self.language languages.first end |
.languages ⇒ Array<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.
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'os/mac.rb', line 78 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") if os_langs.blank? # User settings don't exist so check the system-wide one. os_langs = Utils.popen_read("defaults", "read", "/Library/Preferences/.GlobalPreferences", "AppleLanguages") end os_langs = os_langs.scan(/[^ \n"(),]+/) @languages = os_langs end |
.latest_sdk_version ⇒ ::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.
60 61 62 63 64 |
# File 'os/mac.rb', line 60 def self.latest_sdk_version # TODO: bump version when new Xcode macOS SDK is released # NOTE: We only track the major version of the SDK. ::Version.new("26") end |
.macports_or_fink ⇒ Array<Pathname>
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.
See these issues for some history:
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'os/mac.rb', line 184 def self.macports_or_fink paths = [] # First look in the path because MacPorts is relocatable and Fink # may become relocatable in the future. %w[port fink].each do |ponk| path = which(ponk) paths << path unless path.nil? end # Look in the standard locations, because even if port or fink are # not in the path they can still break builds if the build scripts # have these paths baked in. %w[/sw/bin/fink /opt/local/bin/port].each do |ponk| path = ::Pathname.new(ponk) paths << path if path.exist? end # Finally, some users make their MacPorts or Fink directories # read-only in order to try out Homebrew, but this doesn't work as # some build scripts error out when trying to read from these now # unreadable paths. %w[/sw /opt/local].map { |p| ::Pathname.new(p) }.each do |path| paths << path if path.exist? && !path.readable? end paths.uniq end |
.mdfind(*ids) ⇒ Array<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.
227 228 229 230 231 232 |
# File 'os/mac.rb', line 227 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 |
.mdfind_query(*ids) ⇒ 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.
243 244 245 |
# File 'os/mac.rb', line 243 def self.mdfind_query(*ids) ids.map! { |id| "kMDItemCFBundleIdentifier == #{id}" }.join(" || ") end |
.pkgutil_info(id) ⇒ 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.
235 236 237 238 239 240 |
# File 'os/mac.rb', line 235 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 end |
.preferred_perl_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.
67 68 69 70 71 72 73 74 75 |
# File 'os/mac.rb', line 67 def self.preferred_perl_version if version >= :sonoma "5.34" elsif version >= :big_sur "5.30" else "5.18" end end |
.sdk(version = nil) ⇒ SDK?
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.
If a specific SDK is requested:
- The requested SDK is returned, if it's installed.
- If the requested SDK is not installed, the newest SDK (if any SDKs are available) is returned.
- If no SDKs are available, nil is returned.
If no specific SDK is requested, the SDK matching the OS version is returned, if available. Otherwise, the latest SDK is returned.
130 131 132 |
# File 'os/mac.rb', line 130 def self.sdk(version = nil) sdk_locator.sdk_if_applicable(version) end |
.sdk_for_formula(formula, version = nil, check_only_runtime_requirements: false) ⇒ SDK?
Returns the path to the SDK needed based on the formula's requirements.
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'os/mac.rb', line 144 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 # Xcode SDK if the XcodeRequirement is only a build or test requirement. return Xcode.sdk if formula.requirements.any? do |req| next false unless req.is_a? XcodeRequirement next false if check_only_runtime_requirements && req.build? && !req.test? true end sdk(version) end |
.sdk_locator ⇒ CLTSDKLocator, XcodeSDKLocator
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.
112 113 114 115 116 117 118 |
# File 'os/mac.rb', line 112 def self.sdk_locator if CLT.installed? CLT.sdk_locator else Xcode.sdk_locator end end |
.sdk_path(version = nil) ⇒ ::Pathname?
Returns the path to an SDK or nil, following the rules set by sdk.
162 163 164 165 |
# File 'os/mac.rb', line 162 def self.sdk_path(version = nil) s = sdk(version) s&.path end |
.sdk_path_if_needed(version = nil) ⇒ ::Pathname?
Prefer CLT SDK when both Xcode and the CLT are installed. Expected results:
- On Xcode-only systems, return the Xcode SDK.
- On CLT-only systems, return the CLT SDK.
174 175 176 |
# File 'os/mac.rb', line 174 def self.sdk_path_if_needed(version = nil) sdk_path(version) end |
.sdk_root_needed? ⇒ Boolean
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.
106 107 108 109 |
# File 'os/mac.rb', line 106 def self.sdk_root_needed? odeprecated "OS::Mac.sdk_root_needed?" true end |
.system_dir?(dir) ⇒ Boolean
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.
382 383 384 |
# File 'cask/macos.rb', line 382 def self.system_dir?(dir) SYSTEM_DIRS.include?(::Pathname.new(dir).) end |
.undeletable?(path) ⇒ Boolean
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.
387 388 389 |
# File 'cask/macos.rb', line 387 def self.undeletable?(path) UNDELETABLE_PATHS.include?(::Pathname.new(path).) end |
.version ⇒ MacOSVersion
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This can be compared to numerics, strings, or symbols using the standard Ruby Comparable methods.
32 33 34 |
# File 'os/mac.rb', line 32 def self.version @version ||= T.let(full_version.strip_patch, T.nilable(MacOSVersion)) end |