Class: Rscons::Builder
- Inherits:
-
Object
- Object
- Rscons::Builder
- Defined in:
- lib/rscons/builder.rb,
lib/rscons/builders/mixins/object.rb
Overview
Class to hold an object that knows how to build a certain type of file.
Direct Known Subclasses
Rscons::Builders::CFile, Rscons::Builders::Command, Rscons::Builders::Copy, Rscons::Builders::Directory, Rscons::Builders::Disassemble, Rscons::Builders::Library, Rscons::Builders::Object, Rscons::Builders::Preprocess, Rscons::Builders::Program, Rscons::Builders::SharedLibrary, Rscons::Builders::SharedObject, Rscons::Builders::SimpleBuilder
Instance Attribute Summary collapse
-
#build_step ⇒ Integer
Build step.
-
#cache ⇒ Cache
Cache instance.
-
#env ⇒ Environment
The Environment performing the build operation.
-
#preferred_ld ⇒ String?
readonly
Preferred linker for this object file, or a construction variable reference thereto.
-
#side_effects ⇒ Set<String>
Side effect file(s) produced when this builder runs.
-
#sources ⇒ Array<String>
Source file name(s).
-
#target ⇒ String, Symbol
Target file name.
-
#vars ⇒ Hash, VarSet
Construction variables used to perform the build operation.
Class Method Summary collapse
-
.extra_path ⇒ String?
Return a String specifying an extra path component used to differentiate build targets built by this builder from others.
-
.name ⇒ String
Return the name of the builder.
Instance Method Summary collapse
-
#depends(*user_deps) ⇒ void
Manually record a given build target as depending on the specified files.
-
#finalize_command(options = {}) ⇒ true
Register build results from a Command with the cache.
-
#initialize(options) ⇒ Builder
constructor
Create an instance of the Builder to build a target.
-
#name ⇒ String
Return the name of the builder.
-
#nop? ⇒ Boolean
Return whether the builder is a no-op.
-
#print_run_message(short_description, command) ⇒ void
Print the builder run message, depending on the Environment's echo mode.
-
#produces(*side_effects) ⇒ void
Manually record the given side effect file(s) as being produced when the named target is produced.
-
#register_command(short_description, command, options = {}) ⇒ Object
Create a Command object to execute the build command in a thread.
-
#run(options) ⇒ Object
Run the builder to produce a build target.
-
#standard_command(short_description, command, options = {}) ⇒ Object
Check if the cache is up to date for the target and if not create a Command object to execute the build command in a thread.
-
#wait_for(things) ⇒ Object
A builder can indicate to Rscons that it needs to wait for a separate operation to complete by using this method.
Constructor Details
#initialize(options) ⇒ Builder
Create an instance of the Builder to build a target.
72 73 74 75 76 77 78 79 |
# File 'lib/rscons/builder.rb', line 72 def initialize() @target = [:target] @sources = [:sources] @cache = [:cache] @env = [:env] @vars = [:vars] @side_effects = Set.new end |
Instance Attribute Details
#build_step ⇒ Integer
Returns Build step.
56 57 58 |
# File 'lib/rscons/builder.rb', line 56 def build_step @build_step end |
#cache ⇒ Cache
Returns Cache instance.
40 41 42 |
# File 'lib/rscons/builder.rb', line 40 def cache @cache end |
#env ⇒ Environment
Returns The Environment performing the build operation.
44 45 46 |
# File 'lib/rscons/builder.rb', line 44 def env @env end |
#preferred_ld ⇒ String? (readonly)
Returns Preferred linker for this object file, or a construction variable reference thereto.
6 7 8 |
# File 'lib/rscons/builders/mixins/object.rb', line 6 def preferred_ld @preferred_ld end |
#side_effects ⇒ Set<String>
Returns Side effect file(s) produced when this builder runs.
52 53 54 |
# File 'lib/rscons/builder.rb', line 52 def side_effects @side_effects end |
#sources ⇒ Array<String>
Returns Source file name(s).
36 37 38 |
# File 'lib/rscons/builder.rb', line 36 def sources @sources end |
#target ⇒ String, Symbol
Returns Target file name.
32 33 34 |
# File 'lib/rscons/builder.rb', line 32 def target @target end |
#vars ⇒ Hash, VarSet
Returns Construction variables used to perform the build operation.
48 49 50 |
# File 'lib/rscons/builder.rb', line 48 def vars @vars end |
Class Method Details
.extra_path ⇒ String?
Return a String specifying an extra path component used to differentiate build targets built by this builder from others.
17 18 |
# File 'lib/rscons/builder.rb', line 17 def extra_path end |
.name ⇒ String
Return the name of the builder.
If not overridden this defaults to the last component of the class name.
25 26 27 |
# File 'lib/rscons/builder.rb', line 25 def name super.split(":").last end |
Instance Method Details
#depends(*user_deps) ⇒ void
This method returns an undefined value.
Manually record a given build target as depending on the specified files.
104 105 106 |
# File 'lib/rscons/builder.rb', line 104 def depends(*user_deps) @env.depends(@target, *user_deps) end |
#finalize_command(options = {}) ⇒ true
Register build results from a Command with the cache.
211 212 213 214 215 |
# File 'lib/rscons/builder.rb', line 211 def finalize_command( = {}) sources = [:sources] || @sources @cache.register_build(@target, @command, sources, @env) true end |
#name ⇒ String
Return the name of the builder.
If not overridden this defaults to the last component of the class name.
86 87 88 |
# File 'lib/rscons/builder.rb', line 86 def name self.class.name end |
#nop? ⇒ Boolean
Return whether the builder is a no-op.
94 95 96 |
# File 'lib/rscons/builder.rb', line 94 def nop? false end |
#print_run_message(short_description, command) ⇒ void
This method returns an undefined value.
Print the builder run message, depending on the Environment's echo mode.
144 145 146 |
# File 'lib/rscons/builder.rb', line 144 def (short_description, command) @env.(self, short_description, command) end |
#produces(*side_effects) ⇒ void
This method returns an undefined value.
Manually record the given side effect file(s) as being produced when the named target is produced.
112 113 114 115 116 117 118 |
# File 'lib/rscons/builder.rb', line 112 def produces(*side_effects) side_effects.each do |side_effect| = @env.(@env.(side_effect)) @env.register_side_effect() @side_effects << end end |
#register_command(short_description, command, options = {}) ⇒ Object
Create a Command object to execute the build command in a thread.
162 163 164 165 166 167 168 169 |
# File 'lib/rscons/builder.rb', line 162 def register_command(short_description, command, = {}) = {} if [:stdout] [:system_options] = {out: [:stdout]} end (short_description, @command) wait_for(Command.new(command, self, )) end |
#run(options) ⇒ Object
Run the builder to produce a build target.
131 132 133 |
# File 'lib/rscons/builder.rb', line 131 def run() raise "This method must be overridden in a subclass" end |
#standard_command(short_description, command, options = {}) ⇒ Object
Check if the cache is up to date for the target and if not create a Command object to execute the build command in a thread.
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rscons/builder.rb', line 188 def standard_command(short_description, command, = {}) @command = command sources = [:sources] || @sources if @cache.up_to_date?(@target, @command, sources, @env) true else unless Rscons.phony_target?(@target) @cache.mkdir_p(File.dirname(@target)) FileUtils.rm_f(@target) end register_command(short_description, @command, ) end end |
#wait_for(things) ⇒ Object
A builder can indicate to Rscons that it needs to wait for a separate operation to complete by using this method. The return value from this method should be returned from the builder's #run method.
224 225 226 |
# File 'lib/rscons/builder.rb', line 224 def wait_for(things) Array(things) end |