sbsv2/raptor/python/raptor_api.py
author Ross Qin <ross.qin@nokia.com>
Tue, 30 Nov 2010 14:05:41 +0800
changeset 713 7b7f0409fc00
parent 625 a1925fb7753a
permissions -rw-r--r--
merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     1
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     2
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     3
# All rights reserved.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     4
# This component and the accompanying materials are made available
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     6
# which accompanies this distribution, and is available
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     8
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     9
# Initial Contributors:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    11
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    12
# Contributors:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    13
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    14
# Description: 
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    15
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    16
# raptor_api module
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    17
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    18
# Python API for Raptor. External code should interact with Raptor via this
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    19
# module only, as it is the only programatic interface considered public. The
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    20
# command line --query option is also implemented using this module.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    21
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    22
# constants
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    23
ALL = 1
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    24
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    25
# objects
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    26
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    27
class Reply(object):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    28
	"""object to return values from API calls.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    29
	"""
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    30
	def __init__(self, text="", raptor=None):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    31
		self._raptor = raptor
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    32
		self.text = text
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    33
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    34
	def _getEvaluator(self, meaning):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    35
		""" Note: Will pass on Evaluator constructor exceptions """
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    36
		try:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    37
			return self.__evaluator
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    38
		except AttributeError:	
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    39
			# create an evaluator for the named configuration
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    40
			tmp = raptor_data.Alias("tmp")
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    41
			tmp.SetProperty("meaning", meaning)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    42
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    43
			units = tmp.GenerateBuildUnits(self._raptor.cache)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    44
			self.__evaluator = self._raptor.GetEvaluator(None, units[0])
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    45
			return self.__evaluator
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    46
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    47
	def __str__(self):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    48
		name = type(self).__name__.lower()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    49
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    50
		string = "<" + name
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    51
		children = []
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    52
		longend = False
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    53
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    54
		for attribute,value in self.__dict__.items():
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    55
			if attribute != "text" and not attribute.startswith('_'):
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    56
				if isinstance(value, Reply):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    57
					children.append(value)
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    58
				elif isinstance(value, list):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    59
					for item in value:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    60
						if isinstance(item, Reply):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    61
							children.append(item)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    62
						else:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    63
							raise BadReply(str(item)+" is not a Reply object")
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    64
				else:
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    65
					if value != None: # skip attributes whose value is None
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    66
						string += " %s='%s'" % (attribute, value)
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    67
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    68
		if children or self.text:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    69
			string += ">"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    70
			longend = True
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    71
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    72
		if self.text:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    73
			string += self.text
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    74
			children.sort()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    75
			# Note mixing sortable and unsortable lists results in
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    76
			# sort not working, so if you really need your
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    77
			# children to come out in the right order, put them in
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    78
			# a list.  This is only for niceness, where it works.
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    79
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    80
		if children:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    81
			string += "\n"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    82
				
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    83
			for c in children:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    84
				clines = str(c).rstrip().split("\n")
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    85
				string += "".join(map(lambda l:"  "+l+"\n",clines))
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    86
			
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    87
		if longend:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    88
			string += "</%s>\n" % name
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    89
		else:	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    90
			string += "/>\n"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    91
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    92
		return string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    93
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    94
	
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    95
class BadReply(Exception):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    96
	pass
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
    97
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    98
class Alias(Reply):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    99
	def __init__(self, name, meaning):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   100
		super(Alias,self).__init__()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   101
		self.name = name
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   102
		self.meaning = meaning
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   103
	
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   104
	def __cmp__(self, other):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   105
		""" Add __cmp__ to enable comparisons between two Alias objects based upon name."""
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   106
		return cmp(self.name, other.name)
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   107
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   108
class Config(Reply):
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   109
	def __init__(self, raptor, name, text = None):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   110
		""" Constructor to create a Config from a user-supplied name.
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   111
		possibly including aliases (but not groups)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   112
		"""
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   113
		super(Config,self).__init__(text, raptor)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   114
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   115
		self.query = name
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   116
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   117
		# Work out the real name
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   118
		names = name.split(".")
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   119
		if names[0] in self._raptor.cache.aliases:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   120
			x = self._raptor.cache.FindNamedAlias(names[0])
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   121
			
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   122
			if len(names) > 1:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   123
				self.meaning = x.meaning + "." + ".".join(names[1:])
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   124
			else:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   125
				self.meaning = x.meaning
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   126
				
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   127
		elif names[0] in self._raptor.cache.variants:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   128
			self.meaning = name
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   129
			
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   130
		else:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   131
			raise BadQuery("'%s' is not an alias or a variant" % names[0])
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   132
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   133
	def resolveOutputPath(self):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   134
		""" Get the outputpath """
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   135
		try:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   136
			evaluator = self._getEvaluator(self.meaning)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   137
			# This is messy as some configs construct the path inside the FLM
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   138
			# rather than talking it from the XML: usually because of some
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   139
			# conditional logic... but maybe some refactoring could avoid that.
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   140
			releasepath = evaluator.Get("RELEASEPATH")
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   141
			if not releasepath:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   142
				raise BadQuery("could not get RELEASEPATH for config '%s'" % self.fullname)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   143
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   144
			variantplatform = evaluator.Get("VARIANTPLATFORM")
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   145
			varianttype = evaluator.Get("VARIANTTYPE")
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   146
			featurevariantname = evaluator.Get("FEATUREVARIANTNAME")
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   147
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   148
			platform = evaluator.Get("TRADITIONAL_PLATFORM")
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   149
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   150
			if platform == "TOOLS2":
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   151
				self.outputpath = releasepath
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   152
			else:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   153
				if not variantplatform:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   154
					raise BadQuery("could not get VARIANTPLATFORM for config '%s'" % self.fullname)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   155
			
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   156
				if featurevariantname:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   157
					variantplatform += featurevariantname
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   158
				
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   159
				if not varianttype:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   160
					raise BadQuery("could not get VARIANTTYPE for config '%s'" % self.fullname)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   161
			
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   162
				self.outputpath = str(generic_path.Join(releasepath, variantplatform, varianttype))
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   163
		except Exception, e: # Unable to determine output path
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   164
			self.text = str(e)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   165
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   166
	def resolveMetadata(self):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   167
		try:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   168
			metadata = self.metadata
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   169
		except AttributeError:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   170
			metadata = MetaData(self.meaning, self._raptor)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   171
			self.metadata = metadata
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   172
			
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   173
		try:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   174
			metadata.resolve()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   175
		except Exception:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   176
			# Evaluator exception hopefully - already handled
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   177
			self.metadata = None
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   178
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   179
	def resolveBuild(self):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   180
		try:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   181
			build = self.build
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   182
		except AttributeError:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   183
			build = Build(self.meaning, self._raptor)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   184
			self.build = build
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   185
			
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   186
		try:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   187
			build.resolve()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   188
		except Exception:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   189
			# Evaluator exception, hopefully - already handled
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   190
			self.build = None
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   191
	
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   192
	def resolveTargettypes(self):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   193
		try:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   194
			build = self.build
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   195
		except AttributeError:	
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   196
			build = Build(self.meaning, self._raptor)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   197
			self.build = build
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   198
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   199
		try:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   200
			build.resolveTargettypes()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   201
		except Exception:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   202
			# Evaluator exception hopefully - already handled
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   203
			self.build = None
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   204
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   205
class MetaData(Reply):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   206
	def __init__(self, meaning, raptor):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   207
		super(MetaData,self).__init__("", raptor)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   208
		self.__meaning = meaning
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   209
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   210
	def resolve(self):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   211
		includepaths = []
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   212
		preincludeheader = ""
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   213
		platmacros = []
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   214
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   215
		evaluator = self._getEvaluator(self.__meaning)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   216
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   217
		# Initialise data and metadata objects
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   218
		buildunits = raptor_data.GetBuildUnits([self.__meaning], self._raptor.cache, self._raptor)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   219
		metareader = raptor_meta.MetaReader(self._raptor, buildunits)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   220
		metadatafile = raptor_meta.MetaDataFile(generic_path.Path("bld.inf"), "cpp", [], None, self._raptor)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   221
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   222
		# There is only one build platform here; obtain the pre-processing include paths,
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   223
		# OS pre-include file, compiler pre-include file and macros.			
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   224
		includepaths = metadatafile.preparePreProcessorIncludePaths(metareader.BuildPlatforms[0])
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   225
		preincludeheader = metareader.BuildPlatforms[0]['VARIANT_HRH']
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   226
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   227
		# Macros arrive as a a list of strings, or a single string, containing definitions of the form "name" or "name=value". 
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   228
		platmacrolist = metadatafile.preparePreProcessorMacros(metareader.BuildPlatforms[0])
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   229
		platmacros.extend(map(lambda macrodef: [macrodef.partition("=")[0], macrodef.partition("=")[2]], platmacrolist))
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   230
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   231
		# Add child elements to appropriate areas if they were calculated
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   232
		if len(includepaths) > 0:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   233
			self.includepaths = map(lambda x: Include(str(x)), includepaths)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   234
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   235
		if preincludeheader != "":
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   236
			self.preincludeheader = PreInclude(str(preincludeheader))
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   237
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   238
		if len(platmacros):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   239
			self.platmacros = map(lambda x: Macro(x[0],x[1]) if x[1] else Macro(x[0]), platmacros)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   240
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   241
class Build(Reply):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   242
	def __init__(self, meaning, raptor):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   243
		super(Build,self).__init__("", raptor)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   244
		self.__meaning = meaning
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   245
		
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   246
	def resolve(self):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   247
		compilerpreincludeheader = ""
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   248
		sourcemacros = []
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   249
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   250
		evaluator = self._getEvaluator(self.__meaning)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   251
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   252
		platform = evaluator.Get("TRADITIONAL_PLATFORM")
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   253
			
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   254
		# Compiler preinclude files may or may not be present, depending on the configuration.
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   255
		if evaluator.Get("PREINCLUDE"):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   256
			compilerpreincludeheader = generic_path.Path(evaluator.Get("PREINCLUDE"))
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   257
			
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   258
		# Macros arrive as a a list of strings, or a single string, containing definitions of the form "name" or "name=value". 
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   259
		# If required, we split to a list, and then processes the constituent parts of the macro.
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   260
		sourcemacrolist = evaluator.Get("CDEFS").split()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   261
		sourcemacros.extend(map(lambda macrodef: [macrodef.partition("=")[0], macrodef.partition("=")[2]], sourcemacrolist))
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   262
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   263
		if platform == "TOOLS2":
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   264
			# Source macros are determined in the FLM for tools2 builds, therefore we have to
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   265
			# mimic the logic here
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   266
			if 'win' in raptor.hostplatform or 'win32' in self.__meaning:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   267
				sourcemacrolist = evaluator.Get("CDEFS.WIN32").split()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   268
			else:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   269
				sourcemacrolist = evaluator.Get("CDEFS.LINUX").split()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   270
			sourcemacros.extend(map(lambda macrodef: [macrodef.partition("=")[0], macrodef.partition("=")[2]], sourcemacrolist))
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   271
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   272
		if len(sourcemacros):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   273
			self.sourcemacros = map(lambda x: Macro(x[0],x[1]) if x[1] else Macro(x[0]), sourcemacros)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   274
			
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   275
		if compilerpreincludeheader:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   276
			self.compilerpreincludeheader = PreInclude(str(compilerpreincludeheader))
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   277
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   278
	def resolveTargettypes(self):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   279
		evaluator = self._getEvaluator(self.__meaning)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   280
		targettypes = evaluator.Get("TARGET_TYPES").split(' ')
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   281
		self.targettypes = []
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   282
		for type in targettypes:
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   283
			self.targettypes.append(TargetType(type))
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   284
		self.targettypes.sort()	
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   285
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   286
class TargetType(Reply):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   287
	def __init__(self, name):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   288
		super(TargetType,self).__init__()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   289
		self.name = name
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   290
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   291
	def __cmp__(self, other):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   292
		return cmp(self.name, other.name)
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   293
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   294
class Product(Reply):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   295
	def __init__(self, name):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   296
		super(Product,self).__init__()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   297
		self.name = name
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   298
	
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   299
	def __cmp__(self, other):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   300
		""" Add __cmp__ to enable comparisons between two Product objects based upon name."""
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   301
		return cmp(self.name, other.name)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   302
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   303
class Include(Reply):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   304
	def __init__(self, path):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   305
		super(Include,self).__init__()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   306
		self.path = path
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   307
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   308
class PreInclude(Reply):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   309
	def __init__(self, file):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   310
		super(PreInclude,self).__init__()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   311
		self.file = file
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   312
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   313
class Macro(Reply):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   314
	def __init__(self, name, value=None):
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   315
		super(Macro,self).__init__()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   316
		self.name = name
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   317
		self.value = value
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   318
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   319
import generic_path
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   320
import raptor
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   321
import raptor_data
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   322
import raptor_meta
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   323
import re
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   324
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   325
class Context(object):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   326
	"""object to contain state information for API calls.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   327
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   328
	For example,
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   329
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   330
	api = raptor_api.Context()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   331
	val = api.getaliases("X")
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   332
	"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   333
	def __init__(self, initialiser=None):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   334
		# this object has a private Raptor object that can either be
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   335
		# passed in or created internally.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   336
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   337
		if initialiser == None:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   338
			self.__raptor = raptor.Raptor()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   339
		else:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   340
			self.__raptor = initialiser
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   341
			
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   342
	def stringquery(self, query):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   343
		"""turn a string into an API call and execute it.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   344
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   345
		This is a convenience method for "lazy" callers.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   346
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   347
		The return value is also converted into a well-formed XML string.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   348
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   349
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   350
		if query == "aliases":
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   351
			aliases = self.getaliases()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   352
			return "".join(map(str, aliases)).strip()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   353
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   354
		elif query == "products":
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   355
			variants = self.getproducts()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   356
			return "".join(map(str, variants)).strip()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   357
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   358
		elif query.startswith("config"):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   359
			match = re.match("config\[(.*)\]", query)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   360
			if match:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   361
				config = self.getconfig(match.group(1))
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   362
				return str(config).strip()
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   363
			else:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   364
				raise BadQuery("syntax error")
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   365
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   366
		raise BadQuery("unknown query")
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   367
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   368
	def getaliases(self, type=""):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   369
		"""extract all aliases of a given type.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   370
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   371
		the default type is "".
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   372
		to get all aliases pass type=ALL
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   373
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   374
		aliases = []
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   375
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   376
		for a in self.__raptor.cache.aliases.values():
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   377
			if type == ALL or a.type == type:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   378
				# copy the members we want to expose
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   379
				aliases.append( Alias(a.name, a.meaning) )
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   380
		aliases.sort()	
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   381
		return aliases
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   382
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   383
	def getconfig(self, name):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   384
		"""extract the values for a given configuration.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   385
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   386
		'name' should be an alias or variant followed optionally by a
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   387
		dot-separated list of variants. For example "armv5_urel" or
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   388
		"armv5_urel.savespace.vasco".
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   389
		"""
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   390
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   391
		config = Config(self.__raptor, name)
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   392
		config.resolveOutputPath()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   393
		config.resolveTargettypes()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   394
		config.resolveMetadata()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   395
		config.resolveBuild()
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   396
		return config		
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   397
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   398
	def getproducts(self):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   399
		"""extract all product variants."""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   400
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   401
		variants = []
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   402
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   403
		for v in self.__raptor.cache.variants.values():
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   404
			if v.type == "product":
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   405
				# copy the members we want to expose
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   406
				variants.append( Product(v.name) )
625
a1925fb7753a sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents: 591
diff changeset
   407
		variants.sort()	
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   408
		return variants
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   409
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   410
class BadQuery(Exception):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   411
	pass
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   412
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   413
# end of the raptor_api module