Module: OS::Mac::XQuartz

Defined in:
brew/Library/Homebrew/os/mac/xquartz.rb

Constant Summary collapse

DEFAULT_BUNDLE_PATH =
Pathname.new("Applications/Utilities/XQuartz.app").freeze
FORGE_BUNDLE_ID =
"org.macosforge.xquartz.X11"
FORGE_PKG_ID =
"org.macosforge.xquartz.pkg"
PKGINFO_VERSION_MAP =
{
  "2.6.34"  => "2.6.3",
  "2.7.4"   => "2.7.0",
  "2.7.14"  => "2.7.1",
  "2.7.28"  => "2.7.2",
  "2.7.32"  => "2.7.3",
  "2.7.43"  => "2.7.4",
  "2.7.50"  => "2.7.5_rc1",
  "2.7.51"  => "2.7.5_rc2",
  "2.7.52"  => "2.7.5_rc3",
  "2.7.53"  => "2.7.5_rc4",
  "2.7.54"  => "2.7.5",
  "2.7.61"  => "2.7.6",
  "2.7.73"  => "2.7.7",
  "2.7.86"  => "2.7.8",
  "2.7.94"  => "2.7.9",
  "2.7.108" => "2.7.10",
  "2.7.112" => "2.7.11",
}.freeze

Class Method Summary collapse

Class Method Details

.binObject



105
106
107
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 105

def bin
  prefix/"bin"
end

.bundle_pathObject



65
66
67
68
69
70
71
72
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 65

def bundle_path
  # Use the default location if it exists.
  return DEFAULT_BUNDLE_PATH if DEFAULT_BUNDLE_PATH.exist?

  # Ask Spotlight where XQuartz is. If the user didn't install XQuartz
  # in the conventional place, this is our only option.
  MacOS.app_with_bundle_id(FORGE_BUNDLE_ID)
end

.detect_versionObject



45
46
47
48
49
50
51
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 45

def detect_version
  if (path = bundle_path) && path.exist? && (version = version_from_mdls(path))
    version
  else
    version_from_pkgutil
  end
end

.includeObject



109
110
111
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 109

def include
  prefix/"include"
end

.installed?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 95

def installed?
  !version.null? && !prefix.nil?
end

.latest_versionObject

  • https://xquartz.macosforge.org/trac/wiki
  • https://xquartz.macosforge.org/trac/wiki/Releases


61
62
63
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 61

def latest_version
  "2.7.11"
end

.libObject



113
114
115
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 113

def lib
  prefix/"lib"
end

.minimum_versionObject



53
54
55
56
57
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 53

def minimum_version
  # Update this a little later than latest_version to give people
  # time to upgrade.
  "2.7.11"
end

.outdated?Boolean

Returns:

  • (Boolean)


99
100
101
102
103
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 99

def outdated?
  return false unless installed?

  version < latest_version
end

.prefixObject

This should really be private, but for compatibility reasons it must remain public. New code should use MacOS::X11.bin, MacOS::X11.lib and MacOS::X11.include instead, as that accounts for Xcode-only systems.



91
92
93
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 91

def prefix
  @prefix ||= Pathname.new("/opt/X11") if Pathname.new("/opt/X11/lib/libpng.dylib").exist?
end

.shareObject



117
118
119
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 117

def share
  prefix/"share"
end

.versionObject

This returns the version number of XQuartz, not of the upstream X.org. The X11.app distributed by Apple is also XQuartz, and therefore covered by this method.



37
38
39
40
41
42
43
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 37

def version
  if @version ||= detect_version
    ::Version.new @version
  else
    ::Version::NULL
  end
end

.version_from_mdls(path) ⇒ Object



74
75
76
77
78
79
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 74

def version_from_mdls(path)
  version = Utils.popen_read(
    "/usr/bin/mdls", "-raw", "-nullMarker", "", "-name", "kMDItemVersion", path.to_s
  ).strip
  version unless version.empty?
end

.version_from_pkgutilObject

Upstream XQuartz does have a pkg-info entry, so if we can’t get it from mdls, we can try pkgutil. This is very slow.



83
84
85
86
# File 'brew/Library/Homebrew/os/mac/xquartz.rb', line 83

def version_from_pkgutil
  str = MacOS.pkgutil_info(FORGE_PKG_ID)[/version: (\d\.\d\.\d+)$/, 1]
  PKGINFO_VERSION_MAP.fetch(str, str)
end