Class: R::Target

Inherits:
Object show all
Defined in:
lib/rub/r/target.rb

Overview

The base target class.

It has simple building logic and a way to register targets. All targets should inherit from this class.

Constant Summary collapse

@@symbolcounter =

Shouldn’t repeat very often.

rand(2**160)

Instance Method Summary collapse

Instance Method Details

#buildvoid

This method returns an undefined value.

Build.

This is a simple build method. It calls #build_dependancies then #build_self. Either or both of these methods can be overwritten to customize the build or this function can be overwritten to have more control.



180
181
182
183
184
185
# File 'lib/rub/r/target.rb', line 180

def build
	build_dependancies
	build_self
	
	nil
end

#clean?Boolean

Is this target up to date?

Returns:

  • (Boolean)


116
117
118
# File 'lib/rub/r/target.rb', line 116

def clean?
	false
end

#descriptionString?

Description.

Shown for :help.

Returns:

  • (String, nil)


100
101
102
# File 'lib/rub/r/target.rb', line 100

def description
	nil
end

#hash_inputString

Return a hash of this target.

This hash should represent a unique build environment and change if anything in that environment does. This includes, but is not limited to:

  • Input files.

  • Output files.

  • Build commands.

Returns:

  • (String)

    the hash.



130
131
132
133
134
135
136
# File 'lib/rub/r/target.rb', line 130

def hash_input
	Digest::SHA1.digest(
		(
			input.map{|i| R::get_target(i).hash_output(i) }
		).join
	)
end

#hash_output(t) ⇒ Object



139
140
141
142
143
144
145
146
# File 'lib/rub/r/target.rb', line 139

def hash_output(t)
	if t.is_a? Symbol
		@@symbolcounter++
		"symbol-#{@@symbolcounter.to_s(16)}" # Never clean.
	else
		Digest::SHA1.file(t).to_s
	end
end

#hash_outputs(t = output) ⇒ Object



148
149
150
# File 'lib/rub/r/target.rb', line 148

def hash_outputs(t = output)
	Digest::SHA1.digest(t.map{|o| hash_output(o)}.join)
end

#hash_selfObject



152
153
154
# File 'lib/rub/r/target.rb', line 152

def hash_self
	Digest::SHA1.digest(hash_input+hash_outputs)
end

#inputSet<Pathname>

Inputs

Returns:

  • (Set<Pathname>)

    The inputs this target depends on.



85
86
87
# File 'lib/rub/r/target.rb', line 85

def input
	Set.new
end

#outputSet<Pathname>

Outputs

Returns:

  • (Set<Pathname>)

    The outputs this target creates.



92
93
94
# File 'lib/rub/r/target.rb', line 92

def output
	Set.new
end

#registervoid

This method returns an undefined value.

Register this target.

Registers this target as building it’s #outputs.



109
110
111
112
113
# File 'lib/rub/r/target.rb', line 109

def register
	output.each do |d|
		R.set_target(d, self)
	end
end