Module: OS::Mac::XQuartz

Defined in:
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".freeze
APPLE_BUNDLE_ID =
"org.x.X11".freeze
FORGE_PKG_ID =
"org.macosforge.xquartz.pkg".freeze
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



153
154
155
# File 'Library/Homebrew/os/mac/xquartz.rb', line 153

def bin
  prefix/"bin"
end

.bundle_pathObject



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

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, APPLE_BUNDLE_ID)
end

.detect_versionObject



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

def detect_version
  if (path = bundle_path) && path.exist? && (version = version_from_mdls(path))
    version
  elsif prefix.to_s == "/usr/X11" || prefix.to_s == "/usr/X11R6"
    guess_system_version
  else
    version_from_pkgutil
  end
end

.effective_prefixObject

If XQuartz and/or the CLT are installed, headers will be found under /opt/X11/include or /usr/X11/include. For Xcode-only systems, they are found in the SDK, so we use sdk_path for both the headers and libraries. Confusingly, executables (e.g. config scripts) are only found under /opt/X11/bin or /usr/X11/bin in all cases.



145
146
147
148
149
150
151
# File 'Library/Homebrew/os/mac/xquartz.rb', line 145

def effective_prefix
  if provided_by_apple? && Xcode.without_clt?
    Pathname.new("#{OS::Mac.sdk_path}/usr/X11")
  else
    prefix
  end
end

.guess_system_versionObject

The XQuartz that Apple shipped in OS X through 10.7 does not have a pkg-util entry, so if Spotlight indexing is disabled we must make an educated guess as to what version is installed.



93
94
95
96
97
98
99
100
101
# File 'Library/Homebrew/os/mac/xquartz.rb', line 93

def guess_system_version
  case MacOS.version
  when "10.4" then "1.1.3"
  when "10.5" then "2.1.6"
  when "10.6" then "2.3.6"
  when "10.7" then "2.6.3"
  else "dunno"
  end
end

.includeObject



157
158
159
# File 'Library/Homebrew/os/mac/xquartz.rb', line 157

def include
  effective_prefix/"include"
end

.installed?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'Library/Homebrew/os/mac/xquartz.rb', line 130

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

.latest_versionObject



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

def latest_version
  case MacOS.version
  when "10.5"
    "2.6.3"
  else
    "2.7.11"
  end
end

.libObject



161
162
163
# File 'Library/Homebrew/os/mac/xquartz.rb', line 161

def lib
  effective_prefix/"lib"
end

.minimum_versionObject



54
55
56
57
58
59
60
61
# File 'Library/Homebrew/os/mac/xquartz.rb', line 54

def minimum_version
  version = guess_system_version
  return version unless version == "dunno"

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

.outdated?Boolean

Returns:

  • (Boolean)


134
135
136
137
138
# File 'Library/Homebrew/os/mac/xquartz.rb', line 134

def outdated?
  return false unless installed?
  return false if provided_by_apple?
  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.



119
120
121
122
123
124
125
126
127
128
# File 'Library/Homebrew/os/mac/xquartz.rb', line 119

def prefix
  @prefix ||= if Pathname.new("/opt/X11/lib/libpng.dylib").exist?
    Pathname.new("/opt/X11")
  elsif Pathname.new("/usr/X11/lib/libpng.dylib").exist?
    Pathname.new("/usr/X11")
  # X11 doesn't include libpng on Tiger
  elsif Pathname.new("/usr/X11R6/lib/libX11.dylib").exist?
    Pathname.new("/usr/X11R6")
  end
end

.provided_by_apple?Boolean

Returns:

  • (Boolean)


110
111
112
113
114
# File 'Library/Homebrew/os/mac/xquartz.rb', line 110

def provided_by_apple?
  [FORGE_BUNDLE_ID, APPLE_BUNDLE_ID].find do |id|
    MacOS.app_with_bundle_id(id)
  end == APPLE_BUNDLE_ID
end

.shareObject



165
166
167
# File 'Library/Homebrew/os/mac/xquartz.rb', line 165

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.



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

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

.version_from_mdls(path) ⇒ Object



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

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.



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

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