Class: MxxRu::AbstractTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/mxx_ru/abstract_target.rb

Overview

Base class for all targets.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_prj_alias) ⇒ AbstractTarget

Returns a new instance of AbstractTarget.



237
238
239
240
241
242
243
244
# File 'lib/mxx_ru/abstract_target.rb', line 237

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_namesObject (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.



210
211
212
# File 'lib/mxx_ru/abstract_target.rb', line 210

def mxx_full_targets_names
  @mxx_full_targets_names
end

#mxx_generatorsObject (readonly)

Vector of source code generators.



216
217
218
# File 'lib/mxx_ru/abstract_target.rb', line 216

def mxx_generators
  @mxx_generators
end

#mxx_required_prjsObject (readonly)

Vector of subordinated projects.



213
214
215
# File 'lib/mxx_ru/abstract_target.rb', line 213

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 )


229
230
231
232
233
234
235
# File 'lib/mxx_ru/abstract_target.rb', line 229

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)



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/mxx_ru/abstract_target.rb', line 309

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

#buildObject

Child classes should redefine this method. TargetState object is returned.

Raises:



288
289
290
# File 'lib/mxx_ru/abstract_target.rb', line 288

def build
  raise AbstractMethodEx.new( "AbstractTarget::build" )
end

#cleanObject

Child classes should redefine this method.

Raises:



293
294
295
# File 'lib/mxx_ru/abstract_target.rb', line 293

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.



281
282
283
284
# File 'lib/mxx_ru/abstract_target.rb', line 281

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.



247
248
249
# File 'lib/mxx_ru/abstract_target.rb', line 247

def mxx_add_full_target_name( a_full_name )
  @mxx_full_targets_names << a_full_name
end

#prj_aliasObject



251
252
253
# File 'lib/mxx_ru/abstract_target.rb', line 251

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.



258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/mxx_ru/abstract_target.rb', line 258

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 )
    require a_prj
  end

  target = MxxRu::query_target( a_prj, true )
  @mxx_required_prjs << target

  return target
end

#resetObject

Child classes should redefine this method. Base class does not implement it.



299
300
# File 'lib/mxx_ru/abstract_target.rb', line 299

def reset
end