Add guards to calls that would trigger Xcode install requests

add guard in Formula#file_modified? to prevent git popup

add guard in Superenv.bin before calling MacOS::Xcode.version

add guard against missing Xcode/CLT in Xcode.uncached_version

return nil instread of 0 in uncached_version when Xcode/CLT are not present, to distinguish from linuxbrew behavior

checks against pour_bottle? and needs_relocation?, add guard around keg.relocate_install_names to check pour_bottle?/needs_relocation? as well

needs_relocation? becomes skip_relocation?, use cellar attr to indicate relocation instead of does_not_need_relocation

MacOS.can_build? becomes MacOS.has_apple_developer_tools?
This commit is contained in:
William Woodruff 2015-07-26 16:49:16 -04:00 committed by Misty De Meo
parent f58506ea6f
commit 1face808f5
12 changed files with 33 additions and 35 deletions

View File

@ -7,23 +7,23 @@ module Homebrew
end
def llvm
@llvm ||= MacOS.llvm_build_version
@llvm ||= MacOS.llvm_build_version if MacOS.has_apple_developer_tools?
end
def gcc_42
@gcc_42 ||= MacOS.gcc_42_build_version
@gcc_42 ||= MacOS.gcc_42_build_version if MacOS.has_apple_developer_tools?
end
def gcc_40
@gcc_40 ||= MacOS.gcc_40_build_version
@gcc_40 ||= MacOS.gcc_40_build_version if MacOS.has_apple_developer_tools?
end
def clang
@clang ||= MacOS.clang_version
@clang ||= MacOS.clang_version if MacOS.has_apple_developer_tools?
end
def clang_build
@clang_build ||= MacOS.clang_build_version
@clang_build ||= MacOS.clang_build_version if MacOS.has_apple_developer_tools?
end
def xcode

View File

@ -40,7 +40,7 @@ module Homebrew
# if the user's flags will prevent bottle only-installations when no
# developer tools are available, we need to stop them early on
FormulaInstaller.prevent_build_flags unless MacOS.can_build?
FormulaInstaller.prevent_build_flags unless MacOS.has_apple_developer_tools?
ARGV.formulae.each do |f|
# head-only without --HEAD is an error
@ -126,11 +126,6 @@ module Homebrew
end
def check_xcode
# TODO: reinstate check_for_bad_install_name_tool and check_for_installed_developer_tools
# currently check_for_bad_install_name_tool fails because it tries to call
# the /usr/bin/otool stub program on systems without XCode/CLT
# check_for_installed_developer_tools doesn't fail, but produces a warning
# when one is no longer required
checks = Checks.new
%w[
check_for_unsupported_osx

View File

@ -2,7 +2,7 @@ require "formula_installer"
module Homebrew
def reinstall
FormulaInstaller.prevent_build_flags unless MacOS.can_build?
FormulaInstaller.prevent_build_flags unless MacOS.has_apple_developer_tools?
ARGV.resolved_formulae.each { |f| reinstall_formula(f) }
end

View File

@ -3,7 +3,7 @@ require "cmd/outdated"
module Homebrew
def upgrade
FormulaInstaller.prevent_build_flags unless MacOS.can_build?
FormulaInstaller.prevent_build_flags unless MacOS.has_apple_developer_tools?
Homebrew.perform_preinstall_checks

View File

@ -29,7 +29,7 @@ module Stdenv
self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir
# make any aclocal stuff installed in Homebrew available
self["ACLOCAL_PATH"] = "#{HOMEBREW_PREFIX}/share/aclocal" if MacOS::Xcode.provides_autotools?
self["ACLOCAL_PATH"] = "#{HOMEBREW_PREFIX}/share/aclocal" if MacOS.has_apple_developer_tools? && MacOS::Xcode.provides_autotools?
self["MAKEFLAGS"] = "-j#{make_jobs}"

View File

@ -23,6 +23,8 @@ module Superenv
end
def self.bin
return unless MacOS.has_apple_developer_tools?
bin = (HOMEBREW_REPOSITORY/"Library/ENV").subdirs.reject { |d| d.basename.to_s > MacOS::Xcode.version }.max
bin.realpath unless bin.nil?
end

View File

@ -720,7 +720,11 @@ class Formula
end
def file_modified?
return false unless which("git")
git_dir = MacOS.locate("git").dirname.to_s
# /usr/bin/git is a popup stub when Xcode/CLT aren't installed, so bail out
return false if git_dir == "/usr/bin" && !MacOS.has_apple_developer_tools?
path.parent.cd do
diff = Utils.popen_read("git", "diff", "origin/master", "--", "#{path}")
!diff.empty? && $?.exitstatus == 0

View File

@ -154,7 +154,7 @@ class FormulaInstaller
check_conflicts
if !pour_bottle? && !MacOS.can_build?
if !pour_bottle? && !MacOS.has_apple_developer_tools?
raise BuildToolsError.new([formula])
end
@ -182,7 +182,7 @@ class FormulaInstaller
if pour_bottle?(:warn => true)
begin
install_relocation_tools if formula.bottle.needs_relocation?
install_relocation_tools unless formula.bottle.skip_relocation?
pour
rescue => e
raise if ARGV.homebrew_developer?
@ -243,7 +243,7 @@ class FormulaInstaller
def check_dependencies_bottled(deps)
unbottled = deps.select do |dep, _|
formula = dep.to_formula
!formula.pour_bottle? && !MacOS.can_build?
!formula.pour_bottle? && !MacOS.has_apple_developer_tools?
end
raise BuildToolsError.new(unbottled) unless unbottled.empty?
@ -434,9 +434,7 @@ class FormulaInstaller
keg = Keg.new(formula.prefix)
link(keg)
# this needs to be changed to a test against build_bottle? and
# formula.bottle.needs_relocation?
fix_install_names(keg) unless formula.name == 'cctools'
fix_install_names(keg) unless @poured_bottle && formula.bottle.skip_relocation?
if build_bottle? && formula.post_install_defined?
ohai "Not running post_install as we're building a bottle"
@ -668,8 +666,10 @@ class FormulaInstaller
end
keg = Keg.new(formula.prefix)
keg.relocate_install_names Keg::PREFIX_PLACEHOLDER, HOMEBREW_PREFIX.to_s,
Keg::CELLAR_PLACEHOLDER, HOMEBREW_CELLAR.to_s, :keg_only => formula.keg_only?
unless formula.bottle.skip_relocation?
keg.relocate_install_names Keg::PREFIX_PLACEHOLDER, HOMEBREW_PREFIX.to_s,
Keg::CELLAR_PLACEHOLDER, HOMEBREW_CELLAR.to_s, :keg_only => formula.keg_only?
end
Pathname.glob("#{formula.bottle_prefix}/{etc,var}/**/*") do |path|
path.extend(InstallRenamed)

View File

@ -99,7 +99,7 @@ class Keg
def install_name_tool(*args)
tool = MacOS.install_name_tool
system(tool, *args) || raise ErrorDuringExecution.new(tool, args)
system(tool, *args) or raise ErrorDuringExecution.new(tool, args)
end
# If file is a dylib or bundle itself, look for the dylib named by

View File

@ -52,7 +52,7 @@ module OS
end
end
def can_build?
def has_apple_developer_tools?
Xcode.installed? || CLT.installed?
end

View File

@ -76,6 +76,8 @@ module OS
return "0" unless OS.mac?
return nil if !MacOS::Xcode.installed? && !MacOS::CLT.installed?
%W[#{prefix}/usr/bin/xcodebuild #{which("xcodebuild")}].uniq.each do |path|
if File.file? path
Utils.popen_read(path, "-version") =~ /Xcode (\d(\.\d)*)/

View File

@ -245,8 +245,8 @@ class Bottle
@spec.compatible_cellar?
end
def needs_relocation?
@spec.needs_relocation?
def skip_relocation?
@spec.skip_relocation?
end
def stage
@ -274,7 +274,6 @@ class BottleSpecification
@prefix = DEFAULT_PREFIX
@cellar = DEFAULT_CELLAR
@collector = BottleCollector.new
@does_not_need_relocation = false
end
def root_url(var = nil)
@ -286,15 +285,11 @@ class BottleSpecification
end
def compatible_cellar?
cellar == :any || cellar == HOMEBREW_CELLAR.to_s
cellar == :any || cellar == :any_skip_relocation || cellar == HOMEBREW_CELLAR.to_s
end
def does_not_need_relocation
@does_not_need_relocation = true
end
def needs_relocation?
!@does_not_need_relocation
def skip_relocation?
cellar == :any_skip_relocation
end
def tag?(tag)