| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  | module OS | 
					
						
							|  |  |  |   module Mac | 
					
						
							|  |  |  |     module Xcode | 
					
						
							| 
									
										
										
										
											2016-09-24 20:11:54 +02:00
										 |  |  |       module_function | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-09 21:30:32 +00:00
										 |  |  |       DEFAULT_BUNDLE_PATH = Pathname.new("/Applications/Xcode.app").freeze | 
					
						
							| 
									
										
										
										
											2017-01-09 21:30:20 +00:00
										 |  |  |       BUNDLE_ID = "com.apple.dt.Xcode".freeze | 
					
						
							|  |  |  |       OLD_BUNDLE_ID = "com.apple.Xcode".freeze | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       def latest_version | 
					
						
							|  |  |  |         case MacOS.version | 
					
						
							| 
									
										
										
										
											2014-08-09 22:00:06 -05:00
										 |  |  |         when "10.4"  then "2.5" | 
					
						
							|  |  |  |         when "10.5"  then "3.1.4" | 
					
						
							|  |  |  |         when "10.6"  then "3.2.6" | 
					
						
							|  |  |  |         when "10.7"  then "4.6.3" | 
					
						
							|  |  |  |         when "10.8"  then "5.1.1" | 
					
						
							| 
									
										
										
										
											2015-03-10 00:08:43 +00:00
										 |  |  |         when "10.9"  then "6.2" | 
					
						
							| 
									
										
										
										
											2016-02-07 19:30:51 +00:00
										 |  |  |         when "10.10" then "7.2.1" | 
					
						
							| 
									
										
										
										
											2017-03-28 11:16:02 -04:00
										 |  |  |         when "10.11" then "8.2.1" | 
					
						
							| 
									
										
										
										
											2017-12-08 14:59:15 +00:00
										 |  |  |         when "10.12" then "9.2" | 
					
						
							| 
									
										
										
										
											2018-06-05 06:46:32 +01:00
										 |  |  |         when "10.13" then "9.4" | 
					
						
							| 
									
										
										
										
											2018-06-04 21:23:27 +01:00
										 |  |  |         when "10.14" then "10.0" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2016-09-23 22:02:23 +02:00
										 |  |  |           raise "macOS '#{MacOS.version}' is invalid" unless OS::Mac.prerelease? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 19:57:19 +01:00
										 |  |  |           # Default to newest known version of Xcode for unreleased macOS versions. | 
					
						
							| 
									
										
										
										
											2018-06-04 21:23:27 +01:00
										 |  |  |           "10.0" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-06-04 13:58:08 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-08-17 17:18:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-05 10:35:39 -04:00
										 |  |  |       def minimum_version | 
					
						
							|  |  |  |         case MacOS.version | 
					
						
							| 
									
										
										
										
											2018-06-04 21:23:27 +01:00
										 |  |  |         when "10.14" then "10.0" | 
					
						
							| 
									
										
										
										
											2017-06-06 04:33:55 +01:00
										 |  |  |         when "10.13" then "9.0" | 
					
						
							| 
									
										
										
										
											2016-11-05 10:35:39 -04:00
										 |  |  |         when "10.12" then "8.0" | 
					
						
							|  |  |  |         else "2.0" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-18 15:31:15 -08:00
										 |  |  |       def below_minimum_version? | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         return false unless installed? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-05 10:35:39 -04:00
										 |  |  |         version < minimum_version | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-17 19:53:38 +00:00
										 |  |  |       def latest_sdk_version? | 
					
						
							|  |  |  |         OS::Mac.version == OS::Mac.latest_sdk_version | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def needs_clt_installed? | 
					
						
							|  |  |  |         return false if latest_sdk_version? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-17 19:53:38 +00:00
										 |  |  |         without_clt? | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def outdated? | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         return false unless installed? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         version < latest_version | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-05-22 22:26:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def without_clt? | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         version >= "4.3" && !MacOS::CLT.installed? | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-08-09 20:47:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-16 22:51:39 -07:00
										 |  |  |       # Returns a Pathname object corresponding to Xcode.app's Developer | 
					
						
							|  |  |  |       # directory or nil if Xcode.app is not installed | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def prefix | 
					
						
							| 
									
										
										
										
											2014-05-02 16:48:59 -05:00
										 |  |  |         @prefix ||= | 
					
						
							|  |  |  |           begin | 
					
						
							|  |  |  |             dir = MacOS.active_developer_dir | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-09 21:30:20 +00:00
										 |  |  |             if dir.empty? || dir == CLT::PKG_PATH || !File.directory?(dir) | 
					
						
							| 
									
										
										
										
											2014-05-02 16:48:59 -05:00
										 |  |  |               path = bundle_path | 
					
						
							| 
									
										
										
										
											2017-01-09 21:30:20 +00:00
										 |  |  |               path/"Contents/Developer" if path | 
					
						
							| 
									
										
										
										
											2014-05-02 16:48:59 -05:00
										 |  |  |             else | 
					
						
							| 
									
										
										
										
											2016-03-15 23:40:59 -07:00
										 |  |  |               # Use cleanpath to avoid pathological trailing slash | 
					
						
							|  |  |  |               Pathname.new(dir).cleanpath | 
					
						
							| 
									
										
										
										
											2014-05-02 16:48:59 -05:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2012-07-09 15:18:02 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-01 18:36:46 -05:00
										 |  |  |       def toolchain_path | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         return if version < "4.3" | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 11:09:21 +00:00
										 |  |  |         Pathname.new("#{prefix}/Toolchains/XcodeDefault.xctoolchain") | 
					
						
							| 
									
										
										
										
											2014-05-01 18:36:46 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def bundle_path | 
					
						
							| 
									
										
										
										
											2017-01-09 21:30:32 +00:00
										 |  |  |         # Use the default location if it exists. | 
					
						
							|  |  |  |         return DEFAULT_BUNDLE_PATH if DEFAULT_BUNDLE_PATH.exist? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Ask Spotlight where Xcode is. If the user didn't install the | 
					
						
							|  |  |  |         # helper tools and installed Xcode in a non-conventional place, this | 
					
						
							|  |  |  |         # is our only option. See: https://superuser.com/questions/390757 | 
					
						
							|  |  |  |         MacOS.app_with_bundle_id(BUNDLE_ID, OLD_BUNDLE_ID) | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-07-21 16:41:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def installed? | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |         !prefix.nil? | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-07-09 15:18:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-26 17:57:11 -07:00
										 |  |  |       def sdk(v = nil) | 
					
						
							|  |  |  |         @locator ||= XcodeSDKLocator.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         @locator.sdk_if_applicable(v) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def sdk_path(v = nil) | 
					
						
							|  |  |  |         sdk(v)&.path | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:34 +01:00
										 |  |  |       def update_instructions | 
					
						
							| 
									
										
										
										
											2016-12-05 11:09:21 +00:00
										 |  |  |         if MacOS.version >= "10.9" && !OS::Mac.prerelease? | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |           <<~EOS | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:34 +01:00
										 |  |  |             Xcode can be updated from the App Store. | 
					
						
							|  |  |  |           EOS | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |           <<~EOS | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:34 +01:00
										 |  |  |             Xcode can be updated from | 
					
						
							| 
									
										
										
										
											2017-03-28 11:12:34 -04:00
										 |  |  |               https://developer.apple.com/download/more/ | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:34 +01:00
										 |  |  |           EOS | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def version | 
					
						
							|  |  |  |         # may return a version string | 
					
						
							|  |  |  |         # that is guessed based on the compiler, so do not | 
					
						
							|  |  |  |         # use it in order to check if Xcode is installed. | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         if @version ||= detect_version | 
					
						
							|  |  |  |           ::Version.new @version | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           ::Version::NULL | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-07-09 15:18:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |       def detect_version | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |         # This is a separate function as you can't cache the value out of a block | 
					
						
							|  |  |  |         # if return is used in the middle, which we do many times in here. | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         return if !MacOS::Xcode.installed? && !MacOS::CLT.installed? | 
					
						
							| 
									
										
										
										
											2015-07-26 16:49:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-04 20:44:19 +02:00
										 |  |  |         %W[
 | 
					
						
							|  |  |  |           #{prefix}/usr/bin/xcodebuild | 
					
						
							|  |  |  |           #{which("xcodebuild")} | 
					
						
							|  |  |  |         ].uniq.each do |xcodebuild_path| | 
					
						
							| 
									
										
										
										
											2016-09-11 17:49:27 +01:00
										 |  |  |           next unless File.executable? xcodebuild_path | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-11 17:49:27 +01:00
										 |  |  |           xcodebuild_output = Utils.popen_read(xcodebuild_path, "-version") | 
					
						
							| 
									
										
										
										
											2017-06-10 20:12:55 +03:00
										 |  |  |           next unless $CHILD_STATUS.success? | 
					
						
							| 
									
										
										
										
											2016-05-04 20:44:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-05 19:44:11 -06:00
										 |  |  |           xcode_version = xcodebuild_output[/Xcode (\d+(\.\d+)*)/, 1] | 
					
						
							| 
									
										
										
										
											2016-09-11 17:49:27 +01:00
										 |  |  |           return xcode_version if xcode_version | 
					
						
							| 
									
										
										
										
											2014-04-17 08:23:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-11 17:49:27 +01:00
										 |  |  |           # Xcode 2.x's xcodebuild has a different version string | 
					
						
							|  |  |  |           case xcodebuild_output[/DevToolsCore-(\d+\.\d)/, 1] | 
					
						
							|  |  |  |           when "515.0" then return "2.0" | 
					
						
							|  |  |  |           when "798.0" then return "2.5" | 
					
						
							| 
									
										
										
										
											2014-04-15 14:18:45 -05:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 14:59:15 +00:00
										 |  |  |         detect_version_from_clang_version | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def detect_version_from_clang_version | 
					
						
							| 
									
										
										
										
											2018-06-05 14:53:24 -07:00
										 |  |  |         return "dunno" if DevelopmentTools.clang_version.null? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 14:59:15 +00:00
										 |  |  |         # This logic provides a fake Xcode version based on the | 
					
						
							| 
									
										
										
										
											2017-04-22 16:28:07 +01:00
										 |  |  |         # installed CLT version. This is useful as they are packaged | 
					
						
							|  |  |  |         # simultaneously so workarounds need to apply to both based on their | 
					
						
							|  |  |  |         # comparable version. | 
					
						
							| 
									
										
										
										
											2016-05-22 09:40:08 +01:00
										 |  |  |         case (DevelopmentTools.clang_version.to_f * 10).to_i | 
					
						
							| 
									
										
										
										
											2016-09-11 17:49:27 +01:00
										 |  |  |         when 0       then "dunno" | 
					
						
							|  |  |  |         when 1..14   then "3.2.2" | 
					
						
							|  |  |  |         when 15      then "3.2.4" | 
					
						
							|  |  |  |         when 16      then "3.2.5" | 
					
						
							|  |  |  |         when 17..20  then "4.0" | 
					
						
							|  |  |  |         when 21      then "4.1" | 
					
						
							|  |  |  |         when 22..30  then "4.2" | 
					
						
							|  |  |  |         when 31      then "4.3" | 
					
						
							|  |  |  |         when 40      then "4.4" | 
					
						
							|  |  |  |         when 41      then "4.5" | 
					
						
							|  |  |  |         when 42      then "4.6" | 
					
						
							|  |  |  |         when 50      then "5.0" | 
					
						
							|  |  |  |         when 51      then "5.1" | 
					
						
							|  |  |  |         when 60      then "6.0" | 
					
						
							|  |  |  |         when 61      then "6.1" | 
					
						
							|  |  |  |         when 70      then "7.0" | 
					
						
							|  |  |  |         when 73      then "7.3" | 
					
						
							|  |  |  |         when 80      then "8.0" | 
					
						
							| 
									
										
										
										
											2017-03-28 11:16:02 -04:00
										 |  |  |         when 81      then "8.3" | 
					
						
							| 
									
										
										
										
											2018-04-17 06:26:12 -07:00
										 |  |  |         when 90      then "9.2" | 
					
						
							| 
									
										
										
										
											2018-06-05 06:46:32 +01:00
										 |  |  |         when 91      then "9.4" | 
					
						
							| 
									
										
										
										
											2018-06-04 21:23:27 +01:00
										 |  |  |         when 100     then "10.0" | 
					
						
							|  |  |  |         else              "10.0" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-08-06 13:46:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def provides_gcc? | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         version < "4.3" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-08-06 13:46:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def default_prefix? | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         if version < "4.3" | 
					
						
							| 
									
										
										
										
											2016-01-14 13:57:18 +01:00
										 |  |  |           prefix.to_s.start_with? "/Developer" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2016-03-15 23:50:08 -07:00
										 |  |  |           prefix.to_s == "/Applications/Xcode.app/Contents/Developer" | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2012-07-09 15:18:02 -05:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-07-09 15:19:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |     module CLT | 
					
						
							| 
									
										
										
										
											2017-10-07 00:31:28 +02:00
										 |  |  |       module_function | 
					
						
							| 
									
										
										
										
											2012-07-10 21:01:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-11 17:49:27 +01:00
										 |  |  |       STANDALONE_PKG_ID = "com.apple.pkg.DeveloperToolsCLILeo".freeze | 
					
						
							|  |  |  |       FROM_XCODE_PKG_ID = "com.apple.pkg.DeveloperToolsCLI".freeze | 
					
						
							| 
									
										
										
										
											2018-07-06 15:15:23 -07:00
										 |  |  |       # The original Mavericks CLT package ID | 
					
						
							| 
									
										
										
										
											2018-06-12 14:30:27 -07:00
										 |  |  |       EXECUTABLE_PKG_ID = "com.apple.pkg.CLTools_Executables".freeze | 
					
						
							| 
									
										
										
										
											2016-09-11 17:49:27 +01:00
										 |  |  |       MAVERICKS_NEW_PKG_ID = "com.apple.pkg.CLTools_Base".freeze # obsolete | 
					
						
							| 
									
										
										
										
											2017-01-09 21:30:20 +00:00
										 |  |  |       PKG_PATH = "/Library/Developer/CommandLineTools".freeze | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |       HEADER_PKG_PATH = | 
					
						
							|  |  |  |         "/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_:macos_version.pkg".freeze | 
					
						
							| 
									
										
										
										
											2018-07-06 15:15:23 -07:00
										 |  |  |       HEADER_PKG_ID = "com.apple.pkg.macOS_SDK_headers_for_macOS_10.14".freeze | 
					
						
							| 
									
										
										
										
											2012-09-14 13:24:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-26 10:35:30 -07:00
										 |  |  |       # Returns true even if outdated tools are installed, e.g. | 
					
						
							|  |  |  |       # tools from Xcode 4.x on 10.9 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def installed? | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         !version.null? | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-07-21 16:41:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 14:30:27 -07:00
										 |  |  |       def separate_header_package? | 
					
						
							| 
									
										
										
										
											2018-07-23 16:22:02 -07:00
										 |  |  |         version >= "10" | 
					
						
							| 
									
										
										
										
											2018-06-12 14:30:27 -07:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-26 17:56:47 -07:00
										 |  |  |       def provides_sdk? | 
					
						
							|  |  |  |         version >= "8" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 14:30:27 -07:00
										 |  |  |       def headers_installed? | 
					
						
							|  |  |  |         if !separate_header_package? | 
					
						
							|  |  |  |           installed? | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           headers_version == version | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-26 17:57:11 -07:00
										 |  |  |       def sdk(v = nil) | 
					
						
							|  |  |  |         @locator ||= CLTSDKLocator.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         @locator.sdk_if_applicable(v) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def sdk_path(v = nil) | 
					
						
							|  |  |  |         sdk(v)&.path | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:34 +01:00
										 |  |  |       def update_instructions | 
					
						
							| 
									
										
										
										
											2016-12-05 11:09:21 +00:00
										 |  |  |         if MacOS.version >= "10.9" | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |           <<~EOS | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:34 +01:00
										 |  |  |             Update them from Software Update in the App Store. | 
					
						
							|  |  |  |           EOS | 
					
						
							|  |  |  |         elsif MacOS.version == "10.8" || MacOS.version == "10.7" | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |           <<~EOS | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:34 +01:00
										 |  |  |             The standalone package can be obtained from | 
					
						
							| 
									
										
										
										
											2017-03-28 11:12:34 -04:00
										 |  |  |               https://developer.apple.com/download/more/ | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:34 +01:00
										 |  |  |             or it can be installed via Xcode's preferences. | 
					
						
							|  |  |  |           EOS | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-01 16:16:01 -05:00
										 |  |  |       def latest_version | 
					
						
							| 
									
										
										
										
											2016-09-22 17:48:28 +01:00
										 |  |  |         # As of Xcode 8 CLT releases are no longer in sync with Xcode releases | 
					
						
							|  |  |  |         # on the older supported platform for that Xcode release, i.e there's no | 
					
						
							|  |  |  |         # CLT package for 10.11 that contains the Clang version from Xcode 8. | 
					
						
							| 
									
										
										
										
											2014-09-18 10:09:14 -05:00
										 |  |  |         case MacOS.version | 
					
						
							| 
									
										
										
										
											2018-08-14 00:02:19 +01:00
										 |  |  |         when "10.14" then "1000.10.43.1" | 
					
						
							| 
									
										
										
										
											2018-06-05 06:46:32 +01:00
										 |  |  |         when "10.13" then "902.0.39.2" | 
					
						
							| 
									
										
										
										
											2017-12-08 14:59:15 +00:00
										 |  |  |         when "10.12" then "900.0.39.2" | 
					
						
							| 
									
										
										
										
											2017-03-28 11:16:02 -04:00
										 |  |  |         when "10.11" then "800.0.42.1" | 
					
						
							| 
									
										
										
										
											2015-12-09 05:06:00 +00:00
										 |  |  |         when "10.10" then "700.1.81" | 
					
						
							| 
									
										
										
										
											2015-03-10 00:08:43 +00:00
										 |  |  |         when "10.9"  then "600.0.57" | 
					
						
							| 
									
										
										
										
											2014-09-18 10:09:14 -05:00
										 |  |  |         when "10.8"  then "503.0.40" | 
					
						
							| 
									
										
										
										
											2017-12-08 14:59:15 +00:00
										 |  |  |         else              "425.0.28" | 
					
						
							| 
									
										
										
										
											2013-11-01 16:16:01 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-08-17 17:18:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-05 10:35:39 -04:00
										 |  |  |       def minimum_version | 
					
						
							|  |  |  |         case MacOS.version | 
					
						
							| 
									
										
										
										
											2018-08-14 00:02:19 +01:00
										 |  |  |         when "10.14" then "10.0.0" | 
					
						
							| 
									
										
										
										
											2017-06-22 18:18:52 +01:00
										 |  |  |         when "10.13" then "9.0.0" | 
					
						
							| 
									
										
										
										
											2016-11-05 10:35:39 -04:00
										 |  |  |         when "10.12" then "8.0.0" | 
					
						
							| 
									
										
										
										
											2017-12-08 14:59:15 +00:00
										 |  |  |         else              "1.0.0" | 
					
						
							| 
									
										
										
										
											2016-11-05 10:35:39 -04:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-18 15:31:15 -08:00
										 |  |  |       def below_minimum_version? | 
					
						
							|  |  |  |         # Lion was the first version of OS X to ship with a CLT | 
					
						
							|  |  |  |         return false if MacOS.version < :lion | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         return false unless installed? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-05 10:35:39 -04:00
										 |  |  |         version < minimum_version | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def outdated? | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         clang_version = detect_clang_version | 
					
						
							|  |  |  |         return false unless clang_version | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         ::Version.new(clang_version) < latest_version | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def detect_clang_version | 
					
						
							| 
									
										
										
										
											2016-12-18 15:31:15 -08:00
										 |  |  |         # Lion was the first version of OS X to ship with a CLT | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         return if MacOS.version < :lion | 
					
						
							| 
									
										
										
										
											2016-12-18 15:31:15 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         path = if MacOS.version >= :mavericks | 
					
						
							|  |  |  |           "#{PKG_PATH}/usr/bin/clang" | 
					
						
							| 
									
										
										
										
											2014-05-12 14:33:41 -05:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |           "/usr/bin/clang" | 
					
						
							| 
									
										
										
										
											2014-05-12 14:33:41 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         version_output = Utils.popen_read("#{path} --version") | 
					
						
							|  |  |  |         version_output[/clang-(\d+\.\d+\.\d+(\.\d+)?)/, 1] | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-05-22 22:26:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-22 10:14:20 +00:00
										 |  |  |       # Version string (a pretty long one) of the CLT package. | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       # Note, that different ways to install the CLTs lead to different | 
					
						
							|  |  |  |       # version numbers. | 
					
						
							|  |  |  |       def version | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         if @version ||= detect_version | 
					
						
							|  |  |  |           ::Version.new @version | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           ::Version::NULL | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-07-21 20:09:55 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 14:30:27 -07:00
										 |  |  |       # Version string of the header package, which is a | 
					
						
							|  |  |  |       # separate package as of macOS 10.14. | 
					
						
							|  |  |  |       def headers_version | 
					
						
							|  |  |  |         if !separate_header_package? | 
					
						
							|  |  |  |           version | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2018-07-06 15:15:23 -07:00
										 |  |  |           @header_version ||= MacOS.pkgutil_info(HEADER_PKG_ID)[/version: (.+)$/, 1] | 
					
						
							| 
									
										
										
										
											2018-06-12 14:30:27 -07:00
										 |  |  |           return ::Version::NULL unless @header_version | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-12 14:30:27 -07:00
										 |  |  |           ::Version.new(@header_version) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       def detect_version | 
					
						
							| 
									
										
										
										
											2014-04-20 16:14:37 -07:00
										 |  |  |         # CLT isn't a distinct entity pre-4.3, and pkgutil doesn't exist | 
					
						
							|  |  |  |         # at all on Tiger, so just count it as installed if Xcode is installed | 
					
						
							| 
									
										
										
										
											2018-04-17 12:04:53 +01:00
										 |  |  |         if MacOS::Xcode.installed? && MacOS::Xcode.version < "3.0" | 
					
						
							|  |  |  |           return MacOS::Xcode.version | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2014-04-20 16:14:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         version = nil | 
					
						
							| 
									
										
										
										
											2018-06-12 14:30:27 -07:00
										 |  |  |         [EXECUTABLE_PKG_ID, MAVERICKS_NEW_PKG_ID, STANDALONE_PKG_ID, FROM_XCODE_PKG_ID].each do |id| | 
					
						
							| 
									
										
										
										
											2016-11-26 13:59:55 -05:00
										 |  |  |           if MacOS.version >= :mavericks | 
					
						
							| 
									
										
										
										
											2017-01-09 21:30:20 +00:00
										 |  |  |             next unless File.exist?("#{PKG_PATH}/usr/bin/clang") | 
					
						
							| 
									
										
										
										
											2014-10-17 19:36:25 +01:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |           version = MacOS.pkgutil_info(id)[/version: (.+)$/, 1] | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |           break if version | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-11-05 12:09:04 +00:00
										 |  |  |         version | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-07-21 20:09:55 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-07-09 15:18:02 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | end |