class R::Target
The base target class.
It has simple building logic and a way to register targets. All targets should inherit from this class.
Public Instance Methods
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.
@return [void]
# File lib/rub/r/target.rb, line 180 def build build_dependancies build_self nil end
Is this target up to date?
# File lib/rub/r/target.rb, line 116 def clean? false end
Description.
Shown for :help. @return [String,nil]
# File lib/rub/r/target.rb, line 100 def description nil end
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.
@return [String] the hash.
# 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
# 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
# File lib/rub/r/target.rb, line 148 def hash_outputs(t = output) Digest::SHA1.digest(t.map{|o| hash_output(o)}.join) end
# File lib/rub/r/target.rb, line 152 def hash_self Digest::SHA1.digest(hash_input+hash_outputs) end
Inputs
@return [Set<Pathname>] The inputs this target depends on.
# File lib/rub/r/target.rb, line 85 def input Set.new end
Outputs
@return [Set<Pathname>] The outputs this target creates.
# File lib/rub/r/target.rb, line 92 def output Set.new end
Register this target.
Registers this target as building it’s {#output}s.
@return [void]
# File lib/rub/r/target.rb, line 109 def register output.each do |d| R.set_target(d, self) end end
Private Instance Methods
Build the inputs.
# File lib/rub/r/target.rb, line 157 def build_dependancies input.each{|i| R::get_target(i).build } end
@return [void]
# File lib/rub/r/target.rb, line 167 def build_self raise "#build_self not implemented in #{self.class}." end