mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
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:
parent
16ee849c43
commit
f161e56ce0
@ -28,6 +28,23 @@ module Homebrew
|
||||
missing
|
||||
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.
|
||||
class Checks
|
||||
def initialize(verbose: true)
|
||||
@ -74,6 +91,10 @@ module Homebrew
|
||||
].freeze
|
||||
end
|
||||
|
||||
def fatal_setup_build_environment_checks
|
||||
[].freeze
|
||||
end
|
||||
|
||||
def supported_configuration_checks
|
||||
[].freeze
|
||||
end
|
||||
|
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hardware"
|
||||
require "diagnostic"
|
||||
require "extend/ENV/shared"
|
||||
require "extend/ENV/std"
|
||||
require "extend/ENV/super"
|
||||
|
@ -41,8 +41,8 @@ module Homebrew
|
||||
end
|
||||
|
||||
class Checks
|
||||
undef fatal_build_from_source_checks, supported_configuration_checks,
|
||||
build_from_source_checks
|
||||
undef fatal_build_from_source_checks, fatal_setup_build_environment_checks,
|
||||
supported_configuration_checks, build_from_source_checks
|
||||
|
||||
def fatal_build_from_source_checks
|
||||
%w[
|
||||
@ -54,6 +54,12 @@ module Homebrew
|
||||
].freeze
|
||||
end
|
||||
|
||||
def fatal_setup_build_environment_checks
|
||||
%w[
|
||||
check_if_supported_sdk_available
|
||||
].freeze
|
||||
end
|
||||
|
||||
def supported_configuration_checks
|
||||
%w[
|
||||
check_for_unsupported_macos
|
||||
|
@ -83,6 +83,7 @@ module Stdenv
|
||||
sdk = formula ? MacOS.sdk_for_formula(formula, version) : MacOS.sdk(version)
|
||||
return if !MacOS.sdk_root_needed? && sdk&.source != :xcode
|
||||
|
||||
Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks)
|
||||
sdk = sdk.path
|
||||
|
||||
# Extra setup to support Xcode 4.3+ without CLT.
|
||||
|
@ -110,7 +110,9 @@ module Superenv
|
||||
formula = options[:formula]
|
||||
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)
|
||||
self["HOMEBREW_SDKROOT"] = sdk.path
|
||||
|
||||
self["HOMEBREW_DEVELOPER_DIR"] = if sdk.source == :xcode
|
||||
MacOS::Xcode.prefix
|
||||
else
|
||||
|
@ -16,15 +16,15 @@ module Homebrew
|
||||
check_cpu
|
||||
attempt_directory_creation
|
||||
check_cc_argv(cc)
|
||||
diagnostic_checks(:supported_configuration_checks, fatal: all_fatal)
|
||||
diagnostic_checks(:fatal_preinstall_checks)
|
||||
Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal)
|
||||
Diagnostic.checks(:fatal_preinstall_checks)
|
||||
end
|
||||
alias generic_perform_preinstall_checks perform_preinstall_checks
|
||||
module_function :generic_perform_preinstall_checks
|
||||
|
||||
def perform_build_from_source_checks(all_fatal: false)
|
||||
diagnostic_checks(:fatal_build_from_source_checks)
|
||||
diagnostic_checks(:build_from_source_checks, fatal: all_fatal)
|
||||
Diagnostic.checks(:fatal_build_from_source_checks)
|
||||
Diagnostic.checks(:build_from_source_checks, fatal: all_fatal)
|
||||
end
|
||||
|
||||
def check_cpu
|
||||
@ -69,24 +69,6 @@ module Homebrew
|
||||
EOS
|
||||
end
|
||||
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user