author | yiluzhu |
Wed, 26 May 2010 10:25:38 +0100 | |
branch | fix |
changeset 572 | c1583702caf5 |
parent 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 |
# |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
14 |
# Description: |
3 | 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") |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
70 |
|
3 | 71 |
# ignore the file it matches the "invalid" schema |
72 |
if fileVersion.endswith(xsdIgnore): |
|
73 |
return objects |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
74 |
|
3 | 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) |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
78 |
|
3 | 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 |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
150 |
self.__LayerName = aLayerName |
3 | 151 |
self.__SystemDefinitionFile = aSystemDefinitionFile |
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
152 |
self.__SystemDefinitionBase = aSystemDefinitionBase |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
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 |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
160 |
|
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
161 |
def GetSystemDefinitionVersion(self): |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
162 |
return self.__SystemDefinitionVersion |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
163 |
|
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
164 |
def GetLayerName(self): |
332
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() |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
180 |
self.__Version = {'MAJOR':0,'MID':0,'MINOR':0} |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
181 |
self.__IdAttribute = "name" |
3 | 182 |
self.__ComponentRoot = "" |
183 |
self.__TotalComponents = 0 |
|
184 |
self.__LayerList = [] |
|
185 |
self.__LayerDetails = {} |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
186 |
self.__MissingBldInfs = {} |
3 | 187 |
|
188 |
self.__DOM = None |
|
189 |
self.__SystemDefinitionElement = None |
|
190 |
||
191 |
if self.__Read(): |
|
192 |
if self.__Validate(): |
|
193 |
self.__Parse() |
|
194 |
||
195 |
if self.__DOM: |
|
196 |
self.__DOM.unlink() |
|
197 |
||
198 |
def HasLayer(self, aLayer): |
|
199 |
return aLayer in self.__LayerList |
|
200 |
||
201 |
def GetLayerNames(self): |
|
202 |
return self.__LayerList |
|
203 |
||
204 |
def GetLayerComponents(self, aLayer): |
|
205 |
if not self.HasLayer(aLayer): |
|
206 |
self.__Logger.Error("System Definition layer \"%s\" does not exist in %s", aLayer, self.__SystemDefinitionFile) |
|
207 |
return [] |
|
208 |
||
209 |
return self.__LayerDetails[aLayer] |
|
210 |
||
211 |
def IsLayerBuildable(self, aLayer): |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
212 |
if aLayer in self.__MissingBldInfs: |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
213 |
for missingbldinf in self.__MissingBldInfs[aLayer]: |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
214 |
self.__Logger.Error("System Definition layer \"%s\" from system definition file \"%s\" " + \ |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
215 |
"refers to non existent bld.inf file %s", aLayer, self.__SystemDefinitionFile, missingbldinf) |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
216 |
|
3 | 217 |
if len(self.GetLayerComponents(aLayer)): |
218 |
return True |
|
219 |
return False |
|
220 |
||
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
221 |
|
3 | 222 |
def GetAllComponents(self): |
223 |
components = [] |
|
224 |
||
225 |
for layer in self.GetLayerNames(): |
|
226 |
components.extend(self.GetLayerComponents(layer)) |
|
227 |
||
228 |
return components |
|
229 |
||
230 |
def DumpLayerInfo(self, aLayer): |
|
231 |
if self.HasLayer(aLayer): |
|
232 |
self.__Logger.Info("Found %d bld.inf references in layer \"%s\"", len(self.GetLayerComponents(aLayer)), aLayer) |
|
233 |
||
234 |
def DumpInfo(self): |
|
235 |
self.__Logger.Info("Found %d bld.inf references in %s within %d layers:", len(self.GetAllComponents()), self.__SystemDefinitionFile, len(self.GetLayerNames())) |
|
236 |
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
|
237 |
self.__Logger.InfoDiscovery(object_type = "layers", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
238 |
count = len(self.GetLayerNames())) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
239 |
self.__Logger.InfoDiscovery(object_type = "bld.inf references", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
240 |
count = len(self.GetAllComponents())) |
3 | 241 |
|
242 |
def __Read(self): |
|
243 |
if not os.path.exists(self.__SystemDefinitionFile): |
|
244 |
self.__Logger.Error("System Definition file %s does not exist", self.__SystemDefinitionFile) |
|
245 |
return False |
|
246 |
||
247 |
self.__Logger.Info("System Definition file %s", self.__SystemDefinitionFile) |
|
248 |
||
249 |
# try to read the XML file |
|
250 |
try: |
|
251 |
self.__DOM = xml.dom.minidom.parse(self.__SystemDefinitionFile) |
|
252 |
||
253 |
except: # a whole bag of exceptions can be raised here |
|
254 |
self.__Logger.Error("Failed to parse XML file %s", self.__SystemDefinitionFile) |
|
255 |
return False |
|
256 |
||
257 |
# <SystemDefinition> is always the root element |
|
258 |
self.__SystemDefinitionElement = self.__DOM.documentElement |
|
259 |
||
260 |
return True |
|
261 |
||
262 |
def __Validate(self): |
|
263 |
# account for different schema versions in processing |
|
264 |
# old format : version >= 1.3.0 |
|
265 |
# new format : version >= 2.0.0 (assume later versions are compatible...at least for now) |
|
266 |
version = re.match(r'(?P<MAJOR>\d)\.(?P<MID>\d)(\.(?P<MINOR>\d))?', self.__SystemDefinitionElement.getAttribute("schema")) |
|
267 |
||
268 |
if not version: |
|
269 |
self.__Logger.Error("Cannot determine schema version of XML file %s", self.__SystemDefinitionFile) |
|
270 |
return False |
|
271 |
||
272 |
self.__Version['MAJOR'] = int(version.group('MAJOR')) |
|
273 |
self.__Version['MID'] = int(version.group('MID')) |
|
274 |
self.__Version['MINOR'] = int(version.group('MINOR')) |
|
275 |
||
276 |
if self.__Version['MAJOR'] == 1 and self.__Version['MID'] > 2: |
|
277 |
self.__ComponentRoot = self.__SystemDefinitionBase |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
278 |
elif self.__Version['MAJOR'] == 2 or self.__Version['MAJOR'] == 3: |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
279 |
# 2.0.x and 3.0.0 formats support SOURCEROOT or SRCROOT as an environment specified base - we respect this, unless |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
280 |
# explicitly overridden on the command line |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
281 |
if os.environ.has_key('SRCROOT'): |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
282 |
self.__ComponentRoot = generic_path.Path(os.environ['SRCROOT']) |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
283 |
elif os.environ.has_key('SOURCEROOT'): |
3 | 284 |
self.__ComponentRoot = generic_path.Path(os.environ['SOURCEROOT']) |
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
285 |
|
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
286 |
if self.__SystemDefinitionBase and self.__SystemDefinitionBase != ".": |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
287 |
self.__ComponentRoot = self.__SystemDefinitionBase |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
288 |
if os.environ.has_key('SRCROOT'): |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
289 |
self.__Logger.Info("Command line specified System Definition file base \'%s\' overriding environment SRCROOT \'%s\'", self.__SystemDefinitionBase, os.environ['SRCROOT']) |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
290 |
elif os.environ.has_key('SOURCEROOT'): |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
291 |
self.__Logger.Info("Command line specified System Definition file base \'%s\' overriding environment SOURCEROOT \'%s\'", self.__SystemDefinitionBase, os.environ['SOURCEROOT']) |
3 | 292 |
else: |
293 |
self.__Logger.Error("Cannot process schema version %s of file %s", version.string, self.__SystemDefinitionFile) |
|
294 |
return False |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
295 |
|
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
296 |
if self.__Version['MAJOR'] >= 3: |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
297 |
# id is the unique identifier for 3.0 and later schema |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
298 |
self.__IdAttribute = "id" |
3 | 299 |
|
300 |
return True |
|
301 |
||
302 |
def __Parse(self): |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
303 |
# 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 |
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
304 |
# the <layer> context of captured "bldFile" attributes is recorded as we go |
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
305 |
# For 3.0 and later, process any architectural topmost element, use the topmost element with an id as the "layer" |
3 | 306 |
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
|
307 |
if child.localName in ["systemModel", "layer", "package", "collection", "component"]: |
3 | 308 |
self.__ProcessSystemModelElement(child) |
309 |
||
310 |
def __CreateComponent(self, aBldInfFile, aUnitElement): |
|
311 |
# take a resolved bld.inf file and associated <unit/> element and returns a populated Component object |
|
312 |
containers = {} |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
313 |
self.__GetElementContainers(aUnitElement, containers) |
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
314 |
layer = self.__GetEffectiveLayer(aUnitElement) |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
315 |
component = SystemModelComponent(aBldInfFile, layer, containers, self.__SystemDefinitionFile, self.__SystemDefinitionBase, self.__Version) |
3 | 316 |
|
317 |
return component |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
318 |
|
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
319 |
def __GetEffectiveLayer(self, aElement): |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
320 |
#' 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 |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
321 |
# never call this on the root element |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
322 |
if aElement.parentNode.hasAttribute(self.__IdAttribute): |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
323 |
return self.__GetEffectiveLayer(aElement.parentNode) |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
324 |
elif aElement.hasAttribute(self.__IdAttribute): |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
325 |
return aElement.getAttribute(self.__IdAttribute) |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
326 |
return "" |
3 | 327 |
|
328 |
def __GetElementContainers(self, aElement, aContainers): |
|
329 |
# take a <unit/> element and creates a type->name dictionary of all of its parent containers |
|
330 |
# We're only interested in parent nodes if they're not the top-most node |
|
331 |
if aElement.parentNode.parentNode: |
|
332 |
parent = aElement.parentNode |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
333 |
name = parent.getAttribute(self.__IdAttribute) |
3 | 334 |
|
335 |
if name: |
|
336 |
aContainers[parent.tagName] = name |
|
337 |
||
338 |
self.__GetElementContainers(parent, aContainers) |
|
339 |
||
340 |
def __ProcessSystemModelElement(self, aElement): |
|
341 |
"""Search for XML <unit/> elements with 'bldFile' attributes and resolve concrete bld.inf locations |
|
342 |
with an appreciation of different schema versions.""" |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
343 |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
344 |
# 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
|
345 |
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
|
346 |
currentLayer = aElement.getAttribute(self.__IdAttribute) |
3 | 347 |
|
348 |
if not self.__LayerDetails.has_key(currentLayer): |
|
349 |
self.__LayerDetails[currentLayer] = [] |
|
350 |
||
351 |
if not currentLayer in self.__LayerList: |
|
352 |
self.__LayerList.append(currentLayer) |
|
353 |
||
354 |
elif aElement.tagName == "unit" and aElement.hasAttributes(): |
|
355 |
bldFileValue = aElement.getAttribute("bldFile") |
|
356 |
||
357 |
if bldFileValue: |
|
358 |
bldInfRoot = self.__ComponentRoot |
|
359 |
||
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
360 |
if self.__Version['MAJOR'] == 1: |
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
361 |
# version 1.x schema paths can use DOS slashes |
3 | 362 |
bldFileValue = raptor_utilities.convertToUnixSlash(bldFileValue) |
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
363 |
elif self.__Version['MAJOR'] >= 2: |
3 | 364 |
# version 2.x.x schema paths are subject to a "root" attribute off-set, if it exists |
365 |
rootValue = aElement.getAttribute("root") |
|
366 |
||
367 |
if rootValue: |
|
368 |
if os.environ.has_key(rootValue): |
|
369 |
bldInfRoot = generic_path.Path(os.environ[rootValue]) |
|
370 |
else: |
|
371 |
# Assume that this is an error i.e. don't attempt to resolve in relation to SOURCEROOT |
|
372 |
bldInfRoot = None |
|
373 |
self.__Logger.Error("Cannot resolve \'root\' attribute value \"%s\" in %s", rootValue, self.__SystemDefinitionFile) |
|
374 |
return |
|
375 |
||
376 |
group = generic_path.Path(bldFileValue) |
|
377 |
||
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
378 |
if self.__Version['MAJOR'] < 3: |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
379 |
# absolute paths are not changed by root var in 1.x and 2.x |
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
380 |
if not group.isAbsolute() and bldInfRoot: |
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
381 |
group = generic_path.Join(bldInfRoot, group) |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
382 |
else: |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
383 |
# only absolute paths are changed by root var in 3.x |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
384 |
if group.isAbsolute() and bldInfRoot: |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
385 |
group = generic_path.Join(bldInfRoot, group) |
3 | 386 |
|
387 |
bldinf = generic_path.Join(group, "bld.inf").FindCaseless() |
|
388 |
||
389 |
if bldinf == None: |
|
491
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
390 |
# recording layers containing non existent bld.infs |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
391 |
bldinfname = group.GetLocalString() |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
392 |
bldinfname = bldinfname + 'bld.inf' |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
393 |
layer = self.__GetEffectiveLayer(aElement) |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
394 |
if not layer in self.__MissingBldInfs: |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
395 |
self.__MissingBldInfs[layer]=[] |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
396 |
self.__MissingBldInfs[layer].append(bldinfname) |
f60c4282816c
Release note: sf bug 2174: --layer option shows errors when bld.inf missing in another layer
Dean Draper <dean.draper@nokia.com>
parents:
333
diff
changeset
|
397 |
|
3 | 398 |
else: |
399 |
component = self.__CreateComponent(bldinf, aElement) |
|
332
dae2dfe18db2
prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents:
29
diff
changeset
|
400 |
layer = component.GetLayerName() |
3 | 401 |
if layer: |
402 |
self.__LayerDetails[layer].append(component) |
|
403 |
self.__TotalComponents += 1 |
|
404 |
else: |
|
405 |
self.__Logger.Error("No containing layer found for %s in %s", str(bldinf), self.__SystemDefinitionFile) |
|
406 |
||
407 |
# search the sub-elements |
|
408 |
for child in aElement.childNodes: |
|
409 |
if child.nodeType == child.ELEMENT_NODE: |
|
410 |
self.__ProcessSystemModelElement(child) |
|
411 |
||
412 |
||
413 |
# end of the raptor_xml module |