summaryrefslogtreecommitdiffstats
path: root/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake-dev/lib/bb/parse/parse_py/BBHandler.py')
-rw-r--r--bitbake-dev/lib/bb/parse/parse_py/BBHandler.py410
1 files changed, 0 insertions, 410 deletions
diff --git a/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py b/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py
deleted file mode 100644
index 86fa18ebd2..0000000000
--- a/bitbake-dev/lib/bb/parse/parse_py/BBHandler.py
+++ /dev/null
@@ -1,410 +0,0 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4"""
5 class for handling .bb files
6
7 Reads a .bb file and obtains its metadata
8
9"""
10
11
12# Copyright (C) 2003, 2004 Chris Larson
13# Copyright (C) 2003, 2004 Phil Blundell
14#
15# This program is free software; you can redistribute it and/or modify
16# it under the terms of the GNU General Public License version 2 as
17# published by the Free Software Foundation.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License along
25# with this program; if not, write to the Free Software Foundation, Inc.,
26# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27
28import re, bb, os, sys, time, string
29import bb.fetch, bb.build, bb.utils
30from bb import data, fetch, methodpool
31
32from ConfHandler import include, localpath, obtain, init
33from bb.parse import ParseError
34
35__func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" )
36__inherit_regexp__ = re.compile( r"inherit\s+(.+)" )
37__export_func_regexp__ = re.compile( r"EXPORT_FUNCTIONS\s+(.+)" )
38__addtask_regexp__ = re.compile("addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*")
39__addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" )
40__def_regexp__ = re.compile( r"def\s+(\w+).*:" )
41__python_func_regexp__ = re.compile( r"(\s+.*)|(^$)" )
42__word__ = re.compile(r"\S+")
43
44__infunc__ = ""
45__inpython__ = False
46__body__ = []
47__classname__ = ""
48classes = [ None, ]
49
50# We need to indicate EOF to the feeder. This code is so messy that
51# factoring it out to a close_parse_file method is out of question.
52# We will use the IN_PYTHON_EOF as an indicator to just close the method
53#
54# The two parts using it are tightly integrated anyway
55IN_PYTHON_EOF = -9999999999999
56
57__parsed_methods__ = methodpool.get_parsed_dict()
58
59def supports(fn, d):
60 localfn = localpath(fn, d)
61 return localfn[-3:] == ".bb" or localfn[-8:] == ".bbclass" or localfn[-4:] == ".inc"
62
63def inherit(files, d):
64 __inherit_cache = data.getVar('__inherit_cache', d) or []
65 fn = ""
66 lineno = 0
67 files = data.expand(files, d)
68 for file in files:
69 if file[0] != "/" and file[-8:] != ".bbclass":
70 file = os.path.join('classes', '%s.bbclass' % file)
71
72 if not file in __inherit_cache:
73 bb.msg.debug(2, bb.msg.domain.Parsing, "BB %s:%d: inheriting %s" % (fn, lineno, file))
74 __inherit_cache.append( file )
75 data.setVar('__inherit_cache', __inherit_cache, d)
76 include(fn, file, d, "inherit")
77 __inherit_cache = data.getVar('__inherit_cache', d) or []
78
79
80def finalise(fn, d):
81 data.expandKeys(d)
82 data.update_data(d)
83 anonqueue = data.getVar("__anonqueue", d, 1) or []
84 body = [x['content'] for x in anonqueue]
85 flag = { 'python' : 1, 'func' : 1 }
86 data.setVar("__anonfunc", "\n".join(body), d)
87 data.setVarFlags("__anonfunc", flag, d)
88 from bb import build
89 try:
90 t = data.getVar('T', d)
91 data.setVar('T', '${TMPDIR}/anonfunc/', d)
92 anonfuncs = data.getVar('__BBANONFUNCS', d) or []
93 code = ""
94 for f in anonfuncs:
95 code = code + " %s(d)\n" % f
96 data.setVar("__anonfunc", code, d)
97 build.exec_func("__anonfunc", d)
98 data.delVar('T', d)
99 if t:
100 data.setVar('T', t, d)
101 except Exception, e:
102 bb.msg.debug(1, bb.msg.domain.Parsing, "Exception when executing anonymous function: %s" % e)
103 raise
104 data.delVar("__anonqueue", d)
105 data.delVar("__anonfunc", d)
106 data.update_data(d)
107
108 all_handlers = {}
109 for var in data.getVar('__BBHANDLERS', d) or []:
110 # try to add the handler
111 handler = data.getVar(var,d)
112 bb.event.register(var, handler)
113
114 tasklist = data.getVar('__BBTASKS', d) or []
115 bb.build.add_tasks(tasklist, d)
116
117 bb.event.fire(bb.event.RecipeParsed(fn), d)
118
119
120def handle(fn, d, include = 0):
121 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__
122 __body__ = []
123 __infunc__ = ""
124 __classname__ = ""
125 __residue__ = []
126
127 if include == 0:
128 bb.msg.debug(2, bb.msg.domain.Parsing, "BB " + fn + ": handle(data)")
129 else:
130 bb.msg.debug(2, bb.msg.domain.Parsing, "BB " + fn + ": handle(data, include)")
131
132 (root, ext) = os.path.splitext(os.path.basename(fn))
133 base_name = "%s%s" % (root,ext)
134 init(d)
135
136 if ext == ".bbclass":
137 __classname__ = root
138 classes.append(__classname__)
139 __inherit_cache = data.getVar('__inherit_cache', d) or []
140 if not fn in __inherit_cache:
141 __inherit_cache.append(fn)
142 data.setVar('__inherit_cache', __inherit_cache, d)
143
144 if include != 0:
145 oldfile = data.getVar('FILE', d)
146 else:
147 oldfile = None
148
149 fn = obtain(fn, d)
150 bbpath = (data.getVar('BBPATH', d, 1) or '').split(':')
151 if not os.path.isabs(fn):
152 f = None
153 for p in bbpath:
154 j = os.path.join(p, fn)
155 if os.access(j, os.R_OK):
156 abs_fn = j
157 f = open(j, 'r')
158 break
159 if f is None:
160 raise IOError("file %s not found" % fn)
161 else:
162 f = open(fn,'r')
163 abs_fn = fn
164
165 if include:
166 bb.parse.mark_dependency(d, abs_fn)
167
168 if ext != ".bbclass":
169 data.setVar('FILE', fn, d)
170
171 lineno = 0
172 while 1:
173 lineno = lineno + 1
174 s = f.readline()
175 if not s: break
176 s = s.rstrip()
177 feeder(lineno, s, fn, base_name, d)
178 if __inpython__:
179 # add a blank line to close out any python definition
180 feeder(IN_PYTHON_EOF, "", fn, base_name, d)
181 if ext == ".bbclass":
182 classes.remove(__classname__)
183 else:
184 if include == 0:
185 multi = data.getVar('BBCLASSEXTEND', d, 1)
186 if multi:
187 based = bb.data.createCopy(d)
188 else:
189 based = d
190 try:
191 finalise(fn, based)
192 except bb.parse.SkipPackage:
193 bb.data.setVar("__SKIPPED", True, based)
194 darray = {"": based}
195
196 for cls in (multi or "").split():
197 pn = data.getVar('PN', d, True)
198 based = bb.data.createCopy(d)
199 data.setVar('PN', pn + '-' + cls, based)
200 inherit([cls], based)
201 try:
202 finalise(fn, based)
203 except bb.parse.SkipPackage:
204 bb.data.setVar("__SKIPPED", True, based)
205 darray[cls] = based
206 return darray
207
208 bbpath.pop(0)
209 if oldfile:
210 bb.data.setVar("FILE", oldfile, d)
211
212 # we have parsed the bb class now
213 if ext == ".bbclass" or ext == ".inc":
214 __parsed_methods__[base_name] = 1
215
216 return d
217
218def feeder(lineno, s, fn, root, d):
219 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, classes, bb, __residue__
220 if __infunc__:
221 if s == '}':
222 __body__.append('')
223 if __infunc__ == "__anonymous":
224 funcname = ("__anon_%s_%s" % (lineno, fn.translate(string.maketrans('/.+-', '____'))))
225 if not funcname in methodpool._parsed_fns:
226 text = "def %s(d):\n" % (funcname) + '\n'.join(__body__)
227 methodpool.insert_method(funcname, text, fn)
228 anonfuncs = data.getVar('__BBANONFUNCS', d) or []
229 anonfuncs.append(funcname)
230 data.setVar('__BBANONFUNCS', anonfuncs, d)
231 else:
232 data.setVarFlag(__infunc__, "func", 1, d)
233 data.setVar(__infunc__, '\n'.join(__body__), d)
234 __infunc__ = ""
235 __body__ = []
236 else:
237 __body__.append(s)
238 return
239
240 if __inpython__:
241 m = __python_func_regexp__.match(s)
242 if m and lineno != IN_PYTHON_EOF:
243 __body__.append(s)
244 return
245 else:
246 # Note we will add root to parsedmethods after having parse
247 # 'this' file. This means we will not parse methods from
248 # bb classes twice
249 if not root in __parsed_methods__:
250 text = '\n'.join(__body__)
251 methodpool.insert_method( root, text, fn )
252 __body__ = []
253 __inpython__ = False
254
255 if lineno == IN_PYTHON_EOF:
256 return
257
258# fall through
259
260 if s == '' or s[0] == '#': return # skip comments and empty lines
261
262 if s[-1] == '\\':
263 __residue__.append(s[:-1])
264 return
265
266 s = "".join(__residue__) + s
267 __residue__ = []
268
269 m = __func_start_regexp__.match(s)
270 if m:
271 __infunc__ = m.group("func") or "__anonymous"
272 key = __infunc__
273 if data.getVar(key, d):
274# clean up old version of this piece of metadata, as its
275# flags could cause problems
276 data.setVarFlag(key, 'python', None, d)
277 data.setVarFlag(key, 'fakeroot', None, d)
278 if m.group("py") is not None:
279 data.setVarFlag(key, "python", "1", d)
280 else:
281 data.delVarFlag(key, "python", d)
282 if m.group("fr") is not None:
283 data.setVarFlag(key, "fakeroot", "1", d)
284 else:
285 data.delVarFlag(key, "fakeroot", d)
286 return
287
288 m = __def_regexp__.match(s)
289 if m:
290 __body__.append(s)
291 __inpython__ = True
292 return
293
294 m = __export_func_regexp__.match(s)
295 if m:
296 fns = m.group(1)
297 n = __word__.findall(fns)
298 for f in n:
299 allvars = []
300 allvars.append(f)
301 allvars.append(classes[-1] + "_" + f)
302
303 vars = [[ allvars[0], allvars[1] ]]
304 if len(classes) > 1 and classes[-2] is not None:
305 allvars.append(classes[-2] + "_" + f)
306 vars = []
307 vars.append([allvars[2], allvars[1]])
308 vars.append([allvars[0], allvars[2]])
309
310 for (var, calledvar) in vars:
311 if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d):
312 continue
313
314 if data.getVar(var, d):
315 data.setVarFlag(var, 'python', None, d)
316 data.setVarFlag(var, 'func', None, d)
317
318 for flag in [ "func", "python" ]:
319 if data.getVarFlag(calledvar, flag, d):
320 data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d)
321 for flag in [ "dirs" ]:
322 if data.getVarFlag(var, flag, d):
323 data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d)
324
325 if data.getVarFlag(calledvar, "python", d):
326 data.setVar(var, "\tbb.build.exec_func('" + calledvar + "', d)\n", d)
327 else:
328 data.setVar(var, "\t" + calledvar + "\n", d)
329 data.setVarFlag(var, 'export_func', '1', d)
330
331 return
332
333 m = __addtask_regexp__.match(s)
334 if m:
335 func = m.group("func")
336 before = m.group("before")
337 after = m.group("after")
338 if func is None:
339 return
340 if func[:3] != "do_":
341 var = "do_" + func
342
343 data.setVarFlag(var, "task", 1, d)
344
345 bbtasks = data.getVar('__BBTASKS', d) or []
346 if not var in bbtasks:
347 bbtasks.append(var)
348 data.setVar('__BBTASKS', bbtasks, d)
349
350 existing = data.getVarFlag(var, "deps", d) or []
351 if after is not None:
352 # set up deps for function
353 for entry in after.split():
354 if entry not in existing:
355 existing.append(entry)
356 data.setVarFlag(var, "deps", existing, d)
357 if before is not None:
358 # set up things that depend on this func
359 for entry in before.split():
360 existing = data.getVarFlag(entry, "deps", d) or []
361 if var not in existing:
362 data.setVarFlag(entry, "deps", [var] + existing, d)
363 return
364
365 m = __addhandler_regexp__.match(s)
366 if m:
367 fns = m.group(1)
368 hs = __word__.findall(fns)
369 bbhands = data.getVar('__BBHANDLERS', d) or []
370 for h in hs:
371 bbhands.append(h)
372 data.setVarFlag(h, "handler", 1, d)
373 data.setVar('__BBHANDLERS', bbhands, d)
374 return
375
376 m = __inherit_regexp__.match(s)
377 if m:
378
379 files = m.group(1)
380 n = __word__.findall(files)
381 inherit(n, d)
382 return
383
384 from bb.parse import ConfHandler
385 return ConfHandler.feeder(lineno, s, fn, d)
386
387__pkgsplit_cache__={}
388def vars_from_file(mypkg, d):
389 if not mypkg:
390 return (None, None, None)
391 if mypkg in __pkgsplit_cache__:
392 return __pkgsplit_cache__[mypkg]
393
394 myfile = os.path.splitext(os.path.basename(mypkg))
395 parts = myfile[0].split('_')
396 __pkgsplit_cache__[mypkg] = parts
397 if len(parts) > 3:
398 raise ParseError("Unable to generate default variables from the filename: %s (too many underscores)" % mypkg)
399 exp = 3 - len(parts)
400 tmplist = []
401 while exp != 0:
402 exp -= 1
403 tmplist.append(None)
404 parts.extend(tmplist)
405 return parts
406
407# Add us to the handlers list
408from bb.parse import handlers
409handlers.append({'supports': supports, 'handle': handle, 'init': init})
410del handlers