Class: R::TargetGenerator

Inherits:
TargetSmart show all
Defined in:
lib/rub/r/targetgenerator.rb

Overview

A target that executes a command.

This is a target that executes a command. It can be used directly but it is easier and prettier to use C.generator

Direct Known Subclasses

L::Test::TargetTestExecutable

Instance Attribute Summary collapse

Attributes inherited from TargetSmart

#input, #output

Instance Method Summary collapse

Methods inherited from TargetSmart

#build, #clean, #clean?

Methods inherited from Target

#build, #clean?, #description, #hash_output, #hash_outputs, #hash_self, #input, #output, #register

Constructor Details

#initializeTargetGenerator

Returns a new instance of TargetGenerator.



33
34
35
36
37
38
39
# File 'lib/rub/r/targetgenerator.rb', line 33

def initialize
	super
	
	@action = 'Building'
	
	@cmd = []
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



31
32
33
# File 'lib/rub/r/targetgenerator.rb', line 31

def action
  @action
end

Instance Method Details

#add_cmd(cmd) ⇒ Array<String>

Add a command to be executed.

Parameters:

  • cmd (Array<String,#to_s])

    md [Array<String,#to_s]

Returns:

  • (Array<String>)

    The command.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rub/r/targetgenerator.rb', line 45

def add_cmd(cmd)
	cmd = cmd.map{|a| a.to_s}
	exe = C.find_command(cmd[0])
	if not exe
		raise "Can't find #{cmd[0]}."
		exit 1
	end
	cmd[0] = exe
	@input << cmd[0]
	@cmd << cmd
	
	cmd
end

#add_cmds(cmds) ⇒ Array<Array<String>>

Add multiple commands.

Parameters:

  • cmds (Array<Array<String,#to_s>>)

    The commands.

Returns:

  • (Array<Array<String>>)

    The commands.

See Also:



65
66
67
# File 'lib/rub/r/targetgenerator.rb', line 65

def add_cmds(cmds)
	cmds.map{|c| add_cmd c}
end

#build_selfObject



75
76
77
78
# File 'lib/rub/r/targetgenerator.rb', line 75

def build_self
	R::run(['mkdir', '-pv', *@output.map{|o| o.dirname}], "Preparing output directories", importance: :low)
	@cmd.all?{|c| R::run(c, "#@action #{@output.to_a.join", "}")} or exit 1
end

#hash_inputObject



69
70
71
72
73
# File 'lib/rub/r/targetgenerator.rb', line 69

def hash_input
	super + Digest::SHA1.digest(
		@cmd.join("\0")
	)
end