sbsv2/raptor/python/raptor_xml.py
author Dean Draper <dean.draper@nokia.com>
Wed, 05 May 2010 09:48:16 +0100
branchfix
changeset 510 e006d1d3ddc3
parent 491 f60c4282816c
permissions -rw-r--r--
Release note: sf bug 2495: KDLL TARGETTYPEs do not support .def file freezing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     3
# All rights reserved.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     4
# This component and the accompanying materials are made available
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     6
# which accompanies this distribution, and is available
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     8
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     9
# Initial Contributors:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    10
# Nokia Corporation - initial contribution.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    11
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    12
# Contributors:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    15
# raptor_xml module
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    16
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    17
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    18
import os
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    19
import raptor_data
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    20
import raptor_utilities
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    21
import xml.dom.minidom
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    22
import re
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    23
import generic_path
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    24
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    25
# raptor_xml module attributes
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    26
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    27
namespace = "http://symbian.com/xml/build"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    28
xsdVersion = "build/2_0.xsd"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    29
xsdIgnore = "build/666.xsd"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    30
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    31
_constructors = {"alias":raptor_data.Alias,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    32
				 "aliasRef":raptor_data.AliasRef,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    33
				 "append":raptor_data.Append,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    34
				 "env":raptor_data.Env,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    35
				 "group":raptor_data.Group,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    36
				 "groupRef":raptor_data.GroupRef,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    37
				 "interface":raptor_data.Interface,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    38
				 "interfaceRef":raptor_data.InterfaceRef,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    39
				 "param":raptor_data.Parameter,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    40
				 "paramgroup":raptor_data.ParameterGroup,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    41
				 "prepend":raptor_data.Prepend,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    42
				 "set":raptor_data.Set,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    43
				 "spec":raptor_data.Specification,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    44
				 "var":raptor_data.Variant,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    45
				 "varRef":raptor_data.VariantRef}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    46
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    47
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    48
# raptor_xml module classes
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    49
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    50
class XMLError(Exception):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    51
	pass
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    52
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    53
# raptor_xml module functions
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    54
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    55
def Read(Raptor, filename):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    56
	"Read in a Raptor XML document"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    57
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    58
	# try to read and parse the XML file
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    59
	try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    60
		dom = xml.dom.minidom.parse(filename)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    61
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    62
	except: # a whole bag of exceptions can be raised here
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    63
		raise XMLError
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    64
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    65
	# <build> is always the root element
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    66
	build = dom.documentElement
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    67
	objects = []
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    68
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    71
	# ignore the file it matches the "invalid" schema
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    72
	if fileVersion.endswith(xsdIgnore):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    75
	# check that the file matches the expected schema
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    76
	if not fileVersion.endswith(xsdVersion):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    79
	# create a Data Model object from each sub-element
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    80
	for child in build.childNodes:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    81
		if child.namespaceURI == namespace \
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    82
		and child.nodeType == child.ELEMENT_NODE:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    83
			try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    84
				o = XMLtoDataModel(Raptor, child)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    85
				if o is not None:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    86
					objects.append(o)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    87
			except raptor_data.InvalidChildError:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    88
				Raptor.Warn("Invalid element %s in %s", child.localName, filename)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    89
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    90
	# discard the XML
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    91
	dom.unlink()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    92
	return objects
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    93
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    94
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    95
def XMLtoDataModel(Raptor, node):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    96
	"Create a data-model object from an XML element"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    97
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    98
	# look-up a function to create an object from the node name
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    99
	try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   100
		constructor = _constructors[node.localName]
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   101
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   102
	except KeyError:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   103
		Raptor.Warn("Unknown element %s", node.localName)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   104
		return
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   105
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   106
	model = constructor()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   107
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   108
	# deal with the attributes first
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   109
	if node.hasAttributes():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   110
		for i in range(node.attributes.length):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   111
			attribute = node.attributes.item(i)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   112
			try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   113
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   114
				model.SetProperty(attribute.localName, attribute.value)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   115
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   116
			except raptor_data.InvalidPropertyError:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   117
				Raptor.Warn("Can't set attribute %s for element %s",
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   118
							 attribute.localName, node.localName)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   119
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   120
	# add the sub-elements
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   121
	for child in node.childNodes:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   122
		if child.namespaceURI == namespace \
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   123
		and child.nodeType == child.ELEMENT_NODE:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   124
			try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   125
				gc = XMLtoDataModel(Raptor, child)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   126
				if gc is not None:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   127
					model.AddChild(gc)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   128
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   129
			except raptor_data.InvalidChildError:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   130
				Raptor.Warn("Can't add child %s to element %s",
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   131
							 child.localName, node.localName)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   132
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   133
	# only return a valid object (or raise error)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   134
	if model.Valid():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   135
		if model.IsApplicable():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   136
			return model
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   137
		else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   138
			return None
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   139
	else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   140
		raise raptor_data.InvalidChildError
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   141
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   142
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   143
class SystemModelComponent(generic_path.Path):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   144
	"""Path sub-class that wraps up a component bld.inf file with
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   145
	system_definition.xml context information."""
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   148
		generic_path.Path.__init__(self, aBldInfFile.Absolute().path)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   154
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   155
	def GetSystemDefinitionFile(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   156
		return self.__SystemDefinitionFile
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   157
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   158
	def GetSystemDefinitionBase(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   166
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   167
	def GetContainerName(self, aContainerType):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   170
		return ""
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   171
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   172
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   173
class SystemModel(object):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   174
	"""A representation of the SystemModel section of a Symbian system_definition.xml file."""
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   175
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   176
	def __init__(self, aLogger, aSystemDefinitionFile, aSystemDefinitionBase):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   177
		self.__Logger = aLogger
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   178
		self.__SystemDefinitionFile = aSystemDefinitionFile.GetLocalString()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   182
		self.__ComponentRoot = ""
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   183
		self.__TotalComponents = 0
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   184
		self.__LayerList = []
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   187
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   188
		self.__DOM = None
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   189
		self.__SystemDefinitionElement = None
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   190
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   191
		if self.__Read():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   192
			if self.__Validate():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   193
				self.__Parse()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   194
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   195
		if self.__DOM:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   196
			self.__DOM.unlink()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   197
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   198
	def HasLayer(self, aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   199
		return aLayer in self.__LayerList
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   200
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   201
	def GetLayerNames(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   202
		return self.__LayerList
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   203
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   204
	def GetLayerComponents(self, aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   205
		if not self.HasLayer(aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   206
			self.__Logger.Error("System Definition layer \"%s\" does not exist in %s", aLayer, self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   207
			return []
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   208
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   209
		return self.__LayerDetails[aLayer]
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   210
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   217
		if len(self.GetLayerComponents(aLayer)):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   218
			return True
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   219
		return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   222
	def GetAllComponents(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   223
		components = []
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   224
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   225
		for layer in self.GetLayerNames():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   226
			components.extend(self.GetLayerComponents(layer))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   227
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   228
		return components
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   229
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   230
	def DumpLayerInfo(self, aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   231
		if self.HasLayer(aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   232
			self.__Logger.Info("Found %d bld.inf references in layer \"%s\"", len(self.GetLayerComponents(aLayer)), aLayer)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   233
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   234
	def DumpInfo(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   235
		self.__Logger.Info("Found %d bld.inf references in %s within %d layers:", len(self.GetAllComponents()), self.__SystemDefinitionFile, len(self.GetLayerNames()))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   241
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   242
	def __Read(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   243
		if not os.path.exists(self.__SystemDefinitionFile):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   244
			self.__Logger.Error("System Definition file %s does not exist", self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   245
			return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   246
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   247
		self.__Logger.Info("System Definition file %s", self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   248
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   249
		# try to read the XML file
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   250
		try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   251
			self.__DOM = xml.dom.minidom.parse(self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   252
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   253
		except: # a whole bag of exceptions can be raised here
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   254
			self.__Logger.Error("Failed to parse XML file %s", self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   255
			return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   256
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   257
		# <SystemDefinition> is always the root element
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   258
		self.__SystemDefinitionElement = self.__DOM.documentElement
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   259
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   260
		return True
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   261
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   262
	def __Validate(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   263
		# account for different schema versions in processing
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   264
		# old format : version >= 1.3.0
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   265
		# new format : version >= 2.0.0 (assume later versions are compatible...at least for now)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   266
		version = re.match(r'(?P<MAJOR>\d)\.(?P<MID>\d)(\.(?P<MINOR>\d))?', self.__SystemDefinitionElement.getAttribute("schema"))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   267
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   268
		if not version:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   269
			self.__Logger.Error("Cannot determine schema version of XML file %s", self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   270
			return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   271
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   272
		self.__Version['MAJOR'] = int(version.group('MAJOR'))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   273
		self.__Version['MID'] = int(version.group('MID'))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   274
		self.__Version['MINOR'] = int(version.group('MINOR'))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   275
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   276
		if self.__Version['MAJOR'] == 1 and self.__Version['MID'] > 2:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   292
		else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   293
			self.__Logger.Error("Cannot process schema version %s of file %s", version.string, self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   299
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   300
		return True
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   301
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   308
				self.__ProcessSystemModelElement(child)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   309
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   310
	def __CreateComponent(self, aBldInfFile, aUnitElement):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   311
		# take a resolved bld.inf file and associated <unit/> element and returns a populated Component object
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   316
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   327
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   328
	def __GetElementContainers(self, aElement, aContainers):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   329
		# take a <unit/> element and creates a type->name dictionary of all of its parent containers
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   330
		# We're only interested in parent nodes if they're not the top-most node
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   331
		if aElement.parentNode.parentNode:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   334
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   335
			if name:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   336
				aContainers[parent.tagName] = name
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   337
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   338
			self.__GetElementContainers(parent, aContainers)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   339
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   340
	def __ProcessSystemModelElement(self, aElement):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   341
		"""Search for XML <unit/> elements with 'bldFile' attributes and resolve concrete bld.inf locations
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   347
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   348
			if not self.__LayerDetails.has_key(currentLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   349
				self.__LayerDetails[currentLayer] = []
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   350
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   351
			if not currentLayer in self.__LayerList:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   352
				self.__LayerList.append(currentLayer)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   353
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   354
		elif aElement.tagName == "unit" and aElement.hasAttributes():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   355
			bldFileValue = aElement.getAttribute("bldFile")
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   356
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   357
			if bldFileValue:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   358
				bldInfRoot = self.__ComponentRoot
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   364
					# version 2.x.x schema paths are subject to a "root" attribute off-set, if it exists
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   365
					rootValue = aElement.getAttribute("root")
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   366
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   367
					if rootValue:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   368
						if os.environ.has_key(rootValue):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   369
							bldInfRoot = generic_path.Path(os.environ[rootValue])
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   370
						else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   371
							# Assume that this is an error i.e. don't attempt to resolve in relation to SOURCEROOT
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   372
							bldInfRoot = None
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   373
							self.__Logger.Error("Cannot resolve \'root\' attribute value \"%s\" in %s", rootValue, self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   374
							return
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   375
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   376
				group = generic_path.Path(bldFileValue)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   386
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   387
				bldinf = generic_path.Join(group, "bld.inf").FindCaseless()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   388
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   398
				else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   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
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   401
					if layer:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   402
						self.__LayerDetails[layer].append(component)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   403
						self.__TotalComponents += 1
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   404
					else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   405
						self.__Logger.Error("No containing layer found for %s in %s", str(bldinf), self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   406
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   407
		# search the sub-elements
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   408
		for child in aElement.childNodes:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   409
			if child.nodeType == child.ELEMENT_NODE:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   410
				self.__ProcessSystemModelElement(child)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   411
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   412
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   413
# end of the raptor_xml module