| 
									
										
										
										
											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 | 
					
						
							|  |  |  |       APPLE_BUNDLE_ID = "org.x.X11".freeze | 
					
						
							|  |  |  |       FORGE_PKG_ID = "org.macosforge.xquartz.pkg".freeze | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -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", | 
					
						
							| 
									
										
										
										
											2013-11-01 16:04:52 -05:00
										 |  |  |         "2.7.52" => "2.7.5_rc3", | 
					
						
							| 
									
										
										
										
											2013-11-05 22:32:18 -06:00
										 |  |  |         "2.7.53" => "2.7.5_rc4", | 
					
						
							| 
									
										
										
										
											2013-11-12 10:11:32 -06:00
										 |  |  |         "2.7.54" => "2.7.5", | 
					
						
							| 
									
										
										
										
											2014-09-21 10:06:07 -07:00
										 |  |  |         "2.7.61" => "2.7.6", | 
					
						
							| 
									
										
										
										
											2015-10-22 22:32:23 +02:00
										 |  |  |         "2.7.73" => "2.7.7", | 
					
						
							| 
									
										
										
										
											2016-06-01 11:45:52 +02:00
										 |  |  |         "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 | 
					
						
							| 
									
										
										
										
											2016-04-17 14:29:12 -07:00
										 |  |  |         elsif prefix.to_s == "/usr/X11" || prefix.to_s == "/usr/X11R6" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |           guess_system_version | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           version_from_pkgutil | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-03 13:33:16 +00:00
										 |  |  |       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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 05:02:27 +01: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 | 
					
						
							| 
									
										
										
										
											2013-11-06 09:48:18 -06:00
										 |  |  |         case MacOS.version | 
					
						
							| 
									
										
										
										
											2013-11-12 10:11:32 -06:00
										 |  |  |         when "10.5" | 
					
						
							|  |  |  |           "2.6.3" | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2017-10-31 16:21:03 +00:00
										 |  |  |           "2.7.11" | 
					
						
							| 
									
										
										
										
											2013-11-06 09:48:18 -06:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											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. | 
					
						
							| 
									
										
										
										
											2014-04-01 20:47:26 -05:00
										 |  |  |         MacOS.app_with_bundle_id(FORGE_BUNDLE_ID, APPLE_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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # 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 | 
					
						
							| 
									
										
										
										
											2016-04-17 14:29:42 -07:00
										 |  |  |         when "10.4" then "1.1.3" | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |         when "10.5" then "2.1.6" | 
					
						
							|  |  |  |         when "10.6" then "2.3.6" | 
					
						
							|  |  |  |         when "10.7" then "2.6.3" | 
					
						
							|  |  |  |         else "dunno" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |         end | 
					
						
							|  |  |  |       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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def provided_by_apple? | 
					
						
							|  |  |  |         [FORGE_BUNDLE_ID, APPLE_BUNDLE_ID].find do |id| | 
					
						
							|  |  |  |           MacOS.app_with_bundle_id(id) | 
					
						
							|  |  |  |         end == APPLE_BUNDLE_ID | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # This should really be private, but for compatibility reasons it must | 
					
						
							| 
									
										
										
										
											2014-10-26 15:42:41 +00: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") | 
					
						
							|  |  |  |         elsif Pathname.new("/usr/X11/lib/libpng.dylib").exist? | 
					
						
							|  |  |  |           Pathname.new("/usr/X11") | 
					
						
							| 
									
										
										
										
											2016-04-17 14:34:18 -07:00
										 |  |  |         # X11 doesn't include libpng on Tiger | 
					
						
							|  |  |  |         elsif Pathname.new("/usr/X11R6/lib/libX11.dylib").exist? | 
					
						
							|  |  |  |           Pathname.new("/usr/X11R6") | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							|  |  |  |         return false if provided_by_apple? | 
					
						
							|  |  |  |         version < latest_version | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # 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. | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:52 -05:00
										 |  |  |       def effective_prefix | 
					
						
							|  |  |  |         if provided_by_apple? && Xcode.without_clt? | 
					
						
							|  |  |  |           Pathname.new("#{OS::Mac.sdk_path}/usr/X11") | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           prefix | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def bin | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:52 -05:00
										 |  |  |         prefix/"bin" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def include | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:52 -05:00
										 |  |  |         effective_prefix/"include" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def lib | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:52 -05:00
										 |  |  |         effective_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 |