mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Fix Style/GuardClause.
This commit is contained in:
parent
bbc3f1c3a8
commit
58e36c7319
@ -118,43 +118,6 @@ Style/GlobalVars:
|
||||
- 'Homebrew/diagnostic.rb'
|
||||
- 'Homebrew/utils.rb'
|
||||
|
||||
# Offense count: 70
|
||||
# Configuration parameters: MinBodyLength.
|
||||
Style/GuardClause:
|
||||
Exclude:
|
||||
- 'Taps/**/*'
|
||||
- 'Homebrew/cmd/update-report.rb'
|
||||
- 'Homebrew/dependency_collector.rb'
|
||||
- 'Homebrew/dev-cmd/audit.rb'
|
||||
- 'Homebrew/dev-cmd/pull.rb'
|
||||
- 'Homebrew/dev-cmd/test-bot.rb'
|
||||
- 'Homebrew/download_strategy.rb'
|
||||
- 'Homebrew/extend/ARGV.rb'
|
||||
- 'Homebrew/extend/ENV/shared.rb'
|
||||
- 'Homebrew/extend/ENV/std.rb'
|
||||
- 'Homebrew/extend/ENV/super.rb'
|
||||
- 'Homebrew/extend/fileutils.rb'
|
||||
- 'Homebrew/extend/os/mac/extend/ENV/std.rb'
|
||||
- 'Homebrew/extend/os/mac/formula_cellar_checks.rb'
|
||||
- 'Homebrew/extend/os/mac/utils/bottles.rb'
|
||||
- 'Homebrew/extend/string.rb'
|
||||
- 'Homebrew/formula.rb'
|
||||
- 'Homebrew/formula_installer.rb'
|
||||
- 'Homebrew/formula_lock.rb'
|
||||
- 'Homebrew/formulary.rb'
|
||||
- 'Homebrew/keg.rb'
|
||||
- 'Homebrew/migrator.rb'
|
||||
- 'Homebrew/os/mac/xcode.rb'
|
||||
- 'Homebrew/patch.rb'
|
||||
- 'Homebrew/requirement.rb'
|
||||
- 'Homebrew/tap.rb'
|
||||
- 'Homebrew/test/test_cmd_testbot.rb'
|
||||
- 'Homebrew/test/test_integration_cmds.rb'
|
||||
- 'Homebrew/test/testing_env.rb'
|
||||
- 'Homebrew/utils.rb'
|
||||
- 'Homebrew/utils/popen.rb'
|
||||
- 'Homebrew/version.rb'
|
||||
|
||||
# Offense count: 51
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: MaxLineLength.
|
||||
|
@ -203,7 +203,7 @@ module Homebrew
|
||||
# If they haven't updated in 48 hours (172800 seconds), that
|
||||
# might explain the error
|
||||
master = HOMEBREW_REPOSITORY/".git/refs/heads/master"
|
||||
if master.exist? && (Time.now.to_i - File.mtime(master).to_i) > 172800
|
||||
return unless master.exist? && (Time.now.to_i - File.mtime(master).to_i) > 172800
|
||||
ohai "You haven't updated Homebrew in a while."
|
||||
puts <<-EOS.undent
|
||||
A formula for #{e.name} might have been added recently.
|
||||
@ -212,7 +212,6 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_ppc
|
||||
case Hardware::CPU.type
|
||||
|
@ -549,12 +549,11 @@ class ReporterHub
|
||||
end
|
||||
end
|
||||
|
||||
unless formulae.empty?
|
||||
return if formulae.empty?
|
||||
# Dump formula list.
|
||||
ohai title
|
||||
puts_columns(formulae)
|
||||
end
|
||||
end
|
||||
|
||||
def installed?(formula)
|
||||
(HOMEBREW_CELLAR/formula.split("/").last).directory?
|
||||
|
@ -128,11 +128,11 @@ class DependencyCollector
|
||||
end
|
||||
|
||||
def parse_class_spec(spec, tags)
|
||||
if spec < Requirement
|
||||
spec.new(tags)
|
||||
else
|
||||
unless spec < Requirement
|
||||
raise TypeError, "#{spec.inspect} is not a Requirement subclass"
|
||||
end
|
||||
|
||||
spec.new(tags)
|
||||
end
|
||||
|
||||
def ant_dep(spec, tags)
|
||||
|
@ -284,10 +284,9 @@ class FormulaAuditor
|
||||
problem "Should not have both `head` and `head do`"
|
||||
end
|
||||
|
||||
if present.include?("bottle modifier") && present.include?("bottle block")
|
||||
return unless present.include?("bottle modifier") && present.include?("bottle block")
|
||||
problem "Should not have `bottle :unneeded/:disable` and `bottle do`"
|
||||
end
|
||||
end
|
||||
|
||||
def audit_class
|
||||
if @strict
|
||||
@ -350,10 +349,9 @@ class FormulaAuditor
|
||||
|
||||
same_name_tap_formulae.delete(full_name)
|
||||
|
||||
unless same_name_tap_formulae.empty?
|
||||
return if same_name_tap_formulae.empty?
|
||||
problem "Formula name conflicts with #{same_name_tap_formulae.join ", "}"
|
||||
end
|
||||
end
|
||||
|
||||
def audit_deps
|
||||
@specs.each do |spec|
|
||||
@ -485,10 +483,9 @@ class FormulaAuditor
|
||||
problem "Description shouldn't start with an indefinite article (#{$1})"
|
||||
end
|
||||
|
||||
if desc.downcase.start_with? "#{formula.name} "
|
||||
return unless desc.downcase.start_with? "#{formula.name} "
|
||||
problem "Description shouldn't include the formula name"
|
||||
end
|
||||
end
|
||||
|
||||
def audit_homepage
|
||||
homepage = formula.homepage
|
||||
@ -564,10 +561,10 @@ class FormulaAuditor
|
||||
end
|
||||
|
||||
def audit_bottle_spec
|
||||
if formula.bottle_disabled? && !formula.bottle_disable_reason.valid?
|
||||
return unless formula.bottle_disabled?
|
||||
return if formula.bottle_disable_reason.valid?
|
||||
problem "Unrecognized bottle modifier"
|
||||
end
|
||||
end
|
||||
|
||||
def audit_github_repository
|
||||
return unless @online
|
||||
@ -594,10 +591,9 @@ class FormulaAuditor
|
||||
problem "GitHub repository not notable enough (<20 forks, <20 watchers and <50 stars)"
|
||||
end
|
||||
|
||||
if Date.parse(metadata["created_at"]) > (Date.today - 30)
|
||||
return if Date.parse(metadata["created_at"]) <= (Date.today - 30)
|
||||
problem "GitHub repository too new (<30 days old)"
|
||||
end
|
||||
end
|
||||
|
||||
def audit_specs
|
||||
if head_only?(formula) && formula.tap.to_s.downcase !~ %r{[-/]head-only$}
|
||||
@ -736,10 +732,9 @@ class FormulaAuditor
|
||||
problem "Please set plist_options when using a formula-defined plist."
|
||||
end
|
||||
|
||||
if text.include?('require "language/go"') && !text.include?("go_resource")
|
||||
return unless text.include?('require "language/go"') && !text.include?("go_resource")
|
||||
problem "require \"language/go\" is unnecessary unless using `go_resource`s"
|
||||
end
|
||||
end
|
||||
|
||||
def audit_line(line, lineno)
|
||||
if line =~ /<(Formula|AmazonWebServicesFormula|ScriptFileFormula|GithubGistFormula)/
|
||||
@ -983,10 +978,9 @@ class FormulaAuditor
|
||||
problem "Use \#{pkgshare} instead of \#{share}/#{formula.name}"
|
||||
end
|
||||
|
||||
if line =~ %r{share(\s*[/+]\s*)(['"])#{Regexp.escape(formula.name)}(?:\2|/)}
|
||||
return unless line =~ %r{share(\s*[/+]\s*)(['"])#{Regexp.escape(formula.name)}(?:\2|/)}
|
||||
problem "Use pkgshare instead of (share#{$1}\"#{formula.name}\")"
|
||||
end
|
||||
end
|
||||
|
||||
def audit_caveats
|
||||
return unless formula.caveats.to_s.include?("setuid")
|
||||
@ -1115,10 +1109,9 @@ class ResourceAuditor
|
||||
problem "version #{version} should not have a leading 'v'"
|
||||
end
|
||||
|
||||
if version.to_s =~ /_\d+$/
|
||||
return unless version.to_s =~ /_\d+$/
|
||||
problem "version #{version} should not end with an underline and a number"
|
||||
end
|
||||
end
|
||||
|
||||
def audit_checksum
|
||||
return unless checksum
|
||||
@ -1183,10 +1176,9 @@ class ResourceAuditor
|
||||
end
|
||||
end
|
||||
|
||||
if url_strategy == DownloadStrategyDetector.detect("", using)
|
||||
return unless url_strategy == DownloadStrategyDetector.detect("", using)
|
||||
problem "Redundant :using value in URL"
|
||||
end
|
||||
end
|
||||
|
||||
def audit_urls
|
||||
# Check GNU urls; doesn't apply to mirrors
|
||||
|
@ -531,9 +531,12 @@ module Homebrew
|
||||
req = Net::HTTP::Head.new bottle_info.url
|
||||
req.initialize_http_header "User-Agent" => HOMEBREW_USER_AGENT_RUBY
|
||||
res = http.request req
|
||||
if res.is_a?(Net::HTTPSuccess)
|
||||
break
|
||||
elsif res.is_a?(Net::HTTPClientError)
|
||||
break if res.is_a?(Net::HTTPSuccess)
|
||||
|
||||
unless res.is_a?(Net::HTTPClientError)
|
||||
raise "Failed to find published #{f} bottle at #{url} (#{res.code} #{res.message})!"
|
||||
end
|
||||
|
||||
if retry_count >= max_retries
|
||||
raise "Failed to find published #{f} bottle at #{url}!"
|
||||
end
|
||||
@ -541,9 +544,6 @@ module Homebrew
|
||||
wrote_dots = true
|
||||
sleep poll_retry_delay_seconds
|
||||
retry_count += 1
|
||||
else
|
||||
raise "Failed to find published #{f} bottle at #{url} (#{res.code} #{res.message})!"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -123,7 +123,7 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
if git_url = ENV["UPSTREAM_GIT_URL"] || ENV["GIT_URL"]
|
||||
return unless git_url = ENV["UPSTREAM_GIT_URL"] || ENV["GIT_URL"]
|
||||
# Also can get tap from Jenkins GIT_URL.
|
||||
url_path = git_url.sub(%r{^https?://github\.com/}, "").chomp("/").sub(/\.git$/, "")
|
||||
begin
|
||||
@ -131,7 +131,6 @@ module Homebrew
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Wraps command invocations. Instantiated by Test#test.
|
||||
# Handles logging and pretty-printing.
|
||||
@ -1001,11 +1000,10 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
if git_tag
|
||||
return unless git_tag
|
||||
safe_system "git", "tag", "--force", git_tag
|
||||
safe_system "git", "push", "--force", remote, "master:master", "refs/tags/#{git_tag}"
|
||||
end
|
||||
end
|
||||
|
||||
def sanitize_argv_and_env
|
||||
if Pathname.pwd == HOMEBREW_PREFIX && ARGV.include?("--cleanup")
|
||||
@ -1053,14 +1051,13 @@ module Homebrew
|
||||
|
||||
ARGV << "--fast" if ARGV.include?("--ci-master")
|
||||
|
||||
if ARGV.include? "--local"
|
||||
return unless ARGV.include?("--local")
|
||||
ENV["HOMEBREW_CACHE"] = "#{ENV["HOME"]}/Library/Caches/Homebrew"
|
||||
mkdir_p ENV["HOMEBREW_CACHE"]
|
||||
ENV["HOMEBREW_HOME"] = ENV["HOME"] = "#{Dir.pwd}/home"
|
||||
mkdir_p ENV["HOME"]
|
||||
ENV["HOMEBREW_LOGS"] = "#{Dir.pwd}/logs"
|
||||
end
|
||||
end
|
||||
|
||||
def test_bot
|
||||
sanitize_argv_and_env
|
||||
|
@ -158,15 +158,14 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
|
||||
|
||||
version.update_commit(last_commit) if head?
|
||||
|
||||
if @ref_type == :tag && @revision && current_revision
|
||||
unless current_revision == @revision
|
||||
return unless @ref_type == :tag
|
||||
return unless @revision && current_revision
|
||||
return if current_revision == @revision
|
||||
raise <<-EOS.undent
|
||||
#{@ref} tag should be #{@revision}
|
||||
but is actually #{current_revision}
|
||||
EOS
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_last_commit
|
||||
fetch
|
||||
@ -336,14 +335,14 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
||||
rescue ErrorDuringExecution
|
||||
# 33 == range not supported
|
||||
# try wiping the incomplete download and retrying once
|
||||
if $?.exitstatus == 33 && had_incomplete_download
|
||||
unless $?.exitstatus == 33 && had_incomplete_download
|
||||
raise CurlDownloadStrategyError, @url
|
||||
end
|
||||
|
||||
ohai "Trying a full download"
|
||||
temporary_path.unlink
|
||||
had_incomplete_download = false
|
||||
retry
|
||||
else
|
||||
raise CurlDownloadStrategyError, @url
|
||||
end
|
||||
end
|
||||
ignore_interrupts { temporary_path.rename(cached_location) }
|
||||
end
|
||||
@ -717,14 +716,14 @@ class GitDownloadStrategy < VCSDownloadStrategy
|
||||
end
|
||||
|
||||
def update_repo
|
||||
if @ref_type == :branch || !ref?
|
||||
return unless @ref_type == :branch || !ref?
|
||||
|
||||
if !shallow_clone? && shallow_dir?
|
||||
quiet_safe_system "git", "fetch", "origin", "--unshallow"
|
||||
else
|
||||
quiet_safe_system "git", "fetch", "origin"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def clone_repo
|
||||
safe_system "git", *clone_args
|
||||
@ -798,10 +797,10 @@ end
|
||||
class GitHubGitDownloadStrategy < GitDownloadStrategy
|
||||
def initialize(name, resource)
|
||||
super
|
||||
if @url =~ %r{^https?://github\.com/([^/]+)/([^/]+)\.git$}
|
||||
@user = $1
|
||||
@repo = $2
|
||||
end
|
||||
|
||||
return unless %r{^https?://github\.com/(?<user>[^/]+)/(?<repo>[^/]+)\.git$} =~ @url
|
||||
@user = user
|
||||
@repo = repo
|
||||
end
|
||||
|
||||
def github_last_commit
|
||||
|
@ -88,11 +88,11 @@ module HomebrewArgvExtension
|
||||
Formulary.from_rack(rack)
|
||||
end
|
||||
|
||||
if (prefix = f.installed_prefix).directory?
|
||||
Keg.new(prefix)
|
||||
else
|
||||
unless (prefix = f.installed_prefix).directory?
|
||||
raise MultipleVersionsInstalledError, rack.basename
|
||||
end
|
||||
|
||||
Keg.new(prefix)
|
||||
end
|
||||
rescue FormulaUnavailableError
|
||||
raise <<-EOS.undent
|
||||
|
@ -289,13 +289,12 @@ module SharedEnvExtension
|
||||
EOS
|
||||
end
|
||||
|
||||
unless gcc_formula.opt_prefix.exist?
|
||||
return if gcc_formula.opt_prefix.exist?
|
||||
raise <<-EOS.undent
|
||||
The requested Homebrew GCC was not installed. You must:
|
||||
brew install #{gcc_formula.full_name}
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
def permit_arch_flags; end
|
||||
|
||||
@ -328,10 +327,9 @@ module SharedEnvExtension
|
||||
end
|
||||
|
||||
def check_for_compiler_universal_support
|
||||
if homebrew_cc =~ GNU_GCC_REGEXP
|
||||
return unless homebrew_cc =~ GNU_GCC_REGEXP
|
||||
raise "Non-Apple GCC can't build universal binaries"
|
||||
end
|
||||
end
|
||||
|
||||
def gcc_with_cxx11_support?(cc)
|
||||
version = cc[/^gcc-(\d+(?:\.\d+)?)$/, 1]
|
||||
|
@ -48,11 +48,10 @@ module Stdenv
|
||||
|
||||
send(compiler)
|
||||
|
||||
if cc =~ GNU_GCC_REGEXP
|
||||
return unless cc =~ GNU_GCC_REGEXP
|
||||
gcc_formula = gcc_version_formula($&)
|
||||
append_path "PATH", gcc_formula.opt_bin.to_s
|
||||
end
|
||||
end
|
||||
alias generic_setup_build_environment setup_build_environment
|
||||
|
||||
def homebrew_extra_pkg_config_paths
|
||||
@ -174,11 +173,11 @@ module Stdenv
|
||||
append_to_cflags Hardware::CPU.universal_archs.as_arch_flags
|
||||
append "LDFLAGS", Hardware::CPU.universal_archs.as_arch_flags
|
||||
|
||||
if compiler != :clang && Hardware.is_32_bit?
|
||||
return if compiler == :clang
|
||||
return unless Hardware.is_32_bit?
|
||||
# Can't mix "-march" for a 32-bit CPU with "-arch x86_64"
|
||||
replace_in_cflags(/-march=\S*/, "-Xarch_#{Hardware::CPU.arch_32_bit} \\0")
|
||||
end
|
||||
end
|
||||
|
||||
def cxx11
|
||||
if compiler == :clang
|
||||
|
@ -276,13 +276,13 @@ module Superenv
|
||||
self["HOMEBREW_ARCHFLAGS"] = Hardware::CPU.universal_archs.as_arch_flags
|
||||
|
||||
# GCC doesn't accept "-march" for a 32-bit CPU with "-arch x86_64"
|
||||
if compiler != :clang && Hardware::CPU.is_32_bit?
|
||||
return if compiler == :clang
|
||||
return unless Hardware::CPU.is_32_bit?
|
||||
self["HOMEBREW_OPTFLAGS"] = self["HOMEBREW_OPTFLAGS"].sub(
|
||||
/-march=\S*/,
|
||||
"-Xarch_#{Hardware::CPU.arch_32_bit} \\0"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def permit_arch_flags
|
||||
append "HOMEBREW_CCCFG", "K"
|
||||
|
@ -89,12 +89,11 @@ module FileUtils
|
||||
# A version of mkdir that also changes to that folder in a block.
|
||||
def mkdir(name, &_block)
|
||||
old_mkdir(name)
|
||||
if block_given?
|
||||
return unless block_given?
|
||||
chdir name do
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
module_function :mkdir
|
||||
|
||||
# Run `scons` using a Homebrew-installed version rather than whatever is in the `PATH`.
|
||||
|
@ -20,7 +20,7 @@ module Stdenv
|
||||
|
||||
# Leopard's ld needs some convincing that it's building 64-bit
|
||||
# See: https://github.com/mistydemeo/tigerbrew/issues/59
|
||||
if MacOS.version == :leopard && MacOS.prefer_64_bit?
|
||||
return unless MacOS.version == :leopard && MacOS.prefer_64_bit?
|
||||
append "LDFLAGS", "-arch #{Hardware::CPU.arch_64_bit}"
|
||||
|
||||
# Many, many builds are broken thanks to Leopard's buggy ld.
|
||||
@ -28,7 +28,6 @@ module Stdenv
|
||||
# depend on it already being installed to build itself.
|
||||
ld64 if Formula["ld64"].installed?
|
||||
end
|
||||
end
|
||||
|
||||
def homebrew_extra_pkg_config_paths
|
||||
["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"]
|
||||
@ -65,7 +64,7 @@ module Stdenv
|
||||
delete("CPATH")
|
||||
remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"
|
||||
|
||||
if (sdk = MacOS.sdk_path(version)) && !MacOS::CLT.installed?
|
||||
return unless (sdk = MacOS.sdk_path(version)) && !MacOS::CLT.installed?
|
||||
delete("SDKROOT")
|
||||
remove_from_cflags "-isysroot #{sdk}"
|
||||
remove "CPPFLAGS", "-isysroot #{sdk}"
|
||||
@ -78,7 +77,6 @@ module Stdenv
|
||||
end
|
||||
remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks"
|
||||
end
|
||||
end
|
||||
|
||||
def macosxsdk(version = MacOS.version)
|
||||
# Sets all needed lib and include dirs to CFLAGS, CPPFLAGS, LDFLAGS.
|
||||
@ -89,7 +87,7 @@ module Stdenv
|
||||
self["CPATH"] = "#{HOMEBREW_PREFIX}/include"
|
||||
prepend "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"
|
||||
|
||||
if (sdk = MacOS.sdk_path(version)) && !MacOS::CLT.installed?
|
||||
return unless (sdk = MacOS.sdk_path(version)) && !MacOS::CLT.installed?
|
||||
# Extra setup to support Xcode 4.3+ without CLT.
|
||||
self["SDKROOT"] = sdk
|
||||
# Tell clang/gcc where system include's are:
|
||||
@ -103,7 +101,6 @@ module Stdenv
|
||||
append_path "CMAKE_PREFIX_PATH", "#{sdk}/usr"
|
||||
append_path "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks"
|
||||
end
|
||||
end
|
||||
|
||||
# Some configure scripts won't find libxml2 without help
|
||||
def libxml2
|
||||
|
@ -64,14 +64,13 @@ module FormulaCellarChecks
|
||||
keg = Keg.new(formula.prefix)
|
||||
checker = LinkageChecker.new(keg, formula)
|
||||
|
||||
if checker.broken_dylibs?
|
||||
return unless checker.broken_dylibs?
|
||||
audit_check_output <<-EOS.undent
|
||||
The installation was broken.
|
||||
Broken dylib links found:
|
||||
#{checker.broken_dylibs.to_a * "\n "}
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
def audit_installed
|
||||
generic_audit_installed
|
||||
|
@ -31,11 +31,10 @@ module Utils
|
||||
# sometimes a formula has just :tiger_altivec, other times it has
|
||||
# :tiger_g4, :tiger_g5, etc.
|
||||
def find_altivec_tag(tag)
|
||||
if tag.to_s =~ /(\w+)_(g4|g4e|g5)$/
|
||||
return unless tag.to_s =~ /(\w+)_(g4|g4e|g5)$/
|
||||
altivec_tag = "#{$1}_altivec".to_sym
|
||||
altivec_tag if key?(altivec_tag)
|
||||
end
|
||||
end
|
||||
|
||||
# Allows a bottle tag to specify a specific OS or later,
|
||||
# so the same bottle can target multiple OSs.
|
||||
|
@ -59,10 +59,9 @@ module StringInreplaceExtension
|
||||
# Looks for Makefile style variable defintions and replaces the
|
||||
# value with "new_value", or removes the definition entirely.
|
||||
def change_make_var!(flag, new_value)
|
||||
unless gsub!(/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, "#{flag}=#{new_value}", false)
|
||||
return if gsub!(/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, "#{flag}=#{new_value}", false)
|
||||
errors << "expected to change #{flag.inspect} to #{new_value.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
# Removes variable assignments completely.
|
||||
def remove_make_var!(flags)
|
||||
|
@ -224,11 +224,10 @@ class Formula
|
||||
|
||||
def set_spec(name)
|
||||
spec = self.class.send(name)
|
||||
if spec.url
|
||||
return unless spec.url
|
||||
spec.owner = self
|
||||
instance_variable_set("@#{name}", spec)
|
||||
end
|
||||
end
|
||||
|
||||
def determine_active_spec(requested)
|
||||
spec = send(requested) || stable || devel || head
|
||||
@ -246,10 +245,9 @@ class Formula
|
||||
end
|
||||
|
||||
val = version.respond_to?(:to_str) ? version.to_str : version
|
||||
if val.nil? || val.empty? || val =~ /\s/
|
||||
return unless val.nil? || val.empty? || val =~ /\s/
|
||||
raise FormulaValidationError.new(full_name, :version, val)
|
||||
end
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
@ -1065,11 +1063,10 @@ class Formula
|
||||
|
||||
# @private
|
||||
def patch
|
||||
unless patchlist.empty?
|
||||
return if patchlist.empty?
|
||||
ohai "Patching"
|
||||
patchlist.each(&:apply)
|
||||
end
|
||||
end
|
||||
|
||||
# yields |self,staging| with current working directory set to the uncompressed tarball
|
||||
# where staging is a Mktemp staging context
|
||||
@ -1094,11 +1091,12 @@ class Formula
|
||||
def lock
|
||||
@lock = FormulaLock.new(name)
|
||||
@lock.lock
|
||||
if oldname && (oldname_rack = HOMEBREW_CELLAR/oldname).exist? && oldname_rack.resolved_path == rack
|
||||
return unless oldname
|
||||
return unless (oldname_rack = HOMEBREW_CELLAR/oldname).exist?
|
||||
return unless oldname_rack.resolved_path == rack
|
||||
@oldname_lock = FormulaLock.new(oldname)
|
||||
@oldname_lock.lock
|
||||
end
|
||||
end
|
||||
|
||||
# @private
|
||||
def unlock
|
||||
@ -1427,11 +1425,10 @@ class Formula
|
||||
|
||||
# @private
|
||||
def print_tap_action(options = {})
|
||||
if tap?
|
||||
return unless tap?
|
||||
verb = options[:verb] || "Installing"
|
||||
ohai "#{verb} #{name} from #{tap}"
|
||||
end
|
||||
end
|
||||
|
||||
# @private
|
||||
def env
|
||||
|
@ -133,13 +133,11 @@ class FormulaInstaller
|
||||
begin
|
||||
compute_dependencies
|
||||
rescue TapFormulaUnavailableError => e
|
||||
if e.tap.installed?
|
||||
raise
|
||||
else
|
||||
raise if e.tap.installed?
|
||||
|
||||
e.tap.install
|
||||
retry
|
||||
end
|
||||
end
|
||||
rescue FormulaUnavailableError => e
|
||||
e.dependent = formula.full_name
|
||||
raise
|
||||
@ -148,24 +146,25 @@ class FormulaInstaller
|
||||
def check_install_sanity
|
||||
raise FormulaInstallationAlreadyAttemptedError, formula if @@attempted.include?(formula)
|
||||
|
||||
unless skip_deps_check?
|
||||
return if skip_deps_check?
|
||||
|
||||
recursive_deps = formula.recursive_dependencies
|
||||
unlinked_deps = recursive_deps.map(&:to_formula).select do |dep|
|
||||
dep.installed? && !dep.keg_only? && !dep.linked_keg.directory?
|
||||
end
|
||||
raise CannotInstallFormulaError,
|
||||
"You must `brew link #{unlinked_deps*" "}` before #{formula.full_name} can be installed" unless unlinked_deps.empty?
|
||||
|
||||
unless unlinked_deps.empty?
|
||||
raise CannotInstallFormulaError, "You must `brew link #{unlinked_deps*" "}` before #{formula.full_name} can be installed"
|
||||
end
|
||||
|
||||
pinned_unsatisfied_deps = recursive_deps.select do |dep|
|
||||
dep.to_formula.pinned? && !dep.satisfied?(inherited_options_for(dep))
|
||||
end
|
||||
|
||||
unless pinned_unsatisfied_deps.empty?
|
||||
return if pinned_unsatisfied_deps.empty?
|
||||
raise CannotInstallFormulaError,
|
||||
"You must `brew unpin #{pinned_unsatisfied_deps*" "}` as installing #{formula.full_name} requires the latest version of pinned dependencies"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def build_bottle_preinstall
|
||||
@etc_var_glob ||= "#{HOMEBREW_PREFIX}/{etc,var}/**/*"
|
||||
@ -285,11 +284,10 @@ class FormulaInstaller
|
||||
#{formula}: #{e.message}
|
||||
'conflicts_with \"#{c.name}\"' should be removed from #{formula.path.basename}.
|
||||
EOS
|
||||
if ARGV.homebrew_developer?
|
||||
raise
|
||||
else
|
||||
|
||||
raise if ARGV.homebrew_developer?
|
||||
|
||||
$stderr.puts "Please report this to the #{formula.tap} tap!"
|
||||
end
|
||||
false
|
||||
else
|
||||
f.linked_keg.exist? && f.opt_prefix.exist?
|
||||
@ -492,11 +490,10 @@ class FormulaInstaller
|
||||
|
||||
c = Caveats.new(formula)
|
||||
|
||||
unless c.empty?
|
||||
return if c.empty?
|
||||
@show_summary_heading = true
|
||||
ohai "Caveats", c.caveats
|
||||
end
|
||||
end
|
||||
|
||||
def finish
|
||||
return if only_deps?
|
||||
@ -706,14 +703,13 @@ class FormulaInstaller
|
||||
raise
|
||||
end
|
||||
|
||||
unless link_overwrite_backup.empty?
|
||||
return if link_overwrite_backup.empty?
|
||||
opoo "These files were overwritten during `brew link` step:"
|
||||
puts link_overwrite_backup.keys
|
||||
puts
|
||||
puts "They have been backed up in #{backup_dir}"
|
||||
@show_summary_heading = true
|
||||
end
|
||||
end
|
||||
|
||||
def install_plist
|
||||
return unless formula.plist
|
||||
@ -804,11 +800,10 @@ class FormulaInstaller
|
||||
end
|
||||
|
||||
def audit_check_output(output)
|
||||
if output
|
||||
return unless output
|
||||
opoo output
|
||||
@show_summary_heading = true
|
||||
end
|
||||
end
|
||||
|
||||
def audit_installed
|
||||
audit_check_output(check_env_path(formula.bin))
|
||||
@ -823,7 +818,7 @@ class FormulaInstaller
|
||||
end
|
||||
|
||||
def lock
|
||||
if (@@locked ||= []).empty?
|
||||
return unless (@@locked ||= []).empty?
|
||||
formula.recursive_dependencies.each do |dep|
|
||||
@@locked << dep.to_formula
|
||||
end unless ignore_deps?
|
||||
@ -832,13 +827,11 @@ class FormulaInstaller
|
||||
@@locked.each(&:lock)
|
||||
@hold_locks = true
|
||||
end
|
||||
end
|
||||
|
||||
def unlock
|
||||
if hold_locks?
|
||||
return unless hold_locks?
|
||||
@@locked.each(&:unlock)
|
||||
@@locked.clear
|
||||
@hold_locks = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -10,17 +10,15 @@ class FormulaLock
|
||||
def lock
|
||||
HOMEBREW_LOCK_DIR.mkpath
|
||||
@lockfile = get_or_create_lockfile
|
||||
unless @lockfile.flock(File::LOCK_EX | File::LOCK_NB)
|
||||
return if @lockfile.flock(File::LOCK_EX | File::LOCK_NB)
|
||||
raise OperationInProgressError, @name
|
||||
end
|
||||
end
|
||||
|
||||
def unlock
|
||||
unless @lockfile.nil? || @lockfile.closed?
|
||||
return if @lockfile.nil? || @lockfile.closed?
|
||||
@lockfile.flock(File::LOCK_UN)
|
||||
@lockfile.close
|
||||
end
|
||||
end
|
||||
|
||||
def with_lock
|
||||
lock
|
||||
|
@ -314,7 +314,9 @@ class Formulary
|
||||
possible_tap_formulae = tap_paths(ref)
|
||||
if possible_tap_formulae.size > 1
|
||||
raise TapFormulaAmbiguityError.new(ref, possible_tap_formulae)
|
||||
elsif possible_tap_formulae.size == 1
|
||||
end
|
||||
|
||||
if possible_tap_formulae.size == 1
|
||||
path = possible_tap_formulae.first.resolved_path
|
||||
name = path.basename(".rb").to_s
|
||||
return FormulaLoader.new(name, path)
|
||||
@ -336,7 +338,9 @@ class Formulary
|
||||
|
||||
if possible_tap_newname_formulae.size > 1
|
||||
raise TapFormulaWithOldnameAmbiguityError.new(ref, possible_tap_newname_formulae)
|
||||
elsif !possible_tap_newname_formulae.empty?
|
||||
end
|
||||
|
||||
unless possible_tap_newname_formulae.empty?
|
||||
return TapLoader.new(possible_tap_newname_formulae.first)
|
||||
end
|
||||
|
||||
@ -368,7 +372,9 @@ class Formulary
|
||||
possible_pinned_tap_formulae = tap_paths(ref, Dir["#{HOMEBREW_LIBRARY}/PinnedTaps/*/*/"]).map(&:realpath)
|
||||
if possible_pinned_tap_formulae.size > 1
|
||||
raise TapFormulaAmbiguityError.new(ref, possible_pinned_tap_formulae)
|
||||
elsif possible_pinned_tap_formulae.size == 1
|
||||
end
|
||||
|
||||
if possible_pinned_tap_formulae.size == 1
|
||||
selected_formula = factory(possible_pinned_tap_formulae.first, spec)
|
||||
if core_path(ref).file?
|
||||
opoo <<-EOS.undent
|
||||
|
@ -394,11 +394,10 @@ class Keg
|
||||
opt_record.delete if opt_record.symlink? || opt_record.exist?
|
||||
make_relative_symlink(opt_record, path, mode)
|
||||
|
||||
if oldname_opt_record
|
||||
return unless oldname_opt_record
|
||||
oldname_opt_record.delete
|
||||
make_relative_symlink(oldname_opt_record, path, mode)
|
||||
end
|
||||
end
|
||||
|
||||
def delete_pyc_files!
|
||||
find { |pn| pn.delete if %w[.pyc .pyo].include?(pn.extname) }
|
||||
@ -423,18 +422,19 @@ class Keg
|
||||
return
|
||||
end
|
||||
|
||||
if stat.directory?
|
||||
return unless stat.directory?
|
||||
begin
|
||||
keg = Keg.for(src)
|
||||
rescue NotAKegError
|
||||
puts "Won't resolve conflicts for symlink #{dst} as it doesn't resolve into the Cellar" if ARGV.verbose?
|
||||
if ARGV.verbose?
|
||||
puts "Won't resolve conflicts for symlink #{dst} as it doesn't resolve into the Cellar"
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
dst.unlink unless mode.dry_run
|
||||
keg.link_dir(src, mode) { :mkpath }
|
||||
return true
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def make_relative_symlink(dst, src, mode)
|
||||
@ -462,9 +462,8 @@ class Keg
|
||||
dst.delete if mode.overwrite && (dst.exist? || dst.symlink?)
|
||||
dst.make_relative_symlink(src)
|
||||
rescue Errno::EEXIST => e
|
||||
if dst.exist?
|
||||
raise ConflictError.new(self, src.relative_path_from(path), dst, e)
|
||||
elsif dst.symlink?
|
||||
raise ConflictError.new(self, src.relative_path_from(path), dst, e) if dst.exist?
|
||||
if dst.symlink?
|
||||
dst.unlink
|
||||
retry
|
||||
end
|
||||
|
@ -182,7 +182,7 @@ class Migrator
|
||||
end
|
||||
|
||||
def repin
|
||||
if pinned?
|
||||
return unless pinned?
|
||||
# old_pin_record is a relative symlink and when we try to to read it
|
||||
# from <dir> we actually try to find file
|
||||
# <dir>/../<...>/../Cellar/name/version.
|
||||
@ -198,7 +198,6 @@ class Migrator
|
||||
new_pin_record.make_relative_symlink(src_oldname.sub(oldname, newname))
|
||||
old_pin_record.delete
|
||||
end
|
||||
end
|
||||
|
||||
def unlink_oldname
|
||||
oh1 "Unlinking #{Tty.green}#{oldname}#{Tty.reset}"
|
||||
@ -254,11 +253,10 @@ class Migrator
|
||||
|
||||
# Link keg to opt if it was linked before migrating.
|
||||
def link_oldname_opt
|
||||
if old_opt_record
|
||||
return unless old_opt_record
|
||||
old_opt_record.delete if old_opt_record.symlink?
|
||||
old_opt_record.make_relative_symlink(new_linked_keg_record)
|
||||
end
|
||||
end
|
||||
|
||||
# After migtaion every INSTALL_RECEIPT.json has wrong path to the formula
|
||||
# so we must update INSTALL_RECEIPTs
|
||||
@ -316,7 +314,7 @@ class Migrator
|
||||
end
|
||||
end
|
||||
|
||||
unless old_linked_keg.nil?
|
||||
return if old_linked_keg.nil?
|
||||
# The keg used to be linked and when we backup everything we restore
|
||||
# Cellar/oldname, the target also gets restored, so we are able to
|
||||
# create a keg using its old path
|
||||
@ -334,7 +332,6 @@ class Migrator
|
||||
old_linked_keg.optlink
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def backup_oldname_cellar
|
||||
FileUtils.mv(new_cellar, old_cellar) unless old_cellar.exist?
|
||||
|
@ -18,12 +18,10 @@ module OS
|
||||
when "10.11" then "8.0"
|
||||
when "10.12" then "8.0"
|
||||
else
|
||||
raise "macOS '#{MacOS.version}' is invalid" unless OS::Mac.prerelease?
|
||||
|
||||
# Default to newest known version of Xcode for unreleased macOS versions.
|
||||
if OS::Mac.prerelease?
|
||||
"8.0"
|
||||
else
|
||||
raise "macOS '#{MacOS.version}' is invalid"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -130,14 +130,13 @@ class ExternalPatch
|
||||
patch_dir = Pathname.pwd
|
||||
if patch_files.empty?
|
||||
children = patch_dir.children
|
||||
if children.length == 1 && children.first.file?
|
||||
patch_files << children.first.basename
|
||||
else
|
||||
if children.length != 1 || !children.first.file?
|
||||
raise MissingApplyError, <<-EOS.undent
|
||||
There should be exactly one patch file in the staging directory unless
|
||||
the "apply" method was used one or more times in the patch-do block.
|
||||
EOS
|
||||
end
|
||||
patch_files << children.first.basename
|
||||
end
|
||||
dir.cd do
|
||||
patch_files.each do |patch_file|
|
||||
|
@ -83,13 +83,12 @@ class Requirement
|
||||
# PATH.
|
||||
# This is undocumented magic and it should be removed, but we need to add
|
||||
# a way to declare path-based requirements that work with superenv first.
|
||||
if @satisfied_result.is_a?(Pathname)
|
||||
return unless @satisfied_result.is_a?(Pathname)
|
||||
parent = @satisfied_result.parent
|
||||
unless ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s)
|
||||
|
||||
return if ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s)
|
||||
ENV.append_path("PATH", parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def env
|
||||
self.class.env
|
||||
@ -199,13 +198,10 @@ class Requirement
|
||||
|
||||
formulae.each do |f|
|
||||
f.requirements.each do |req|
|
||||
if prune?(f, req, &block)
|
||||
next
|
||||
else
|
||||
next if prune?(f, req, &block)
|
||||
reqs << req
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
reqs
|
||||
end
|
||||
|
@ -130,10 +130,9 @@ class Tap
|
||||
# The issues URL of this {Tap}.
|
||||
# e.g. `https://github.com/user/homebrew-repo/issues`
|
||||
def issues_url
|
||||
if official? || !custom_remote?
|
||||
return unless official? || !custom_remote?
|
||||
"https://github.com/#{user}/homebrew-#{repo}/issues"
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
@ -236,7 +235,9 @@ class Tap
|
||||
puts "Tapped #{formula_count} formula#{plural(formula_count, "e")} (#{path.abv})" unless quiet
|
||||
Descriptions.cache_formulae(formula_names)
|
||||
|
||||
if !options[:clone_target] && private? && !quiet
|
||||
return if options[:clone_target]
|
||||
return unless private?
|
||||
return if quiet
|
||||
puts <<-EOS.undent
|
||||
It looks like you tapped a private repository. To avoid entering your
|
||||
credentials each time you update, you can use git HTTP credential
|
||||
@ -245,7 +246,6 @@ class Tap
|
||||
git remote set-url origin git@github.com:#{user}/homebrew-#{repo}.git
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
def link_manpages
|
||||
link_path_manpages(path, "brew tap --repair")
|
||||
|
@ -45,10 +45,9 @@ class TestbotStepTests < Homebrew::TestCase
|
||||
end
|
||||
|
||||
def teardown
|
||||
unless passed?
|
||||
return if passed?
|
||||
raise "INFO: Previous test failed with ENV['TRAVIS'] = #{ENV["TRAVIS"].inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
def stub_test_instance
|
||||
stub(
|
||||
|
@ -39,10 +39,9 @@ class IntegrationCommandTests < Homebrew::TestCase
|
||||
end
|
||||
|
||||
def needs_test_cmd_taps
|
||||
unless ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"]
|
||||
return if ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"]
|
||||
skip "HOMEBREW_TEST_OFFICIAL_CMD_TAPS is not set"
|
||||
end
|
||||
end
|
||||
|
||||
def needs_macos
|
||||
skip "Not on MacOS" unless OS.mac?
|
||||
|
@ -57,11 +57,10 @@ module Homebrew
|
||||
super
|
||||
files_after_test = []
|
||||
Find.find(TEST_TMPDIR) { |f| files_after_test << f.sub(TEST_TMPDIR, "") }
|
||||
if @__files_before_test != files_after_test
|
||||
return if @__files_before_test == files_after_test
|
||||
@@log.puts location, diff(@__files_before_test, files_after_test)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class TestCase < ::Minitest::Test
|
||||
require "test/helper/shutup"
|
||||
|
@ -218,13 +218,9 @@ def interactive_shell(f = nil)
|
||||
|
||||
Process.wait fork { exec ENV["SHELL"] }
|
||||
|
||||
if $?.success?
|
||||
return
|
||||
elsif $?.exited?
|
||||
raise "Aborted due to non-zero exit status (#{$?.exitstatus})"
|
||||
else
|
||||
return if $?.success?
|
||||
raise "Aborted due to non-zero exit status (#{$?.exitstatus})" if $?.exited?
|
||||
raise $?.inspect
|
||||
end
|
||||
end
|
||||
|
||||
module Homebrew
|
||||
@ -325,7 +321,7 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
if $times.nil?
|
||||
return unless $times.nil?
|
||||
$times = {}
|
||||
at_exit do
|
||||
col_width = [$times.keys.map(&:size).max + 2, 15].max
|
||||
@ -334,7 +330,6 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def with_system_path
|
||||
@ -608,14 +603,14 @@ def link_src_dst_dirs(src_dir, dst_dir, command, link_dir: false)
|
||||
dst_dir.parent.mkpath
|
||||
dst.make_relative_symlink(src)
|
||||
end
|
||||
unless conflicts.empty?
|
||||
|
||||
return if conflicts.empty?
|
||||
onoe <<-EOS.undent
|
||||
Could not link:
|
||||
#{conflicts.join("\n")}
|
||||
|
||||
Please delete these paths and run `#{command}`.
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
def link_path_manpages(path, command)
|
||||
|
@ -14,11 +14,8 @@ module Utils
|
||||
def self.popen(args, mode)
|
||||
IO.popen("-", mode) do |pipe|
|
||||
if pipe
|
||||
if block_given?
|
||||
return pipe.read unless block_given?
|
||||
yield pipe
|
||||
else
|
||||
return pipe.read
|
||||
end
|
||||
else
|
||||
$stderr.reopen("/dev/null", "w")
|
||||
exec(*args)
|
||||
|
@ -192,11 +192,10 @@ class Version
|
||||
end
|
||||
|
||||
def initialize(val)
|
||||
if val.respond_to?(:to_str)
|
||||
@version = val.to_str
|
||||
else
|
||||
unless val.respond_to?(:to_str)
|
||||
raise TypeError, "Version value must be a string; got a #{val.class} (#{val})"
|
||||
end
|
||||
@version = val.to_str
|
||||
end
|
||||
|
||||
def detected_from_url?
|
||||
|
Loading…
x
Reference in New Issue
Block a user