2010-07-04 09:56:50 -07:00
|
|
|
# `brew readall` tries to import all formulae one-by-one.
|
|
|
|
# This can be useful for debugging issues across all formulae
|
2010-07-18 14:20:54 -07:00
|
|
|
# when making significant changes to formula.rb,
|
|
|
|
# or to determine if any current formulae have Ruby issues
|
2010-07-04 09:56:50 -07:00
|
|
|
|
2015-07-22 05:10:27 +01:00
|
|
|
require "formula"
|
2015-12-19 19:10:22 +08:00
|
|
|
require "tap"
|
2015-07-22 05:10:27 +01:00
|
|
|
require "thread"
|
2014-04-13 16:25:46 +01:00
|
|
|
|
2014-04-27 19:45:18 -05:00
|
|
|
module Homebrew
|
|
|
|
def readall
|
2015-03-07 11:55:14 +00:00
|
|
|
if ARGV.delete("--syntax")
|
|
|
|
ruby_files = Queue.new
|
|
|
|
Dir.glob("#{HOMEBREW_LIBRARY}/Homebrew/**/*.rb").each do |rb|
|
2015-08-03 21:14:20 +08:00
|
|
|
next if rb.include?("/vendor/")
|
2015-03-07 11:55:14 +00:00
|
|
|
ruby_files << rb
|
|
|
|
end
|
|
|
|
|
|
|
|
failed = false
|
2016-04-20 17:47:10 +02:00
|
|
|
workers = (0...Hardware::CPU.cores).map do
|
|
|
|
Thread.new do
|
|
|
|
begin
|
|
|
|
while rb = ruby_files.pop(true)
|
|
|
|
# As a side effect, print syntax errors/warnings to `$stderr`.
|
|
|
|
failed = true if syntax_errors_or_warnings?(rb)
|
2015-03-07 11:55:14 +00:00
|
|
|
end
|
2016-04-20 17:47:10 +02:00
|
|
|
rescue ThreadError # ignore empty queue error
|
2015-03-07 11:55:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-20 17:47:10 +02:00
|
|
|
workers.each(&:join)
|
2015-03-07 11:55:14 +00:00
|
|
|
Homebrew.failed = failed
|
|
|
|
end
|
|
|
|
|
2014-04-27 19:45:18 -05:00
|
|
|
formulae = []
|
2015-12-19 18:47:20 +08:00
|
|
|
alias_dirs = []
|
2015-04-11 14:18:13 +01:00
|
|
|
if ARGV.named.empty?
|
2015-08-01 00:02:19 +08:00
|
|
|
formulae = Formula.files
|
2015-12-19 18:47:20 +08:00
|
|
|
alias_dirs = Tap.map(&:alias_dir)
|
2014-04-27 19:45:18 -05:00
|
|
|
else
|
2015-12-07 14:11:04 +08:00
|
|
|
tap = Tap.fetch(ARGV.named.first)
|
2015-06-13 14:32:10 +08:00
|
|
|
raise TapUnavailableError, tap.name unless tap.installed?
|
2015-06-08 18:05:58 +08:00
|
|
|
formulae = tap.formula_files
|
2015-12-19 18:47:20 +08:00
|
|
|
alias_dirs = [tap.alias_dir]
|
|
|
|
end
|
|
|
|
|
|
|
|
if ARGV.delete("--aliases")
|
|
|
|
alias_dirs.each do |alias_dir|
|
|
|
|
next unless alias_dir.directory?
|
|
|
|
Pathname.glob("#{alias_dir}/*").each do |f|
|
|
|
|
next unless f.symlink?
|
|
|
|
next if f.file?
|
|
|
|
onoe "Broken alias: #{f}"
|
|
|
|
Homebrew.failed = true
|
|
|
|
end
|
|
|
|
end
|
2014-04-27 19:45:18 -05:00
|
|
|
end
|
2014-04-13 16:25:46 +01:00
|
|
|
|
2015-08-01 00:02:19 +08:00
|
|
|
formulae.each do |file|
|
2014-04-27 19:45:18 -05:00
|
|
|
begin
|
2015-08-01 00:02:19 +08:00
|
|
|
Formulary.factory(file)
|
2015-12-19 18:40:48 +08:00
|
|
|
rescue Interrupt
|
|
|
|
raise
|
2014-04-27 19:45:18 -05:00
|
|
|
rescue Exception => e
|
2015-08-01 00:02:19 +08:00
|
|
|
onoe "problem in #{file}"
|
2014-04-27 19:45:18 -05:00
|
|
|
puts e
|
|
|
|
Homebrew.failed = true
|
|
|
|
end
|
|
|
|
end
|
2010-07-18 14:20:54 -07:00
|
|
|
end
|
2016-04-20 01:18:40 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def syntax_errors_or_warnings?(rb)
|
|
|
|
# Retrieve messages about syntax errors/warnings printed to `$stderr`, but
|
|
|
|
# discard a `Syntax OK` printed to `$stdout` (in absence of syntax errors).
|
|
|
|
messages = Utils.popen_read("#{RUBY_PATH} -c -w #{rb} 2>&1 >/dev/null")
|
|
|
|
$stderr.print messages
|
|
|
|
|
|
|
|
# Only syntax errors result in a non-zero status code. To detect syntax
|
|
|
|
# warnings we also need to inspect the output to `$stderr`.
|
|
|
|
!$?.success? || !messages.chomp.empty?
|
|
|
|
end
|
2010-07-18 14:20:54 -07:00
|
|
|
end
|