bake-toolkit 2.20.4 → 2.21.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.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile.rb +3 -3
  3. data/bin/bake +46 -46
  4. data/bin/bake-doc +11 -11
  5. data/bin/bakery +179 -179
  6. data/bin/createVSProjects +213 -213
  7. data/documentation/_build/html/_sources/changelog.txt +456 -451
  8. data/documentation/_build/html/_sources/commandline/commandline.txt +107 -107
  9. data/documentation/_build/html/_sources/concepts/build_hierarchy.txt +34 -34
  10. data/documentation/_build/html/_sources/concepts/concepts.txt +14 -14
  11. data/documentation/_build/html/_sources/concepts/inject.txt +65 -65
  12. data/documentation/_build/html/_sources/concepts/link_order.txt +91 -91
  13. data/documentation/_build/html/_sources/concepts/prebuild.txt +56 -56
  14. data/documentation/_build/html/_sources/concepts/the_main_project.txt +45 -45
  15. data/documentation/_build/html/_sources/concepts/the_project_meta_file.txt +72 -72
  16. data/documentation/_build/html/_sources/ide/eclipse/eclipse.txt +25 -25
  17. data/documentation/_build/html/_sources/ide/eclipse/how_to_convert_existing_cdt_workspace.txt +31 -31
  18. data/documentation/_build/html/_sources/ide/eclipse/how_to_create_a_new_project_in_eclipse.txt +18 -18
  19. data/documentation/_build/html/_sources/ide/eclipse/how_to_create_a_workspace_in_eclipse.txt +27 -27
  20. data/documentation/_build/html/_sources/ide/eclipse/how_to_debug_in_eclipse.txt +38 -38
  21. data/documentation/_build/html/_sources/ide/eclipse/how_to_install_eclipse_plugin.txt +44 -44
  22. data/documentation/_build/html/_sources/ide/eclipse/how_to_use_bake_in_eclipse.txt +86 -86
  23. data/documentation/_build/html/_sources/ide/ide_integrations.txt +8 -8
  24. data/documentation/_build/html/_sources/ide/vs/how_to_create_vs_projects.txt +15 -15
  25. data/documentation/_build/html/_sources/ide/vs/how_to_debug_in_vs.txt +35 -35
  26. data/documentation/_build/html/_sources/ide/vs/how_to_used_bake_in_vs.txt +35 -35
  27. data/documentation/_build/html/_sources/ide/vs/vs.txt +10 -10
  28. data/documentation/_build/html/_sources/ide/vs/vs_install.txt +43 -43
  29. data/documentation/_build/html/_sources/index.txt +33 -33
  30. data/documentation/_build/html/_sources/install/install_bake.txt +112 -112
  31. data/documentation/_build/html/_sources/internal.txt +50 -50
  32. data/documentation/_build/html/_sources/known_issues.txt +9 -9
  33. data/documentation/_build/html/_sources/license.txt +4 -4
  34. data/documentation/_build/html/_sources/performance/performance.txt +104 -104
  35. data/documentation/_build/html/_sources/quickstart/quickstart.txt +70 -70
  36. data/documentation/_build/html/_sources/syntax/adapt_configs.txt +143 -143
  37. data/documentation/_build/html/_sources/syntax/auto_adjustment.txt +43 -43
  38. data/documentation/_build/html/_sources/syntax/derive_configs.txt +93 -94
  39. data/documentation/_build/html/_sources/syntax/project_meta_syntax.txt +19 -19
  40. data/documentation/_build/html/_sources/syntax/syntax.txt +11 -11
  41. data/documentation/_build/html/_sources/syntax/variable_substitutions.txt +147 -147
  42. data/documentation/_build/html/_sources/tips_and_tricks/dot.txt +34 -34
  43. data/documentation/_build/html/_sources/tips_and_tricks/how_to_use_bake_with_cygwin.txt +62 -62
  44. data/documentation/_build/html/_sources/tips_and_tricks/static_code_analysis.txt +122 -122
  45. data/documentation/_build/html/_sources/tips_and_tricks/the_bakery.txt +72 -72
  46. data/documentation/_build/html/_sources/tips_and_tricks/the_clang.txt +43 -43
  47. data/documentation/_build/html/_sources/tips_and_tricks/tips_and_tricks.txt +34 -34
  48. data/documentation/_build/html/_sources/why_bake/why_bake.txt +40 -40
  49. data/documentation/_build/html/changelog.html +7 -0
  50. data/documentation/_build/html/commandline/commandline.html +2 -2
  51. data/documentation/_build/html/concepts/link_order.html +2 -2
  52. data/documentation/_build/html/concepts/prebuild.html +2 -2
  53. data/documentation/_build/html/index.html +4 -4
  54. data/documentation/_build/html/performance/performance.html +2 -2
  55. data/documentation/_build/html/searchindex.js +1 -1
  56. data/documentation/_build/html/syntax/adapt_configs.html +2 -2
  57. data/documentation/_build/html/syntax/syntax.html +2 -2
  58. data/documentation/_build/html/tips_and_tricks/the_clang.html +2 -2
  59. data/documentation/_build/html/why_bake/why_bake.html +2 -2
  60. data/lib/adapt/config/loader.rb +112 -112
  61. data/lib/bake/bundle.rb +158 -158
  62. data/lib/bake/cache.rb +179 -180
  63. data/lib/bake/config/checks.rb +68 -68
  64. data/lib/bake/config/loader.rb +363 -363
  65. data/lib/bake/libElement.rb +176 -176
  66. data/lib/bake/mergeConfig.rb +208 -208
  67. data/lib/bake/model/language.rb +45 -45
  68. data/lib/bake/model/loader.rb +99 -99
  69. data/lib/bake/model/metamodel.rb +307 -307
  70. data/lib/bake/model/metamodel_ext.rb +27 -27
  71. data/lib/bake/options/create.rb +95 -95
  72. data/lib/bake/options/options.rb +315 -310
  73. data/lib/bake/options/showDoc.rb +20 -20
  74. data/lib/bake/options/showLicense.rb +9 -9
  75. data/lib/bake/options/showToolchains.rb +38 -38
  76. data/lib/bake/options/usage.rb +79 -68
  77. data/lib/bake/subst.rb +313 -313
  78. data/lib/bake/toolchain/clang.rb +44 -44
  79. data/lib/bake/toolchain/clang_analyze.rb +31 -31
  80. data/lib/bake/toolchain/colorizing_formatter.rb +125 -125
  81. data/lib/bake/toolchain/diab.rb +53 -53
  82. data/lib/bake/toolchain/errorparser/diab_compiler_error_parser.rb +40 -40
  83. data/lib/bake/toolchain/errorparser/diab_linker_error_parser.rb +41 -41
  84. data/lib/bake/toolchain/errorparser/error_parser.rb +71 -71
  85. data/lib/bake/toolchain/errorparser/gcc_compiler_error_parser.rb +35 -35
  86. data/lib/bake/toolchain/errorparser/gcc_linker_error_parser.rb +35 -35
  87. data/lib/bake/toolchain/errorparser/greenhills_compiler_error_parser.rb +32 -32
  88. data/lib/bake/toolchain/errorparser/greenhills_linker_error_parser.rb +44 -44
  89. data/lib/bake/toolchain/errorparser/keil_compiler_error_parser.rb +40 -40
  90. data/lib/bake/toolchain/errorparser/keil_linker_error_parser.rb +30 -30
  91. data/lib/bake/toolchain/errorparser/lint_error_parser.rb +34 -34
  92. data/lib/bake/toolchain/errorparser/msvc_compiler_error_parser.rb +63 -63
  93. data/lib/bake/toolchain/errorparser/msvc_linker_error_parser.rb +42 -42
  94. data/lib/bake/toolchain/errorparser/process_output.rb +2 -2
  95. data/lib/bake/toolchain/errorparser/ti_compiler_error_parser.rb +30 -30
  96. data/lib/bake/toolchain/errorparser/ti_linker_error_parser.rb +30 -30
  97. data/lib/bake/toolchain/gcc.rb +49 -49
  98. data/lib/bake/toolchain/gcc_env.rb +55 -55
  99. data/lib/bake/toolchain/greenhills.rb +52 -52
  100. data/lib/bake/toolchain/keil.rb +53 -53
  101. data/lib/bake/toolchain/lint.rb +20 -20
  102. data/lib/bake/toolchain/msvc.rb +58 -58
  103. data/lib/bake/toolchain/provider.rb +146 -146
  104. data/lib/bake/toolchain/ti.rb +47 -47
  105. data/lib/bake/util.rb +149 -149
  106. data/lib/bakery/buildPattern.rb +24 -24
  107. data/lib/bakery/model/language.rb +22 -22
  108. data/lib/bakery/model/loader.rb +55 -55
  109. data/lib/bakery/model/metamodel.rb +48 -48
  110. data/lib/bakery/options/options.rb +87 -87
  111. data/lib/bakery/toBake.rb +81 -81
  112. data/lib/blocks/block.rb +324 -324
  113. data/lib/blocks/blockBase.rb +204 -204
  114. data/lib/blocks/commandLine.rb +38 -38
  115. data/lib/blocks/compile.rb +529 -528
  116. data/lib/blocks/convert.rb +41 -41
  117. data/lib/blocks/docu.rb +30 -30
  118. data/lib/blocks/executable.rb +174 -174
  119. data/lib/blocks/has_execute_command.rb +31 -31
  120. data/lib/blocks/library.rb +114 -114
  121. data/lib/blocks/lint.rb +56 -56
  122. data/lib/blocks/makefile.rb +100 -100
  123. data/lib/blocks/showIncludes.rb +140 -125
  124. data/lib/common/abortException.rb +4 -4
  125. data/lib/common/cleanup.rb +10 -10
  126. data/lib/common/exit_helper.rb +38 -38
  127. data/lib/common/ext/file.rb +88 -88
  128. data/lib/common/ext/rtext.rb +11 -11
  129. data/lib/common/ext/stdout.rb +45 -45
  130. data/lib/common/ide_interface.rb +194 -194
  131. data/lib/common/options/parser.rb +95 -85
  132. data/lib/common/process.rb +64 -64
  133. data/lib/common/utils.rb +52 -52
  134. data/lib/common/version.rb +31 -23
  135. data/lib/multithread/job.rb +44 -44
  136. data/lib/tocxx.rb +558 -555
  137. data/lib/vs/options.rb +69 -69
  138. data/license.txt +90 -90
  139. metadata +2 -2
@@ -1,176 +1,176 @@
1
- module Bake
2
-
3
- class LibElement
4
-
5
- LIB = 1
6
- USERLIB = 2
7
- LIB_WITH_PATH = 3
8
- SEARCH_PATH = 4
9
- DEPENDENCY = 5
10
-
11
- attr_reader :type, :value
12
-
13
- def initialize(type, value)
14
- @type = type
15
- @value = value
16
- end
17
- end
18
-
19
- class LibElements
20
-
21
- def self.calc_linker_lib_string(block, tcs)
22
- @@lib_path_set = []
23
- @@dep_set = Set.new
24
- @@linker = tcs[:LINKER]
25
- @@projectDir = block.projectDir
26
- @@source_libraries = []
27
- @@linker_libs_array = []
28
-
29
- collect_recursive(block)
30
-
31
- if Bake.options.oldLinkOrder
32
- if @@linker[:LIST_MODE] and not @@lib_path_set.empty?
33
- @@linker_libs_array << (@@linker[:LIB_PATH_FLAG] + @@lib_path_set.join(","));
34
- end
35
- else
36
- @@source_libraries.reverse!
37
- @@lib_path_set.reverse!
38
- if @@linker[:LIST_MODE] and not @@lib_path_set.empty?
39
- @@linker_libs_array.unshift (@@linker[:LIB_PATH_FLAG] + @@lib_path_set.join(","));
40
- end
41
- @@linker_libs_array.reverse!
42
- end
43
-
44
- return [@@source_libraries, @@linker_libs_array]
45
- end
46
-
47
- def self.adaptPath(path, block, prefix)
48
- adaptedPath = path
49
- if not File.is_absolute?(path)
50
- prefix ||= File.rel_from_to_project(@@projectDir,block.projectDir)
51
- adaptedPath = prefix + path if prefix
52
- end
53
- #adaptedPath = "\"" + adaptedPath + "\"" if adaptedPath.include?(" ")
54
- [adaptedPath, prefix]
55
- end
56
-
57
- def self.addOwnLib(block)
58
- if block.library
59
- adaptedPath, prefix = adaptPath(block.library.archive_name, block, prefix)
60
- if (block.prebuild and File.exist?adaptedPath) or
61
- (not block.library.compileBlock.objects.empty?) or
62
- (not block.library.compileBlock.calcSources(true, true).empty?)
63
- @@linker_libs_array << adaptedPath
64
- @@source_libraries << adaptedPath
65
- end
66
- end
67
- end
68
-
69
- def self.collect_recursive(block)
70
- return if @@dep_set.include?block
71
- @@dep_set << block
72
-
73
- prefix = nil
74
-
75
- if Bake.options.oldLinkOrder
76
- addOwnLib(block)
77
- elems = block.lib_elements
78
- else
79
- elems = block.lib_elements.reverse
80
- end
81
-
82
- elems.each do |elem|
83
- case elem.type
84
- when LibElement::LIB
85
- @@linker_libs_array << "#{@@linker[:LIB_FLAG]}#{elem.value}"
86
- when LibElement::USERLIB
87
- @@linker_libs_array << "#{@@linker[:USER_LIB_FLAG]}#{elem.value}"
88
- when LibElement::LIB_WITH_PATH
89
- adaptedPath, prefix = adaptPath(elem.value, block, prefix)
90
- @@linker_libs_array << adaptedPath
91
- when LibElement::SEARCH_PATH
92
- adaptedPath, prefix = adaptPath(elem.value, block, prefix)
93
- lpf = "#{@@linker[:LIB_PATH_FLAG]}#{adaptedPath}"
94
-
95
- if not Bake.options.oldLinkOrder
96
- if not @@lib_path_set.include?adaptedPath
97
- @@lib_path_set << adaptedPath
98
- @@linker_libs_array << lpf if @@linker[:LIST_MODE] == false
99
- end
100
- end
101
-
102
- if not Bake.options.oldLinkOrder
103
- # must be moved to the end, so delete it...
104
- ind1 = @@lib_path_set.index(adaptedPath)
105
- ind2 = @@linker_libs_array.index(lpf)
106
- @@lib_path_set.delete_at(ind1) if not ind1.nil?
107
- @@linker_libs_array.delete_at(ind2) if not ind2.nil?
108
- end
109
-
110
- if (not Bake.options.oldLinkOrder) or (not @@lib_path_set.include?adaptedPath)
111
- # end place it at the end again
112
- @@lib_path_set << adaptedPath
113
- @@linker_libs_array << lpf if @@linker[:LIST_MODE] == false
114
- end
115
-
116
- when LibElement::DEPENDENCY
117
- if Blocks::ALL_BLOCKS.include?elem.value
118
- bb = Blocks::ALL_BLOCKS[elem.value]
119
- collect_recursive(bb)
120
- else
121
- # TODO: warning or error?
122
- end
123
- end
124
- end
125
-
126
- addOwnLib(block) if not Bake.options.oldLinkOrder
127
-
128
- end
129
-
130
-
131
-
132
-
133
- def self.calcLibElements(block)
134
- lib_elements = [] # value = array pairs [type, name/path string]
135
-
136
- block.config.libStuff.each do |l|
137
-
138
- if (Metamodel::UserLibrary === l)
139
- ln = l.name
140
- ls = nil
141
- if l.name.include?("/")
142
- pos = l.name.rindex("/")
143
- ls = block.convPath(l.name[0..pos-1], l)
144
- ln = l.name[pos+1..-1]
145
- end
146
- lib_elements << LibElement.new(LibElement::SEARCH_PATH, ls) if !ls.nil?
147
- lib_elements << LibElement.new(LibElement::USERLIB, ln)
148
- elsif (Metamodel::ExternalLibrarySearchPath === l)
149
- lib_elements << LibElement.new(LibElement::SEARCH_PATH, block.convPath(l))
150
- elsif (Metamodel::ExternalLibrary === l)
151
- ln = l.name
152
- ls = nil
153
- if l.name.include?("/")
154
- pos = l.name.rindex("/")
155
- ls = block.convPath(l.name[0..pos-1], l)
156
- ln = l.name[pos+1..-1]
157
- end
158
- if l.search
159
- lib_elements << LibElement.new(LibElement::SEARCH_PATH, ls) if !ls.nil?
160
- lib_elements << LibElement.new(LibElement::LIB, ln)
161
- else
162
- ln = ls + "/" + ln unless ls.nil?
163
- lib_elements << LibElement.new(LibElement::LIB_WITH_PATH, ln)
164
- end
165
- elsif (Metamodel::Dependency === l)
166
- lib_elements << LibElement.new(LibElement::DEPENDENCY, l.name+","+l.config)
167
- end
168
-
169
- end
170
-
171
- return lib_elements
172
- end
173
-
174
- end
175
-
176
- end
1
+ module Bake
2
+
3
+ class LibElement
4
+
5
+ LIB = 1
6
+ USERLIB = 2
7
+ LIB_WITH_PATH = 3
8
+ SEARCH_PATH = 4
9
+ DEPENDENCY = 5
10
+
11
+ attr_reader :type, :value
12
+
13
+ def initialize(type, value)
14
+ @type = type
15
+ @value = value
16
+ end
17
+ end
18
+
19
+ class LibElements
20
+
21
+ def self.calc_linker_lib_string(block, tcs)
22
+ @@lib_path_set = []
23
+ @@dep_set = Set.new
24
+ @@linker = tcs[:LINKER]
25
+ @@projectDir = block.projectDir
26
+ @@source_libraries = []
27
+ @@linker_libs_array = []
28
+
29
+ collect_recursive(block)
30
+
31
+ if Bake.options.oldLinkOrder
32
+ if @@linker[:LIST_MODE] and not @@lib_path_set.empty?
33
+ @@linker_libs_array << (@@linker[:LIB_PATH_FLAG] + @@lib_path_set.join(","));
34
+ end
35
+ else
36
+ @@source_libraries.reverse!
37
+ @@lib_path_set.reverse!
38
+ if @@linker[:LIST_MODE] and not @@lib_path_set.empty?
39
+ @@linker_libs_array.unshift (@@linker[:LIB_PATH_FLAG] + @@lib_path_set.join(","));
40
+ end
41
+ @@linker_libs_array.reverse!
42
+ end
43
+
44
+ return [@@source_libraries, @@linker_libs_array]
45
+ end
46
+
47
+ def self.adaptPath(path, block, prefix)
48
+ adaptedPath = path
49
+ if not File.is_absolute?(path)
50
+ prefix ||= File.rel_from_to_project(@@projectDir,block.projectDir)
51
+ adaptedPath = prefix + path if prefix
52
+ end
53
+ #adaptedPath = "\"" + adaptedPath + "\"" if adaptedPath.include?(" ")
54
+ [adaptedPath, prefix]
55
+ end
56
+
57
+ def self.addOwnLib(block)
58
+ if block.library
59
+ adaptedPath, prefix = adaptPath(block.library.archive_name, block, prefix)
60
+ if (block.prebuild and File.exist?adaptedPath) or
61
+ (not block.library.compileBlock.objects.empty?) or
62
+ (not block.library.compileBlock.calcSources(true, true).empty?)
63
+ @@linker_libs_array << adaptedPath
64
+ @@source_libraries << adaptedPath
65
+ end
66
+ end
67
+ end
68
+
69
+ def self.collect_recursive(block)
70
+ return if @@dep_set.include?block
71
+ @@dep_set << block
72
+
73
+ prefix = nil
74
+
75
+ if Bake.options.oldLinkOrder
76
+ addOwnLib(block)
77
+ elems = block.lib_elements
78
+ else
79
+ elems = block.lib_elements.reverse
80
+ end
81
+
82
+ elems.each do |elem|
83
+ case elem.type
84
+ when LibElement::LIB
85
+ @@linker_libs_array << "#{@@linker[:LIB_FLAG]}#{elem.value}"
86
+ when LibElement::USERLIB
87
+ @@linker_libs_array << "#{@@linker[:USER_LIB_FLAG]}#{elem.value}"
88
+ when LibElement::LIB_WITH_PATH
89
+ adaptedPath, prefix = adaptPath(elem.value, block, prefix)
90
+ @@linker_libs_array << adaptedPath
91
+ when LibElement::SEARCH_PATH
92
+ adaptedPath, prefix = adaptPath(elem.value, block, prefix)
93
+ lpf = "#{@@linker[:LIB_PATH_FLAG]}#{adaptedPath}"
94
+
95
+ if not Bake.options.oldLinkOrder
96
+ if not @@lib_path_set.include?adaptedPath
97
+ @@lib_path_set << adaptedPath
98
+ @@linker_libs_array << lpf if @@linker[:LIST_MODE] == false
99
+ end
100
+ end
101
+
102
+ if not Bake.options.oldLinkOrder
103
+ # must be moved to the end, so delete it...
104
+ ind1 = @@lib_path_set.index(adaptedPath)
105
+ ind2 = @@linker_libs_array.index(lpf)
106
+ @@lib_path_set.delete_at(ind1) if not ind1.nil?
107
+ @@linker_libs_array.delete_at(ind2) if not ind2.nil?
108
+ end
109
+
110
+ if (not Bake.options.oldLinkOrder) or (not @@lib_path_set.include?adaptedPath)
111
+ # end place it at the end again
112
+ @@lib_path_set << adaptedPath
113
+ @@linker_libs_array << lpf if @@linker[:LIST_MODE] == false
114
+ end
115
+
116
+ when LibElement::DEPENDENCY
117
+ if Blocks::ALL_BLOCKS.include?elem.value
118
+ bb = Blocks::ALL_BLOCKS[elem.value]
119
+ collect_recursive(bb)
120
+ else
121
+ # TODO: warning or error?
122
+ end
123
+ end
124
+ end
125
+
126
+ addOwnLib(block) if not Bake.options.oldLinkOrder
127
+
128
+ end
129
+
130
+
131
+
132
+
133
+ def self.calcLibElements(block)
134
+ lib_elements = [] # value = array pairs [type, name/path string]
135
+
136
+ block.config.libStuff.each do |l|
137
+
138
+ if (Metamodel::UserLibrary === l)
139
+ ln = l.name
140
+ ls = nil
141
+ if l.name.include?("/")
142
+ pos = l.name.rindex("/")
143
+ ls = block.convPath(l.name[0..pos-1], l)
144
+ ln = l.name[pos+1..-1]
145
+ end
146
+ lib_elements << LibElement.new(LibElement::SEARCH_PATH, ls) if !ls.nil?
147
+ lib_elements << LibElement.new(LibElement::USERLIB, ln)
148
+ elsif (Metamodel::ExternalLibrarySearchPath === l)
149
+ lib_elements << LibElement.new(LibElement::SEARCH_PATH, block.convPath(l))
150
+ elsif (Metamodel::ExternalLibrary === l)
151
+ ln = l.name
152
+ ls = nil
153
+ if l.name.include?("/")
154
+ pos = l.name.rindex("/")
155
+ ls = block.convPath(l.name[0..pos-1], l)
156
+ ln = l.name[pos+1..-1]
157
+ end
158
+ if l.search
159
+ lib_elements << LibElement.new(LibElement::SEARCH_PATH, ls) if !ls.nil?
160
+ lib_elements << LibElement.new(LibElement::LIB, ln)
161
+ else
162
+ ln = ls + "/" + ln unless ls.nil?
163
+ lib_elements << LibElement.new(LibElement::LIB_WITH_PATH, ln)
164
+ end
165
+ elsif (Metamodel::Dependency === l)
166
+ lib_elements << LibElement.new(LibElement::DEPENDENCY, l.name+","+l.config)
167
+ end
168
+
169
+ end
170
+
171
+ return lib_elements
172
+ end
173
+
174
+ end
175
+
176
+ end
@@ -1,209 +1,209 @@
1
- require 'common/ext/rtext'
2
-
3
- module Bake
4
-
5
- class MergeConfig
6
-
7
- def initialize(child, parent)
8
- @child = child
9
- @parent = parent
10
- end
11
-
12
- def self.clone(obj)
13
- if obj.is_a?(Metamodel::ModelElement)
14
- cloneModelElement(obj)
15
- elsif Array === obj
16
- obj.map { |o| clone(o) }
17
- else
18
- obj # no clone, should not happen
19
- end
20
- end
21
-
22
- def self.cloneModelElement(obj)
23
- cpy = obj.class.new
24
- cpy.file_name = obj.file_name
25
- obj.class.ecore.eAllStructuralFeatures.each do |f|
26
- value = obj.getGeneric(f.name)
27
- if f.is_a?(RGen::ECore::EReference) && f.containment
28
- if value.is_a?(Array)
29
- cpy.setGeneric(f.name, value.collect{|v| clone(v)})
30
- elsif !value.nil?
31
- cpy.setGeneric(f.name, clone(value))
32
- end
33
- elsif f.is_a?(RGen::ECore::EAttribute)
34
- cpy.setGeneric(f.name, value) if obj.eIsSet(f.name)
35
- end
36
- end
37
- cpy
38
- end
39
-
40
-
41
- def replace()
42
- @child.class.ecore.eAllReferences.each do |f|
43
- next unless @parent.class.ecore.eAllReferences.include?f
44
- next unless f.containment
45
- childData = @child.getGeneric(f.name)
46
- if Metamodel::ModelElement === childData
47
- @parent.setGeneric(f.name,childData) if !childData.nil?
48
- elsif Array === childData
49
- if !childData.empty?
50
- parentData = @parent.getGeneric(f.name)
51
- cclasses = childData.map { |c| c.class }.uniq
52
- parentData.delete_if { |p| cclasses.include?p.class }
53
- parentData += childData
54
- @parent.setGeneric(f.name,parentData)
55
- end
56
- end
57
- end
58
- end
59
-
60
- def hasSubNodes(elem)
61
- elem.class.ecore.eAllReferences.each do |f|
62
- next unless f.containment
63
- elemData = elem.getGeneric(f.name)
64
- return true if (Array === elemData && !elemData.empty?)
65
- return true if (Metamodel::ModelElement === elemData)
66
- end
67
- false
68
- end
69
-
70
- def sameAttr(childData, parentData)
71
- childData.class.ecore.eAllAttributes.all? { |a|
72
- a.eAnnotations.each do |x| x.details.each do |y|
73
- return true if (y.key == :internal and y.value == true)
74
- end; end
75
- a.name == "line_number" || (not childData.eIsSet(a.name)) || (childData.getGeneric(a.name) == parentData.getGeneric(a.name))
76
- }
77
- end
78
-
79
- def removeChilds(childElem, parentElem)
80
- return if childElem.nil? or parentElem.nil?
81
-
82
- childElem.class.ecore.eAllReferences.each do |f|
83
- next unless f.containment
84
- begin
85
- childData = childElem.getGeneric(f.name)
86
- parentData = parentElem.getGeneric(f.name)
87
- rescue Exception => ex
88
- next # how to check fast if f.name is valid?
89
- end
90
- next if childData.nil? or parentData.nil?
91
- if (Array === childData)
92
- if !parentData.empty? && !childData.empty?
93
- childData.each do |c|
94
- cN = hasSubNodes(c)
95
- toRemove = []
96
- parentData.each do |p|
97
- next if p.class != c.class
98
- if (not cN)
99
- if sameAttr(c, p)
100
- toRemove << p
101
- end
102
- else
103
- removeChilds(c, p);
104
- end
105
- end
106
- toRemove.each do |r|
107
- parentElem.removeGeneric(f.name, r)
108
- end
109
- end
110
- end
111
- elsif Metamodel::ModelElement === childData
112
- if parentData.class == childData.class && sameAttr(childData, parentData)
113
- cN = hasSubNodes(childData)
114
- if (not cN)
115
- parentElem.setGeneric(f.name, nil)
116
- else
117
- removeChilds(childData, parentData)
118
- end
119
- end # otherwise not equal, will not be deleted
120
- end
121
- end
122
- end
123
-
124
- def extendAttributes(childData, parentData)
125
- parentData.class.ecore.eAllAttributes.each do |a|
126
- childData.setGeneric(a.name, parentData.getGeneric(a.name)) if !childData.eIsSet(a.name) && parentData.eIsSet(a.name)
127
- end
128
- end
129
-
130
- def extend(child, parent)
131
- (parent.class.ecore.eAllReferences & child.class.ecore.eAllReferences).each do |f|
132
- next unless f.containment
133
- parentData = parent.getGeneric(f.name)
134
- next if parentData.nil? or (Array === parentData && parentData.empty?)
135
- childData = child.getGeneric(f.name)
136
-
137
- if Array === parentData
138
- if f.name == "compiler"
139
- extendedParentData = []
140
- parentData.each do |p|
141
- c = childData.find { |c| p.ctype == c.ctype }
142
- if c
143
- extendAttributes(c, p)
144
- extend(c, p)
145
- extendedParentData << c
146
- else
147
- extendedParentData << p
148
- end
149
- end
150
- restOfChildData = childData.find_all { |c| parentData.find {|p| p.ctype != c.ctype } }
151
- child.setGeneric(f.name, extendedParentData + restOfChildData)
152
- else
153
- child.setGeneric(f.name, parentData + childData)
154
- end
155
- elsif Metamodel::ModelElement === parentData
156
- if childData.nil? || childData.class != parentData.class
157
- child.setGeneric(f.name, parentData)
158
- else
159
- extendAttributes(childData, parentData)
160
- extend(childData, parentData)
161
- end
162
- end
163
- end
164
- end
165
-
166
- def copyChildToParent(c, p)
167
- (p.class.ecore.eAllReferences & c.class.ecore.eAllReferences).each do |f|
168
- next unless f.containment
169
- childData = c.getGeneric(f.name)
170
- next if childData.nil? || (Array === childData && childData.empty?)
171
- p.setGeneric(f.name, childData)
172
- end
173
- end
174
-
175
- def merge(type)
176
- s = StringIO.new
177
- ser = RText::Serializer.new(Language)
178
-
179
- if Bake.options.debug
180
- s.puts "\n>>>> child <<<<"
181
- ser.serialize(@child, s)
182
- s.puts "\n>>>> parent <<<<"
183
- ser.serialize(@parent, s)
184
- end
185
-
186
- if (type == :remove)
187
- removeChilds(@child, @parent)
188
- elsif (type == :replace)
189
- replace
190
- elsif (type == :extend)
191
- c = MergeConfig.clone(@child)
192
- extend(c, @parent)
193
- copyChildToParent(c, @parent)
194
- elsif (type == :merge)
195
- extend(@child, MergeConfig.clone(@parent))
196
- end
197
-
198
- if Bake.options.debug
199
- s.puts "\n>>>> result of #{type.to_s} <<<<"
200
- ser.serialize(type == :merge ? @child : @parent, s)
201
- puts "#{s.string}"
202
- end
203
-
204
-
205
- end
206
-
207
- end
208
-
1
+ require 'common/ext/rtext'
2
+
3
+ module Bake
4
+
5
+ class MergeConfig
6
+
7
+ def initialize(child, parent)
8
+ @child = child
9
+ @parent = parent
10
+ end
11
+
12
+ def self.clone(obj)
13
+ if obj.is_a?(Metamodel::ModelElement)
14
+ cloneModelElement(obj)
15
+ elsif Array === obj
16
+ obj.map { |o| clone(o) }
17
+ else
18
+ obj # no clone, should not happen
19
+ end
20
+ end
21
+
22
+ def self.cloneModelElement(obj)
23
+ cpy = obj.class.new
24
+ cpy.file_name = obj.file_name
25
+ obj.class.ecore.eAllStructuralFeatures.each do |f|
26
+ value = obj.getGeneric(f.name)
27
+ if f.is_a?(RGen::ECore::EReference) && f.containment
28
+ if value.is_a?(Array)
29
+ cpy.setGeneric(f.name, value.collect{|v| clone(v)})
30
+ elsif !value.nil?
31
+ cpy.setGeneric(f.name, clone(value))
32
+ end
33
+ elsif f.is_a?(RGen::ECore::EAttribute)
34
+ cpy.setGeneric(f.name, value) if obj.eIsSet(f.name)
35
+ end
36
+ end
37
+ cpy
38
+ end
39
+
40
+
41
+ def replace()
42
+ @child.class.ecore.eAllReferences.each do |f|
43
+ next unless @parent.class.ecore.eAllReferences.include?f
44
+ next unless f.containment
45
+ childData = @child.getGeneric(f.name)
46
+ if Metamodel::ModelElement === childData
47
+ @parent.setGeneric(f.name,childData) if !childData.nil?
48
+ elsif Array === childData
49
+ if !childData.empty?
50
+ parentData = @parent.getGeneric(f.name)
51
+ cclasses = childData.map { |c| c.class }.uniq
52
+ parentData.delete_if { |p| cclasses.include?p.class }
53
+ parentData += childData
54
+ @parent.setGeneric(f.name,parentData)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ def hasSubNodes(elem)
61
+ elem.class.ecore.eAllReferences.each do |f|
62
+ next unless f.containment
63
+ elemData = elem.getGeneric(f.name)
64
+ return true if (Array === elemData && !elemData.empty?)
65
+ return true if (Metamodel::ModelElement === elemData)
66
+ end
67
+ false
68
+ end
69
+
70
+ def sameAttr(childData, parentData)
71
+ childData.class.ecore.eAllAttributes.all? { |a|
72
+ a.eAnnotations.each do |x| x.details.each do |y|
73
+ return true if (y.key == :internal and y.value == true)
74
+ end; end
75
+ a.name == "line_number" || (not childData.eIsSet(a.name)) || (childData.getGeneric(a.name) == parentData.getGeneric(a.name))
76
+ }
77
+ end
78
+
79
+ def removeChilds(childElem, parentElem)
80
+ return if childElem.nil? or parentElem.nil?
81
+
82
+ childElem.class.ecore.eAllReferences.each do |f|
83
+ next unless f.containment
84
+ begin
85
+ childData = childElem.getGeneric(f.name)
86
+ parentData = parentElem.getGeneric(f.name)
87
+ rescue Exception => ex
88
+ next # how to check fast if f.name is valid?
89
+ end
90
+ next if childData.nil? or parentData.nil?
91
+ if (Array === childData)
92
+ if !parentData.empty? && !childData.empty?
93
+ childData.each do |c|
94
+ cN = hasSubNodes(c)
95
+ toRemove = []
96
+ parentData.each do |p|
97
+ next if p.class != c.class
98
+ if (not cN)
99
+ if sameAttr(c, p)
100
+ toRemove << p
101
+ end
102
+ else
103
+ removeChilds(c, p);
104
+ end
105
+ end
106
+ toRemove.each do |r|
107
+ parentElem.removeGeneric(f.name, r)
108
+ end
109
+ end
110
+ end
111
+ elsif Metamodel::ModelElement === childData
112
+ if parentData.class == childData.class && sameAttr(childData, parentData)
113
+ cN = hasSubNodes(childData)
114
+ if (not cN)
115
+ parentElem.setGeneric(f.name, nil)
116
+ else
117
+ removeChilds(childData, parentData)
118
+ end
119
+ end # otherwise not equal, will not be deleted
120
+ end
121
+ end
122
+ end
123
+
124
+ def extendAttributes(childData, parentData)
125
+ parentData.class.ecore.eAllAttributes.each do |a|
126
+ childData.setGeneric(a.name, parentData.getGeneric(a.name)) if !childData.eIsSet(a.name) && parentData.eIsSet(a.name)
127
+ end
128
+ end
129
+
130
+ def extend(child, parent)
131
+ (parent.class.ecore.eAllReferences & child.class.ecore.eAllReferences).each do |f|
132
+ next unless f.containment
133
+ parentData = parent.getGeneric(f.name)
134
+ next if parentData.nil? or (Array === parentData && parentData.empty?)
135
+ childData = child.getGeneric(f.name)
136
+
137
+ if Array === parentData
138
+ if f.name == "compiler"
139
+ extendedParentData = []
140
+ parentData.each do |p|
141
+ c = childData.find { |c| p.ctype == c.ctype }
142
+ if c
143
+ extendAttributes(c, p)
144
+ extend(c, p)
145
+ extendedParentData << c
146
+ else
147
+ extendedParentData << p
148
+ end
149
+ end
150
+ restOfChildData = childData.find_all { |c| parentData.find {|p| p.ctype != c.ctype } }
151
+ child.setGeneric(f.name, extendedParentData + restOfChildData)
152
+ else
153
+ child.setGeneric(f.name, parentData + childData)
154
+ end
155
+ elsif Metamodel::ModelElement === parentData
156
+ if childData.nil? || childData.class != parentData.class
157
+ child.setGeneric(f.name, parentData)
158
+ else
159
+ extendAttributes(childData, parentData)
160
+ extend(childData, parentData)
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ def copyChildToParent(c, p)
167
+ (p.class.ecore.eAllReferences & c.class.ecore.eAllReferences).each do |f|
168
+ next unless f.containment
169
+ childData = c.getGeneric(f.name)
170
+ next if childData.nil? || (Array === childData && childData.empty?)
171
+ p.setGeneric(f.name, childData)
172
+ end
173
+ end
174
+
175
+ def merge(type)
176
+ s = StringIO.new
177
+ ser = RText::Serializer.new(Language)
178
+
179
+ if Bake.options.debug
180
+ s.puts "\n>>>> child <<<<"
181
+ ser.serialize(@child, s)
182
+ s.puts "\n>>>> parent <<<<"
183
+ ser.serialize(@parent, s)
184
+ end
185
+
186
+ if (type == :remove)
187
+ removeChilds(@child, @parent)
188
+ elsif (type == :replace)
189
+ replace
190
+ elsif (type == :extend)
191
+ c = MergeConfig.clone(@child)
192
+ extend(c, @parent)
193
+ copyChildToParent(c, @parent)
194
+ elsif (type == :merge)
195
+ extend(@child, MergeConfig.clone(@parent))
196
+ end
197
+
198
+ if Bake.options.debug
199
+ s.puts "\n>>>> result of #{type.to_s} <<<<"
200
+ ser.serialize(type == :merge ? @child : @parent, s)
201
+ puts "#{s.string}"
202
+ end
203
+
204
+
205
+ end
206
+
207
+ end
208
+
209
209
  end