diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/std.rb b/Library/Homebrew/extend/os/linux/extend/ENV/std.rb index fb287efc33..56d7793a57 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/std.rb @@ -2,8 +2,8 @@ # frozen_string_literal: true module Stdenv - def setup_build_environment(**options) - generic_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(formula: formula, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch) prepend_path "CPATH", HOMEBREW_PREFIX/"include" prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib" diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index ebf600ad0d..2e6b36be95 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -10,8 +10,8 @@ module Superenv end # @private - def setup_build_environment(**options) - generic_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(formula: formula, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch) self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2" self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(@formula) diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb index b5e9e1e925..51a63c1cf0 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb @@ -10,8 +10,8 @@ module Stdenv ["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.sdk_version}"] end - def setup_build_environment(**options) - generic_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(formula: formula, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch) # sed is strict, and errors out when it encounters files with # mixed character sets @@ -19,7 +19,7 @@ module Stdenv self["LC_CTYPE"] = "C" # 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? @@ -50,7 +50,7 @@ module Stdenv remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" 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. remove_macosxsdk min_version = version || MacOS.version @@ -58,7 +58,11 @@ module Stdenv self["CPATH"] = "#{HOMEBREW_PREFIX}/include" 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 Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks) diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index 233ba71269..9d1a452c53 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -106,8 +106,7 @@ module Superenv end # @private - def setup_build_environment(**options) - formula = options[:formula] + def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false) sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk if MacOS.sdk_root_needed? || sdk&.source == :xcode Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks) @@ -122,7 +121,7 @@ module Superenv self["HOMEBREW_SDKROOT"] = nil self["HOMEBREW_DEVELOPER_DIR"] = nil 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 # reliably figure this out with Xcode 8 and above. diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 1d291b235f..f916ae0948 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -120,9 +120,16 @@ module OS sdk_locator.sdk_if_applicable(v) 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 - 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) end diff --git a/Library/Homebrew/test.rb b/Library/Homebrew/test.rb index 6ef080962d..c92cdaf0d2 100644 --- a/Library/Homebrew/test.rb +++ b/Library/Homebrew/test.rb @@ -36,7 +36,7 @@ begin formula.extend(Debrew::Formula) if args.debug? 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 Timeout.timeout TEST_TIMEOUT_SECONDS do