Mxx_ru 1.6.10.1 → 1.6.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS +17 -0
- data/lib/mxx_ru/cpp.rb +3 -1
- data/lib/mxx_ru/cpp/ext_cmake_project.rb +473 -0
- data/lib/mxx_ru/cpp/obj_placement.rb +69 -1
- data/lib/mxx_ru/cpp/target.rb +8 -4
- data/lib/mxx_ru/cpp/toolset.rb +25 -1
- data/lib/mxx_ru/cpp/toolsets/clang_family.rb +17 -0
- data/lib/mxx_ru/cpp/toolsets/gcc_family.rb +17 -0
- data/lib/mxx_ru/cpp/toolsets/vc_family.rb +24 -0
- data/lib/mxx_ru/externals.rb +31 -17
- data/lib/mxx_ru/generators/ext-cmake-prj/g.rb +181 -0
- data/lib/mxx_ru/generators/ext-cmake-prj/template.erb +24 -0
- data/lib/mxx_ru/generators/externals/g.rb +172 -0
- data/lib/mxx_ru/generators/externals/template.erb +60 -0
- data/lib/mxx_ru/helpers.rb +46 -0
- data/lib/mxx_ru/version.rb +2 -2
- data/tests/cmake/build.rb +16 -0
- data/tests/cmake/hello_shared/CMakeLists.txt +18 -0
- data/tests/cmake/hello_shared/include/hello_shared.hpp +20 -0
- data/tests/cmake/hello_shared/src/hello_shared.cpp +10 -0
- data/tests/cmake/hello_shared_cmake_wrapper.rb +8 -0
- data/tests/cmake/hello_static/CMakeLists.txt +16 -0
- data/tests/cmake/hello_static/include/hello_static.hpp +9 -0
- data/tests/cmake/hello_static/src/hello_static.cpp +9 -0
- data/tests/cmake/hello_static_cmake_wrapper.rb +7 -0
- data/tests/cmake/main_app.cpp +9 -0
- data/tests/cmake/main_app.rb +15 -0
- data/tests/cmake/tc_cmake_build.rb +29 -0
- data/tests/mxx_ru/vc8/tc_default_manifest.rb +1 -1
- data/tests/mxx_ru/vc8/ts_vc8.rb +1 -1
- metadata +20 -2
@@ -1,7 +1,7 @@
|
|
1
1
|
#--
|
2
2
|
# Copyright (c) 1996-2004, Yauheni Akhotnikau
|
3
3
|
# Copyright (c) 2004-2006, JSC Intervale
|
4
|
-
# Copyright (c) 2006-
|
4
|
+
# Copyright (c) 2006-2016, The Mxx_ru Project
|
5
5
|
# All rights reserved.
|
6
6
|
#
|
7
7
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -319,6 +319,74 @@ module MxxRu
|
|
319
319
|
# For compatibility with older versions.
|
320
320
|
Runtime_subdir_obj_placement = RuntimeSubdirObjPlacement
|
321
321
|
|
322
|
+
# The generator of folder name for compilation results,
|
323
|
+
# building a hierarchy of subfolders in a special folder,
|
324
|
+
# which name is choosen based on toolset and runtime mode.
|
325
|
+
#
|
326
|
+
# For example, let src/lib/l.cpp and src/main/m.cpp files would be
|
327
|
+
# the sources of lib/l.lib library and m.exe application.
|
328
|
+
# If project is compiled in RELEASE mode, then following files
|
329
|
+
# would be created: toolset-id/release/src/lib/l.obj,
|
330
|
+
# toolset-id/release/src/main/m.obj,
|
331
|
+
# toolset-id/release/lib/l.lib and toolset-id/release/m.exe.
|
332
|
+
# Thus the presence of subfolders required will be supervised
|
333
|
+
# (for example, toolset-id/release/src/lib,
|
334
|
+
# toolset-id/release/src/main,...).
|
335
|
+
# If some subfolder doesn't exist, it will be created.
|
336
|
+
#
|
337
|
+
# An example of usage:
|
338
|
+
#
|
339
|
+
# MxxRu::Cpp::composite_target( MxxRu::BUILD_ROOT )
|
340
|
+
# global_obj_placement(
|
341
|
+
# MxxRu::Cpp::ToolsetRuntimeSubdirObjPlacement.new(
|
342
|
+
# "output" ) )
|
343
|
+
#
|
344
|
+
# required_prj( "src/lib/prj.rb" )
|
345
|
+
# required_prj( "src/main/prj.rb" )
|
346
|
+
# end
|
347
|
+
# end
|
348
|
+
#
|
349
|
+
class ToolsetRuntimeSubdirObjPlacement < RuntimeSubdirObjPlacement
|
350
|
+
# a_root_dir A folder, where subfolders for exact toolset and
|
351
|
+
# runtime-modes will be created. If contains nil, subfolders are created
|
352
|
+
# in current folder.
|
353
|
+
#
|
354
|
+
# [_a_debug_subdir_] Subfolder name for MxxRu::Cpp::RUNTIME_DEBUG mode.
|
355
|
+
# [_a_default_subdir_] Subfolder name for MxxRu::Cpp::RUNTIME_DEFAULT mode.
|
356
|
+
# [_a_release_subdir_] Subfolder name for MxxRu::Cpp::RUNTIME_RELEASE mode.
|
357
|
+
def initialize(
|
358
|
+
a_root_dir = nil,
|
359
|
+
a_debug_subdir = "debug",
|
360
|
+
a_default_subdir = "default",
|
361
|
+
a_release_subdir = "release" )
|
362
|
+
|
363
|
+
super( a_root_dir, a_debug_subdir, a_debug_subdir, a_release_subdir )
|
364
|
+
end
|
365
|
+
|
366
|
+
def get_obj(
|
367
|
+
source_path_name,
|
368
|
+
toolset,
|
369
|
+
target )
|
370
|
+
|
371
|
+
if source_path_name &&
|
372
|
+
"" != source_path_name &&
|
373
|
+
"." != source_path_name
|
374
|
+
result = File.join( @root_dir,
|
375
|
+
toolset.make_identification_string,
|
376
|
+
runtime_mode_path( target ),
|
377
|
+
source_path_name )
|
378
|
+
else
|
379
|
+
result = File.join( @root_dir,
|
380
|
+
toolset.make_identification_string,
|
381
|
+
runtime_mode_path( target ) )
|
382
|
+
end
|
383
|
+
|
384
|
+
MxxRu::Util.ensure_path_exists( result )
|
385
|
+
|
386
|
+
return result
|
387
|
+
end
|
388
|
+
end # class ToolsetRuntimeSubdirObjPlacement
|
389
|
+
|
322
390
|
# Creation of obj_placement object, which should be used by default.
|
323
391
|
def Cpp.default_obj_placement
|
324
392
|
return SourceSubdirObjPlacement.new
|
data/lib/mxx_ru/cpp/target.rb
CHANGED
@@ -906,8 +906,6 @@ module MxxRu
|
|
906
906
|
def build
|
907
907
|
if nil == @mxx_last_build_result
|
908
908
|
|
909
|
-
check_all_options_definition
|
910
|
-
|
911
909
|
builder = self.method( :normal_mode_builder )
|
912
910
|
builder = self.method( :option_extraction_mode_builder ) \
|
913
911
|
if MxxRu::Cpp::Mode.instance.is_option_extraction
|
@@ -922,8 +920,6 @@ module MxxRu
|
|
922
920
|
def clean
|
923
921
|
if nil == @mxx_last_build_result
|
924
922
|
|
925
|
-
check_all_options_definition
|
926
|
-
|
927
923
|
cleaner = self.method( :normal_mode_cleaner )
|
928
924
|
cleaner = self.method( :option_extraction_mode_cleaner ) \
|
929
925
|
if MxxRu::Cpp::Mode.instance.is_option_extraction
|
@@ -1009,6 +1005,10 @@ module MxxRu
|
|
1009
1005
|
required_prjs_state = build_required_projects
|
1010
1006
|
MxxRu::Cpp::Mode.instance.after_subprj_processing
|
1011
1007
|
|
1008
|
+
# Since v.1.6.11 options are set only after building
|
1009
|
+
# of required projects.
|
1010
|
+
check_all_options_definition
|
1011
|
+
|
1012
1012
|
run_generators
|
1013
1013
|
if !MxxRu::Cpp::Mode.instance.is_no_depends_analyzer
|
1014
1014
|
run_depends_analyzer
|
@@ -1033,6 +1033,10 @@ module MxxRu
|
|
1033
1033
|
clean_required_prjs
|
1034
1034
|
MxxRu::Cpp::Mode.instance.after_subprj_processing
|
1035
1035
|
|
1036
|
+
# Since v.1.6.11 options are set only after processing
|
1037
|
+
# of required projects.
|
1038
|
+
check_all_options_definition
|
1039
|
+
|
1036
1040
|
clean_generators
|
1037
1041
|
clean_objs
|
1038
1042
|
clean_resources
|
data/lib/mxx_ru/cpp/toolset.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#--
|
2
2
|
# Copyright (c) 1996-2004, Yauheni Akhotnikau
|
3
3
|
# Copyright (c) 2004-2006, JSC Intervale
|
4
|
-
# Copyright (c) 2006-
|
4
|
+
# Copyright (c) 2006-2016, The Mxx_ru Project
|
5
5
|
# All rights reserved.
|
6
6
|
#
|
7
7
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -1034,6 +1034,22 @@ module MxxRu
|
|
1034
1034
|
# Get the C++ standard version
|
1035
1035
|
attr_reader :cpp_std
|
1036
1036
|
|
1037
|
+
# Make toolset identification string.
|
1038
|
+
#
|
1039
|
+
# This string can be used for creation of toolset-specific
|
1040
|
+
# file or directory names and so on.
|
1041
|
+
#
|
1042
|
+
# Since v.1.6.11
|
1043
|
+
def make_identification_string
|
1044
|
+
if @id_string.nil?
|
1045
|
+
raw_id = make_toolset_id_string
|
1046
|
+
# Normalize ID alphabet.
|
1047
|
+
@id_string = raw_id.gsub( /[^A-Za-z0-9_]/, '_' )
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
@id_string
|
1051
|
+
end
|
1052
|
+
|
1037
1053
|
protected
|
1038
1054
|
# Creating object file names.
|
1039
1055
|
# Returns array of ObjInfo objects.
|
@@ -1282,6 +1298,14 @@ module MxxRu
|
|
1282
1298
|
@cpp_std = version if @cpp_std < version
|
1283
1299
|
end
|
1284
1300
|
|
1301
|
+
# Real implementation of make_identification_string.
|
1302
|
+
#
|
1303
|
+
# Must be reimplemented the proper way in derived classes.
|
1304
|
+
#
|
1305
|
+
# Since v.1.6.11
|
1306
|
+
def make_toolset_id_string
|
1307
|
+
"#{name}_generic"
|
1308
|
+
end
|
1285
1309
|
end # class Toolset
|
1286
1310
|
|
1287
1311
|
# Current toolset.
|
@@ -156,6 +156,23 @@ module MxxRu
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
+
private
|
160
|
+
# Create toolset identification string.
|
161
|
+
def make_toolset_id_string
|
162
|
+
result = IO.popen( "clang -v 2>&1", :err => [:child, :out] ) do |io|
|
163
|
+
target = 'generic'
|
164
|
+
version = 'unknown'
|
165
|
+
io.each_line do |line|
|
166
|
+
if /^Target:\s*(?<trgt>\S+)/ =~ line
|
167
|
+
target = trgt
|
168
|
+
elsif /clang version (?<v>\S+)/ =~ line
|
169
|
+
version = v
|
170
|
+
end
|
171
|
+
end
|
172
|
+
version + '--' + target
|
173
|
+
end
|
174
|
+
"clang_#{result}"
|
175
|
+
end
|
159
176
|
end # class ClangFamily
|
160
177
|
|
161
178
|
end # module Toolsets
|
@@ -316,6 +316,23 @@ module MxxRu
|
|
316
316
|
def port_specific_lib_name_checker(library_name)
|
317
317
|
library_name
|
318
318
|
end
|
319
|
+
|
320
|
+
# Create toolset identification string.
|
321
|
+
def make_toolset_id_string
|
322
|
+
result = IO.popen( "gcc -v 2>&1", :err => [:child, :out] ) do |io|
|
323
|
+
target = 'generic'
|
324
|
+
version = 'unknown'
|
325
|
+
io.each_line do |line|
|
326
|
+
if /^Target:\s*(?<trgt>\S+)/ =~ line
|
327
|
+
target = trgt
|
328
|
+
elsif /^gcc version (?<v>\S+)/ =~ line
|
329
|
+
version = v
|
330
|
+
end
|
331
|
+
end
|
332
|
+
version + '--' + target
|
333
|
+
end
|
334
|
+
"gcc_#{result}"
|
335
|
+
end
|
319
336
|
end # class GccFamily
|
320
337
|
|
321
338
|
# For compatibility with previous versions.
|
@@ -62,6 +62,14 @@ module MxxRu
|
|
62
62
|
return tag( RC_NAME_TAG, "rc" )
|
63
63
|
end
|
64
64
|
|
65
|
+
# Returns C compiler name.
|
66
|
+
# For Visual C++ the only one compiler is used.
|
67
|
+
def c_compiler_name; compiler_name end
|
68
|
+
|
69
|
+
# Returns C++ compiler name.
|
70
|
+
# For Visual C++ the only one compiler is used.
|
71
|
+
def cpp_compiler_name; compiler_name; end
|
72
|
+
|
65
73
|
# See description at MxxRu::Cpp::Toolset#setup_mandatory_options.
|
66
74
|
def setup_mandatory_options( target )
|
67
75
|
|
@@ -436,6 +444,22 @@ module MxxRu
|
|
436
444
|
}
|
437
445
|
end
|
438
446
|
|
447
|
+
# Create toolset identification string.
|
448
|
+
def make_toolset_id_string
|
449
|
+
result = IO.popen( 'cl /?', :err => [:child, :out] ) do |io|
|
450
|
+
target = 'generic'
|
451
|
+
version = 'unknown'
|
452
|
+
io.each_line do |line|
|
453
|
+
if /Optimizing Compiler Version (?<v>\S+) for (?<trgt>\S+)/ =~ line
|
454
|
+
target = trgt
|
455
|
+
version = v
|
456
|
+
break
|
457
|
+
end
|
458
|
+
end
|
459
|
+
version + '_' + target
|
460
|
+
end
|
461
|
+
"vc#{tag('ver_hi','x')}_#{tag('ver_lo','x')}_#{result}"
|
462
|
+
end
|
439
463
|
end # class VcFamily
|
440
464
|
|
441
465
|
# For compatibility with previous versions.
|
data/lib/mxx_ru/externals.rb
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2006-2016, The Mxx_ru Project
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
# are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
# 3. The name of the author may not be used to endorse or promote products derived
|
14
|
+
# from this software without specific prior written permission.
|
15
|
+
#
|
16
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
17
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
18
|
+
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
19
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
22
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
23
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
24
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
#++
|
26
|
+
|
1
27
|
require 'rake'
|
2
28
|
require 'rake/tasklib'
|
3
29
|
|
@@ -8,6 +34,8 @@ require 'digest'
|
|
8
34
|
|
9
35
|
require 'json'
|
10
36
|
|
37
|
+
require 'mxx_ru/helpers'
|
38
|
+
|
11
39
|
module MxxRu
|
12
40
|
|
13
41
|
module Externals
|
@@ -54,7 +82,7 @@ class Registry
|
|
54
82
|
if old_hash == fresh_version
|
55
83
|
puts "[Note] #{name} previous rules the same with current"
|
56
84
|
else
|
57
|
-
puts "[Note] #{name} previous rules
|
85
|
+
puts "[Note] #{name} previous rules differ with current"
|
58
86
|
puts "[Note] #{name} WILL BE REGET"
|
59
87
|
obj.define_rules :old_rules
|
60
88
|
end
|
@@ -69,20 +97,6 @@ end
|
|
69
97
|
|
70
98
|
module Impl
|
71
99
|
|
72
|
-
module Utils
|
73
|
-
# Return nil if tool not found.
|
74
|
-
# Return version if tool is found.
|
75
|
-
def Utils.external_tool_version_probe(cmd_line, version_re)
|
76
|
-
ver = nil
|
77
|
-
IO.popen(cmd_line, :err => [:child, :out]).grep(version_re) do |s|
|
78
|
-
ver = version_re.match(s)[1]
|
79
|
-
end
|
80
|
-
ver
|
81
|
-
rescue
|
82
|
-
nil
|
83
|
-
end
|
84
|
-
end # module Utils
|
85
|
-
|
86
100
|
module OptionsHolder
|
87
101
|
def option(*values)
|
88
102
|
make_options.push(*values)
|
@@ -110,7 +124,7 @@ class CurlDownloder
|
|
110
124
|
include OptionsHolder
|
111
125
|
|
112
126
|
def CurlDownloder.check_presence
|
113
|
-
|
127
|
+
MxxRu::Helpers.external_tool_version_probe('curl --version', /^curl\s(\S+)\s/)
|
114
128
|
end
|
115
129
|
|
116
130
|
def CurlDownloder.downloader_id
|
@@ -130,7 +144,7 @@ class WgetDownloder
|
|
130
144
|
include OptionsHolder
|
131
145
|
|
132
146
|
def WgetDownloder.check_presence
|
133
|
-
|
147
|
+
MxxRu::Helpers.external_tool_version_probe('wget --version', /^GNU Wget\s(\S+)\s/)
|
134
148
|
end
|
135
149
|
|
136
150
|
def WgetDownloder.downloader_id
|
@@ -0,0 +1,181 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 1996-2004, Yauheni Akhotnikau
|
3
|
+
# Copyright (c) 2004-2006, JSC Intervale
|
4
|
+
# Copyright (c) 2006-2016, The Mxx_ru Project
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
# are permitted provided that the following conditions are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer.
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
# this list of conditions and the following disclaimer in the documentation
|
14
|
+
# and/or other materials provided with the distribution.
|
15
|
+
# 3. The name of the author may not be used to endorse or promote products derived
|
16
|
+
# from this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
19
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
+
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
21
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
26
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#++
|
28
|
+
|
29
|
+
# Since v.1.6.11
|
30
|
+
#
|
31
|
+
# Implementation of project's stabs generation for external cmake projects.
|
32
|
+
|
33
|
+
require 'erb'
|
34
|
+
require 'optparse'
|
35
|
+
|
36
|
+
require 'mxx_ru/generators/impl/std_receiver'
|
37
|
+
|
38
|
+
module MxxRu
|
39
|
+
|
40
|
+
module Generators
|
41
|
+
|
42
|
+
module ExtCMakeProject
|
43
|
+
|
44
|
+
# Class for storing command-line arguments as options.
|
45
|
+
#
|
46
|
+
# Usage:
|
47
|
+
# options = Options.parse( args, banner )
|
48
|
+
#
|
49
|
+
class Options
|
50
|
+
# Name of subfolder with CMakeLists.txt file
|
51
|
+
attr_accessor :where
|
52
|
+
# Name of output file (-o, --output-file). nil if missing.
|
53
|
+
attr_accessor :output_file
|
54
|
+
|
55
|
+
# Parsing command-line arguments and returning Options instance.
|
56
|
+
#
|
57
|
+
# Calls exit(1) if --help present in _args_.
|
58
|
+
#
|
59
|
+
def Options.parse( args, banner )
|
60
|
+
parser = OptionParser.new
|
61
|
+
|
62
|
+
result = Options.new
|
63
|
+
|
64
|
+
parser.banner = banner
|
65
|
+
|
66
|
+
parser.on( '-w', '--where SUBFOLDER', 'Name of subfolder with CMakeLists.txt' ) do |p|
|
67
|
+
result.where = p
|
68
|
+
end
|
69
|
+
parser.on( '-o', '--output-file FILE', 'Output file name' ) do |p|
|
70
|
+
result.output_file = p
|
71
|
+
end
|
72
|
+
|
73
|
+
parser.on_tail( '-h', '--help', 'Show this message' ) do
|
74
|
+
puts parser
|
75
|
+
exit(1)
|
76
|
+
end
|
77
|
+
|
78
|
+
parser.parse!(args)
|
79
|
+
|
80
|
+
result
|
81
|
+
end
|
82
|
+
end # class Options
|
83
|
+
|
84
|
+
# Class to be used in ERb template generation.
|
85
|
+
#
|
86
|
+
# Usage:
|
87
|
+
# template_params = TemplateParams.new( target_type, options )
|
88
|
+
# template = ERb.new( IO.read( some_template_file ) )
|
89
|
+
# result = template.generate( template.get_binding )
|
90
|
+
#
|
91
|
+
class TemplateParams
|
92
|
+
# For a case when project_path is undetectable.
|
93
|
+
UNKNOWN_CMAKELISTS_LOCATION = 'subfolder with CMakeLists.txt'
|
94
|
+
# For a case when output_file is undetectable.
|
95
|
+
DEFAULT_PROJECT_NAME = 'prj.rb'
|
96
|
+
|
97
|
+
attr_reader :where
|
98
|
+
attr_reader :project
|
99
|
+
|
100
|
+
# Param target_type must be present in @@setup_target_functions.
|
101
|
+
def initialize( options )
|
102
|
+
@where = try_detect_where( options )
|
103
|
+
@project = try_detect_project( options )
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns binding to use in ERb generation.
|
107
|
+
def get_binding
|
108
|
+
binding
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
def try_detect_where( options )
|
113
|
+
options.where ? options.where : UNKNOWN_CMAKELISTS_LOCATION
|
114
|
+
end
|
115
|
+
|
116
|
+
def try_detect_project( options )
|
117
|
+
options.output_file ?
|
118
|
+
File.basename( options.output_file ) :
|
119
|
+
DEFAULT_PROJECT_NAME
|
120
|
+
end
|
121
|
+
|
122
|
+
end # class TemplateParams
|
123
|
+
|
124
|
+
# Main class for code generation of binary unit test projects.
|
125
|
+
#
|
126
|
+
# Usage:
|
127
|
+
# receiver = StdReceiver.new
|
128
|
+
# generator = Generator.new( args, receiver )
|
129
|
+
# generator.run
|
130
|
+
#
|
131
|
+
class Generator
|
132
|
+
def initialize( args, receiver )
|
133
|
+
@args = args
|
134
|
+
@receiver = receiver
|
135
|
+
end
|
136
|
+
|
137
|
+
def run
|
138
|
+
options = Options.parse( @args,
|
139
|
+
"Stubs for externals cmake projects generator\n\n" +
|
140
|
+
"Usage:\n" +
|
141
|
+
"mxxrugen [<mxxrugen-options>] ext-cmake-prj [<options>]\n\n" )
|
142
|
+
result = do_generation( options )
|
143
|
+
@receiver.receive( result, options.output_file )
|
144
|
+
end
|
145
|
+
|
146
|
+
private
|
147
|
+
# Performs main generation actions.
|
148
|
+
#
|
149
|
+
# Returns generation result as String.
|
150
|
+
def do_generation( options )
|
151
|
+
template = IO.read( File.join( File.dirname( __FILE__ ), 'template.erb' ) )
|
152
|
+
generator = ERB.new( template )
|
153
|
+
|
154
|
+
params = TemplateParams.new( options )
|
155
|
+
generator.result( params.get_binding ).gsub( /\n\n\n+/, "\n\n" )
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Helper method for generation.
|
160
|
+
#
|
161
|
+
# Usage:
|
162
|
+
# # For using StdReceiver.
|
163
|
+
# generate_for( ARGV )
|
164
|
+
#
|
165
|
+
# # For using custom Receiver.
|
166
|
+
# generate_for( ARGV, CustomReceiver.new )
|
167
|
+
#
|
168
|
+
def ExtCMakeProject.generate_for( args, receiver = nil )
|
169
|
+
generator = Generator.new( args,
|
170
|
+
receiver ? receiver : MxxRu::Generators::Impl::StdReceiver.new )
|
171
|
+
generator.run
|
172
|
+
end
|
173
|
+
|
174
|
+
end # module ExtCMakeProject
|
175
|
+
|
176
|
+
end # module Generators
|
177
|
+
|
178
|
+
end # module MxxRu
|
179
|
+
|
180
|
+
MxxRu::Generators::ExtCMakeProject::generate_for( ARGV )
|
181
|
+
|