From 7fce76d1761ce9782072d61ac529c38059b20acd Mon Sep 17 00:00:00 2001
From: Markus Reiter <me@reitermark.us>
Date: Mon, 17 Aug 2020 18:39:55 +0200
Subject: [PATCH] Refactor and document `Install`.

---
 Library/Homebrew/extend/os/linux/install.rb | 13 +++++---
 Library/Homebrew/formula_installer.rb       |  5 +--
 Library/Homebrew/install.rb                 | 37 ++++++++++++---------
 3 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/Library/Homebrew/extend/os/linux/install.rb b/Library/Homebrew/extend/os/linux/install.rb
index 073c0c813d..2184287f53 100644
--- a/Library/Homebrew/extend/os/linux/install.rb
+++ b/Library/Homebrew/extend/os/linux/install.rb
@@ -14,6 +14,12 @@ module Homebrew
       "/system/bin/linker64",
       "/system/bin/linker",
     ].freeze
+    private_constant :DYNAMIC_LINKERS
+
+    def perform_preinstall_checks(all_fatal: false, cc: nil)
+      generic_perform_preinstall_checks(all_fatal: all_fatal, cc: cc)
+      symlink_ld_so
+    end
 
     def check_cpu
       return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
@@ -28,6 +34,7 @@ module Homebrew
       end
       abort message
     end
+    private_class_method :check_cpu
 
     def symlink_ld_so
       brew_ld_so = HOMEBREW_PREFIX/"lib/ld.so"
@@ -42,10 +49,6 @@ module Homebrew
       FileUtils.mkdir_p HOMEBREW_PREFIX/"lib"
       FileUtils.ln_sf ld_so, brew_ld_so
     end
-
-    def perform_preinstall_checks(all_fatal: false, cc: nil)
-      generic_perform_preinstall_checks(all_fatal: all_fatal, cc: cc)
-      symlink_ld_so
-    end
+    private_class_method :symlink_ld_so
   end
 end
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb
index 06d5db08b8..bb207ba2ef 100644
--- a/Library/Homebrew/formula_installer.rb
+++ b/Library/Homebrew/formula_installer.rb
@@ -21,7 +21,6 @@ require "cmd/install"
 require "find"
 
 class FormulaInstaller
-  include Homebrew::Install
   include FormulaCellarChecks
   extend Predicable
 
@@ -261,7 +260,9 @@ class FormulaInstaller
     lock
 
     start_time = Time.now
-    perform_build_from_source_checks if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed?
+    if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed?
+      Homebrew::Install.perform_build_from_source_checks
+    end
 
     # not in initialize so upgrade can unlink the active keg before calling this
     # function but after instantiating this class so that it can avoid having to
diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb
index f858d8f9d8..10f8df4547 100644
--- a/Library/Homebrew/install.rb
+++ b/Library/Homebrew/install.rb
@@ -6,9 +6,27 @@ require "hardware"
 require "development_tools"
 
 module Homebrew
+  # Helper module for performing (pre-)install checks.
+  #
+  # @api private
   module Install
     module_function
 
+    def perform_preinstall_checks(all_fatal: false, cc: nil)
+      check_cpu
+      attempt_directory_creation
+      check_cc_argv(cc)
+      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)
+    end
+
     def check_cpu
       return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
 
@@ -24,6 +42,7 @@ module Homebrew
       end
       abort message
     end
+    private_class_method :check_cpu
 
     def attempt_directory_creation
       Keg::MUST_EXIST_DIRECTORIES.each do |dir|
@@ -38,6 +57,7 @@ module Homebrew
         nil
       end
     end
+    private_class_method :attempt_directory_creation
 
     def check_cc_argv(cc)
       return unless cc
@@ -48,21 +68,7 @@ module Homebrew
         #{@checks.please_create_pull_requests}
       EOS
     end
-
-    def perform_preinstall_checks(all_fatal: false, cc: nil)
-      check_cpu
-      attempt_directory_creation
-      check_cc_argv(cc)
-      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)
-    end
+    private_class_method :check_cc_argv
 
     def diagnostic_checks(type, fatal: true)
       @checks ||= Diagnostic::Checks.new
@@ -80,6 +86,7 @@ module Homebrew
       end
       exit 1 if failed && fatal
     end
+    private_class_method :diagnostic_checks
   end
 end
 
-- 
GitLab