Class: MxxRu::AbstractTarget
- Inherits:
-
Object
- Object
- MxxRu::AbstractTarget
- Defined in:
- lib/mxx_ru/abstract_target.rb
Overview
Base class for all targets.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#mxx_full_targets_names ⇒ Object
readonly
List of full file names, created during a build of the target.
-
#mxx_generators ⇒ Object
readonly
Vector of source code generators.
-
#mxx_required_prjs ⇒ Object
readonly
Vector of subordinated projects.
Class Method Summary collapse
-
.define_plural_form_method(singular_method) ⇒ Object
Metacode for generating ‘plural’ version of singular method.
-
.run(a_cmd_lines, a_to_destroy_on_fail, brief_desc = nil) ⇒ Object
Executing command line given.
Instance Method Summary collapse
-
#build ⇒ Object
Child classes should redefine this method.
-
#clean ⇒ Object
Child classes should redefine this method.
-
#generator(a_generator) ⇒ Object
Add one more generator to the target.
-
#initialize(a_prj_alias) ⇒ AbstractTarget
constructor
A new instance of AbstractTarget.
-
#mxx_add_full_target_name(a_full_name) ⇒ Object
Add one more file, created during a target build.
- #prj_alias ⇒ Object
-
#required_prj(a_prj) ⇒ Object
Add one more project in a list of subordinated projects.
-
#reset ⇒ Object
Child classes should redefine this method.
Constructor Details
#initialize(a_prj_alias) ⇒ AbstractTarget
Returns a new instance of AbstractTarget.
238 239 240 241 242 243 244 245 |
# File 'lib/mxx_ru/abstract_target.rb', line 238 def initialize( a_prj_alias ) @mxx_full_targets_names = Array.new @mxx_prj_alias = a_prj_alias @mxx_required_prjs = Array.new @mxx_generators = Array.new MxxRu.try_set_first_target_alias( a_prj_alias ) end |
Instance Attribute Details
#mxx_full_targets_names ⇒ Object (readonly)
List of full file names, created during a build of the target. It may be an empty array if target doesn’t create any files. For example, if target is a composite or unittest.
211 212 213 |
# File 'lib/mxx_ru/abstract_target.rb', line 211 def mxx_full_targets_names @mxx_full_targets_names end |
#mxx_generators ⇒ Object (readonly)
Vector of source code generators.
217 218 219 |
# File 'lib/mxx_ru/abstract_target.rb', line 217 def mxx_generators @mxx_generators end |
#mxx_required_prjs ⇒ Object (readonly)
Vector of subordinated projects.
214 215 216 |
# File 'lib/mxx_ru/abstract_target.rb', line 214 def mxx_required_prjs @mxx_required_prjs end |
Class Method Details
.define_plural_form_method(singular_method) ⇒ Object
Metacode for generating ‘plural’ version of singular method. Plural version accept Enumerable-type argument and call singular version for each member of Enumerable argument.
For example:
define_plural_form_method :required_prj
define_plural_form_method :cpp_source
produces methods
required_prjs( items )
cpp_sources( items )
230 231 232 233 234 235 236 |
# File 'lib/mxx_ru/abstract_target.rb', line 230 def AbstractTarget.define_plural_form_method( singular_method ) class_eval %Q{ def #{singular_method}s(a) a.each { |e| #{singular_method}( e ) } end } end |
.run(a_cmd_lines, a_to_destroy_on_fail, brief_desc = nil) ⇒ Object
Executing command line given.
- a_cmd_lines
-
Array of String
- a_to_destroy_on_fail
-
Files required to be cleaned up if any of given command fail.
- brief_desc
-
Brief description of command (will be shown if –mxx-brief-show specified in command line)
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/mxx_ru/abstract_target.rb', line 313 def AbstractTarget.run( a_cmd_lines, a_to_destroy_on_fail, brief_desc = nil ) MxxRu.show_brief( brief_desc ) a_cmd_lines.each { |c| puts "<<< #{c} >>>" \ if MxxRu::Util::Mode.instance.is_show_cmd # Do not actually execute in dry-run mode. if !MxxRu::Util::Mode.instance.is_dry_run if !system( c ) a_to_destroy_on_fail.each { |d| MxxRu::Util::delete_file( d ) } raise BuildEx.new( c, $? ) end end } end |
Instance Method Details
#build ⇒ Object
Child classes should redefine this method. TargetState object is returned.
292 293 294 |
# File 'lib/mxx_ru/abstract_target.rb', line 292 def build raise AbstractMethodEx.new( "AbstractTarget::build" ) end |
#clean ⇒ Object
Child classes should redefine this method.
297 298 299 |
# File 'lib/mxx_ru/abstract_target.rb', line 297 def clean raise AbstractMethodEx.new( "AbstractTarget::clean" ) end |
#generator(a_generator) ⇒ Object
Add one more generator to the target. Reference to the target is returned.
285 286 287 288 |
# File 'lib/mxx_ru/abstract_target.rb', line 285 def generator( a_generator ) @mxx_generators << a_generator return a_generator end |
#mxx_add_full_target_name(a_full_name) ⇒ Object
Add one more file, created during a target build.
248 249 250 |
# File 'lib/mxx_ru/abstract_target.rb', line 248 def mxx_add_full_target_name( a_full_name ) @mxx_full_targets_names << a_full_name end |
#prj_alias ⇒ Object
252 253 254 |
# File 'lib/mxx_ru/abstract_target.rb', line 252 def prj_alias return @mxx_prj_alias end |
#required_prj(a_prj) ⇒ Object
Add one more project in a list of subordinated projects.
Returns target object, which is defined in subordinated project.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/mxx_ru/abstract_target.rb', line 259 def required_prj( a_prj ) # If project is not loaded yet, loading it. # Then adding created target object to the list ofd subordinated projects. # If no target will be created, exception would be thrown. if !MxxRu::target_defined_for?( a_prj ) # expand_path is called because $: in Ruby 1.9.2 doesn't contain # the current path. So the form "required_prj 'some/project/prj.rb'" # doesn't work in Ruby 1.9.2. require File.( a_prj ) end target = MxxRu::query_target( a_prj, true ) @mxx_required_prjs << target return target end |
#reset ⇒ Object
Child classes should redefine this method. Base class does not implement it.
303 304 |
# File 'lib/mxx_ru/abstract_target.rb', line 303 def reset end |