Module: Ninja::Rule::Description

Defined in:
lib/ninja/rule.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.validate!(desc) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ninja/rule.rb', line 18

def self.validate!(desc)
  # This might be overkill, but we want this to be idiot-proof.
  raise "Name not specified." unless desc.include?(:name)
   raise "Expected name to be a string composed of [a-Z,0-9,-,_] characters." unless /\A([-\w]+?)+\z/.match(desc[:name])

  raise "Command not specified." unless desc.include?(:command)
   # TODO(mtwilliams): Check response file.
   # raise "Input not used by the command." unless desc[:command].include? '$in'
   # raise "Output not used by the command." unless desc[:command].include? '$out'

  if desc[:dependencies]
    if desc[:dependencies].is_a?(String)
    elsif desc[:dependencies].is_a?(Symbol)
      raise "Unknown or unsupported dependency auto-detection method: '#{desc[:dependencies]}'." unless [:gcc, :clang, :msvc].include?(desc[:dependencies])
    else
      raise "Expected dependencies to be name or auto-detection method."
    end
  end

  if desc[:response_file]
    raise "Expected a `Ninja::Responsefile`." unless desc[:response_file].is_a?(ResponseFile)
  end
end