summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorChris Larson <kergoth@openedhand.com>2006-08-07 10:24:05 +0000
committerChris Larson <kergoth@openedhand.com>2006-08-07 10:24:05 +0000
commit0c8c1405192bba2bbc93af8f4f927bd9495f99ec (patch)
treef72b5ef7c822a63baa34db67091258bbb491f717 /scripts
parentc7274f6f00ad79ab55e7833c1288247459f78bef (diff)
downloadpoky-0c8c1405192bba2bbc93af8f4f927bd9495f99ec.tar.gz
First pass of the emitter for the jhbuild script.
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@590 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/jhbuild/rewrite.py74
1 files changed, 64 insertions, 10 deletions
diff --git a/scripts/jhbuild/rewrite.py b/scripts/jhbuild/rewrite.py
index 7200a195c6..ecd6444860 100755
--- a/scripts/jhbuild/rewrite.py
+++ b/scripts/jhbuild/rewrite.py
@@ -153,8 +153,10 @@ class Handlers(object):
153 153
154 def metamodule(self, element, parent): 154 def metamodule(self, element, parent):
155 # grab the deps 155 # grab the deps
156 dependlist = [child for child in element if child.tag == "dependencies"] 156 deps = None
157 deps = [self.packagename(dep.attrib.get('package')) for dep in dependlist[0] if child.tag == "dep"] 157 for child in element:
158 if child.tag == 'dependencies':
159 deps = [self.packagename(dep.attrib.get('package')) for dep in child if dep.tag == "dep"]
158 160
159 # create the package 161 # create the package
160 d = bb.data.init() 162 d = bb.data.init()
@@ -193,20 +195,55 @@ class Handlers(object):
193 bb.data.setVar('S', os.path.join('${WORKDIR}', checkoutdir), d) 195 bb.data.setVar('S', os.path.join('${WORKDIR}', checkoutdir), d)
194 196
195 # build class 197 # build class
196 bb.data.setVar('INCLUDES', 'autotools', d) 198 bb.data.setVar('INHERITS', 'autotools', d)
197 bb.data.setVarFlag('INCLUDES', 'operator', '+=', d) 199 bb.data.setVarFlag('INHERITS', 'operator', '+=', d)
198 bb.data.setVar('_handler', 'autotools', d) 200 bb.data.setVar('_handler', 'autotools', d)
199 self.packages.append(d) 201 self.packages.append(d)
200 202
201class Emitter(object): 203class Emitter(object):
202 """ 204 """
203 Class to take a Handlers object after processing and emit the 205 Class which contains a single method for the emission of a bitbake
204 bitbake files from the metadata. It supports either emitting 206 package from the bitbake data produced by a Handlers object.
205 the data as is, using templates based on package name, and using
206 templates based on the name of handler / xml element associated
207 with the package itself.
208 """ 207 """
209 208
209 def __init__(self, filefunc = None, basedir = None):
210 def _defaultfilefunc(package):
211 # return a relative path to the bitbake .bb which will be written
212 return bb.data.getVar('PN', package, 1) + '.bb'
213
214 self.filefunc = filefunc or _defaultfilefunc
215 self.basedir = basedir or os.path.abspath(os.curdir)
216
217 def write(self, package, template = None):
218 # 1) Assemble new file contents in ram, either new from bitbake
219 # metadata, or a combination of the template and that metadata.
220 # 2) Open the path returned by the filefunc + the basedir for writing.
221 # 3) Write the new bitbake data file.
222 fdata = ''
223 if template:
224 f = file(template, 'r')
225 fdata = f.read()
226 f.close()
227
228 for key in bb.data.keys(package):
229 fdata.replace('@@'+key+'@@', bb.data.getVar(key, package))
230 else:
231 for key in bb.data.keys(package):
232 if key == '_handler':
233 continue
234 elif key == 'INHERITS':
235 fdata += 'inherit %s\n' % bb.data.getVar('INHERITS', package)
236 else:
237 oper = bb.data.getVarFlag(key, 'operator', package) or '='
238 fdata += '%s %s "%s"\n' % (key, oper, bb.data.getVar(key, package))
239
240 if not os.path.exists(os.path.join(self.basedir, os.path.dirname(self.filefunc(package)))):
241 os.makedirs(os.path.join(self.basedir, os.path.dirname(self.filefunc(package))))
242
243 out = file(os.path.join(self.basedir, self.filefunc(package)), 'w')
244 out.write(fdata)
245 out.close()
246
210def _test(): 247def _test():
211 msfile = os.path.join(os.path.abspath(os.curdir), 'modulesets', moduleset) 248 msfile = os.path.join(os.path.abspath(os.curdir), 'modulesets', moduleset)
212 tree = ElementTree.ElementTree(file=msfile) 249 tree = ElementTree.ElementTree(file=msfile)
@@ -215,8 +252,25 @@ def _test():
215 handlers = Handlers(msfile) 252 handlers = Handlers(msfile)
216 handlers.handle(elem, None) 253 handlers.handle(elem, None)
217 254
255 def filefunc(package):
256 # return a relative path to the bitbake .bb which will be written
257 src_uri = bb.data.getVar('SRC_URI', package, 1)
258 filename = bb.data.getVar('PN', package, 1) + '.bb'
259 if not src_uri:
260 return filename
261 else:
262 substr = src_uri[src_uri.find('xorg/'):]
263 subdirlist = substr.split('/')[:2]
264 subdir = '-'.join(subdirlist)
265 return os.path.join(subdir, filename)
266
267 emitter = Emitter(filefunc)
218 for package in handlers.packages: 268 for package in handlers.packages:
219 print(bb.data.getVar('PN', package)) 269 template = os.path.join(emitter.filefunc(package), '.in')
270 if os.path.exists(template):
271 emitter.write(package, template)
272 else:
273 emitter.write(package)
220 274
221if __name__ == "__main__": 275if __name__ == "__main__":
222 _test() 276 _test()