class MxxRu::AbstractTarget

Base class for all targets.

Attributes

mxx_full_targets_names[R]

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.

mxx_generators[R]

Vector of source code generators.

mxx_required_prjs[R]

Vector of subordinated projects.

Public Class Methods

define_plural_form_method( singular_method ) click to toggle source

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 )
# 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
new( a_prj_alias ) click to toggle source
# 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
run( a_cmd_lines, a_to_destroy_on_fail, brief_desc = nil ) click to toggle source

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)

# 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

Public Instance Methods

build() click to toggle source

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

# File lib/mxx_ru/abstract_target.rb, line 292
def build
  raise AbstractMethodEx.new( "AbstractTarget::build" )
end
clean() click to toggle source

Child classes should redefine this method.

# File lib/mxx_ru/abstract_target.rb, line 297
def clean
  raise AbstractMethodEx.new( "AbstractTarget::clean" )
end
generator( a_generator ) click to toggle source

Add one more generator to the target. Reference to the target is returned.

# 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 ) click to toggle source

Add one more file, created during a target build.

# 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() click to toggle source
# File lib/mxx_ru/abstract_target.rb, line 252
def prj_alias
  return @mxx_prj_alias
end
required_prj( a_prj ) click to toggle source

Add one more project in a list of subordinated projects.

Returns target object, which is defined in subordinated project.

# 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.expand_path( a_prj )
  end

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

  return target
end
reset() click to toggle source

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

# File lib/mxx_ru/abstract_target.rb, line 303
def reset
end

Protected Instance Methods

build_required_projects() click to toggle source

Build of all projects required for the target. Returns MxxRu::TargetState.

# File lib/mxx_ru/abstract_target.rb, line 336
def build_required_projects
  state = MxxRu::TargetState::EXISTS
  @mxx_required_prjs.each { |p|
      prj_state = MxxRu::Util::build_call_wrapper( p )
      if MxxRu::TargetState::EXISTS != prj_state.state
        state = prj_state.state
      end
    }

  return MxxRu::TargetState.new( state )
end
clean_required_prjs() click to toggle source

Cleanup of all projects required for the target. Executed only if dry-run mode is disabled.

# File lib/mxx_ru/abstract_target.rb, line 350
def clean_required_prjs
  if !MxxRu::Util::Mode.instance.is_dry_run
    @mxx_required_prjs.each { |p| p.clean }
  end
end
reset_required_projects() click to toggle source

Reset build status for all projects required for the target.

# File lib/mxx_ru/abstract_target.rb, line 357
def reset_required_projects
  @mxx_required_prjs.each { |p| p.reset }
end