Module: Readall

Defined in:
Library/Homebrew/readall.rb

Class Method Summary collapse

Class Method Details

.valid_aliases?(alias_dir, formula_dir) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'Library/Homebrew/readall.rb', line 26

def valid_aliases?(alias_dir, formula_dir)
  return true unless alias_dir.directory?

  failed = false
  alias_dir.each_child do |f|
    if !f.symlink?
      onoe "Non-symlink alias: #{f}"
      failed = true
    elsif !f.file?
      onoe "Non-file alias: #{f}"
      failed = true
    end

    if (formula_dir/"#{f.basename}.rb").exist?
      onoe "Formula duplicating alias: #{f}"
      failed = true
    end
  end
  !failed
end

.valid_formulae?(formulae) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'Library/Homebrew/readall.rb', line 47

def valid_formulae?(formulae)
  failed = false
  formulae.each do |file|
    begin
      Formulary.factory(file)
    rescue Interrupt
      raise
    rescue Exception => e # rubocop:disable Lint/RescueException
      onoe "Invalid formula: #{file}"
      puts e
      failed = true
    end
  end
  !failed
end

.valid_ruby_syntax?(ruby_files) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'Library/Homebrew/readall.rb', line 6

def valid_ruby_syntax?(ruby_files)
  ruby_files_queue = Queue.new
  ruby_files.each { |f| ruby_files_queue << f }
  failed = false
  workers = (0...Hardware::CPU.cores).map do
    Thread.new do
      Kernel.loop do
        begin
          # As a side effect, print syntax errors/warnings to `$stderr`.
          failed = true if syntax_errors_or_warnings?(ruby_files_queue.deq(true))
        rescue ThreadError
          break
        end
      end
    end
  end
  workers.each(&:join)
  !failed
end

.valid_tap?(tap, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
72
# File 'Library/Homebrew/readall.rb', line 63

def valid_tap?(tap, options = {})
  failed = false
  if options[:aliases]
    valid_aliases = valid_aliases?(tap.alias_dir, tap.formula_dir)
    failed = true unless valid_aliases
  end
  valid_formulae = valid_formulae?(tap.formula_files)
  failed = true unless valid_formulae
  !failed
end