2013-10-18 12:56:51 -05:00
|
|
|
module OS
|
|
|
|
module Mac
|
2013-10-18 12:56:51 -05:00
|
|
|
X11 = XQuartz = Module.new
|
|
|
|
|
2013-10-18 12:56:51 -05:00
|
|
|
module XQuartz
|
2016-09-24 20:11:54 +02:00
|
|
|
module_function
|
2013-10-18 12:56:51 -05:00
|
|
|
|
2017-01-09 21:30:41 +00:00
|
|
|
DEFAULT_BUNDLE_PATH = Pathname.new("Applications/Utilities/XQuartz.app").freeze
|
2016-09-11 17:49:27 +01:00
|
|
|
FORGE_BUNDLE_ID = "org.macosforge.xquartz.X11".freeze
|
|
|
|
FORGE_PKG_ID = "org.macosforge.xquartz.pkg".freeze
|
2013-10-18 12:56:51 -05:00
|
|
|
|
|
|
|
PKGINFO_VERSION_MAP = {
|
2018-11-02 17:18:07 +00:00
|
|
|
"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",
|
2017-10-31 16:20:47 +00:00
|
|
|
"2.7.108" => "2.7.10",
|
|
|
|
"2.7.112" => "2.7.11",
|
2013-10-18 12:56:51 -05:00
|
|
|
}.freeze
|
|
|
|
|
|
|
|
# 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
|
2017-11-05 12:09:31 +00:00
|
|
|
if @version ||= detect_version
|
|
|
|
::Version.new @version
|
|
|
|
else
|
|
|
|
::Version::NULL
|
|
|
|
end
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def detect_version
|
|
|
|
if (path = bundle_path) && path.exist? && (version = version_from_mdls(path))
|
|
|
|
version
|
|
|
|
else
|
|
|
|
version_from_pkgutil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-03 13:33:16 +00:00
|
|
|
def minimum_version
|
|
|
|
# Update this a little later than latest_version to give people
|
|
|
|
# time to upgrade.
|
|
|
|
"2.7.11"
|
|
|
|
end
|
|
|
|
|
2018-10-18 21:42:43 -04:00
|
|
|
# - https://xquartz.macosforge.org/trac/wiki
|
|
|
|
# - https://xquartz.macosforge.org/trac/wiki/Releases
|
2013-10-18 12:56:51 -05:00
|
|
|
def latest_version
|
2019-01-26 17:13:14 +00:00
|
|
|
"2.7.11"
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def bundle_path
|
2017-01-09 21:30:41 +00:00
|
|
|
# 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.
|
2019-01-26 17:13:14 +00:00
|
|
|
MacOS.app_with_bundle_id(FORGE_BUNDLE_ID)
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def version_from_mdls(path)
|
2014-07-11 15:29:26 -05:00
|
|
|
version = Utils.popen_read(
|
2014-07-11 15:51:19 -05:00
|
|
|
"/usr/bin/mdls", "-raw", "-nullMarker", "", "-name", "kMDItemVersion", path.to_s
|
2014-07-11 15:29:26 -05:00
|
|
|
).strip
|
2013-10-18 12:56:51 -05:00
|
|
|
version unless version.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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
|
|
|
|
str = MacOS.pkgutil_info(FORGE_PKG_ID)[/version: (\d\.\d\.\d+)$/, 1]
|
|
|
|
PKGINFO_VERSION_MAP.fetch(str, str)
|
|
|
|
end
|
|
|
|
|
|
|
|
# This should really be private, but for compatibility reasons it must
|
2018-10-18 21:42:43 -04:00
|
|
|
# remain public. New code should use `MacOS::X11.bin`, `MacOS::X11.lib` and
|
|
|
|
# `MacOS::X11.include` instead, as that accounts for Xcode-only systems.
|
2013-10-18 12:56:51 -05:00
|
|
|
def prefix
|
2015-08-03 13:09:07 +01:00
|
|
|
@prefix ||= if Pathname.new("/opt/X11/lib/libpng.dylib").exist?
|
|
|
|
Pathname.new("/opt/X11")
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def installed?
|
2017-11-05 12:09:31 +00:00
|
|
|
!version.null? && !prefix.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def outdated?
|
|
|
|
return false unless installed?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2017-11-05 12:09:31 +00:00
|
|
|
version < latest_version
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def bin
|
2013-10-18 12:56:52 -05:00
|
|
|
prefix/"bin"
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def include
|
2019-01-26 17:13:14 +00:00
|
|
|
prefix/"include"
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def lib
|
2019-01-26 17:13:14 +00:00
|
|
|
prefix/"lib"
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def share
|
2013-10-18 12:56:52 -05:00
|
|
|
prefix/"share"
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
2012-07-25 15:04:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|