aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/readall.rb
blob: 5e87fcbdb538c2318ea671a67f4e92ca3f085afe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# `brew readall` tries to import all formulae one-by-one.
# This can be useful for debugging issues across all formulae
# when making significant changes to formula.rb,
# or to determine if any current formulae have Ruby issues

require "formula"
require "cmd/tap"
require "thread"

module Homebrew
  def readall
    if ARGV.delete("--syntax")
      ruby_files = Queue.new
      Dir.glob("#{HOMEBREW_LIBRARY}/Homebrew/**/*.rb").each do |rb|
        next if rb.include?("/vendor/")
        ruby_files << rb
      end

      failed = false
      nostdout do
        workers = (0...Hardware::CPU.cores).map do
          Thread.new do
            begin
              while rb = ruby_files.pop(true)
                failed = true unless system RUBY_PATH, "-c", "-w", rb
              end
            rescue ThreadError # ignore empty queue error
            end
          end
        end
        workers.map(&:join)
      end
      Homebrew.failed = failed
    end

    if ARGV.delete("--aliases")
      Pathname.glob("#{HOMEBREW_LIBRARY}/Aliases/*").each do |f|
        next unless f.symlink?
        next if f.file?
        onoe "Broken alias: #{f}"
        Homebrew.failed = true
      end
    end

    formulae = []
    if ARGV.named.empty?
      formulae = Formula.files
    else
      tap = Tap.fetch(*tap_args)
      raise TapUnavailableError, tap.name unless tap.installed?
      formulae = tap.formula_files
    end

    formulae.each do |file|
      begin
        Formulary.factory(file)
      rescue Exception => e
        onoe "problem in #{file}"
        puts e
        Homebrew.failed = true
      end
    end
  end
end