587
|
1 |
#============================================================================
|
|
2 |
#Name : api.py
|
|
3 |
#Part of : Helium
|
|
4 |
|
|
5 |
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
6 |
#All rights reserved.
|
|
7 |
#This component and the accompanying materials are made available
|
|
8 |
#under the terms of the License "Eclipse Public License v1.0"
|
|
9 |
#which accompanies this distribution, and is available
|
|
10 |
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
11 |
#
|
|
12 |
#Initial Contributors:
|
|
13 |
#Nokia Corporation - initial contribution.
|
|
14 |
#
|
|
15 |
#Contributors:
|
|
16 |
#
|
|
17 |
#Description:
|
|
18 |
#===============================================================================
|
|
19 |
|
|
20 |
""" System Definition file parser.
|
|
21 |
|
|
22 |
Priority are not handled yet.
|
|
23 |
Nested task unitlist are not handled properly yet.
|
|
24 |
|
|
25 |
How to use it::
|
|
26 |
|
|
27 |
sdf = SystemDefinition(filename)
|
|
28 |
for name in sdf.layers:
|
|
29 |
print " + Units in layer %s" % name
|
|
30 |
for unit in sdf.layers[name].units:
|
|
31 |
print " - " + sdf.units[name].id
|
|
32 |
|
|
33 |
for name in sdf.units:
|
|
34 |
print sdf.units[name].id
|
|
35 |
|
|
36 |
"""
|
|
37 |
|
|
38 |
import logging
|
|
39 |
import os
|
|
40 |
import re
|
|
41 |
import sys
|
|
42 |
import types
|
|
43 |
|
|
44 |
from xmlhelper import node_scan, recursive_node_scan
|
|
45 |
import xml.dom.minidom
|
|
46 |
|
|
47 |
logging.basicConfig(level=logging.INFO)
|
|
48 |
_logger = logging.getLogger('sysdef.api')
|
|
49 |
|
|
50 |
|
|
51 |
def filter_out(config_filters, unit_filters):
|
|
52 |
""" Function that determines if a unit should be included or not.
|
|
53 |
returns None => could be included, string reason.
|
|
54 |
"""
|
|
55 |
|
|
56 |
def hasvalue(filter_list, value):
|
|
57 |
""" Check if a filter list contains a particular value.
|
|
58 |
It handles list's item negation using "!".
|
|
59 |
"""
|
|
60 |
for list_value in filter_list:
|
|
61 |
if list_value == value:
|
|
62 |
return True
|
|
63 |
return False
|
|
64 |
for filter_ in unit_filters:
|
|
65 |
if filter_.startswith("!"):
|
|
66 |
if hasvalue(config_filters, filter_[1:]):
|
|
67 |
return filter
|
|
68 |
else:
|
|
69 |
if not hasvalue(config_filters, filter_):
|
|
70 |
return filter_
|
|
71 |
return None
|
|
72 |
|
|
73 |
|
|
74 |
def extract_filter_list(filters):
|
|
75 |
""" Convert a comma separated list of filters into a python list.
|
|
76 |
The method will skip empty filters (empty strings).
|
|
77 |
"""
|
|
78 |
result = []
|
|
79 |
for filter_ in [filter_.strip() for filter_ in filters.split(",")]:
|
|
80 |
if len(filter_) > 0:
|
|
81 |
result.append(filter_)
|
|
82 |
return result
|
|
83 |
|
|
84 |
|
|
85 |
class SysDefElement(object):
|
|
86 |
""" A generic element of a System Definition. """
|
|
87 |
def __init__(self, sysDef):
|
|
88 |
""" Initialisation """
|
|
89 |
self._sysDef = sysDef
|
|
90 |
|
|
91 |
def _getname(self):
|
|
92 |
""" Name getter method """
|
|
93 |
return NotImplementedError()
|
|
94 |
|
|
95 |
def get_id(self):
|
|
96 |
""" Use name as default ID. """
|
|
97 |
return getattr(self, 'name').lower()
|
|
98 |
|
|
99 |
def __str__(self):
|
|
100 |
return self.get_id()
|
|
101 |
|
|
102 |
|
|
103 |
class Unit(SysDefElement):
|
|
104 |
""" Abstract unit from SDF file. """
|
|
105 |
def __init__(self, node, sysDef):
|
|
106 |
""" Initialisation """
|
|
107 |
SysDefElement.__init__(self, sysDef)
|
|
108 |
self.__xml = node
|
|
109 |
self.binaries = []
|
|
110 |
|
|
111 |
def __getid(self):
|
|
112 |
""" Id getter. """
|
|
113 |
return self.__xml.getAttribute('unitID')
|
|
114 |
|
|
115 |
def _getname(self):
|
|
116 |
""" Name getter. """
|
|
117 |
if self.__xml.hasAttribute('name'):
|
|
118 |
return self.__xml.getAttribute('name')
|
|
119 |
if self.__xml.hasAttribute('bldFile'):
|
|
120 |
return self.__xml.getAttribute('bldFile')
|
|
121 |
return self.__xml.getAttribute('mrp')
|
|
122 |
|
|
123 |
def __getpath(self):
|
|
124 |
""" Path getter. """
|
|
125 |
if self.__xml.hasAttribute('bldFile'):
|
|
126 |
return os.path.join(os.path.sep, self.__xml.getAttribute('bldFile'))
|
|
127 |
return os.path.join(os.sep, os.path.dirname(self.__xml.getAttribute('mrp')))
|
|
128 |
|
|
129 |
def __getfilters(self):
|
|
130 |
""" filter getter. """
|
|
131 |
filters = []
|
|
132 |
if self.__xml.hasAttribute('filter'):
|
|
133 |
filters = extract_filter_list(self.__xml.getAttribute('filter'))
|
|
134 |
return filters
|
|
135 |
|
|
136 |
id = property(__getid)
|
|
137 |
name = property(_getname)
|
|
138 |
path = property(__getpath)
|
|
139 |
filters = property(__getfilters)
|
|
140 |
|
|
141 |
|
|
142 |
class _UnitGroup(SysDefElement):
|
|
143 |
""" A group of units. """
|
|
144 |
def __init__(self, node, sysDef):
|
|
145 |
""" Initialisation """
|
|
146 |
SysDefElement.__init__(self, sysDef)
|
|
147 |
self._xml = node
|
|
148 |
self._units = []
|
|
149 |
|
|
150 |
def __getname(self):
|
|
151 |
""" Name getter method """
|
|
152 |
return self._xml.getAttribute('name')
|
|
153 |
|
|
154 |
def __getunits(self):
|
|
155 |
""" Units getter method """
|
|
156 |
return self._units
|
|
157 |
|
|
158 |
name = property(__getname)
|
|
159 |
units = property(__getunits)
|
|
160 |
|
|
161 |
|
|
162 |
class Layer(_UnitGroup):
|
|
163 |
""" Abstract layer from SDF file. """
|
|
164 |
def __init__(self, node, sysDef):
|
|
165 |
""" Initialisation """
|
|
166 |
_UnitGroup.__init__(self, node, sysDef)
|
|
167 |
self._modules = []
|
|
168 |
self._module_count = 0
|
|
169 |
for unitNode in recursive_node_scan(self._xml, 'unit'):
|
|
170 |
unit = Unit(unitNode, self._sysDef)
|
|
171 |
self._units.append(unit)
|
|
172 |
self._sysDef.addElement(unit)
|
|
173 |
|
|
174 |
for moduleNode in recursive_node_scan(self._xml, 'module') + recursive_node_scan(self._xml, 'collection'):
|
|
175 |
module = Module(moduleNode, self._sysDef)
|
|
176 |
self._modules.append(module)
|
|
177 |
self._module_count += 1
|
|
178 |
# Not added to the model.
|
|
179 |
#self._sysDef.addElement(module)
|
|
180 |
|
|
181 |
def __getmodules(self):
|
|
182 |
""" Module list accessor. """
|
|
183 |
return self._modules
|
|
184 |
|
|
185 |
def __getmodulescount(self):
|
|
186 |
""" Module cound accessor. """
|
|
187 |
return self._module_count
|
|
188 |
|
|
189 |
modules = property(__getmodules)
|
|
190 |
modules_count = property(__getmodulescount)
|
|
191 |
|
|
192 |
|
|
193 |
class Module(_UnitGroup):
|
|
194 |
""" Abstract module from SDF file. """
|
|
195 |
def __init__(self, node, sysDef):
|
|
196 |
""" Initialisation """
|
|
197 |
_UnitGroup.__init__(self, node, sysDef)
|
|
198 |
for unitNode in recursive_node_scan(self._xml, "unit"):
|
|
199 |
unit = Unit(unitNode, self._sysDef)
|
|
200 |
self._units.append(unit)
|
|
201 |
|
|
202 |
|
|
203 |
class UnitList(_UnitGroup):
|
|
204 |
""" Abstract unitlist from SDF file. """
|
|
205 |
def __init__(self, node, units, sysDef):
|
|
206 |
""" Initialisation """
|
|
207 |
_UnitGroup.__init__(self, node, sysDef)
|
|
208 |
for unitRef in node_scan(self._xml, "unitRef"):
|
|
209 |
try:
|
|
210 |
self._units.append(units[unitRef.getAttribute('unit')])
|
|
211 |
except KeyError, error:
|
|
212 |
sys.stderr.write("ERROR: Could not find unit '%s'\n" % unitRef.getAttribute('unit') + str(error) + "\n")
|
|
213 |
|
|
214 |
|
|
215 |
class BuildLayer(SysDefElement):
|
|
216 |
""" Abstract buildlayer. """
|
|
217 |
def __init__(self, node, config, sysDef):
|
|
218 |
""" Initialisation """
|
|
219 |
SysDefElement.__init__(self, sysDef)
|
|
220 |
self.__xml = node
|
|
221 |
self.config = config
|
|
222 |
self.targetList = []
|
|
223 |
if self.__xml.hasAttribute('targetList'):
|
|
224 |
for tlname in re.split(r'\s+', self.__xml.getAttribute('targetList').strip()):
|
|
225 |
for target in self._sysDef.targetlists[tlname].targets:
|
|
226 |
self.targetList.append(target)
|
|
227 |
|
|
228 |
def __getcommand(self):
|
|
229 |
""" Command getter method. """
|
|
230 |
return self.__xml.getAttribute('command')
|
|
231 |
|
|
232 |
def __getunitParallel(self):
|
|
233 |
""" Unit Parallel getter method (boolean). """
|
|
234 |
return (self.__xml.getAttribute('unitParallel').upper() == "Y")
|
|
235 |
|
|
236 |
command = property(__getcommand)
|
|
237 |
unitParallel = property(__getunitParallel)
|
|
238 |
|
|
239 |
|
|
240 |
class Option(SysDefElement):
|
|
241 |
""" Represents an option used in abld calls. """
|
|
242 |
def __init__(self, node, sysDef):
|
|
243 |
""" Initialisation """
|
|
244 |
SysDefElement.__init__(self, sysDef)
|
|
245 |
self.__xml = node
|
|
246 |
|
|
247 |
def __getname(self):
|
|
248 |
""" Name getter method. """
|
|
249 |
return self.__xml.getAttribute('name')
|
|
250 |
|
|
251 |
def __getabldOption(self):
|
|
252 |
""" Abld option getter method. """
|
|
253 |
return self.__xml.getAttribute('abldOption')
|
|
254 |
|
|
255 |
def __getenable(self):
|
|
256 |
""" Unit Parallel getter method (boolean). """
|
|
257 |
return (self.__xml.getAttribute('enable').upper() == 'Y')
|
|
258 |
|
|
259 |
def __getfilteredOption(self):
|
|
260 |
""" Filtered abld option getter method. """
|
|
261 |
if not self.enable:
|
|
262 |
return ''
|
|
263 |
return self.abldOption
|
|
264 |
|
|
265 |
name = property(__getname)
|
|
266 |
abldOption = property(__getabldOption)
|
|
267 |
enable = property(__getenable)
|
|
268 |
filteredOption = property(__getfilteredOption)
|
|
269 |
|
|
270 |
|
|
271 |
class SpecialInstruction(SysDefElement):
|
|
272 |
""" Reads special instruction command. """
|
|
273 |
def __init__(self, node, sysDef):
|
|
274 |
""" Initialisation """
|
|
275 |
SysDefElement.__init__(self, sysDef)
|
|
276 |
self.__xml = node
|
|
277 |
|
|
278 |
def __getname(self):
|
|
279 |
""" Name getter method """
|
|
280 |
return self.__xml.getAttribute('name')
|
|
281 |
|
|
282 |
def __getcommand(self):
|
|
283 |
""" Command getter method """
|
|
284 |
return self.__xml.getAttribute('command')
|
|
285 |
|
|
286 |
def __getpath(self):
|
|
287 |
""" Path getter method """
|
|
288 |
return self.__xml.getAttribute('cwd')
|
|
289 |
|
|
290 |
name = property(__getname)
|
|
291 |
command = property(__getcommand)
|
|
292 |
path = property(__getpath)
|
|
293 |
|
|
294 |
|
|
295 |
class Task(SysDefElement):
|
|
296 |
""" Abstract task node from SDF xml. """
|
|
297 |
def __init__(self, node, config, sysDef):
|
|
298 |
""" Initialisation """
|
|
299 |
SysDefElement.__init__(self, sysDef)
|
|
300 |
self.__xml = node
|
|
301 |
self._config = config
|
|
302 |
self.__job = None
|
|
303 |
|
|
304 |
def units(self):
|
|
305 |
""" Process unit list from layers """
|
|
306 |
result = []
|
|
307 |
for ref in node_scan(self.__xml, "unitListRef"):
|
|
308 |
units = []
|
|
309 |
try:
|
|
310 |
units = self._config.sdf.unitlists[ref.getAttribute('unitList')].units
|
|
311 |
for unit in units:
|
|
312 |
reason = filter_out(self._config.filters, unit.filters)
|
|
313 |
if reason == None:
|
|
314 |
result.append(unit)
|
|
315 |
else:
|
|
316 |
sys.stderr.write("Filter-out: %s (%s)\n" % (unit.id, reason))
|
|
317 |
except KeyError, error:
|
|
318 |
sys.stderr.write("ERROR: Could not find unitList of layer %s\n" % error)
|
|
319 |
return result
|
|
320 |
|
|
321 |
def __getjob(self):
|
|
322 |
""" Return the job contained inside the task. """
|
|
323 |
for job in node_scan(self.__xml, r"buildLayer|specialInstructions"):
|
|
324 |
if job.nodeName == 'specialInstructions':
|
|
325 |
self.__job = SpecialInstruction(job, self._sysDef)
|
|
326 |
elif job.nodeName == 'buildLayer':
|
|
327 |
self.__job = BuildLayer(job, self._config, self._sysDef)
|
|
328 |
return self.__job
|
|
329 |
|
|
330 |
job = property(__getjob)
|
|
331 |
|
|
332 |
|
|
333 |
class Configuration(SysDefElement):
|
|
334 |
""" Abstract configuration from SDF file. """
|
|
335 |
def __init__(self, node, sysDef):
|
|
336 |
""" Initialisation """
|
|
337 |
SysDefElement.__init__(self, sysDef)
|
|
338 |
self.__xml = node
|
|
339 |
|
|
340 |
def __getname(self):
|
|
341 |
""" Name getter method """
|
|
342 |
return self.__xml.getAttribute('name')
|
|
343 |
|
|
344 |
def __getfilters(self):
|
|
345 |
""" Filters getter method. """
|
|
346 |
filters = []
|
|
347 |
if self.__xml.hasAttribute('filter'):
|
|
348 |
filters = extract_filter_list(self.__xml.getAttribute('filter'))
|
|
349 |
return filters
|
|
350 |
|
|
351 |
def __getlayerrefs(self):
|
|
352 |
""" Layer's references getter method. """
|
|
353 |
result = []
|
|
354 |
for ref in node_scan(self.__xml, "layerRef"):
|
|
355 |
try:
|
|
356 |
result.append(self._sysDef.layers[ref.getAttribute('layerName')])
|
|
357 |
except KeyError, error:
|
|
358 |
sys.stderr.write("ERROR: Could not find layer '%s'\n" % error)
|
|
359 |
return result
|
|
360 |
|
|
361 |
def __getunitlistrefs(self):
|
|
362 |
""" Unit list references getter method. """
|
|
363 |
result = []
|
|
364 |
for ref in node_scan(self.__xml, "unitListRef"):
|
|
365 |
try:
|
|
366 |
result.append(self._sysDef.unitlists[ref.getAttribute('unitList')])
|
|
367 |
except KeyError, error:
|
|
368 |
sys.stderr.write("ERROR: Could not find unitList %s\n" % error)
|
|
369 |
return result
|
|
370 |
|
|
371 |
def __getunits(self):
|
|
372 |
""" Return unit from unitList or layer. """
|
|
373 |
result = []
|
|
374 |
for ref in node_scan(self.__xml, "unitListRef|layerRef"):
|
|
375 |
units = []
|
|
376 |
try:
|
|
377 |
if ref.nodeName == 'unitListRef':
|
|
378 |
units = self._sysDef.unitlists[ref.getAttribute('unitList')].units
|
|
379 |
else:
|
|
380 |
units = self._sysDef.layers[ref.getAttribute('layerName')].units
|
|
381 |
for unit in units:
|
|
382 |
reason = filter_out(self.filters, unit.filters)
|
|
383 |
if reason == None:
|
|
384 |
# Get the unit object from the cache if this is a string
|
|
385 |
# TODO - remove once unitlist returns list of Unit objects
|
|
386 |
if isinstance(unit, types.UnicodeType):
|
|
387 |
unit = self._sysDef[unit]
|
|
388 |
result.append(unit)
|
|
389 |
else:
|
|
390 |
sys.stderr.write("Filter-out: %s (%s)\n" % (unit.id, reason))
|
|
391 |
except KeyError, error:
|
|
392 |
sys.stderr.write("ERROR: Could not find unitList or layer %s\n" % error)
|
|
393 |
return result
|
|
394 |
|
|
395 |
def __gettasks(self):
|
|
396 |
""" Tasks getter method. """
|
|
397 |
result = []
|
|
398 |
for task in node_scan(self.__xml, "task"):
|
|
399 |
result.append(Task(task, self, self._sysDef))
|
|
400 |
return result
|
|
401 |
|
|
402 |
name = property(__getname)
|
|
403 |
filters = property(__getfilters)
|
|
404 |
layerrefs = property(__getlayerrefs)
|
|
405 |
unitlistrefs = property(__getunitlistrefs)
|
|
406 |
units = property(__getunits)
|
|
407 |
tasks = property(__gettasks)
|
|
408 |
|
|
409 |
|
|
410 |
class Target(SysDefElement):
|
|
411 |
""" Abstract target from SDF file. """
|
|
412 |
def __init__(self, node, sysDef):
|
|
413 |
""" Initialisation """
|
|
414 |
SysDefElement.__init__(self, sysDef)
|
|
415 |
self.__xml = node
|
|
416 |
|
|
417 |
def __getname(self):
|
|
418 |
""" Name getter method. """
|
|
419 |
return self.__xml.getAttribute('name')
|
|
420 |
|
|
421 |
def __getabldTarget(self):
|
|
422 |
""" Abld target getter method. """
|
|
423 |
return self.__xml.getAttribute('abldTarget')
|
|
424 |
|
|
425 |
name = property(__getname)
|
|
426 |
abldTarget = property(__getabldTarget)
|
|
427 |
|
|
428 |
|
|
429 |
class TargetList(SysDefElement):
|
|
430 |
""" Abstract targetlist from SDF file. """
|
|
431 |
def __init__(self, node, sysDef):
|
|
432 |
""" Initialisation """
|
|
433 |
SysDefElement.__init__(self, sysDef)
|
|
434 |
self.__xml = node
|
|
435 |
|
|
436 |
def __getname(self):
|
|
437 |
""" Name getter method. """
|
|
438 |
return self.__xml.getAttribute('name')
|
|
439 |
|
|
440 |
def __gettargets(self):
|
|
441 |
""" Targets getter method. """
|
|
442 |
result = []
|
|
443 |
for target in re.split(r'\s+', self.__xml.getAttribute('target')):
|
|
444 |
result.append(self._sysDef.targets[target.strip()])
|
|
445 |
return result
|
|
446 |
|
|
447 |
name = property(__getname)
|
|
448 |
targets = property(__gettargets)
|
|
449 |
|
|
450 |
|
|
451 |
class SystemDefinition(object):
|
|
452 |
""" Logical representation of the System Definition.
|
|
453 |
|
|
454 |
The System Definition is defined in terms of a system model and a
|
|
455 |
build model. The default physical representation of this is the Symbian
|
|
456 |
XML format. """
|
|
457 |
def __init__(self, filename):
|
|
458 |
""" Initialisation """
|
|
459 |
self.__xml = xml.dom.minidom.parse(open(filename, "r"))
|
|
460 |
self._cache = {}
|
|
461 |
#TODO - why store these as hashes?
|
|
462 |
self._units = {}
|
|
463 |
self._layers = {}
|
|
464 |
self._modules = {}
|
|
465 |
self._unitlists = {}
|
|
466 |
self._configurations = {}
|
|
467 |
self._options = {}
|
|
468 |
self._targets = {}
|
|
469 |
self._targetlists = {}
|
|
470 |
self.__parse()
|
|
471 |
|
|
472 |
def __getunits(self):
|
|
473 |
""" Units getter method. """
|
|
474 |
return self._units
|
|
475 |
|
|
476 |
def __getmodules(self):
|
|
477 |
""" Modules getter method. """
|
|
478 |
return self._modules
|
|
479 |
|
|
480 |
def __getlayers(self):
|
|
481 |
""" Layers getter method. """
|
|
482 |
return self._layers
|
|
483 |
|
|
484 |
def __getunitlists(self):
|
|
485 |
""" Unit lists getter method. """
|
|
486 |
return self._unitlists
|
|
487 |
|
|
488 |
def __getoptions(self):
|
|
489 |
""" Options getter method. """
|
|
490 |
return self._options
|
|
491 |
|
|
492 |
def __getconfigurations(self):
|
|
493 |
""" Configurations getter method. """
|
|
494 |
return self._configurations
|
|
495 |
|
|
496 |
def __gettargetlists(self):
|
|
497 |
""" Targets lists getter method. """
|
|
498 |
return self._targetlists
|
|
499 |
|
|
500 |
def __gettargets(self):
|
|
501 |
""" Targets getter method. """
|
|
502 |
return self._targets
|
|
503 |
|
|
504 |
units = property(__getunits)
|
|
505 |
unitlists = property(__getunitlists)
|
|
506 |
layers = property(__getlayers)
|
|
507 |
options = property(__getoptions)
|
|
508 |
configurations = property(__getconfigurations)
|
|
509 |
targetlists = property(__gettargetlists)
|
|
510 |
targets = property(__gettargets)
|
|
511 |
modules = property(__getmodules)
|
|
512 |
|
|
513 |
def __parse(self):
|
|
514 |
"""__parse"""
|
|
515 |
for l_layer in self.__xml.getElementsByTagName('layer'):
|
|
516 |
layer = Layer(l_layer, self)
|
|
517 |
self.layers[layer.name] = layer
|
|
518 |
self.addElement(layer)
|
|
519 |
for unit in layer.units:
|
|
520 |
self._units[unit.get_id()] = unit
|
|
521 |
for mod in layer.modules:
|
|
522 |
self._modules[mod.name] = mod
|
|
523 |
|
|
524 |
for build in self.__xml.getElementsByTagName('build'):
|
|
525 |
for u_list in build.getElementsByTagName('unitList'):
|
|
526 |
unitlist = UnitList(u_list, self._units, self)
|
|
527 |
self.unitlists[unitlist.name] = unitlist
|
|
528 |
self.addElement(unitlist)
|
|
529 |
|
|
530 |
for xml_config in build.getElementsByTagName('configuration'):
|
|
531 |
config = Configuration(xml_config, self)
|
|
532 |
self.configurations[config.name] = config
|
|
533 |
self.addElement(config)
|
|
534 |
|
|
535 |
for option_node in build.getElementsByTagName('option'):
|
|
536 |
option = Option(option_node, self)
|
|
537 |
if option.name == 'SAVESPACE':
|
|
538 |
continue
|
|
539 |
self.options[option.name] = option
|
|
540 |
self.addElement(option)
|
|
541 |
|
|
542 |
for target_node in build.getElementsByTagName('target'):
|
|
543 |
target = Target(target_node, self)
|
|
544 |
self.targets[target.name] = target
|
|
545 |
self.addElement(target)
|
|
546 |
|
|
547 |
for targetlist_node in build.getElementsByTagName('targetList'):
|
|
548 |
targetlist = TargetList(targetlist_node, self)
|
|
549 |
self.targetlists[targetlist.name] = targetlist
|
|
550 |
self.addElement(targetlist)
|
|
551 |
|
|
552 |
def addElement(self, element):
|
|
553 |
""" Adds SysDef element to cache. """
|
|
554 |
#TODO - handle duplicate names of different types
|
|
555 |
if not self._cache.has_key(element.get_id()):
|
|
556 |
self._cache[element.get_id()] = element
|
588
|
557 |
#_logger.info('Adding SysDef element to cache: %s' % str(element))
|
587
|
558 |
else:
|
|
559 |
_logger.warning("Element already exists: %s" % element.name)
|
|
560 |
|
|
561 |
def __getitem__(self, key):
|
|
562 |
""" Item getter method. """
|
|
563 |
return self._cache[key]
|
|
564 |
|
|
565 |
def merge_binaries(self, binaries_reader):
|
|
566 |
""" Merge binaries based on build log and system definition. """
|
|
567 |
for (unit_name, binaries) in binaries_reader:
|
|
568 |
unit_name = unit_name.lower()
|
|
569 |
if self.units.has_key(unit_name):
|
628
|
570 |
for bin_ in binaries:
|
|
571 |
#if bin_.find('_stolon_ekern') != -1:
|
|
572 |
_logger.debug("Merging: %s" % bin_)
|
587
|
573 |
unit = self.units[unit_name]
|
628
|
574 |
unit.binaries = [Binary(bin_.lower(), self) for bin_ in binaries]
|
587
|
575 |
for binary in unit.binaries:
|
|
576 |
self.addElement(binary)
|
|
577 |
_logger.info('Merging binary: %s' % str(binary))
|
|
578 |
else:
|
|
579 |
_logger.warning('Component found in the build log but not in sysdef: %s' % unit_name)
|
|
580 |
|
|
581 |
def merge_binary_sizes(self, binary_sizes_reader):
|
|
582 |
""" Merge binary size base on binary sizes input and system definition. """
|
|
583 |
for (binary_name, size, rom_type) in binary_sizes_reader:
|
|
584 |
#if binary_name.find('_stolon_ekern') != -1:
|
|
585 |
|
|
586 |
binary_name = binary_name.lower()
|
|
587 |
_logger.debug("Merging binary size: %s" % binary_name)
|
|
588 |
if self._cache.has_key(binary_name):
|
|
589 |
binary = self._cache[binary_name]
|
|
590 |
binary.size = size
|
|
591 |
binary.rom_type = rom_type
|
|
592 |
else:
|
|
593 |
_logger.warning('Binary found in the binary sizes input but not in the system definition: %s' % binary_name)
|
|
594 |
|
|
595 |
|
|
596 |
class Binary(SysDefElement):
|
|
597 |
""" A binary file that may go into a ROM image. """
|
|
598 |
|
|
599 |
def __init__(self, name, sysDef):
|
|
600 |
""" Initialisation """
|
|
601 |
SysDefElement.__init__(self, sysDef)
|
|
602 |
self.name = name
|
|
603 |
|
|
604 |
|
|
605 |
|
|
606 |
|
|
607 |
|
|
608 |
|
|
609 |
#if __name__ == "__main__":
|
|
610 |
# sdf = SystemDefinitionFile("Z:/output/build/canonical_system_definition.xml")
|
|
611 |
# writer = MakeWriter2("Z:/output/build/makefile")
|
|
612 |
# writer.write(sdf)
|
|
613 |
# writer.close()
|
|
614 |
# print sdf.toMakefile()
|
|
615 |
|