Install: add BuildToolsError and BuildFlagsError
Add these new errors, and guards in formula installation and
cmd/{,un,re}install to match, move can_build? to the MacOS module,
flatten conditions, remove redundant can_build? check
reinstate removed (doctor) check
			
			
This commit is contained in:
		
							parent
							
								
									76dcad7c82
								
							
						
					
					
						commit
						91e598cf3f
					
				@ -38,6 +38,14 @@ module Homebrew
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      # if the user's flags will prevent bottle only-installations when no
 | 
			
		||||
      # developer tools are available, we need to stop them early on
 | 
			
		||||
      if !MacOS.can_build?
 | 
			
		||||
        bf = ARGV.collect_build_flags
 | 
			
		||||
 | 
			
		||||
        raise BuildFlagsError.new(bf) if !bf.empty?
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      ARGV.formulae.each do |f|
 | 
			
		||||
        # head-only without --HEAD is an error
 | 
			
		||||
        if !ARGV.build_head? && f.stable.nil? && f.devel.nil?
 | 
			
		||||
@ -129,6 +137,9 @@ module Homebrew
 | 
			
		||||
    # when one is no longer required
 | 
			
		||||
    checks = Checks.new
 | 
			
		||||
    %w[
 | 
			
		||||
      check_for_unsupported_osx
 | 
			
		||||
      check_for_bad_install_name_tool
 | 
			
		||||
      check_for_installed_developer_tools
 | 
			
		||||
      check_xcode_license_approved
 | 
			
		||||
      check_for_osx_gcc_installer
 | 
			
		||||
    ].each do |check|
 | 
			
		||||
@ -157,12 +168,7 @@ module Homebrew
 | 
			
		||||
  def perform_preinstall_checks
 | 
			
		||||
    check_ppc
 | 
			
		||||
    check_writable_install_location
 | 
			
		||||
    if MacOS::Xcode.installed?
 | 
			
		||||
      check_xcode
 | 
			
		||||
    else
 | 
			
		||||
      opoo "You have not installed Xcode."
 | 
			
		||||
      puts "Bottles may install correctly, but builds will fail!"
 | 
			
		||||
    end
 | 
			
		||||
    check_xcode if MacOS::Xcode.installed?
 | 
			
		||||
    check_cellar
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,14 @@ require "formula_installer"
 | 
			
		||||
 | 
			
		||||
module Homebrew
 | 
			
		||||
  def reinstall
 | 
			
		||||
    if !MacOS.can_build?
 | 
			
		||||
      bf = ARGV.collect_build_flags
 | 
			
		||||
 | 
			
		||||
      if !bf.empty?
 | 
			
		||||
        raise BuildFlagsError.new(bf)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    ARGV.resolved_formulae.each { |f| reinstall_formula(f) }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,14 @@ require "cmd/outdated"
 | 
			
		||||
 | 
			
		||||
module Homebrew
 | 
			
		||||
  def upgrade
 | 
			
		||||
    if !MacOS.can_build?
 | 
			
		||||
      bf = ARGV.collect_build_flags
 | 
			
		||||
 | 
			
		||||
      if !bf.empty?
 | 
			
		||||
        raise BuildFlagsError.new(bf)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    Homebrew.perform_preinstall_checks
 | 
			
		||||
 | 
			
		||||
    if ARGV.named.empty?
 | 
			
		||||
 | 
			
		||||
@ -226,6 +226,100 @@ class BuildError < RuntimeError
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# raised by FormulaInstaller.check_dependencies_bottled and
 | 
			
		||||
# FormulaInstaller.install if the formula or its dependencies are not bottled
 | 
			
		||||
# and are being installed on a system without necessary build tools
 | 
			
		||||
class BuildToolsError < RuntimeError
 | 
			
		||||
  def initialize(formulae)
 | 
			
		||||
    if formulae.length > 1
 | 
			
		||||
      formula_text = "formulae"
 | 
			
		||||
      package_text = "binary packages"
 | 
			
		||||
    else
 | 
			
		||||
      formula_text = "formula"
 | 
			
		||||
      package_text = "a binary package"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if MacOS.version >= "10.10"
 | 
			
		||||
      xcode_text = <<-EOS.undent
 | 
			
		||||
        To continue, you must install Xcode from the App Store,
 | 
			
		||||
              or the CLT by running:
 | 
			
		||||
                xcode-select --install
 | 
			
		||||
      EOS
 | 
			
		||||
    elsif MacOS.version == "10.9"
 | 
			
		||||
      xcode_text = <<-EOS.undent
 | 
			
		||||
        To continue, you must install Xcode from:
 | 
			
		||||
                https://developer.apple.com/downloads/
 | 
			
		||||
              or the CLT by running:
 | 
			
		||||
                xcode-select --install
 | 
			
		||||
      EOS
 | 
			
		||||
    elsif MacOS.version >= "10.7"
 | 
			
		||||
      xcode_text = <<-EOS.undent
 | 
			
		||||
        To continue, you must install Xcode or the CLT from:
 | 
			
		||||
                https://developer.apple.com/downloads/
 | 
			
		||||
      EOS
 | 
			
		||||
    else
 | 
			
		||||
      xcode_text = <<-EOS.undent
 | 
			
		||||
        To continue, you must install Xcode from:
 | 
			
		||||
                https://developer.apple.com/downloads/
 | 
			
		||||
      EOS
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    super <<-EOS.undent
 | 
			
		||||
      The following #{formula_text}:
 | 
			
		||||
        #{formulae.join(', ')}
 | 
			
		||||
      cannot be installed as a #{package_text} and must be built from source.
 | 
			
		||||
      #{xcode_text}
 | 
			
		||||
    EOS
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# raised by Homebrew.install, Homebrew.reinstall, and Homebrew.upgrade
 | 
			
		||||
# if the user passes any flags/environment that would case a bottle-only
 | 
			
		||||
# installation on a system without build tools to fail
 | 
			
		||||
class BuildFlagsError < RuntimeError
 | 
			
		||||
  def initialize(flags)
 | 
			
		||||
    if flags.length > 1
 | 
			
		||||
      flag_text = "flags"
 | 
			
		||||
      require_text = "require"
 | 
			
		||||
    else
 | 
			
		||||
      flag_text = "flag"
 | 
			
		||||
      require_text = "requires"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if MacOS.version >= "10.10"
 | 
			
		||||
      xcode_text = <<-EOS.undent
 | 
			
		||||
        or install Xcode from the App Store, or the CLT by running:
 | 
			
		||||
                xcode-select --install
 | 
			
		||||
      EOS
 | 
			
		||||
    elsif MacOS.version == "10.9"
 | 
			
		||||
      xcode_text = <<-EOS.undent
 | 
			
		||||
        or install Xcode from:
 | 
			
		||||
                https://developer.apple.com/downloads/
 | 
			
		||||
              or the CLT by running:
 | 
			
		||||
                xcode-select --install
 | 
			
		||||
      EOS
 | 
			
		||||
    elsif MacOS.version >= "10.7"
 | 
			
		||||
      xcode_text = <<-EOS.undent
 | 
			
		||||
        or install Xcode or the CLT from:
 | 
			
		||||
                https://developer.apple.com/downloads/
 | 
			
		||||
      EOS
 | 
			
		||||
    else
 | 
			
		||||
      xcode_text = <<-EOS.undent
 | 
			
		||||
        or install Xcode from:
 | 
			
		||||
                https://developer.apple.com/downloads/
 | 
			
		||||
      EOS
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    super <<-EOS.undent
 | 
			
		||||
      The following #{flag_text}:
 | 
			
		||||
        #{flags.join(', ')}
 | 
			
		||||
      #{require_text} building tools, but none are installed.
 | 
			
		||||
      Either remove the #{flag_text} to attempt bottle installation,
 | 
			
		||||
      #{xcode_text}
 | 
			
		||||
    EOS
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# raised by CompilerSelector if the formula fails with all of
 | 
			
		||||
# the compilers available on the user's system
 | 
			
		||||
class CompilerSelectionError < RuntimeError
 | 
			
		||||
 | 
			
		||||
@ -200,6 +200,19 @@ module HomebrewArgvExtension
 | 
			
		||||
    value "env"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # collect any supplied build flags into an array for reporting
 | 
			
		||||
  def collect_build_flags
 | 
			
		||||
    build_flags = []
 | 
			
		||||
 | 
			
		||||
    build_flags << '--HEAD' if build_head?
 | 
			
		||||
    build_flags << '--universal' if build_universal?
 | 
			
		||||
    build_flags << '--32-bit' if build_32_bit?
 | 
			
		||||
    build_flags << '--build-bottle' if build_bottle?
 | 
			
		||||
    build_flags << '--build-from-source' if build_from_source?
 | 
			
		||||
 | 
			
		||||
    build_flags
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def spec(default = :stable)
 | 
			
		||||
 | 
			
		||||
@ -147,6 +147,10 @@ class FormulaInstaller
 | 
			
		||||
 | 
			
		||||
    check_conflicts
 | 
			
		||||
 | 
			
		||||
    if !pour_bottle? && !MacOS.can_build?
 | 
			
		||||
      raise BuildToolsError.new([formula])
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if !ignore_deps?
 | 
			
		||||
      deps = compute_dependencies
 | 
			
		||||
      check_dependencies_bottled(deps) if pour_bottle?
 | 
			
		||||
 | 
			
		||||
@ -52,6 +52,10 @@ module OS
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def can_build?
 | 
			
		||||
      Xcode.installed? || CLT.installed?
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def active_developer_dir
 | 
			
		||||
      @active_developer_dir ||= Utils.popen_read("/usr/bin/xcode-select", "-print-path").strip
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user