RuCodeGen 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +25 -0
- data/README +34 -0
- data/Rakefile +32 -0
- data/docs/Principle +152 -0
- data/docs/ValueIncapsulator +195 -0
- data/docs/examples/cpp/custom/submit_deliver +909 -0
- data/docs/examples/cpp/value_incapsulator/cfg +127 -0
- data/docs/examples/cpp/value_incapsulator/host_config +51 -0
- data/examples/cpp/custom/submit_deliver/submit_deliver.rb +43 -0
- data/examples/cpp/custom/submit_deliver/submit_deliver_gen.rb +326 -0
- data/examples/cpp/value_incapsulator/cfg.decl.hpp +51 -0
- data/examples/cpp/value_incapsulator/cfg.impl.cpp +63 -0
- data/examples/cpp/value_incapsulator/cg-cfg.rb +19 -0
- data/examples/cpp/value_incapsulator/cg-cfg.test.cpp +15 -0
- data/examples/cpp/value_incapsulator/cg-host_config.rb +12 -0
- data/examples/cpp/value_incapsulator/cout.log +4 -0
- data/examples/cpp/value_incapsulator/host_config.impl.cpp +21 -0
- data/examples/cpp/value_incapsulator/host_config.impl.hpp +21 -0
- data/lib/rucodegen/begin_end.rb +26 -0
- data/lib/rucodegen/codegen.rb +4 -0
- data/lib/rucodegen/filename_producer.rb +57 -0
- data/lib/rucodegen/generation_initiator.rb +92 -0
- data/lib/rucodegen/generators.rb +36 -0
- data/lib/rucodegen/run_mode.rb +89 -0
- data/lib/rucodegen/value_incapsulator.rb +331 -0
- data/lib/rucodegen.rb +4 -0
- data/tests/generators_test_extension.rb +23 -0
- data/tests/tc_class_attribute.rb +87 -0
- data/tests/tc_codegen_initiator.rb +164 -0
- data/tests/tc_filename_producer.rb +54 -0
- data/tests/tc_generators.rb +55 -0
- data/tests/tc_run_mode.rb +72 -0
- data/tests/tc_value_incapsulator.rb +193 -0
- data/tests/tc_value_incapsulator_gen.rb +479 -0
- data/tests/ts_rucodegen.rb +11 -0
- metadata +98 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require_gem 'RuCodeGen'
|
3
|
+
|
4
|
+
cpp_value_incapsulator :host_config_t do |c|
|
5
|
+
c.decl_file :script_relative => "host_config.impl.hpp"
|
6
|
+
c.impl_file :script_relative => "host_config.impl.cpp"
|
7
|
+
|
8
|
+
c.attr_prefix "m_"
|
9
|
+
|
10
|
+
c.attr :host, "std::string", :default => "localhost"
|
11
|
+
c.attr :post, "short", :default => 8080
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
host_config_t::host_config_t()
|
3
|
+
: m_host("localhost")
|
4
|
+
, m_post(8080)
|
5
|
+
|
6
|
+
{}
|
7
|
+
|
8
|
+
const std::string &
|
9
|
+
host_config_t::host() const
|
10
|
+
{ return m_host; }
|
11
|
+
void
|
12
|
+
host_config_t::host( const std::string & v__ )
|
13
|
+
{ m_host = v__; }
|
14
|
+
short
|
15
|
+
host_config_t::post() const
|
16
|
+
{ return m_post; }
|
17
|
+
void
|
18
|
+
host_config_t::post( short v__ )
|
19
|
+
{ m_post = v__; }
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
class host_config_t
|
3
|
+
{
|
4
|
+
private :
|
5
|
+
std::string m_host;
|
6
|
+
short m_post;
|
7
|
+
|
8
|
+
public :
|
9
|
+
host_config_t();
|
10
|
+
|
11
|
+
const std::string &
|
12
|
+
host() const;
|
13
|
+
void
|
14
|
+
host( const std::string & v__ );
|
15
|
+
short
|
16
|
+
post() const;
|
17
|
+
void
|
18
|
+
post( short v__ );
|
19
|
+
|
20
|
+
};
|
21
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
�������� ��������, ������� ������ ����������� �� ���������� ������� �
|
4
|
+
��������� ���������� �������������.
|
5
|
+
|
6
|
+
=end
|
7
|
+
|
8
|
+
require 'rucodegen/run_mode'
|
9
|
+
require 'rucodegen/generation_initiator'
|
10
|
+
|
11
|
+
END {
|
12
|
+
|
13
|
+
RUNMODE = RuCodeGen::RunMode
|
14
|
+
|
15
|
+
RUNMODE.detect
|
16
|
+
#FIXME: ���������� ��������� �������� run_mode.
|
17
|
+
if RUNMODE::BUILD == RUNMODE::mode ||
|
18
|
+
RUNMODE::REBUILD == RUNMODE::mode
|
19
|
+
RuCodeGen::CodegenInitiator.new( $0 ).initiate(
|
20
|
+
RUNMODE::REBUILD == RUNMODE::mode )
|
21
|
+
elsif RUNMODE::CLEAN == RUNMODE::mode
|
22
|
+
RuCodeGen::CodegenInitiator.new( $0 ).clean
|
23
|
+
end
|
24
|
+
# ��������� ������ (DRY_RUN, HELP) ������������.
|
25
|
+
}
|
26
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module RuCodeGen
|
2
|
+
|
3
|
+
# ������ ��� ������������ ����� ��������������� �����.
|
4
|
+
module FilenameProducer
|
5
|
+
# ����, ������� �������, ��� ������ ���������� ���.
|
6
|
+
ABSOLUTE = :absolute
|
7
|
+
# ����, ������� �������, ��� ��� ������ ������������ �������.
|
8
|
+
SCRIPT_RELATIVE = :script_relative
|
9
|
+
# ����, ������� �������, ��� ��� ������ ������������ �������� ��������.
|
10
|
+
CWD_RELATIVE = :cwd_relative
|
11
|
+
|
12
|
+
# ���������� ��� �����.
|
13
|
+
# ��� ����� ���� ������ ����� �� ��������� ��������:
|
14
|
+
#
|
15
|
+
# :absolute => "/usr/lib/mystab.c" # ���������� ���, �� ���������
|
16
|
+
# # � ���������� ���������������.
|
17
|
+
# :script_relative => "h/cfg.hpp" # ��� h/cfg.hpp ������ ������������
|
18
|
+
# # ����, � ������� ���������
|
19
|
+
# # ������������ ������.
|
20
|
+
# :cwd_relative => "h/cfg.hpp" # ��� h/cfg.hpp ������ ������������
|
21
|
+
# # �������� ��������.
|
22
|
+
# ��������, ���� �������:
|
23
|
+
# :absolute => "/usr/local/include/cfg.h"
|
24
|
+
# :script_relative => "h/cfg.hpp"
|
25
|
+
# :cwd_relative => "h/cfg.hpp"
|
26
|
+
# �:
|
27
|
+
# * ������� ��������� �������� /home/eao197/prj,
|
28
|
+
# * ������������ ������ ��������� � �������� /home/eao197/prj/cg
|
29
|
+
# �� ����� �������������� ��������� �����:
|
30
|
+
# /usr/local/include/cfg.h
|
31
|
+
# /home/eao197/prj/cg/h/cfg.hpp
|
32
|
+
# /home/eao197/prj/h/cfg.hpp
|
33
|
+
#
|
34
|
+
# ���������:
|
35
|
+
# [_script_name_] ��� �������, � ������� ����������� ��� �����.
|
36
|
+
# ���������� ��� ��������� ������ :script_relative.
|
37
|
+
# [_file_name_] ���, ��������� ������������� (��� ������ ���� Hash).
|
38
|
+
def FilenameProducer.produce( script_name, file_name )
|
39
|
+
# � file_name ������ ���� ����� ���� �������.
|
40
|
+
fail "1 element expected in file_name" if 1 != file_name.size
|
41
|
+
|
42
|
+
if file_name.has_key?( ABSOLUTE )
|
43
|
+
return file_name[ ABSOLUTE ]
|
44
|
+
elsif file_name.has_key?( SCRIPT_RELATIVE )
|
45
|
+
return File.join( File.dirname( script_name ),
|
46
|
+
file_name[ SCRIPT_RELATIVE ] )
|
47
|
+
elsif file_name.has_key?( CWD_RELATIVE )
|
48
|
+
return File.join( Dir.pwd, file_name[ CWD_RELATIVE ] )
|
49
|
+
else
|
50
|
+
fail "unsupported key: #{file_name.keys[0]}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end # RuCodeGen
|
57
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
require 'rucodegen/generators'
|
4
|
+
|
5
|
+
module RuCodeGen
|
6
|
+
|
7
|
+
# �����, ������� �������� �� ������������� ��������� ����.
|
8
|
+
class CodegenInitiator
|
9
|
+
|
10
|
+
# �����������.
|
11
|
+
#
|
12
|
+
# _file_ ��� ����� � ��������� ��������������.
|
13
|
+
def initialize( file )
|
14
|
+
@file = file
|
15
|
+
@hash_file_name = File.join(
|
16
|
+
File.dirname( file ),
|
17
|
+
"." + File.basename( file ) + ".md5" )
|
18
|
+
|
19
|
+
@original_hash = Digest::MD5.new( File.read( @file ) )
|
20
|
+
end
|
21
|
+
|
22
|
+
# ������������ �������������, ���� ��� ����������.
|
23
|
+
#
|
24
|
+
# ���������
|
25
|
+
# [_force_rebuild_] ���� true, �� ������������ ������ �������������.
|
26
|
+
def initiate( force_rebuild = false )
|
27
|
+
all_files = Generators.all_files
|
28
|
+
if !all_files.empty?
|
29
|
+
if force_rebuild || is_hash_changed
|
30
|
+
# ��������� ������������� ���� ������.
|
31
|
+
all_files.each do |file|
|
32
|
+
regenerate_file( file, Generators.for_file( file ) )
|
33
|
+
end
|
34
|
+
|
35
|
+
update_hash_file
|
36
|
+
else
|
37
|
+
# �������� �� ����������, ������� ���������������� ����� ������
|
38
|
+
# �� �����, ������� �����������.
|
39
|
+
all_files.each do |file|
|
40
|
+
regenerate_file( file, Generators.for_file( file ) ) \
|
41
|
+
unless FileTest.exists?( file )
|
42
|
+
end
|
43
|
+
end
|
44
|
+
else
|
45
|
+
# ��� ������ �� �����.
|
46
|
+
File.delete @hash_file_name if FileTest.exists?( @hash_file_name )
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# �������� ���������� �������������.
|
51
|
+
def clean
|
52
|
+
all_files = Generators.all_files.clone
|
53
|
+
all_files << @hash_file_name
|
54
|
+
|
55
|
+
all_files.each do |f|
|
56
|
+
File.delete f if FileTest.exists?( f )
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# �������� ����, ��� ��������� ���-����.
|
63
|
+
# ��� ��� ��������� ������������, ���� ��� ��� ����� ��� ����
|
64
|
+
# md5 ��������� ����� ���������.
|
65
|
+
def is_hash_changed
|
66
|
+
return true unless FileTest::exists?( @hash_file_name )
|
67
|
+
|
68
|
+
source_hash = ""
|
69
|
+
File.open( @hash_file_name ) do |f| source_hash = f.gets.chop! end
|
70
|
+
|
71
|
+
return @original_hash != source_hash
|
72
|
+
end
|
73
|
+
|
74
|
+
# ��������� � ���-����� ����� �������� ����.
|
75
|
+
def update_hash_file
|
76
|
+
File.open( @hash_file_name, "w" ) { |f| f.puts @original_hash.to_s }
|
77
|
+
#FIXME: ����� �������� � ���, ����� ������� ���-���� �������.
|
78
|
+
end
|
79
|
+
|
80
|
+
# ���������������� ���� � ��������� ������.
|
81
|
+
def regenerate_file( file_name, generator )
|
82
|
+
opened_file = File.new( file_name, "w" )
|
83
|
+
begin
|
84
|
+
generator.generate opened_file
|
85
|
+
ensure
|
86
|
+
opened_file.close
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end # CodegenInitiator
|
91
|
+
|
92
|
+
end # RuCodeGen
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RuCodeGen
|
2
|
+
|
3
|
+
# �����, ����������� ������ �������� ������������� ���
|
4
|
+
# ���������� ������ ���������� ���������������.
|
5
|
+
class Generators
|
6
|
+
|
7
|
+
# Hash ���� ������������ �����������.
|
8
|
+
@@generators = {}
|
9
|
+
|
10
|
+
# �������� ��������� ���������.
|
11
|
+
# ��������� ����������, ���� ��������� ��� ���������� ����� �����
|
12
|
+
# ��� ���������������.
|
13
|
+
def Generators.add( file_name, generator )
|
14
|
+
fail "not unique file name: #{file_name}" \
|
15
|
+
if nil != @@generators[ file_name ]
|
16
|
+
@@generators[ file_name ] = generator
|
17
|
+
end
|
18
|
+
|
19
|
+
# �������� ����� ���� ������, ��� ������� ���������������� ����������.
|
20
|
+
def Generators.all_files
|
21
|
+
return @@generators.keys
|
22
|
+
end
|
23
|
+
|
24
|
+
# �������� ��������� ��� ���������� ����� �����.
|
25
|
+
# ��������� ����������, ���� ��������� �� �����.
|
26
|
+
def Generators.for_file( file_name )
|
27
|
+
fail "unknown file name: #{file_name}" \
|
28
|
+
if nil == @@generators[ file_name ]
|
29
|
+
|
30
|
+
@@generators[ file_name ]
|
31
|
+
end
|
32
|
+
|
33
|
+
end # class Generators
|
34
|
+
|
35
|
+
end # module RuCodeGen
|
36
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#
|
2
|
+
# ����������� ������ ������ ������� RuCodeGen
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
module RuCodeGen
|
8
|
+
|
9
|
+
# �����, �������� ������� �������� �������� ����������� ������ ������
|
10
|
+
# ������� RuCodeGen.
|
11
|
+
#
|
12
|
+
# � ������ ������ ������� ����� ���������� � ������ RunMode#detect.
|
13
|
+
# ��� ��������� ������ � ���������� ����� ���������� � ������
|
14
|
+
# RunMode#mode.
|
15
|
+
#
|
16
|
+
# �������������� ��������� ������:
|
17
|
+
# [_BUILD_] �������������� ������ � ������, ���� �������� ���������� ���
|
18
|
+
# ����������� ���� �� ��������������� ����� ������;
|
19
|
+
# [_REBUILD_] �������������� �������������;
|
20
|
+
# [_CLEAN_] �������� ���� ��������������� ������;
|
21
|
+
# [_DRY_RUN_] �������� ���������, ������� ���������, ����� �������� ��������
|
22
|
+
# �� ���������������.
|
23
|
+
class RunMode
|
24
|
+
|
25
|
+
# ���������� ����� �������������.
|
26
|
+
BUILD = 1
|
27
|
+
# ����� �������������� �������������.
|
28
|
+
REBUILD = 2
|
29
|
+
# ����� ������� ����������� �������������.
|
30
|
+
CLEAN = 3
|
31
|
+
# ����� �������� �������������.
|
32
|
+
DRY_RUN = 4
|
33
|
+
|
34
|
+
# ������� ����, ��� ������� ����� ��� �� ���������.
|
35
|
+
UNKNOWN = 0
|
36
|
+
# ������� ����, ��� ������ ������� � ������ help.
|
37
|
+
HELP = 5
|
38
|
+
|
39
|
+
# ������� ����� ������.
|
40
|
+
@@mode = UNKNOWN
|
41
|
+
|
42
|
+
# ����������� ������ ������ ����������� �������� ����������
|
43
|
+
# ��������� ������.
|
44
|
+
def RunMode.detect
|
45
|
+
mode = UNKNOWN
|
46
|
+
|
47
|
+
options = OptionParser.new do |opts|
|
48
|
+
all_modes = %w[ build rebuild clean dry-run ]
|
49
|
+
all_modes_aliases = {
|
50
|
+
"build" => BUILD,
|
51
|
+
"rebuild" => REBUILD,
|
52
|
+
"clean" => CLEAN,
|
53
|
+
"dry_run" => DRY_RUN
|
54
|
+
}
|
55
|
+
|
56
|
+
opts.on( "-m", "--mode MODE", all_modes, all_modes_aliases,
|
57
|
+
"run mode", "(#{all_modes.join(', ')})" ) do |run_mode|
|
58
|
+
mode = run_mode
|
59
|
+
end
|
60
|
+
|
61
|
+
opts.on( "-h", "--help", "show this screen" ) do
|
62
|
+
puts opts
|
63
|
+
mode = HELP
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
if 0 != ARGV.size
|
68
|
+
options.parse!
|
69
|
+
fail "run mode must be specified" if UNKNOWN == mode
|
70
|
+
else
|
71
|
+
# ������ ��� ���������� �������� ����� ���������� �������������.
|
72
|
+
mode = BUILD
|
73
|
+
end
|
74
|
+
|
75
|
+
@@mode = mode
|
76
|
+
end
|
77
|
+
|
78
|
+
# ��������� �������� ������ ������.
|
79
|
+
# ���� ����� ������ ��� �� ��� ���������, �� ��� ��� �����������
|
80
|
+
# ���������� RunMode#detect.
|
81
|
+
def RunMode.mode
|
82
|
+
RunMode.detect if UNKNOWN == @@mode
|
83
|
+
@@mode
|
84
|
+
end
|
85
|
+
|
86
|
+
end # class RunMode
|
87
|
+
|
88
|
+
end # module RuCodeGen
|
89
|
+
|