| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  | # @private | 
					
						
							|  |  |  | class DevelopmentTools | 
					
						
							|  |  |  |   class << self | 
					
						
							|  |  |  |     def locate(tool) | 
					
						
							|  |  |  |       # Don't call tools (cc, make, strip, etc.) directly! | 
					
						
							|  |  |  |       # Give the name of the binary you look for as a string to this method | 
					
						
							|  |  |  |       # in order to get the full path back as a Pathname. | 
					
						
							|  |  |  |       (@locate ||= {}).fetch(tool) do |key| | 
					
						
							|  |  |  |         @locate[key] = if File.executable?(path = "/usr/bin/#{tool}") | 
					
						
							|  |  |  |           Pathname.new path | 
					
						
							|  |  |  |         # Homebrew GCCs most frequently; much faster to check this before xcrun | 
					
						
							|  |  |  |         elsif (path = HOMEBREW_PREFIX/"bin/#{tool}").executable? | 
					
						
							|  |  |  |           path | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def installed? | 
					
						
							| 
									
										
										
										
											2017-12-20 17:26:17 -08:00
										 |  |  |       locate("clang") || locate("gcc") | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:22 +01:00
										 |  |  |     def installation_instructions | 
					
						
							|  |  |  |       "Install Clang or brew install gcc" | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |     alias custom_installation_instructions installation_instructions | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     def default_cc | 
					
						
							|  |  |  |       cc = DevelopmentTools.locate "cc" | 
					
						
							| 
									
										
										
										
											2016-09-17 15:17:27 +01:00
										 |  |  |       begin | 
					
						
							|  |  |  |         cc.realpath.basename.to_s | 
					
						
							|  |  |  |       rescue | 
					
						
							|  |  |  |         nil | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def default_compiler | 
					
						
							| 
									
										
										
										
											2016-12-30 20:20:13 +00:00
										 |  |  |       :clang | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 20:20:13 +00:00
										 |  |  |     def gcc_4_0_build_version | 
					
						
							|  |  |  |       @gcc_4_0_build_version ||= begin | 
					
						
							| 
									
										
										
										
											2016-11-15 14:43:56 +00:00
										 |  |  |         if (path = locate("gcc-4.0")) && | 
					
						
							|  |  |  |            build_version = `#{path} --version 2>/dev/null`[/build (\d{4,})/, 1] | 
					
						
							|  |  |  |           Version.new build_version | 
					
						
							| 
									
										
										
										
											2016-11-03 16:48:51 -07:00
										 |  |  |         else | 
					
						
							|  |  |  |           Version::NULL | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-11-21 08:49:04 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 20:20:13 +00:00
										 |  |  |     def gcc_4_2_build_version | 
					
						
							|  |  |  |       @gcc_4_2_build_version ||= begin | 
					
						
							| 
									
										
										
										
											2017-06-01 16:06:51 +02:00
										 |  |  |         gcc = locate("gcc-4.2") || HOMEBREW_PREFIX/"opt/apple-gcc42/bin/gcc-4.2" | 
					
						
							|  |  |  |         if gcc.exist? && !gcc.realpath.basename.to_s.start_with?("llvm") && | 
					
						
							| 
									
										
										
										
											2016-11-21 08:49:04 +00:00
										 |  |  |            build_version = `#{gcc} --version 2>/dev/null`[/build (\d{4,})/, 1] | 
					
						
							|  |  |  |           Version.new build_version | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           Version::NULL | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-11-21 08:49:04 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def clang_version | 
					
						
							| 
									
										
										
										
											2016-11-21 08:49:04 +00:00
										 |  |  |       @clang_version ||= begin | 
					
						
							| 
									
										
										
										
											2016-11-15 14:43:56 +00:00
										 |  |  |         if (path = locate("clang")) && | 
					
						
							| 
									
										
										
										
											2018-06-05 05:28:37 +01:00
										 |  |  |            build_version = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d)/, 1] | 
					
						
							| 
									
										
										
										
											2016-11-15 14:43:56 +00:00
										 |  |  |           Version.new build_version | 
					
						
							| 
									
										
										
										
											2016-11-03 16:48:51 -07:00
										 |  |  |         else | 
					
						
							|  |  |  |           Version::NULL | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-11-21 08:49:04 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def clang_build_version | 
					
						
							| 
									
										
										
										
											2016-11-21 08:49:04 +00:00
										 |  |  |       @clang_build_version ||= begin | 
					
						
							| 
									
										
										
										
											2016-11-15 14:43:56 +00:00
										 |  |  |         if (path = locate("clang")) && | 
					
						
							| 
									
										
										
										
											2018-03-17 18:03:19 -07:00
										 |  |  |            build_version = `#{path} --version`[%r{clang(-| version [^ ]+ \(tags/RELEASE_)(\d{2,})}, 2] | 
					
						
							| 
									
										
										
										
											2016-11-15 14:43:56 +00:00
										 |  |  |           Version.new build_version | 
					
						
							| 
									
										
										
										
											2016-11-03 16:48:51 -07:00
										 |  |  |         else | 
					
						
							|  |  |  |           Version::NULL | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-11-21 08:49:29 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-05-10 08:19:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 23:56:54 -04:00
										 |  |  |     def llvm_clang_build_version | 
					
						
							| 
									
										
										
										
											2016-11-21 08:49:29 +00:00
										 |  |  |       @llvm_clang_build_version ||= begin | 
					
						
							| 
									
										
										
										
											2016-09-24 23:56:54 -04:00
										 |  |  |         path = Formulary.factory("llvm").opt_prefix/"bin/clang" | 
					
						
							| 
									
										
										
										
											2016-11-21 08:49:29 +00:00
										 |  |  |         if path.executable? && | 
					
						
							|  |  |  |            build_version = `#{path} --version`[/clang version (\d\.\d\.\d)/, 1] | 
					
						
							|  |  |  |           Version.new build_version | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           Version::NULL | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-09-24 23:56:54 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-10 08:19:48 +01:00
										 |  |  |     def non_apple_gcc_version(cc) | 
					
						
							|  |  |  |       (@non_apple_gcc_version ||= {}).fetch(cc) do | 
					
						
							| 
									
										
										
										
											2017-06-01 16:06:51 +02:00
										 |  |  |         path = HOMEBREW_PREFIX/"opt/gcc/bin"/cc | 
					
						
							| 
									
										
										
										
											2016-05-10 08:19:48 +01:00
										 |  |  |         path = locate(cc) unless path.exist? | 
					
						
							| 
									
										
										
										
											2016-11-15 14:43:56 +00:00
										 |  |  |         version = if path && | 
					
						
							| 
									
										
										
										
											2018-09-27 18:26:03 -07:00
										 |  |  |                      build_version = `#{path} --version`[/gcc(?:(?:-\d(?:\.\d)?)? \(.+\))? (\d\.\d\.\d)/, 1] | 
					
						
							| 
									
										
										
										
											2016-11-15 14:43:56 +00:00
										 |  |  |           Version.new build_version | 
					
						
							| 
									
										
										
										
											2016-11-03 16:48:51 -07:00
										 |  |  |         else | 
					
						
							|  |  |  |           Version::NULL | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-05-10 08:19:48 +01:00
										 |  |  |         @non_apple_gcc_version[cc] = version | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def clear_version_cache | 
					
						
							| 
									
										
										
										
											2016-12-30 20:20:13 +00:00
										 |  |  |       @gcc_4_0_build_version = @gcc_4_2_build_version = nil | 
					
						
							| 
									
										
										
										
											2016-05-10 08:19:48 +01:00
										 |  |  |       @clang_version = @clang_build_version = nil | 
					
						
							|  |  |  |       @non_apple_gcc_version = {} | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-12-30 20:17:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-16 12:41:08 +01:00
										 |  |  |     def curl_handles_most_https_certificates? | 
					
						
							| 
									
										
										
										
											2016-12-30 20:17:34 +00:00
										 |  |  |       true | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-03-05 11:42:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def subversion_handles_most_https_certificates? | 
					
						
							|  |  |  |       true | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "extend/os/development_tools" |