class MxxRu::MakestyleGenerator

A Generator, which allows to define simple make rules in a project.

For example, if it's needed to get from ddl file two other files, cpp and hpp, using typegen program, it should be done like that:

generator( MxxRu::MakestyleGenerator.new(
  [ "myfile.cpp", "myfile.hpp" ],
  [ "myfile.ddl" ],
  [ "typegen --from myfile.ddl --cpp myfile.cpp --header myfile.hpp" ] ) )

NOTE: For C++ projects current value of sources_root isn't taken into account.

Attributes

build_cmds[R]

Command list, which should be ran in a sequence to get result files.

clean_cmds[R]

Command list, which should be ran in a sequence to remove result files.

If this list is empty, removal of result files would occur on clean operation.

dependencies[R]

File names list, result files depends from.

target_files[R]

File names list, which should be built by given generator.

Public Class Methods

new( a_target_files, a_dependencies, a_build_cmds, a_clean_cmds = Array.new ) click to toggle source

Constructor.

a_target_files

Result files list.

a_dependencies

Dependencies list.

a_build_cmds

Command list, which should be ran in a sequence to get result files.

a_clean_cmds

Command list, which should be ran in a sequence to remove result files.

NOTE: Single values may be defined as a strings instead of vectors. For example:

MxxRu::MakestyleGenerator.new( "myfile.cpp", "myfile.ddl",
  [ "typegen --from myfile.ddl --to myfile.cpp" ] )

It's the same as:

MxxRu::MakestyleGenerator.new( [ "myfile.cpp" ], [ "myfile.ddl" ],
  "typegen --from myfile.ddl --to myfile.cpp" )
# File lib/mxx_ru/makestyle_generator.rb, line 76
def initialize(
  a_target_files,
  a_dependencies,
  a_build_cmds,
  a_clean_cmds = Array.new )

  @target_files = make_array( a_target_files )
  @dependencies = make_array( a_dependencies )
  @build_cmds = make_array( a_build_cmds )
  @clean_cmds = make_array( a_clean_cmds )
end

Public Instance Methods

build( target ) click to toggle source

Perform the build of result files.

NOTE: target argument is ignored.

# File lib/mxx_ru/makestyle_generator.rb, line 91
def build( target )
  need_build = false

  # Checking all result files. If one of them is obsolete, performing rebuild.
  index = 0
  while !need_build && index != @target_files.size
    if TargetState::EXISTS != TargetState.detect(
      @target_files[ index ], @dependencies ).state
      need_build = true
    else
      index += 1
    end
  end

  if need_build
    # It's required to run all commands to build target.
    AbstractTarget.run(
        @build_cmds,
        [],
        "building #{@target_files.join(', ')}" )
  end
end
clean( target ) click to toggle source

Perform the cleanup of result files.

NOTE: target argument is ignored.

# File lib/mxx_ru/makestyle_generator.rb, line 117
def clean( target )
  # If cleanup commands weren't set, deleting result files.
  # Otherwise, it's required to run all commands in a sequence,
  # ignoring return codes.
  if 0 != @clean_cmds.size
    @clean_cmds.each do |c|
      system( c )
    end
  else
    @target_files.each do |f|
      Util.delete_file( f )
    end
  end
end

Protected Instance Methods

make_array( a_object ) click to toggle source

Conversion of single object into a vector, which contains that object. If source object is a vector, it's returned without any operations on it.

# File lib/mxx_ru/makestyle_generator.rb, line 135
def make_array( a_object )
  if a_object.instance_of? Array
    return a_object
  end

  return [ a_object ]
end