2024-09-21 12:24:21 -07:00
|
|
|
# typed: strict
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-06 11:07:24 +01:00
|
|
|
require "os/mac/xcode"
|
|
|
|
|
2024-09-21 12:24:21 -07:00
|
|
|
module OS
|
|
|
|
module Mac
|
|
|
|
module DevelopmentTools
|
2025-06-21 21:40:57 -04:00
|
|
|
module ClassMethods
|
|
|
|
extend T::Helpers
|
2018-04-07 20:28:56 +01: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 (located_tool = super(tool))
|
|
|
|
located_tool
|
|
|
|
else
|
|
|
|
path = Utils.popen_read("/usr/bin/xcrun", "-no-cache", "-find", tool, err: :close).chomp
|
|
|
|
Pathname.new(path) if File.executable?(path)
|
|
|
|
end
|
2024-09-21 12:24:21 -07:00
|
|
|
end
|
2016-04-25 18:01:03 +01:00
|
|
|
end
|
|
|
|
|
2025-06-21 21:40:57 -04: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.
|
|
|
|
sig { returns(T::Boolean) }
|
|
|
|
def installed?
|
|
|
|
MacOS::Xcode.installed? || MacOS::CLT.installed?
|
|
|
|
end
|
2016-07-06 11:07:24 +01:00
|
|
|
|
2025-06-21 21:40:57 -04:00
|
|
|
sig { returns(Symbol) }
|
|
|
|
def default_compiler
|
|
|
|
:clang
|
|
|
|
end
|
2018-04-07 20:28:56 +01:00
|
|
|
|
2025-06-21 21:40:57 -04:00
|
|
|
sig { returns(Version) }
|
|
|
|
def ld64_version
|
|
|
|
@ld64_version ||= T.let(begin
|
|
|
|
json = Utils.popen_read("/usr/bin/ld", "-version_details")
|
|
|
|
if $CHILD_STATUS.success?
|
|
|
|
Version.parse(JSON.parse(json)["version"])
|
|
|
|
else
|
|
|
|
Version::NULL
|
|
|
|
end
|
|
|
|
end, T.nilable(Version))
|
|
|
|
end
|
2024-03-08 21:26:25 +00:00
|
|
|
|
2025-06-21 21:40:57 -04:00
|
|
|
sig { returns(T::Boolean) }
|
|
|
|
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
|
2018-04-07 20:28:56 +01:00
|
|
|
|
2025-06-21 21:40:57 -04:00
|
|
|
sig { returns(T::Boolean) }
|
|
|
|
def subversion_handles_most_https_certificates?
|
|
|
|
# The system Subversion is too old for some HTTPS certificates on
|
|
|
|
# older macOS versions.
|
|
|
|
MacOS.version >= :sierra
|
|
|
|
end
|
2018-04-07 20:28:56 +01:00
|
|
|
|
2025-06-21 21:40:57 -04:00
|
|
|
sig { returns(String) }
|
|
|
|
def installation_instructions
|
|
|
|
MacOS::CLT.installation_instructions
|
|
|
|
end
|
2016-07-16 21:01:22 +01:00
|
|
|
|
2025-06-21 21:40:57 -04:00
|
|
|
sig { returns(String) }
|
|
|
|
def custom_installation_instructions
|
|
|
|
<<~EOS
|
|
|
|
Install GNU's GCC:
|
|
|
|
brew install gcc
|
|
|
|
EOS
|
|
|
|
end
|
2020-04-06 13:04:48 +01:00
|
|
|
|
2025-06-21 21:40:57 -04:00
|
|
|
sig { returns(T::Hash[String, T.nilable(String)]) }
|
|
|
|
def build_system_info
|
|
|
|
build_info = {
|
|
|
|
"xcode" => MacOS::Xcode.version.to_s.presence,
|
|
|
|
"clt" => MacOS::CLT.version.to_s.presence,
|
|
|
|
"preferred_perl" => MacOS.preferred_perl_version,
|
|
|
|
}
|
|
|
|
super.merge build_info
|
|
|
|
end
|
2024-09-21 12:24:21 -07:00
|
|
|
end
|
2020-04-06 13:04:48 +01:00
|
|
|
end
|
2016-04-25 18:01:03 +01:00
|
|
|
end
|
|
|
|
end
|
2024-09-21 12:24:21 -07:00
|
|
|
|
2025-06-21 21:40:57 -04:00
|
|
|
DevelopmentTools.singleton_class.prepend(OS::Mac::DevelopmentTools::ClassMethods)
|