qtecomplugins/supplements/xqecom/xqecom.py
changeset 8 71781823f776
child 14 6fbed849b4f4
equal deleted inserted replaced
5:453da2cfceef 8:71781823f776
       
     1 #!/usr/bin/env python
       
     2 """
       
     3 This is part of qtextensions/qtecomplugins extension. It pregenerates few files needed during compilation of ecom plugins.
       
     4 Those includes:
       
     5   * registration resource file
       
     6   * stubs
       
     7   * pkg file
       
     8   * iby file
       
     9 """
       
    10 
       
    11 import logging
       
    12 import datetime
       
    13 import sys
       
    14 from optparse import OptionParser
       
    15 
       
    16 class Generator(object):
       
    17 	def __init__(self, args):
       
    18 		if len(args)==5:
       
    19 			if args[2]=="":
       
    20 				interfaceValue = args[0]+".dll"
       
    21 			else:
       
    22 				interfaceValue = args[2]
       
    23 			self.args = {
       
    24 			'target': args[0],
       
    25 			'uid3': args[1],
       
    26 			'interface': interfaceValue,
       
    27 			'configuration': args[3],
       
    28 			'configurationFile': args[4],
       
    29 			'timestamp': datetime.datetime.now()
       
    30 			}
       
    31 		else:
       
    32 			logging.fatal("illegal number of arguments: %d" % len(args))
       
    33 			sys.exit(1)
       
    34 	def generate(self):
       
    35 		logging.warning("%s is not generating anything useful" % self.__class__.__name__)
       
    36 	def strip(self, s):
       
    37 		l = len(s) - len(s.lstrip())
       
    38 		def stripOrNot(x):
       
    39 			if l>=len(x):
       
    40 				return x
       
    41 			else:
       
    42 				return x[l:]
       
    43 		return ''.join(map(stripOrNot, s.splitlines(True)))
       
    44 		
       
    45 class RssGenerator(Generator):
       
    46 	"""
       
    47 	RSS generator.
       
    48 	"""
       
    49 	def __init__(self, args):
       
    50 		super(self.__class__, self).__init__(args)
       
    51 	def generate(self):
       
    52 		fileName = self.args['target'] + ".rss"
       
    53 		dllName = self.args['target'] + ".dll"
       
    54 		
       
    55 		if self.args['interface'] == "":
       
    56 			self.args['interface'] = dllName
       
    57 
       
    58 		if self.args['configurationFile'] != "":
       
    59 			opaqueDataFile = file(self.args['configurationFile'])
       
    60 			self.args['opaqueData'] = ((''.join(opaqueDataFile.readlines())).replace('\n', '').replace('"', '\\"'))[:255];
       
    61 		else:
       
    62 			self.args['opaqueData'] = self.args['configuration']
       
    63 
       
    64 		output = file(fileName, "w")
       
    65 		header = """\
       
    66 		// ==============================================================================
       
    67 		// Generated by xqecom on %(timestamp)s
       
    68 		// This file is generated by xqecom and should not be modified by the user.
       
    69 		// Name        : %(target)s.rss
       
    70 		// Part of     : 
       
    71 		// Description : Fixes common plugin symbols to known ordinals
       
    72 		// Version     : 
       
    73 		// ==============================================================================
       
    74 		
       
    75 		
       
    76 		#include <registryinfov2.rh>
       
    77 		
       
    78 		#include <xqtecom.hrh>
       
    79 		
       
    80 		#include <ecomstub_%(uid3)s.hrh>
       
    81 		
       
    82 		RESOURCE REGISTRY_INFO theInfo
       
    83 		{
       
    84 		resource_format_version = RESOURCE_FORMAT_VERSION_2;
       
    85 		dll_uid = %(uid3)s;
       
    86 		interfaces =
       
    87 			{
       
    88 			INTERFACE_INFO
       
    89 				{
       
    90 				interface_uid = KQtEcomPluginInterfaceUID;
       
    91 				implementations =
       
    92 					{
       
    93 					IMPLEMENTATION_INFO
       
    94 						{
       
    95 						implementation_uid = KQtEcomPluginImplementationUid;
       
    96 						version_no = 1;
       
    97 						display_name = "%(target)s.dll";
       
    98 						// SERVICE.INTERFACE_NAME
       
    99 						default_data = "%(interface)s";
       
   100 						// SERVICE.CONFIGURATION
       
   101 						opaque_data = "%(opaqueData)s";
       
   102 						}
       
   103 					};
       
   104 				}
       
   105 			};
       
   106 		} 		
       
   107 		"""
       
   108 		
       
   109 		output.write(self.strip(header) % self.args )
       
   110 		
       
   111 
       
   112 class PkgGenerator(Generator):
       
   113 	"""
       
   114 	PKG generator.
       
   115 	"""
       
   116 	def __init__(self, args):
       
   117 		super(self.__class__, self).__init__(args)
       
   118 	def generate(self):
       
   119 		content="""\
       
   120 		// ============================================================================
       
   121 		// Generated by xqecom on %(timestamp)s
       
   122 		// This file is generated by xqecom and should not be modified by the user.
       
   123 		// ============================================================================
       
   124 
       
   125 		; Language
       
   126 		&EN
       
   127 
       
   128 		; SIS header: name, uid, version
       
   129 		#{%(target)s},(%(uid3)s),1,0,0
       
   130 
       
   131 		; Localised Vendor name
       
   132 		%%{"Nokia, Qt Software"}
       
   133 
       
   134 		; Unique Vendor name
       
   135 		:"Nokia, Qt Software"
       
   136 
       
   137 		; Dependencies
       
   138 		[0x101F7961],0,0,0,{"S60ProductID"}
       
   139 		[0x102032BE],0,0,0,{"S60ProductID"}
       
   140 		[0x102752AE],0,0,0,{"S60ProductID"}
       
   141 		[0x1028315F],0,0,0,{"S60ProductID"}
       
   142 		(0x2001E61C), 4, 5, 0, {"QtLibs pre-release"}
       
   143 
       
   144 		;files
       
   145 		"\\epoc32\\release\\armv5\\urel\\%(target)s.dll"    - "!:\\sys\\bin\\%(target)s.dll"
       
   146 		"\\epoc32\\data\\Z\\resource\\plugins\\%(target)s.rsc" - "!:\\resource\\plugins\\%(target)s.rsc" 		
       
   147 		"""
       
   148 		
       
   149 		fileName = self.args['target'] + ".pkg"
       
   150 		output = file(fileName, "w")
       
   151 		output.write(self.strip(content) % self.args)
       
   152 	
       
   153 
       
   154 class IbyGenerator(Generator):
       
   155 	"""
       
   156 	IBY generator.
       
   157 	"""
       
   158 	def __init__(self, args):
       
   159 		super(self.__class__, self).__init__(args)
       
   160 	def generate(self):
       
   161 		self.args['TARGET']=self.args['target'].upper()
       
   162 		content="""\
       
   163 		// ============================================================================
       
   164 		// Generated by xqecom on %(timestamp)s
       
   165 		// This file is generated by xqecom and should not be modified by the user.
       
   166 		// ============================================================================
       
   167 
       
   168 		#ifndef %(TARGET)s_IBY
       
   169 		#define %(TARGET)s_IBY
       
   170 
       
   171 		#include <bldvariant.hrh>
       
   172 
       
   173 		ECOM_PLUGIN( %(target)s.dll, %(target)s.rsc )
       
   174 
       
   175 		#endif //%(TARGET)s_IBY 		
       
   176 		"""
       
   177 		
       
   178 		fileName = self.args['target'] + ".iby"
       
   179 		output = file(fileName, "w")
       
   180 		output.write(self.strip(content) % self.args)
       
   181 	
       
   182 class StubsGenerator(Generator):
       
   183 	"""
       
   184 	Stubs generator.
       
   185 	"""
       
   186 	def __init__(self, args):
       
   187 		super(self.__class__, self).__init__(args)
       
   188 	def generate(self):
       
   189 		contentHrh="""\
       
   190 		// ============================================================================
       
   191 		// Generated by xqecom on %(timestamp)s
       
   192 		// This file is generated by xqecom and should not be modified by the user.
       
   193 		// ============================================================================
       
   194 
       
   195 		#ifndef ECOMSTUB_%(uid3)s_HRH
       
   196 		#define ECOMSTUB_%(uid3)s_HRH
       
   197 		#define KQtEcomPluginImplementationUid %(uid3)s
       
   198 		#endif //ECOMSTUB_%(uid3)s_HRH 
       
   199 		"""
       
   200 
       
   201 		fileName = "ecomstub_" + self.args['uid3'] + ".hrh"
       
   202 		output = file(fileName, "w")
       
   203 		output.write(self.strip(contentHrh) % self.args)
       
   204 
       
   205 		contentCpp="""\
       
   206 		// ============================================================================
       
   207 		// Generated by xqecom on %(timestamp)s
       
   208 		// This file is generated by xqecom and should not be modified by the user.
       
   209 		// ============================================================================
       
   210 
       
   211 		#include <xqplugin.h>
       
   212 		#include <ecomstub_%(uid3)s.hrh>
       
   213 		#include <ecom/implementationproxy.h>
       
   214 		XQ_PLUGIN_ECOM_HEADER(%(target)s)
       
   215 		const TImplementationProxy implementationTable[] = 
       
   216 			{
       
   217 			IMPLEMENTATION_PROXY_ENTRY(%(uid3)s, C%(target)sFactory::NewL)
       
   218 			};
       
   219 
       
   220 		EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   221 			{
       
   222 			aTableCount = sizeof( implementationTable ) / sizeof( TImplementationProxy );
       
   223 			return implementationTable;
       
   224 			} 
       
   225 		"""		
       
   226 
       
   227 		fileName = "ecomstub_" + self.args['uid3'] + ".cpp"
       
   228 		output = file(fileName, "w")
       
   229 		output.write(self.strip(contentCpp) % self.args)
       
   230 	
       
   231 
       
   232 def runGenerators(generators, args):
       
   233 	for g in generators:
       
   234 		logging.debug("about to run generator: %s" % g.__name__)
       
   235 		try:
       
   236 			instance = g(args)
       
   237 			instance.generate()
       
   238 		except Exception, ex:
       
   239 			logging.error("Exception in %s: '%s'" % (g.__name__, ex))
       
   240 			logging.error("Exception in %s: '%s'" % (g.__name__, ex))
       
   241 			raise
       
   242 
       
   243 if (__name__=="__main__"):
       
   244 	arguments = sys.argv[1:]
       
   245 
       
   246 	op = OptionParser()
       
   247 	op.usage="%prog [options] [<target> <uid3> <interface> <configuration> <configurationFile>]"
       
   248 	
       
   249 #	op.add_option("-t", "--target", help="plugin target name")
       
   250 #	op.add_option("-u", "--uid3", help="plugin uid3")
       
   251 #	op.add_option("-i", "--interface", help="interface name")
       
   252 #	op.add_option("-c", "--configuration", help="configuration")
       
   253 #	op.add_option("-f", "--configuration-file", help="configuration file")
       
   254 	
       
   255 	(options, args) = op.parse_args(arguments)
       
   256 	
       
   257 	generators = [RssGenerator, PkgGenerator, IbyGenerator, StubsGenerator]
       
   258 	runGenerators(generators, args)
       
   259