From 8704e79cc0f4c6f5ae50bdbeb35cc2312f8788aa Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 15 Nov 2023 19:52:21 +0000 Subject: [PATCH] Separate `MacOS` references --- Library/Homebrew/cmd/gist-logs.rb | 4 +--- Library/Homebrew/extend/os/linkage_checker.rb | 6 ++++- Library/Homebrew/extend/os/mac/formula.rb | 22 +++++++++++++++++++ .../Homebrew/extend/os/mac/linkage_checker.rb | 13 +++++++++++ Library/Homebrew/extend/os/mac/utils/curl.rb | 15 +++++++++++++ Library/Homebrew/extend/os/utils/curl.rb | 4 ++++ Library/Homebrew/formula.rb | 12 ++-------- Library/Homebrew/linkage_checker.rb | 8 +++++-- Library/Homebrew/utils/curl.rb | 14 +++++++----- 9 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 Library/Homebrew/extend/os/mac/linkage_checker.rb create mode 100644 Library/Homebrew/extend/os/mac/utils/curl.rb create mode 100644 Library/Homebrew/extend/os/utils/curl.rb diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index dba4217ee2..829cec0c4b 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -73,9 +73,7 @@ module Homebrew EOS end - if args.new_issue? - url = GitHub.create_issue(formula.tap, "#{formula.name} failed to build on #{MacOS.full_version}", url) - end + url = GitHub.create_issue(formula.tap, "#{formula.name} failed to build on #{OS_VERSION}", url) if args.new_issue? puts url if url end diff --git a/Library/Homebrew/extend/os/linkage_checker.rb b/Library/Homebrew/extend/os/linkage_checker.rb index 3e8904e5eb..175e201324 100644 --- a/Library/Homebrew/extend/os/linkage_checker.rb +++ b/Library/Homebrew/extend/os/linkage_checker.rb @@ -1,4 +1,8 @@ # typed: strict # frozen_string_literal: true -require "extend/os/linux/linkage_checker" if OS.linux? +if OS.mac? + require "extend/os/mac/linkage_checker" +else + require "extend/os/linux/linkage_checker" +end diff --git a/Library/Homebrew/extend/os/mac/formula.rb b/Library/Homebrew/extend/os/mac/formula.rb index 0d65ad84fe..a5dbd1684c 100644 --- a/Library/Homebrew/extend/os/mac/formula.rb +++ b/Library/Homebrew/extend/os/mac/formula.rb @@ -3,9 +3,31 @@ class Formula undef valid_platform? + undef std_cmake_args sig { returns(T::Boolean) } def valid_platform? requirements.none?(LinuxRequirement) end + + sig { + params( + install_prefix: T.any(String, Pathname), + install_libdir: T.any(String, Pathname), + find_framework: String, + ).returns(T::Array[String]) + } + def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework: "LAST") + args = generic_std_cmake_args(install_prefix: install_prefix, install_libdir: install_libdir, + find_framework: find_framework) + + # Avoid false positives for clock_gettime support on 10.11. + # CMake cache entries for other weak symbols may be added here as needed. + args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0" if MacOS.version == "10.11" && MacOS::Xcode.version >= "8.0" + + # Ensure CMake is using the same SDK we are using. + args << "-DCMAKE_OSX_SYSROOT=#{MacOS.sdk_for_formula(self).path}" if MacOS.sdk_root_needed? + + args + end end diff --git a/Library/Homebrew/extend/os/mac/linkage_checker.rb b/Library/Homebrew/extend/os/mac/linkage_checker.rb new file mode 100644 index 0000000000..9baba42a7d --- /dev/null +++ b/Library/Homebrew/extend/os/mac/linkage_checker.rb @@ -0,0 +1,13 @@ +# typed: true +# frozen_string_literal: true + +class LinkageChecker + undef system_libraries_exist_in_cache? + + private + + def system_libraries_exist_in_cache? + # In macOS Big Sur and later, system libraries do not exist on-disk and instead exist in a cache. + MacOS.version >= :big_sur + end +end diff --git a/Library/Homebrew/extend/os/mac/utils/curl.rb b/Library/Homebrew/extend/os/mac/utils/curl.rb new file mode 100644 index 0000000000..56c7e56f51 --- /dev/null +++ b/Library/Homebrew/extend/os/mac/utils/curl.rb @@ -0,0 +1,15 @@ +# typed: true +# frozen_string_literal: true + +module Utils + module Curl + undef return_value_for_empty_http_status_code + + def return_value_for_empty_http_status_code(url_type, url) + # Hack around https://github.com/Homebrew/brew/issues/3199 + return if MacOS.version == :el_capitan + + generic_return_value_for_empty_http_status_code url_type, url + end + end +end diff --git a/Library/Homebrew/extend/os/utils/curl.rb b/Library/Homebrew/extend/os/utils/curl.rb new file mode 100644 index 0000000000..fbd35e61e4 --- /dev/null +++ b/Library/Homebrew/extend/os/utils/curl.rb @@ -0,0 +1,4 @@ +# typed: strict +# frozen_string_literal: true + +require "extend/os/mac/utils/curl" if OS.mac? diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 1b04c8484d..2ab55beccd 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1646,7 +1646,7 @@ class Formula ).returns(T::Array[String]) } def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework: "LAST") - args = %W[ + %W[ -DCMAKE_INSTALL_PREFIX=#{install_prefix} -DCMAKE_INSTALL_LIBDIR=#{install_libdir} -DCMAKE_BUILD_TYPE=Release @@ -1655,16 +1655,8 @@ class Formula -Wno-dev -DBUILD_TESTING=OFF ] - - # Avoid false positives for clock_gettime support on 10.11. - # CMake cache entries for other weak symbols may be added here as needed. - args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0" if MacOS.version == "10.11" && MacOS::Xcode.version >= "8.0" - - # Ensure CMake is using the same SDK we are using. - args << "-DCMAKE_OSX_SYSROOT=#{MacOS.sdk_for_formula(self).path}" if MacOS.sdk_root_needed? - - args end + alias generic_std_cmake_args std_cmake_args # Standard parameters for Go builds. sig { diff --git a/Library/Homebrew/linkage_checker.rb b/Library/Homebrew/linkage_checker.rb index b3b00bbeb3..d3befd6423 100644 --- a/Library/Homebrew/linkage_checker.rb +++ b/Library/Homebrew/linkage_checker.rb @@ -196,9 +196,8 @@ class LinkageChecker if (dep = dylib_to_dep(dylib)) @broken_deps[dep] |= [dylib] - elsif MacOS.version >= :big_sur && dylib_found_via_dlopen(dylib) + elsif system_libraries_exist_in_cache? && dylib_found_via_dlopen(dylib) # If we cannot associate the dylib with a dependency, then it may be a system library. - # In macOS Big Sur and later, system libraries do not exist on-disk and instead exist in a cache. # If dlopen finds the dylib, then the linkage is not broken. @system_dylibs << dylib elsif !system_framework?(dylib) @@ -227,6 +226,11 @@ class LinkageChecker end alias generic_check_dylibs check_dylibs + def system_libraries_exist_in_cache? + false + end + alias generic_system_libraries_exist_in_cache? system_libraries_exist_in_cache? + def dylib_found_via_dlopen(dylib) Fiddle.dlopen(dylib).close true diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 5f594cc8df..a1b1c1b44b 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -320,12 +320,7 @@ module Utils break if http_status_ok?(details[:status_code]) end - unless details[:status_code] - # Hack around https://github.com/Homebrew/brew/issues/3199 - return if MacOS.version == :el_capitan - - return "The #{url_type} #{url} is not reachable" - end + return return_value_for_empty_http_status_code(url_type, url) unless details[:status_code] unless http_status_ok?(details[:status_code]) return if details[:responses].any? do |response| @@ -486,6 +481,11 @@ module Utils (100..299).cover?(status.to_i) end + def return_value_for_empty_http_status_code(url_type, url) + "The #{url_type} #{url} is not reachable" + end + alias generic_return_value_for_empty_http_status_code return_value_for_empty_http_status_code + # Separates the output text from `curl` into an array of HTTP responses and # the final response body (i.e. content). Response hashes contain the # `:status_code`, `:status_text`, and `:headers`. @@ -619,3 +619,5 @@ module Utils end end end + +require "extend/os/utils/curl"