Class: Comet::Makefile

Inherits:
Object
  • Object
show all
Defined in:
lib/comet/makefile.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMakefile

Returns a new instance of Makefile.



6
7
8
# File 'lib/comet/makefile.rb', line 6

def initialize
  @rules = [tmpdir_rule]
end

Class Method Details

.command(command, args) ⇒ Object



98
99
100
# File 'lib/comet/makefile.rb', line 98

def command(command, args)
  [command, *args].join ' '
end

.fingerprint(dependencies, extension:) ⇒ Object



102
103
104
# File 'lib/comet/makefile.rb', line 102

def fingerprint(dependencies, extension:)
  File.join Comet::TMPDIR, "#{hash dependencies}.#{extension}"
end

.select_command(preferred, alternate, args) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/comet/makefile.rb', line 88

def select_command(preferred, alternate, args)
  return command(alternate, args) if preferred == alternate

  check_command = "(command -v #{preferred} > /dev/null)"
  preferred_cmd = command preferred, args
  alternate_cmd = command alternate, args

  "#{check_command} && #{preferred_cmd} || #{alternate_cmd}"
end

Instance Method Details

#alias(name, rules) ⇒ Object



21
22
23
# File 'lib/comet/makefile.rb', line 21

def alias(name, rules)
  insert Rules::Alias.new(name, rules)
end

#build(firmware, device) ⇒ Object



25
26
27
# File 'lib/comet/makefile.rb', line 25

def build(firmware, device)
  append Rules::Build.new(firmware, device)
end

#cleanObject



33
34
35
# File 'lib/comet/makefile.rb', line 33

def clean
  append Rules::Clean.new(Comet::TMPDIR)
end

#contentsObject



10
11
12
13
# File 'lib/comet/makefile.rb', line 10

def contents
  output = (commands + @rules.map(&:contents))
  output.flatten.map(&:rstrip).join("\n") + "\n"
end

#error(message) ⇒ Object



29
30
31
# File 'lib/comet/makefile.rb', line 29

def error(message)
  insert Rules::Error.new(message)
end

#execute(*args) ⇒ Object



15
16
17
18
19
# File 'lib/comet/makefile.rb', line 15

def execute(*args)
  process_spawn make_command(*args) do |stdin|
    stdin.write contents
  end
end