Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/Homebrew/extend/os/linux/extend/ENV/std.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/extend/os/linux/extend/ENV/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def self.bin
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)
Expand Down
14 changes: 9 additions & 5 deletions Library/Homebrew/extend/os/mac/extend/ENV/std.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ def homebrew_extra_pkg_config_paths
["#{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
delete("LC_ALL")
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?

Expand Down Expand Up @@ -50,15 +50,19 @@ def remove_macosxsdk(version = nil)
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
append_to_cflags("-mmacosx-version-min=#{min_version}")
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)
Expand Down
5 changes: 2 additions & 3 deletions Library/Homebrew/extend/os/mac/extend/ENV/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def determine_cccfg
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)
Expand All @@ -122,7 +121,7 @@ def setup_build_environment(**options)
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.
Expand Down
11 changes: 9 additions & 2 deletions Library/Homebrew/os/mac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,16 @@ def sdk(v = nil)
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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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
Expand Down