author | Jon Chatten |
Fri, 26 Mar 2010 12:06:09 +0000 | |
changeset 406 | 698b9b7141d7 |
parent 333 | 0fe3c56ad89c |
child 491 | f60c4282816c |
permissions | -rw-r--r-- |
3 | 1 |
# |
333
0fe3c56ad89c
release note: prototype System Definition v3 support
Richard Taylor <richard.i.taylor@nokia.com>
parents:
332
diff
changeset
|
2 |
# Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 | 3 |
# All rights reserved. |
4 |
# This component and the accompanying materials are made available |
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
|
6 |
# which accompanies this distribution, and is available |
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
# |
|
9 |
# Initial Contributors: |
|
10 |
# Nokia Corporation - initial contribution. |
|
11 |
# |
|
12 |
# Contributors: |
|
13 |
# |
|
14 |
# Description: |
|
15 |
# raptor_xml module |
|
16 |
# |
|
17 |
||
18 |
import os |
|
19 |
import raptor_data |
|
20 |
import raptor_utilities |
|
21 |
import xml.dom.minidom |
|
22 |
import re |
|
23 |
import generic_path |
|
24 |
||
25 |
# raptor_xml module attributes |
|
26 |
||
27 |
namespace = "http://symbian.com/xml/build" |
|
28 |
xsdVersion = "build/2_0.xsd" |
|
29 |
xsdIgnore = "build/666.xsd" |
|
30 |
||
31 |
_constructors = {"alias":raptor_data.Alias, |
|
32 |
"aliasRef":raptor_data.AliasRef, |
|
33 |
"append":raptor_data.Append, |
|
34 |
"env":raptor_data.Env, |
|
35 |
"group":raptor_data.Group, |
|
36 |
"groupRef":raptor_data.GroupRef, |
|
37 |
"interface":raptor_data.Interface, |
|
38 |
"interfaceRef":raptor_data.InterfaceRef, |
|
39 |
"param":raptor_data.Parameter, |
|
40 |
"paramgroup":raptor_data.ParameterGroup, |
|
41 |
"prepend":raptor_data.Prepend, |
|
42 |
"set":raptor_data.Set, |
|
43 |
"spec":raptor_data.Specification, |
|
44 |
"var":raptor_data.Variant, |
|
45 |
"varRef":raptor_data.VariantRef} |
|
46 |
||
47 |
||
48 |
# raptor_xml module classes |
|
49 |
||
50 |
class XMLError(Exception): |
|
51 |
pass |
|
52 |
||
53 |
# raptor_xml module functions |
|
54 |
||
55 |
def Read(Raptor, filename): |
|
56 |
"Read in a Raptor XML document" |
|
57 |
||
58 |
# try to read and parse the XML file |
|
59 |
try: |
|
60 |
dom = xml.dom.minidom.parse(filename) |
|
61 |
||
62 |
except: # a whole bag of exceptions can be raised here |
|
63 |
raise XMLError |
|
64 |
||
65 |
# <build> is always the root element |
|
66 |
build = dom.documentElement |
|
67 |
objects = [] |
|
68 |
||
69 |
fileVersion = build.getAttribute("xsi:schemaLocation") |
|
70 |
||
71 |
# ignore the file it matches the "invalid" schema |
|
72 |
if fileVersion.endswith(xsdIgnore): |
|
73 |
return objects |
|
74 |
||
75 |
# check that the file matches the expected schema |
|
76 |
if not fileVersion.endswith(xsdVersion): |
|
77 |
Raptor.Warn("file '%s' uses schema '%s' which does not end with the expected version '%s'", filename, fileVersion, xsdVersion) |
|
78 |
||
79 |
# create a Data Model object from each sub-element |
|
80 |
for child in build.childNodes: |
|
81 |
if child.namespaceURI == namespace \ |
|
82 |
and child.nodeType == child.ELEMENT_NODE: |
|
83 |
try: |
|
84 |
o = XMLtoDataModel(Raptor, child) |
|
85 |
if o is not None: |
|
86 |
objects.append(o) |
|
87 |
except raptor_data.InvalidChildError: |
|
88 |
Raptor.Warn("Invalid element %s in %s", child.localName, filename) |
|
89 |
||
90 |
# discard the XML |
|
91 |
dom.unlink() |
|
92 |
return objects |
|
93 |
||
94 |
||
95 |
def XMLtoDataModel(Raptor, node): |
|
96 |
"Create a data-model object from an XML element" |
|
97 |
||
98 |
# look-up a function to create an object from the node name |
|
99 |
try: |
|
100 |
constructor = _constructors[node.localName] |
|
101 |
||
102 |
except KeyError: |
|
103 |
Raptor.Warn("Unknown element %s", node.localName) |
|
104 |
return |
|
105 |
||
106 |
model = constructor() |
|
107 |
||
108 |
# deal with the attributes first |
|
109 |
if node.hasAttributes(): |
|
110 |
for i in range(node.attributes.length): |
|
111 |
attribute = node.attributes.item(i) |
|
112 |
try: |
|
113 |
||
114 |
model.SetProperty(attribute.localName, attribute.value) |
|
115 |
||
116 |
except raptor_data.InvalidPropertyError: |
|
117 |
Raptor.Warn("Can't set attribute %s for element %s", |
|
118 |
attribute.localName, node.localName) |
|
119 |
||
120 |
# add the sub-elements |
|
121 |
for child in node.childNodes: |
|
122 |
if child.namespaceURI == namespace \ |
|
123 |
and child.nodeType == child.ELEMENT_NODE: |
|
124 |
try: |
|
125 |
gc = XMLtoDataModel(Raptor, child) |
|
126 |
if gc is not None: |
|
127 |
model.AddChild(gc) |
|
128 |
||
129 |
except raptor_data.InvalidChildError: |
|
130 |
Raptor.Warn("Can't add child %s to element %s", |
|
131 |
child.localName, node.localName) |
|
132 |
||
133 |
# only return a valid object (or raise error) |
|
134 |
if model.Valid(): |
|
135 |
if model.IsApplicable(): |
|
136 |
return model |
|
137 |
else: |
|
138 |
return None |
|
139 |
else: |
|
140 |
raise raptor_data.InvalidChildError |
|
141 |
||
142 |
||
143 |
class SystemModelComponent(generic_path.Path): |
|
144 |
"""Path sub-class that wraps up a component bld.inf file with |
|
145 |
system_definition.xml context information.""" |
|
146 |
||
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
147 |
def __init__(self, aBldInfFile, aLayerName, aContainerNames, aSystemDefinitionFile, aSystemDefinitionBase, aSystemDefinitionVersion): |
3 | 148 |
generic_path.Path.__init__(self, aBldInfFile.Absolute().path) |
149 |
self.__ContainerNames = aContainerNames |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
150 |
self.__LayerName = aLayerName |
3 | 151 |
self.__SystemDefinitionFile = aSystemDefinitionFile |
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
152 |
self.__SystemDefinitionBase = aSystemDefinitionBase |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
153 |
self.__SystemDefinitionVersion = aSystemDefinitionVersion |
3 | 154 |
|
155 |
def GetSystemDefinitionFile(self): |
|
156 |
return self.__SystemDefinitionFile |
|
157 |
||
158 |
def GetSystemDefinitionBase(self): |
|
159 |
return self.__SystemDefinitionBase |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
160 |
|
333
0fe3c56ad89c
release note: prototype System Definition v3 support
Richard Taylor <richard.i.taylor@nokia.com>
parents:
332
diff
changeset
|
161 |
def GetSystemDefinitionVersion(self): |
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
162 |
return self.__SystemDefinitionVersion |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
163 |
|
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
164 |
def GetLayerName(self): |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
165 |
return self.__LayerName |
3 | 166 |
|
167 |
def GetContainerName(self, aContainerType): |
|
168 |
if self.__ContainerNames.has_key(aContainerType): |
|
333
0fe3c56ad89c
release note: prototype System Definition v3 support
Richard Taylor <richard.i.taylor@nokia.com>
parents:
332
diff
changeset
|
169 |
return self.__ContainerNames[aContainerType] |
3 | 170 |
return "" |
171 |
||
172 |
||
173 |
class SystemModel(object): |
|
174 |
"""A representation of the SystemModel section of a Symbian system_definition.xml file.""" |
|
175 |
||
176 |
def __init__(self, aLogger, aSystemDefinitionFile, aSystemDefinitionBase): |
|
177 |
self.__Logger = aLogger |
|
178 |
self.__SystemDefinitionFile = aSystemDefinitionFile.GetLocalString() |
|
179 |
self.__SystemDefinitionBase = aSystemDefinitionBase.GetLocalString() |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
180 |
self.__Version = {'MAJOR':0,'MID':0,'MINOR':0} |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
181 |
self.__IdAttribute = "name" |
3 | 182 |
self.__ComponentRoot = "" |
183 |
self.__TotalComponents = 0 |
|
184 |
self.__LayerList = [] |
|
185 |
self.__LayerDetails = {} |
|
186 |
||
187 |
self.__DOM = None |
|
188 |
self.__SystemDefinitionElement = None |
|
189 |
||
190 |
if self.__Read(): |
|
191 |
if self.__Validate(): |
|
192 |
self.__Parse() |
|
193 |
||
194 |
if self.__DOM: |
|
195 |
self.__DOM.unlink() |
|
196 |
||
197 |
def HasLayer(self, aLayer): |
|
198 |
return aLayer in self.__LayerList |
|
199 |
||
200 |
def GetLayerNames(self): |
|
201 |
return self.__LayerList |
|
202 |
||
203 |
def GetLayerComponents(self, aLayer): |
|
204 |
if not self.HasLayer(aLayer): |
|
205 |
self.__Logger.Error("System Definition layer \"%s\" does not exist in %s", aLayer, self.__SystemDefinitionFile) |
|
206 |
return [] |
|
207 |
||
208 |
return self.__LayerDetails[aLayer] |
|
209 |
||
210 |
def IsLayerBuildable(self, aLayer): |
|
211 |
if len(self.GetLayerComponents(aLayer)): |
|
212 |
return True |
|
213 |
return False |
|
214 |
||
215 |
def GetAllComponents(self): |
|
216 |
components = [] |
|
217 |
||
218 |
for layer in self.GetLayerNames(): |
|
219 |
components.extend(self.GetLayerComponents(layer)) |
|
220 |
||
221 |
return components |
|
222 |
||
223 |
def DumpLayerInfo(self, aLayer): |
|
224 |
if self.HasLayer(aLayer): |
|
225 |
self.__Logger.Info("Found %d bld.inf references in layer \"%s\"", len(self.GetLayerComponents(aLayer)), aLayer) |
|
226 |
||
227 |
def DumpInfo(self): |
|
228 |
self.__Logger.Info("Found %d bld.inf references in %s within %d layers:", len(self.GetAllComponents()), self.__SystemDefinitionFile, len(self.GetLayerNames())) |
|
229 |
self.__Logger.Info("\t%s", ", ".join(self.GetLayerNames())) |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
230 |
self.__Logger.InfoDiscovery(object_type = "layers", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
231 |
count = len(self.GetLayerNames())) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
232 |
self.__Logger.InfoDiscovery(object_type = "bld.inf references", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
233 |
count = len(self.GetAllComponents())) |
3 | 234 |
|
235 |
def __Read(self): |
|
236 |
if not os.path.exists(self.__SystemDefinitionFile): |
|
237 |
self.__Logger.Error("System Definition file %s does not exist", self.__SystemDefinitionFile) |
|
238 |
return False |
|
239 |
||
240 |
self.__Logger.Info("System Definition file %s", self.__SystemDefinitionFile) |
|
241 |
||
242 |
# try to read the XML file |
|
243 |
try: |
|
244 |
self.__DOM = xml.dom.minidom.parse(self.__SystemDefinitionFile) |
|
245 |
||
246 |
except: # a whole bag of exceptions can be raised here |
|
247 |
self.__Logger.Error("Failed to parse XML file %s", self.__SystemDefinitionFile) |
|
248 |
return False |
|
249 |
||
250 |
# <SystemDefinition> is always the root element |
|
251 |
self.__SystemDefinitionElement = self.__DOM.documentElement |
|
252 |
||
253 |
return True |
|
254 |
||
255 |
def __Validate(self): |
|
256 |
# account for different schema versions in processing |
|
257 |
# old format : version >= 1.3.0 |
|
258 |
# new format : version >= 2.0.0 (assume later versions are compatible...at least for now) |
|
259 |
version = re.match(r'(?P<MAJOR>\d)\.(?P<MID>\d)(\.(?P<MINOR>\d))?', self.__SystemDefinitionElement.getAttribute("schema")) |
|
260 |
||
261 |
if not version: |
|
262 |
self.__Logger.Error("Cannot determine schema version of XML file %s", self.__SystemDefinitionFile) |
|
263 |
return False |
|
264 |
||
265 |
self.__Version['MAJOR'] = int(version.group('MAJOR')) |
|
266 |
self.__Version['MID'] = int(version.group('MID')) |
|
267 |
self.__Version['MINOR'] = int(version.group('MINOR')) |
|
268 |
||
269 |
if self.__Version['MAJOR'] == 1 and self.__Version['MID'] > 2: |
|
270 |
self.__ComponentRoot = self.__SystemDefinitionBase |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
271 |
elif self.__Version['MAJOR'] == 2 or self.__Version['MAJOR'] == 3: |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
272 |
# 2.0.x and 3.0.0 formats support SOURCEROOT or SRCROOT as an environment specified base - we respect this, unless |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
273 |
# explicitly overridden on the command line |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
274 |
if os.environ.has_key('SRCROOT'): |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
275 |
self.__ComponentRoot = generic_path.Path(os.environ['SRCROOT']) |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
276 |
elif os.environ.has_key('SOURCEROOT'): |
3 | 277 |
self.__ComponentRoot = generic_path.Path(os.environ['SOURCEROOT']) |
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
278 |
|
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
279 |
if self.__SystemDefinitionBase and self.__SystemDefinitionBase != ".": |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
280 |
self.__ComponentRoot = self.__SystemDefinitionBase |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
281 |
if os.environ.has_key('SRCROOT'): |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
282 |
self.__Logger.Info("Command line specified System Definition file base \'%s\' overriding environment SRCROOT \'%s\'", self.__SystemDefinitionBase, os.environ['SRCROOT']) |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
283 |
elif os.environ.has_key('SOURCEROOT'): |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
284 |
self.__Logger.Info("Command line specified System Definition file base \'%s\' overriding environment SOURCEROOT \'%s\'", self.__SystemDefinitionBase, os.environ['SOURCEROOT']) |
3 | 285 |
else: |
286 |
self.__Logger.Error("Cannot process schema version %s of file %s", version.string, self.__SystemDefinitionFile) |
|
287 |
return False |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
288 |
|
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
289 |
if self.__Version['MAJOR'] >= 3: |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
290 |
# id is the unique identifier for 3.0 and later schema |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
291 |
self.__IdAttribute = "id" |
3 | 292 |
|
293 |
return True |
|
294 |
||
295 |
def __Parse(self): |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
296 |
# For 2.0 and earlier: find the <systemModel> element (there can be 0 or 1) and search any <layer> elements for <unit> elements with "bldFile" attributes |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
297 |
# the <layer> context of captured "bldFile" attributes is recorded as we go |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
298 |
# For 3.0 and later, process any architectural topmost element, use the topmost element with an id as the "layer" |
3 | 299 |
for child in self.__SystemDefinitionElement.childNodes: |
333
0fe3c56ad89c
release note: prototype System Definition v3 support
Richard Taylor <richard.i.taylor@nokia.com>
parents:
332
diff
changeset
|
300 |
if child.localName in ["systemModel", "layer", "package", "collection", "component"]: |
3 | 301 |
self.__ProcessSystemModelElement(child) |
302 |
||
303 |
def __CreateComponent(self, aBldInfFile, aUnitElement): |
|
304 |
# take a resolved bld.inf file and associated <unit/> element and returns a populated Component object |
|
305 |
containers = {} |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
306 |
self.__GetElementContainers(aUnitElement, containers) |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
307 |
layer = self.__GetEffectiveLayer(aUnitElement) |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
308 |
component = SystemModelComponent(aBldInfFile, layer, containers, self.__SystemDefinitionFile, self.__SystemDefinitionBase, self.__Version) |
3 | 309 |
|
310 |
return component |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
311 |
|
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
312 |
def __GetEffectiveLayer(self, aElement): |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
313 |
#' return the ID of the topmost item which has an ID. For 1.x and 2.x, this will always be layer, for 3.x, it will be the topmost ID'd element in the file |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
314 |
# never call this on the root element |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
315 |
if aElement.parentNode.hasAttribute(self.__IdAttribute): |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
316 |
return self.__GetEffectiveLayer(aElement.parentNode) |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
317 |
elif aElement.hasAttribute(self.__IdAttribute): |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
318 |
return aElement.getAttribute(self.__IdAttribute) |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
319 |
return "" |
3 | 320 |
|
321 |
def __GetElementContainers(self, aElement, aContainers): |
|
322 |
# take a <unit/> element and creates a type->name dictionary of all of its parent containers |
|
323 |
# We're only interested in parent nodes if they're not the top-most node |
|
324 |
if aElement.parentNode.parentNode: |
|
325 |
parent = aElement.parentNode |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
326 |
name = parent.getAttribute(self.__IdAttribute) |
3 | 327 |
|
328 |
if name: |
|
329 |
aContainers[parent.tagName] = name |
|
330 |
||
331 |
self.__GetElementContainers(parent, aContainers) |
|
332 |
||
333 |
def __ProcessSystemModelElement(self, aElement): |
|
334 |
"""Search for XML <unit/> elements with 'bldFile' attributes and resolve concrete bld.inf locations |
|
335 |
with an appreciation of different schema versions.""" |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
336 |
|
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
337 |
# The effective "layer" is the item whose parent does not have an id (or name in 2.x and earlier) |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
338 |
if not aElement.parentNode.hasAttribute(self.__IdAttribute) : |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
339 |
currentLayer = aElement.getAttribute(self.__IdAttribute) |
3 | 340 |
|
341 |
if not self.__LayerDetails.has_key(currentLayer): |
|
342 |
self.__LayerDetails[currentLayer] = [] |
|
343 |
||
344 |
if not currentLayer in self.__LayerList: |
|
345 |
self.__LayerList.append(currentLayer) |
|
346 |
||
347 |
elif aElement.tagName == "unit" and aElement.hasAttributes(): |
|
348 |
bldFileValue = aElement.getAttribute("bldFile") |
|
349 |
||
350 |
if bldFileValue: |
|
351 |
bldInfRoot = self.__ComponentRoot |
|
352 |
||
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
353 |
if self.__Version['MAJOR'] == 1: |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
354 |
# version 1.x schema paths can use DOS slashes |
3 | 355 |
bldFileValue = raptor_utilities.convertToUnixSlash(bldFileValue) |
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
356 |
elif self.__Version['MAJOR'] >= 2: |
3 | 357 |
# version 2.x.x schema paths are subject to a "root" attribute off-set, if it exists |
358 |
rootValue = aElement.getAttribute("root") |
|
359 |
||
360 |
if rootValue: |
|
361 |
if os.environ.has_key(rootValue): |
|
362 |
bldInfRoot = generic_path.Path(os.environ[rootValue]) |
|
363 |
else: |
|
364 |
# Assume that this is an error i.e. don't attempt to resolve in relation to SOURCEROOT |
|
365 |
bldInfRoot = None |
|
366 |
self.__Logger.Error("Cannot resolve \'root\' attribute value \"%s\" in %s", rootValue, self.__SystemDefinitionFile) |
|
367 |
return |
|
368 |
||
369 |
group = generic_path.Path(bldFileValue) |
|
370 |
||
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
371 |
if self.__Version['MAJOR'] < 3: |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
372 |
# absolute paths are not changed by root var in 1.x and 2.x |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
373 |
if not group.isAbsolute() and bldInfRoot: |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
374 |
group = generic_path.Join(bldInfRoot, group) |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
375 |
else: |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
376 |
# only absolute paths are changed by root var in 3.x |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
377 |
if group.isAbsolute() and bldInfRoot: |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
378 |
group = generic_path.Join(bldInfRoot, group) |
3 | 379 |
|
380 |
bldinf = generic_path.Join(group, "bld.inf").FindCaseless() |
|
381 |
||
382 |
if bldinf == None: |
|
383 |
self.__Logger.Error("No bld.inf found at %s in %s", group.GetLocalString(), self.__SystemDefinitionFile) |
|
384 |
else: |
|
385 |
component = self.__CreateComponent(bldinf, aElement) |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
386 |
layer = component.GetLayerName() |
3 | 387 |
if layer: |
388 |
self.__LayerDetails[layer].append(component) |
|
389 |
self.__TotalComponents += 1 |
|
390 |
else: |
|
391 |
self.__Logger.Error("No containing layer found for %s in %s", str(bldinf), self.__SystemDefinitionFile) |
|
392 |
||
393 |
# search the sub-elements |
|
394 |
for child in aElement.childNodes: |
|
395 |
if child.nodeType == child.ELEMENT_NODE: |
|
396 |
self.__ProcessSystemModelElement(child) |
|
397 |
||
398 |
||
399 |
# end of the raptor_xml module |