| 
									
										
										
										
											2024-09-21 12:24:21 -07:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-21 12:24:21 -07:00
										 |  |  | module OS | 
					
						
							|  |  |  |   module Linux | 
					
						
							|  |  |  |     module DevelopmentTools | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |       module ClassMethods | 
					
						
							|  |  |  |         extend T::Helpers | 
					
						
							| 
									
										
										
										
											2024-09-21 12:24:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         requires_ancestor { ::DevelopmentTools } | 
					
						
							| 
									
										
										
										
											2024-09-21 12:24:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         sig { params(tool: T.any(String, Symbol)).returns(T.nilable(Pathname)) } | 
					
						
							|  |  |  |         def locate(tool) | 
					
						
							|  |  |  |           @locate ||= T.let({}, T.nilable(T::Hash[T.any(String, Symbol), Pathname])) | 
					
						
							|  |  |  |           @locate.fetch(tool) do |key| | 
					
						
							|  |  |  |             @locate[key] = if ::DevelopmentTools.needs_build_formulae? && | 
					
						
							|  |  |  |                               (binutils_path = HOMEBREW_PREFIX/"opt/binutils/bin/#{tool}").executable? | 
					
						
							|  |  |  |               binutils_path | 
					
						
							|  |  |  |             elsif ::DevelopmentTools.needs_build_formulae? && | 
					
						
							|  |  |  |                   (glibc_path = HOMEBREW_PREFIX/"opt/glibc/bin/#{tool}").executable? | 
					
						
							|  |  |  |               glibc_path | 
					
						
							|  |  |  |             elsif (homebrew_path = HOMEBREW_PREFIX/"bin/#{tool}").executable? | 
					
						
							|  |  |  |               homebrew_path | 
					
						
							|  |  |  |             elsif File.executable?(system_path = "/usr/bin/#{tool}") | 
					
						
							|  |  |  |               Pathname.new system_path | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2024-09-21 12:24:21 -07:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2018-10-01 15:34:47 -07:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         sig { returns(Symbol) } | 
					
						
							|  |  |  |         def default_compiler = :gcc | 
					
						
							| 
									
										
										
										
											2021-03-31 17:01:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         sig { returns(T::Boolean) } | 
					
						
							|  |  |  |         def needs_libc_formula? | 
					
						
							|  |  |  |           return @needs_libc_formula unless @needs_libc_formula.nil? | 
					
						
							| 
									
										
										
										
											2022-08-25 11:04:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-25 15:56:33 +00:00
										 |  |  |           @needs_libc_formula = T.let(nil, T.nilable(T::Boolean)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           # Undocumented environment variable to make it easier to test libc | 
					
						
							|  |  |  |           # formula automatic installation. | 
					
						
							|  |  |  |           @needs_libc_formula = true if ENV["HOMEBREW_FORCE_LIBC_FORMULA"] | 
					
						
							|  |  |  |           @needs_libc_formula ||= OS::Linux::Glibc.below_ci_version? | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2022-08-25 11:04:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         # Keep this method around for now to make it easier to add this functionality later. | 
					
						
							|  |  |  |         # rubocop:disable Lint/UselessMethodDefinition | 
					
						
							|  |  |  |         sig { returns(Pathname) } | 
					
						
							|  |  |  |         def host_gcc_path | 
					
						
							|  |  |  |           # TODO: override this if/when we to pick the GCC based on e.g. the Ubuntu version. | 
					
						
							|  |  |  |           super | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         # rubocop:enable Lint/UselessMethodDefinition | 
					
						
							| 
									
										
										
										
											2025-04-03 12:47:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         sig { returns(T::Boolean) } | 
					
						
							|  |  |  |         def needs_compiler_formula? | 
					
						
							|  |  |  |           return @needs_compiler_formula unless @needs_compiler_formula.nil? | 
					
						
							| 
									
										
										
										
											2022-09-20 13:06:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |           @needs_compiler_formula = T.let(nil, T.nilable(T::Boolean)) | 
					
						
							| 
									
										
										
										
											2025-07-25 15:56:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |           # Undocumented environment variable to make it easier to test compiler | 
					
						
							|  |  |  |           # formula automatic installation. | 
					
						
							|  |  |  |           @needs_compiler_formula = true if ENV["HOMEBREW_FORCE_COMPILER_FORMULA"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @needs_compiler_formula ||= if host_gcc_path.exist? | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |             ::DevelopmentTools.gcc_version(host_gcc_path.to_s) < OS::LINUX_GCC_CI_VERSION | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             true | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2025-04-03 12:47:21 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2022-08-25 11:04:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  |         sig { returns(T::Hash[String, T.nilable(String)]) } | 
					
						
							|  |  |  |         def build_system_info | 
					
						
							|  |  |  |           super.merge({ | 
					
						
							|  |  |  |             "glibc_version"     => OS::Linux::Glibc.version.to_s.presence, | 
					
						
							|  |  |  |             "oldest_cpu_family" => ::Hardware.oldest_cpu.to_s, | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2024-09-21 12:24:21 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-03-31 17:01:36 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-09-27 18:26:03 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2024-09-21 12:24:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 21:40:57 -04:00
										 |  |  | DevelopmentTools.singleton_class.prepend(OS::Linux::DevelopmentTools::ClassMethods) |