refactoring for --query wip
authorRichard Taylor <richard.i.taylor@nokia.com>
Wed, 28 Apr 2010 16:46:44 +0100
branchwip
changeset 499 cad3b96a4fb1
parent 498 564986768b79
child 500 69637e02a1ce
refactoring for --query
sbsv2/raptor/lib/config/gcc.xml
sbsv2/raptor/lib/config/winscw.xml
sbsv2/raptor/python/raptor_api.py
sbsv2/raptor/test/config/api.xml
sbsv2/raptor/test/smoke_suite/query_cli.py
--- a/sbsv2/raptor/lib/config/gcc.xml	Tue Apr 27 16:46:48 2010 +0100
+++ b/sbsv2/raptor/lib/config/gcc.xml	Wed Apr 28 16:46:44 2010 +0100
@@ -77,7 +77,7 @@
 		<set name='RELEASEPATH' value='$(EPOCROOT)/epoc32/release/tools2$$(TOOLPLATFORMDIR)'/>
 	</var>
 
-	<var name="tools2_deb" extends="tools2_base">
+	<var name="t_deb">
 		<set name='TOOLSPATH' value=''/> <!-- do not install -->
 		<set name='VARIANTTYPE' value='deb'/>
 
@@ -85,8 +85,9 @@
 		<append name='CDEFS' value='_DEBUG'/>
 		<append name='RELEASEPATH' value='/deb' separator=''/>
 	</var>
-
-	<var name="tools2_rel" extends="tools2_base">
+	<alias name="tools2_deb" meaning="tools2_base.t_deb"/>
+	
+	<var name="t_rel">
 		<set name='TOOLSPATH' value='$(EPOCTOOLS)'/> <!-- install -->
 		<set name='VARIANTTYPE' value='rel'/>
 
@@ -94,10 +95,11 @@
 		<append name='CDEFS' value='NDEBUG'/>
 		<append name='RELEASEPATH' value='/rel' separator=''/>
 	</var>
-
+	<alias name="tools2_rel" meaning="tools2_base.t_rel"/>
+	
 	<group name="tools2">
-		<varRef ref='tools2_rel'/>
-		<varRef ref='tools2_deb'/>
+		<aliasRef ref='tools2_rel'/>
+		<aliasRef ref='tools2_deb'/>
 	</group>
 
 </build>
--- a/sbsv2/raptor/lib/config/winscw.xml	Tue Apr 27 16:46:48 2010 +0100
+++ b/sbsv2/raptor/lib/config/winscw.xml	Wed Apr 28 16:46:44 2010 +0100
@@ -127,7 +127,7 @@
 		<set name="PLATMACROS.LINUX" value="$(PLATMACROS.WINDOWS)"/>
 	</var>
 
-	<var name="winscw_udeb" extends="winscw_base">
+	<var name="win_udeb">
 		<set name="FULLVARIANTPATH" value="winscw/udeb"/>
 		<set name="VARIANTTYPE" value="udeb"/>
 
@@ -135,17 +135,19 @@
 		<append name="CFLAGS" value="-g -O0 -inline off"/>
 		<append name="LFLAGS" value="-g"/>
 	</var>
-
-	<var name="winscw_urel" extends="winscw_base">
+	<alias name="winscw_udeb" meaning="winscw_base.win_udeb"/>
+	
+	<var name="win_urel">
 		<set name="FULLVARIANTPATH" value="winscw/urel"/>
 		<set name="VARIANTTYPE" value="urel"/>
 
 		<append name="CDEFS" value="NDEBUG"/>
 		<append name="CFLAGS" value="-O4,s"/>
 	</var>
-
+	<alias name="winscw_urel" meaning="winscw_base.win_urel"/>
+	
 	<group name="winscw">
-		<varRef ref="winscw_urel"/>
-		<varRef ref="winscw_udeb"/>
+		<aliasRef ref="winscw_urel"/>
+		<aliasRef ref="winscw_udeb"/>
 	</group>
 </build>
--- a/sbsv2/raptor/python/raptor_api.py	Tue Apr 27 16:46:48 2010 +0100
+++ b/sbsv2/raptor/python/raptor_api.py	Wed Apr 28 16:46:44 2010 +0100
@@ -23,25 +23,41 @@
 	"""object to return values from API calls.
 	"""
 	def __init__(self, text=""):
-		self.reply_text = text
+		self.text = text
 	
 	def __str__(self):
 		name = type(self).__name__.lower()
 		
-		str = "<" + name
-		end = "/>\n"
+		string = "<" + name
+		children = []
+		longend = False
 		
 		for attribute,value in self.__dict__.items():
-			if attribute != "reply_text":
-				str += " %s='%s'" % (attribute, value)
+			if attribute != "text":
+				if isinstance(value, Reply):
+					children.append(value)
+				else:
+					string += " %s='%s'" % (attribute, value)
+		
+		if children or self.text:
+			string += ">"
+			longend = True
+		
+		if self.text:
+			string += self.text
 		
-		if self.reply_text:
-			str += ">" + self.reply_text
-			end = "</%s>\n" % name
+		if children:
+			string += "\n"
+				
+		for c in children:
+			string += str(c)
 			
-		str += end
+		if longend:
+			string += "</%s>\n" % name
+		else:	
+			string += "/>\n"
 		
-		return str
+		return string
 
 class Alias(Reply):
 	pass
@@ -125,38 +141,59 @@
 		dot-separated list of variants. For example "armv5_urel" or
 		"armv5_urel.savespace.vasco".
 		"""
-		
-		r = Config()
-		
 		names = name.split(".")
 		if names[0] in self.__raptor.cache.aliases:
 			x = self.__raptor.cache.FindNamedAlias(names[0])
 			
 			if len(names) > 1:
-				r.fullname = x.meaning + "." + ".".join(names[1:])
+				fullname = x.meaning + "." + ".".join(names[1:])
 			else:
-				r.fullname = x.meaning
+				fullname = x.meaning
 				
 		elif names[0] in self.__raptor.cache.variants:
-			r.fullname = name
+			fullname = name
 			
 		else:
 			raise BadQuery("'%s' is not an alias or a variant" % names[0])
 		
+		# create an evaluator for the named configuration
 		tmp = raptor_data.Alias("tmp")
-		tmp.SetProperty("meaning", r.fullname)
+		tmp.SetProperty("meaning", fullname)
 		
 		units = tmp.GenerateBuildUnits(self.__raptor.cache)
 		evaluator = self.__raptor.GetEvaluator(None, units[0])
 		
+		# get the outputpath
+		# this is messy as some configs construct the path inside the FLM
+		# rather than talking it from the XML: usually because of some
+		# conditional logic... but maybe some refactoring could avoid that.
 		releasepath = evaluator.Get("RELEASEPATH")
-		fullvariantpath = evaluator.Get("FULLVARIANTPATH")
+		if not releasepath:
+			raise BadQuery("could not get RELEASEPATH for config '%s'" % name)
+		
+		variantplatform = evaluator.Get("VARIANTPLATFORM")
+		varianttype = evaluator.Get("VARIANTTYPE")
+		featurevariantname = evaluator.Get("FEATUREVARIANTNAME")
+		
+		platform = evaluator.Get("TRADITIONAL_PLATFORM")
 		
-		if releasepath and fullvariantpath:
-			r.outputpath = str(generic_path.Join(releasepath, fullvariantpath))
+		if platform == "TOOLS2":
+			outputpath = releasepath.replace("$(TOOLPLATFORMDIR)", "")
 		else:
-			raise BadQuery("could not get outputpath for config '%s'" % name)
+			if not variantplatform:
+				raise BadQuery("could not get VARIANTPLATFORM for config '%s'" % name)
+			
+			if featurevariantname:
+				variantplatform += featurevariantname
+				
+			if not varianttype:
+				raise BadQuery("could not get VARIANTTYPE for config '%s'" % name)
+			
+			outputpath = str(generic_path.Join(releasepath, variantplatform, varianttype))
 		
+		r = Config()
+		r.fullname = fullname
+		r.outputpath = outputpath
 		return r
 		
 	def GetProducts(self):
--- a/sbsv2/raptor/test/config/api.xml	Tue Apr 27 16:46:48 2010 +0100
+++ b/sbsv2/raptor/test/config/api.xml	Wed Apr 28 16:46:44 2010 +0100
@@ -18,7 +18,8 @@
  	
  	<var name="buildme">
  		<set name="RELEASEPATH" value="/home/raptor"/>
- 		<set name="FULLVARIANTPATH" value="foo/bar"/>
+ 		<set name="VARIANTPLATFORM" value="foo"/>
+ 		<set name="VARIANTTYPE" value="bar"/>
  	</var>
  	
  	<var name="foo"/>
--- a/sbsv2/raptor/test/smoke_suite/query_cli.py	Tue Apr 27 16:46:48 2010 +0100
+++ b/sbsv2/raptor/test/smoke_suite/query_cli.py	Wed Apr 28 16:46:44 2010 +0100
@@ -65,6 +65,28 @@
 	t.mustnotmatch_singleline = []
 	t.run()
 	
+	t.name = "query_cli_config_bv"
+	t.command = "sbs --query=config[armv5_urel.test_bv_1] --configpath=test/smoke_suite/test_resources/bv"
+	t.mustmatch_singleline = [
+		"<sbs version='2.*'>",
+		"fullname='arm\.v5\.urel\.rvct._.\.test_bv_1'",
+		"outputpath='.*/epoc32/release/armv5.one/urel'",
+		"</sbs>"
+		]
+	t.mustnotmatch_singleline = []
+	t.run()
+	
+	t.name = "query_cli_config_others"
+	t.command = "sbs --query=config[winscw_urel] --query=config[tools2_rel]"
+	t.mustmatch_singleline = [
+		"<sbs version='2.*'>",
+		"outputpath='.*/epoc32/release/winscw/urel'",
+		"outputpath='.*/epoc32/release/tools2/rel'",
+		"</sbs>"
+		]
+	t.mustnotmatch_singleline = []
+	t.run()
+	
 	t.name = "query_cli_bad"
 	t.command = "sbs --query=nonsense"
 	t.mustmatch_singleline = [