| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 11:07:24 +01:00
										 |  |  | require "os/mac/xcode" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  | # @private | 
					
						
							|  |  |  | class DevelopmentTools | 
					
						
							|  |  |  |   class << self | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  |     alias generic_locate locate | 
					
						
							|  |  |  |     undef installed?, default_compiler, curl_handles_most_https_certificates?, | 
					
						
							| 
									
										
										
										
											2022-02-21 22:49:55 +01:00
										 |  |  |           subversion_handles_most_https_certificates? | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-29 15:12:53 -07:00
										 |  |  |     sig { params(tool: String).returns(T.nilable(Pathname)) } | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     def locate(tool) | 
					
						
							|  |  |  |       (@locate ||= {}).fetch(tool) do |key| | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  |         @locate[key] = if (located_tool = generic_locate(tool)) | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |           located_tool | 
					
						
							| 
									
										
										
										
											2019-01-08 19:13:46 +00:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2017-09-19 10:19:56 -07:00
										 |  |  |           path = Utils.popen_read("/usr/bin/xcrun", "-no-cache", "-find", tool, err: :close).chomp | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |           Pathname.new(path) if File.executable?(path) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 11:07:24 +01:00
										 |  |  |     # Checks if the user has any developer tools installed, either via Xcode | 
					
						
							|  |  |  |     # or the CLT. Convenient for guarding against formula builds when building | 
					
						
							|  |  |  |     # is impossible. | 
					
						
							| 
									
										
										
										
											2021-09-29 15:12:53 -07:00
										 |  |  |     sig { returns(T::Boolean) } | 
					
						
							| 
									
										
										
										
											2016-07-06 11:07:24 +01:00
										 |  |  |     def installed? | 
					
						
							|  |  |  |       MacOS::Xcode.installed? || MacOS::CLT.installed? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(Symbol) } | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  |     def default_compiler | 
					
						
							| 
									
										
										
										
											2019-01-26 17:13:14 +00:00
										 |  |  |       :clang | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(T::Boolean) } | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  |     def curl_handles_most_https_certificates? | 
					
						
							|  |  |  |       # The system Curl is too old for some modern HTTPS certificates on | 
					
						
							|  |  |  |       # older macOS versions. | 
					
						
							|  |  |  |       ENV["HOMEBREW_SYSTEM_CURL_TOO_OLD"].nil? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(T::Boolean) } | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  |     def subversion_handles_most_https_certificates? | 
					
						
							|  |  |  |       # The system Subversion is too old for some HTTPS certificates on | 
					
						
							|  |  |  |       # older macOS versions. | 
					
						
							|  |  |  |       MacOS.version >= :sierra | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:22 +01:00
										 |  |  |     def installation_instructions | 
					
						
							| 
									
										
										
										
											2021-02-07 04:21:59 +00:00
										 |  |  |       MacOS::CLT.installation_instructions | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:22 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:22 +01:00
										 |  |  |     def custom_installation_instructions | 
					
						
							| 
									
										
										
										
											2019-01-08 19:13:46 +00:00
										 |  |  |       <<~EOS | 
					
						
							| 
									
										
										
										
											2019-04-08 12:47:15 -04:00
										 |  |  |         Install GNU's GCC: | 
					
						
							| 
									
										
										
										
											2019-01-08 19:13:46 +00:00
										 |  |  |           brew install gcc | 
					
						
							|  |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:22 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-04-06 13:04:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-29 17:43:47 -07:00
										 |  |  |     sig { returns(T::Hash[String, T.nilable(String)]) } | 
					
						
							| 
									
										
										
										
											2020-04-06 13:04:48 +01:00
										 |  |  |     def build_system_info | 
					
						
							|  |  |  |       build_info = { | 
					
						
							| 
									
										
										
										
											2021-04-29 17:51:41 +01:00
										 |  |  |         "xcode"          => MacOS::Xcode.version.to_s.presence, | 
					
						
							|  |  |  |         "clt"            => MacOS::CLT.version.to_s.presence, | 
					
						
							|  |  |  |         "preferred_perl" => MacOS.preferred_perl_version, | 
					
						
							| 
									
										
										
										
											2020-04-06 13:04:48 +01:00
										 |  |  |       } | 
					
						
							|  |  |  |       generic_build_system_info.merge build_info | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |