2012-07-25 15:04:46 -05:00
|
|
|
module MacOS::XQuartz extend self
|
|
|
|
FORGE_BUNDLE_ID = "org.macosforge.xquartz.X11"
|
|
|
|
APPLE_BUNDLE_ID = "org.x.X11"
|
2012-12-22 14:24:25 -06:00
|
|
|
FORGE_PKG_ID = "org.macosforge.xquartz.pkg"
|
2012-07-25 15:04:46 -05:00
|
|
|
|
2013-07-21 19:11:06 -05:00
|
|
|
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",
|
|
|
|
}.freeze
|
|
|
|
|
2012-07-25 15:04:46 -05:00
|
|
|
# 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.
|
|
|
|
def version
|
2013-07-21 19:11:05 -05:00
|
|
|
@version ||= detect_version
|
|
|
|
end
|
|
|
|
|
|
|
|
def detect_version
|
2013-07-21 19:11:06 -05:00
|
|
|
if (path = bundle_path) && path.exist? && (version = version_from_mdls(path))
|
|
|
|
version
|
2013-07-21 19:11:05 -05:00
|
|
|
elsif prefix.to_s == "/usr/X11"
|
|
|
|
guess_system_version
|
|
|
|
else
|
|
|
|
version_from_pkgutil
|
2012-07-25 15:04:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-11 11:54:03 -08:00
|
|
|
def latest_version
|
|
|
|
"2.7.4"
|
|
|
|
end
|
|
|
|
|
2013-07-21 19:11:04 -05:00
|
|
|
def bundle_path
|
|
|
|
MacOS.app_with_bundle_id(FORGE_BUNDLE_ID) || MacOS.app_with_bundle_id(APPLE_BUNDLE_ID)
|
|
|
|
end
|
|
|
|
|
2013-07-21 19:11:05 -05:00
|
|
|
def version_from_mdls(path)
|
2013-07-21 19:11:06 -05:00
|
|
|
version = `mdls -raw -nullMarker "" -name kMDItemVersion "#{path}" 2>/dev/null`.strip
|
|
|
|
version unless version.empty?
|
2013-07-21 19:11:05 -05:00
|
|
|
end
|
|
|
|
|
2013-07-21 19:11:05 -05:00
|
|
|
# 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.
|
|
|
|
def guess_system_version
|
|
|
|
case MacOS.version
|
|
|
|
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
|
|
|
|
|
2013-07-21 19:11:05 -05:00
|
|
|
# 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.
|
|
|
|
def version_from_pkgutil
|
2013-07-21 19:11:06 -05:00
|
|
|
str = MacOS.pkgutil_info(FORGE_PKG_ID)[/version: (\d\.\d\.\d+)$/, 1]
|
|
|
|
PKGINFO_VERSION_MAP.fetch(str, str)
|
2013-07-21 19:11:05 -05:00
|
|
|
end
|
|
|
|
|
2012-11-12 19:42:26 -06:00
|
|
|
def provided_by_apple?
|
|
|
|
[FORGE_BUNDLE_ID, APPLE_BUNDLE_ID].find do |id|
|
|
|
|
MacOS.app_with_bundle_id(id)
|
|
|
|
end == APPLE_BUNDLE_ID
|
|
|
|
end
|
|
|
|
|
2012-07-25 15:04:46 -05:00
|
|
|
# This should really be private, but for compatibility reasons it must
|
2013-02-03 11:32:34 -08:00
|
|
|
# remain public. New code should use MacOS::X11.{bin,lib,include}
|
2012-07-25 15:04:46 -05:00
|
|
|
# instead, as that accounts for Xcode-only systems.
|
|
|
|
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')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def installed?
|
2012-12-21 12:55:38 -06:00
|
|
|
!version.nil? && !prefix.nil?
|
2012-07-25 15:04:46 -05:00
|
|
|
end
|
2012-08-06 00:33:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
module MacOS::X11 extend self
|
|
|
|
def prefix
|
|
|
|
MacOS::XQuartz.prefix
|
|
|
|
end
|
|
|
|
|
|
|
|
def installed?
|
|
|
|
MacOS::XQuartz.installed?
|
|
|
|
end
|
2012-07-25 15:04:46 -05:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
def bin
|
2013-04-15 15:00:57 -05:00
|
|
|
Pathname.new("#{prefix}/bin")
|
2012-07-25 15:04:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def include
|
|
|
|
@include ||= if use_sdk?
|
2013-04-15 15:00:57 -05:00
|
|
|
Pathname.new("#{MacOS.sdk_path}/usr/X11/include")
|
2012-07-25 15:04:46 -05:00
|
|
|
else
|
2013-04-15 15:00:57 -05:00
|
|
|
Pathname.new("#{prefix}/include")
|
2012-07-25 15:04:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def lib
|
|
|
|
@lib ||= if use_sdk?
|
2013-04-15 15:00:57 -05:00
|
|
|
Pathname.new("#{MacOS.sdk_path}/usr/X11/lib")
|
2012-07-25 15:04:46 -05:00
|
|
|
else
|
2013-04-15 15:00:57 -05:00
|
|
|
Pathname.new("#{prefix}/lib")
|
2012-07-25 15:04:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def share
|
2013-04-15 15:00:57 -05:00
|
|
|
Pathname.new("#{prefix}/share")
|
2012-07-25 15:04:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def use_sdk?
|
|
|
|
not (prefix.to_s == '/opt/X11' or MacOS::CLT.installed?)
|
|
|
|
end
|
|
|
|
end
|