ENV: check SDK exists when setting up.

Reuse code from `brew doctor` that checks and produces a fatal error
and from `install.rb` that runs it.

Closes #8646
This commit is contained in:
Mike McQuaid 2020-09-11 12:05:22 +01:00
parent 16ee849c43
commit f161e56ce0
6 changed files with 37 additions and 24 deletions

View File

@ -28,6 +28,23 @@ module Homebrew
missing missing
end end
def self.checks(type, fatal: true)
@checks ||= Checks.new
failed = false
@checks.public_send(type).each do |check|
out = @checks.public_send(check)
next if out.nil?
if fatal
failed ||= true
ofail out
else
opoo out
end
end
exit 1 if failed && fatal
end
# Diagnostic checks. # Diagnostic checks.
class Checks class Checks
def initialize(verbose: true) def initialize(verbose: true)
@ -74,6 +91,10 @@ module Homebrew
].freeze ].freeze
end end
def fatal_setup_build_environment_checks
[].freeze
end
def supported_configuration_checks def supported_configuration_checks
[].freeze [].freeze
end end

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "hardware" require "hardware"
require "diagnostic"
require "extend/ENV/shared" require "extend/ENV/shared"
require "extend/ENV/std" require "extend/ENV/std"
require "extend/ENV/super" require "extend/ENV/super"

View File

@ -41,8 +41,8 @@ module Homebrew
end end
class Checks class Checks
undef fatal_build_from_source_checks, supported_configuration_checks, undef fatal_build_from_source_checks, fatal_setup_build_environment_checks,
build_from_source_checks supported_configuration_checks, build_from_source_checks
def fatal_build_from_source_checks def fatal_build_from_source_checks
%w[ %w[
@ -54,6 +54,12 @@ module Homebrew
].freeze ].freeze
end end
def fatal_setup_build_environment_checks
%w[
check_if_supported_sdk_available
].freeze
end
def supported_configuration_checks def supported_configuration_checks
%w[ %w[
check_for_unsupported_macos check_for_unsupported_macos

View File

@ -83,6 +83,7 @@ module Stdenv
sdk = formula ? MacOS.sdk_for_formula(formula, version) : MacOS.sdk(version) sdk = formula ? MacOS.sdk_for_formula(formula, version) : MacOS.sdk(version)
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)
sdk = sdk.path sdk = sdk.path
# Extra setup to support Xcode 4.3+ without CLT. # Extra setup to support Xcode 4.3+ without CLT.

View File

@ -110,7 +110,9 @@ module Superenv
formula = options[:formula] 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)
self["HOMEBREW_SDKROOT"] = sdk.path self["HOMEBREW_SDKROOT"] = sdk.path
self["HOMEBREW_DEVELOPER_DIR"] = if sdk.source == :xcode self["HOMEBREW_DEVELOPER_DIR"] = if sdk.source == :xcode
MacOS::Xcode.prefix MacOS::Xcode.prefix
else else

View File

@ -16,15 +16,15 @@ module Homebrew
check_cpu check_cpu
attempt_directory_creation attempt_directory_creation
check_cc_argv(cc) check_cc_argv(cc)
diagnostic_checks(:supported_configuration_checks, fatal: all_fatal) Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal)
diagnostic_checks(:fatal_preinstall_checks) Diagnostic.checks(:fatal_preinstall_checks)
end end
alias generic_perform_preinstall_checks perform_preinstall_checks alias generic_perform_preinstall_checks perform_preinstall_checks
module_function :generic_perform_preinstall_checks module_function :generic_perform_preinstall_checks
def perform_build_from_source_checks(all_fatal: false) def perform_build_from_source_checks(all_fatal: false)
diagnostic_checks(:fatal_build_from_source_checks) Diagnostic.checks(:fatal_build_from_source_checks)
diagnostic_checks(:build_from_source_checks, fatal: all_fatal) Diagnostic.checks(:build_from_source_checks, fatal: all_fatal)
end end
def check_cpu def check_cpu
@ -69,24 +69,6 @@ module Homebrew
EOS EOS
end end
private_class_method :check_cc_argv private_class_method :check_cc_argv
def diagnostic_checks(type, fatal: true)
@checks ||= Diagnostic::Checks.new
failed = false
@checks.public_send(type).each do |check|
out = @checks.public_send(check)
next if out.nil?
if fatal
failed ||= true
ofail out
else
opoo out
end
end
exit 1 if failed && fatal
end
private_class_method :diagnostic_checks
end end
end end