Class: MxxRu::MakestyleGenerator
- Inherits:
-
AbstractGenerator
- Object
- AbstractGenerator
- MxxRu::MakestyleGenerator
- Defined in:
- lib/mxx_ru/makestyle_generator.rb
Overview
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.
Instance Attribute Summary collapse
-
#build_cmds ⇒ Object
readonly
Command list, which should be ran in a sequence to get result files.
-
#clean_cmds ⇒ Object
readonly
Command list, which should be ran in a sequence to remove result files.
-
#dependencies ⇒ Object
readonly
File names list, result files depends from.
-
#target_files ⇒ Object
readonly
File names list, which should be built by given generator.
Instance Method Summary collapse
-
#build(target) ⇒ Object
Perform the build of result files.
-
#clean(target) ⇒ Object
Perform the cleanup of result files.
-
#initialize(a_target_files, a_dependencies, a_build_cmds, a_clean_cmds = Array.new) ⇒ MakestyleGenerator
constructor
Constructor.
Constructor Details
#initialize(a_target_files, a_dependencies, a_build_cmds, a_clean_cmds = Array.new) ⇒ MakestyleGenerator
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" )
76 77 78 79 80 81 82 83 84 85 86 |
# 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 |
Instance Attribute Details
#build_cmds ⇒ Object (readonly)
Command list, which should be ran in a sequence to get result files.
51 52 53 |
# File 'lib/mxx_ru/makestyle_generator.rb', line 51 def build_cmds @build_cmds end |
#clean_cmds ⇒ Object (readonly)
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.
57 58 59 |
# File 'lib/mxx_ru/makestyle_generator.rb', line 57 def clean_cmds @clean_cmds end |
#dependencies ⇒ Object (readonly)
File names list, result files depends from.
48 49 50 |
# File 'lib/mxx_ru/makestyle_generator.rb', line 48 def dependencies @dependencies end |
#target_files ⇒ Object (readonly)
File names list, which should be built by given generator.
45 46 47 |
# File 'lib/mxx_ru/makestyle_generator.rb', line 45 def target_files @target_files end |
Instance Method Details
#build(target) ⇒ Object
Perform the build of result files.
NOTE: target argument is ignored.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# 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) ⇒ Object
Perform the cleanup of result files.
NOTE: target argument is ignored.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# 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 |