test: don't try to use Xcode SDK for build requirement

This commit is contained in:
Rylan Polster 2020-12-17 18:30:03 -05:00
parent 993bf95877
commit af6be13e7c
6 changed files with 25 additions and 15 deletions

View File

@ -2,8 +2,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module Stdenv module Stdenv
def setup_build_environment(**options) def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false)
generic_setup_build_environment(**options) generic_setup_build_environment(formula: formula, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
prepend_path "CPATH", HOMEBREW_PREFIX/"include" prepend_path "CPATH", HOMEBREW_PREFIX/"include"
prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib" prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib"

View File

@ -10,8 +10,8 @@ module Superenv
end end
# @private # @private
def setup_build_environment(**options) def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false)
generic_setup_build_environment(**options) generic_setup_build_environment(formula: formula, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2" self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2"
self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path
self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(@formula) self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(@formula)

View File

@ -10,8 +10,8 @@ module Stdenv
["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.sdk_version}"] ["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.sdk_version}"]
end end
def setup_build_environment(**options) def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false)
generic_setup_build_environment(**options) generic_setup_build_environment(formula: formula, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
# sed is strict, and errors out when it encounters files with # sed is strict, and errors out when it encounters files with
# mixed character sets # mixed character sets
@ -19,7 +19,7 @@ module Stdenv
self["LC_CTYPE"] = "C" self["LC_CTYPE"] = "C"
# Add lib and include etc. from the current macosxsdk to compiler flags: # Add lib and include etc. from the current macosxsdk to compiler flags:
macosxsdk(formula: @formula) macosxsdk(formula: @formula, testing_formula: testing_formula)
return unless MacOS::Xcode.without_clt? return unless MacOS::Xcode.without_clt?
@ -50,7 +50,7 @@ module Stdenv
remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks"
end end
def macosxsdk(version = nil, formula: nil) def macosxsdk(version = nil, formula: nil, testing_formula: false)
# Sets all needed lib and include dirs to CFLAGS, CPPFLAGS, LDFLAGS. # Sets all needed lib and include dirs to CFLAGS, CPPFLAGS, LDFLAGS.
remove_macosxsdk remove_macosxsdk
min_version = version || MacOS.version min_version = version || MacOS.version
@ -58,7 +58,11 @@ module Stdenv
self["CPATH"] = "#{HOMEBREW_PREFIX}/include" self["CPATH"] = "#{HOMEBREW_PREFIX}/include"
prepend "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib" prepend "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"
sdk = formula ? MacOS.sdk_for_formula(formula, version) : MacOS.sdk(version) sdk = if formula
MacOS.sdk_for_formula(formula, version, check_only_runtime_requirements: testing_formula)
else
MacOS.sdk(version)
end
return if !MacOS.sdk_root_needed? && sdk&.source != :xcode return if !MacOS.sdk_root_needed? && sdk&.source != :xcode
Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks) Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks)

View File

@ -106,8 +106,7 @@ module Superenv
end end
# @private # @private
def setup_build_environment(**options) def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false)
formula = options[:formula]
sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk
if MacOS.sdk_root_needed? || sdk&.source == :xcode if MacOS.sdk_root_needed? || sdk&.source == :xcode
Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks) Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks)
@ -122,7 +121,7 @@ module Superenv
self["HOMEBREW_SDKROOT"] = nil self["HOMEBREW_SDKROOT"] = nil
self["HOMEBREW_DEVELOPER_DIR"] = nil self["HOMEBREW_DEVELOPER_DIR"] = nil
end end
generic_setup_build_environment(**options) generic_setup_build_environment(formula: formula, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
# Filter out symbols known not to be defined since GNU Autotools can't # Filter out symbols known not to be defined since GNU Autotools can't
# reliably figure this out with Xcode 8 and above. # reliably figure this out with Xcode 8 and above.

View File

@ -120,9 +120,16 @@ module OS
sdk_locator.sdk_if_applicable(v) sdk_locator.sdk_if_applicable(v)
end end
def sdk_for_formula(f, v = nil) def sdk_for_formula(f, v = nil, check_only_runtime_requirements: false)
# If the formula requires Xcode, don't return the CLT SDK # If the formula requires Xcode, don't return the CLT SDK
return Xcode.sdk if f.requirements.any? { |req| req.is_a? XcodeRequirement } # If check_only_runtime_requirements is true, don't necessarily return the
# Xcode SDK if the XcodeRequirement is only a build or test requirment.
return Xcode.sdk if f.requirements.any? do |req|
next false unless req.is_a? XcodeRequirement
next false if check_only_runtime_requirements && req.build? && !req.test?
true
end
sdk(v) sdk(v)
end end

View File

@ -36,7 +36,7 @@ begin
formula.extend(Debrew::Formula) if args.debug? formula.extend(Debrew::Formula) if args.debug?
ENV.extend(Stdenv) ENV.extend(Stdenv)
T.cast(ENV, Stdenv).setup_build_environment(formula: formula) T.cast(ENV, Stdenv).setup_build_environment(formula: formula, testing_formula: true)
# tests can also return false to indicate failure # tests can also return false to indicate failure
Timeout.timeout TEST_TIMEOUT_SECONDS do Timeout.timeout TEST_TIMEOUT_SECONDS do