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 x = x + '\n' |
|
40 if l>=len(x): |
|
41 return x |
|
42 else: |
|
43 return x[l:] |
|
44 return ''.join(map(stripOrNot, s.splitlines(False))) |
|
45 |
|
46 class RssGenerator(Generator): |
|
47 """ |
|
48 RSS generator. |
|
49 """ |
|
50 def __init__(self, args): |
|
51 super(self.__class__, self).__init__(args) |
|
52 def generate(self): |
|
53 fileName = self.args['target'] + ".rss" |
|
54 dllName = self.args['target'] + ".dll" |
|
55 |
|
56 if self.args['interface'] == "": |
|
57 self.args['interface'] = dllName |
|
58 |
|
59 if self.args['configurationFile'] != "": |
|
60 opaqueDataFile = file(self.args['configurationFile']) |
|
61 self.args['opaqueData'] = ((''.join(opaqueDataFile.readlines())).replace('\n', '').replace('"', '\\"'))[:255]; |
|
62 else: |
|
63 self.args['opaqueData'] = self.args['configuration'] |
|
64 |
|
65 output = file(fileName, "w") |
|
66 header = """\ |
|
67 // ============================================================================== |
|
68 // Generated by xqecom on %(timestamp)s |
|
69 // This file is generated by xqecom and should not be modified by the user. |
|
70 // Name : %(target)s.rss |
|
71 // Part of : |
|
72 // Description : Fixes common plugin symbols to known ordinals |
|
73 // Version : |
|
74 // ============================================================================== |
|
75 |
|
76 |
|
77 #include <registryinfov2.rh> |
|
78 |
|
79 #include <xqtecom.hrh> |
|
80 |
|
81 #include <ecomstub_%(uid3)s.hrh> |
|
82 |
|
83 RESOURCE REGISTRY_INFO theInfo |
|
84 { |
|
85 resource_format_version = RESOURCE_FORMAT_VERSION_2; |
|
86 dll_uid = %(uid3)s; |
|
87 interfaces = |
|
88 { |
|
89 INTERFACE_INFO |
|
90 { |
|
91 interface_uid = KQtEcomPluginInterfaceUID; |
|
92 implementations = |
|
93 { |
|
94 IMPLEMENTATION_INFO |
|
95 { |
|
96 implementation_uid = KQtEcomPluginImplementationUid; |
|
97 version_no = 1; |
|
98 display_name = "%(target)s.dll"; |
|
99 // SERVICE.INTERFACE_NAME |
|
100 default_data = "%(interface)s"; |
|
101 // SERVICE.CONFIGURATION |
|
102 opaque_data = "%(opaqueData)s"; |
|
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 fileName = self.args['target'] + ".pkg" |
|
149 output = file(fileName, "w") |
|
150 output.write(self.strip(content) % self.args) |
|
151 |
|
152 |
|
153 class IbyGenerator(Generator): |
|
154 """ |
|
155 IBY generator. |
|
156 """ |
|
157 def __init__(self, args): |
|
158 super(self.__class__, self).__init__(args) |
|
159 def generate(self): |
|
160 self.args['TARGET']=self.args['target'].upper() |
|
161 content="""\ |
|
162 // ============================================================================ |
|
163 // Generated by xqecom on %(timestamp)s |
|
164 // This file is generated by xqecom and should not be modified by the user. |
|
165 // ============================================================================ |
|
166 |
|
167 #ifndef %(TARGET)s_IBY |
|
168 #define %(TARGET)s_IBY |
|
169 |
|
170 #include <bldvariant.hrh> |
|
171 |
|
172 ECOM_PLUGIN( %(target)s.dll, %(target)s.rsc ) |
|
173 |
|
174 #endif //%(TARGET)s_IBY""" |
|
175 |
|
176 fileName = self.args['target'] + ".iby" |
|
177 output = file(fileName, "w") |
|
178 output.write(self.strip(content) % self.args) |
|
179 |
|
180 class StubsGenerator(Generator): |
|
181 """ |
|
182 Stubs generator. |
|
183 """ |
|
184 def __init__(self, args): |
|
185 super(self.__class__, self).__init__(args) |
|
186 def generate(self): |
|
187 contentHrh="""\ |
|
188 // ============================================================================ |
|
189 // Generated by xqecom on %(timestamp)s |
|
190 // This file is generated by xqecom and should not be modified by the user. |
|
191 // ============================================================================ |
|
192 |
|
193 #ifndef ECOMSTUB_%(uid3)s_HRH |
|
194 #define ECOMSTUB_%(uid3)s_HRH |
|
195 #define KQtEcomPluginImplementationUid %(uid3)s |
|
196 #endif //ECOMSTUB_%(uid3)s_HRH""" |
|
197 |
|
198 fileName = "ecomstub_" + self.args['uid3'] + ".hrh" |
|
199 output = file(fileName, "w") |
|
200 output.write(self.strip(contentHrh) % self.args) |
|
201 |
|
202 contentCpp="""\ |
|
203 // ============================================================================ |
|
204 // Generated by xqecom on %(timestamp)s |
|
205 // This file is generated by xqecom and should not be modified by the user. |
|
206 // ============================================================================ |
|
207 |
|
208 #include <xqplugin.h> |
|
209 #include <ecomstub_%(uid3)s.hrh> |
|
210 #include <ecom/implementationproxy.h> |
|
211 XQ_PLUGIN_ECOM_HEADER(%(target)s) |
|
212 const TImplementationProxy implementationTable[] = |
|
213 { |
|
214 IMPLEMENTATION_PROXY_ENTRY(%(uid3)s, C%(target)sFactory::NewL) |
|
215 }; |
|
216 |
|
217 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
218 { |
|
219 aTableCount = sizeof( implementationTable ) / sizeof( TImplementationProxy ); |
|
220 return implementationTable; |
|
221 }""" |
|
222 |
|
223 fileName = "ecomstub_" + self.args['uid3'] + ".cpp" |
|
224 output = file(fileName, "w") |
|
225 output.write(self.strip(contentCpp) % self.args) |
|
226 |
|
227 |
|
228 def runGenerators(generators, args): |
|
229 for g in generators: |
|
230 logging.debug("about to run generator: %s" % g.__name__) |
|
231 try: |
|
232 instance = g(args) |
|
233 instance.generate() |
|
234 except Exception, ex: |
|
235 logging.error("Exception in %s: '%s'" % (g.__name__, ex)) |
|
236 logging.error("Exception in %s: '%s'" % (g.__name__, ex)) |
|
237 raise |
|
238 |
|
239 if (__name__=="__main__"): |
|
240 arguments = sys.argv[1:] |
|
241 |
|
242 op = OptionParser() |
|
243 op.usage="%prog [options] [<target> <uid3> <interface> <configuration> <configurationFile>]" |
|
244 |
|
245 # op.add_option("-t", "--target", help="plugin target name") |
|
246 # op.add_option("-u", "--uid3", help="plugin uid3") |
|
247 # op.add_option("-i", "--interface", help="interface name") |
|
248 # op.add_option("-c", "--configuration", help="configuration") |
|
249 # op.add_option("-f", "--configuration-file", help="configuration file") |
|
250 |
|
251 (options, args) = op.parse_args(arguments) |
|
252 |
|
253 generators = [RssGenerator, PkgGenerator, IbyGenerator, StubsGenerator] |
|
254 runGenerators(generators, args) |
|
255 |
|