1 """class for handling .oe files
3 Reads the file and obtains its metadata"""
7 from oe import debug, data, fetch, fatal
9 from oe.parse.ConfHandler import include, localpath, obtain, init
11 __func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>\w+)?\s*\(\s*\)\s*{$" )
12 __inherit_regexp__ = re.compile( r"inherit\s+(.+)" )
13 __export_func_regexp__ = re.compile( r"EXPORT_FUNCTIONS\s+(.+)" )
14 __addtask_regexp__ = re.compile("addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*")
15 __addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" )
16 __def_regexp__ = re.compile( r"def\s+.*:" )
17 __python_func_regexp__ = re.compile( r"\s+.*" )
18 __word__ = re.compile(r"\S+")
28 localfn = localpath(fn, d)
29 return localfn[-3:] == ".oe" or localfn[-8:] == ".oeclass"
31 def inherit(files, d):
32 __inherit_cache = data.getVar('__inherit_cache', d) or ""
36 file = data.expand(f, d)
37 if file[0] != "/" and file[-8:] != ".oeclass":
38 file = "classes/%s.oeclass" % file
40 if not file in __inherit_cache.split():
41 debug(2, "OE %s:%d: inheriting %s" % (fn, lineno, file))
42 __inherit_cache += " %s" % file
44 data.setVar('__inherit_cache', __inherit_cache, d)
47 def handle(fn, d = {}, include = 0):
48 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __oepath_found__
55 debug(2, "OE " + fn + ": handle(data)")
57 debug(2, "OE " + fn + ": handle(data, include)")
59 (root, ext) = os.path.splitext(os.path.basename(fn))
64 classes.append(__classname__)
67 oldfile = data.getVar('FILE', d)
73 if not os.path.isabs(fn):
75 voepath = data.getVar("OEPATH", d)
77 oepath += voepath.split(":")
80 j = os.path.join(p, fn)
81 if os.access(j, os.R_OK):
85 raise IOError("file not found")
90 data.setVar('FILE', fn, d)
91 i = (data.getVar("INHERIT", d, 1) or "").split()
92 if not "base" in i and __classname__ != "base":
102 if not w: continue # skip empty lines
105 s2 = f.readline()[:-1].strip()
107 feeder(lineno, s, fn, d)
108 if ext == ".oeclass":
109 classes.remove(__classname__)
114 set_additional_vars(fn, d, include)
115 anonqueue = data.getVar("__anonqueue", d, 1) or []
116 for anon in anonqueue:
117 data.setVar("__anonfunc", anon["content"], d)
118 data.setVarFlags("__anonfunc", anon["flags"], d)
121 t = data.getVar('T', d)
122 data.setVar('T', '${TMPDIR}/', d)
123 build.exec_func("__anonfunc", d)
126 data.setVar('T', t, d)
128 oe.debug(1, "executing anonymous function: %s" % e)
130 data.delVar("__anonqueue", d)
131 data.delVar("__anonfunc", d)
134 if data.getVarFlag(var, 'handler', d):
135 oe.event.register(data.getVar(var, d))
138 if not data.getVarFlag(var, 'task', d):
141 deps = data.getVarFlag(var, 'deps', d) or []
142 postdeps = data.getVarFlag(var, 'postdeps', d) or []
143 oe.build.add_task(var, deps, d)
145 pdeps = data.getVarFlag(p, 'deps', d) or []
147 data.setVarFlag(p, 'deps', pdeps, d)
148 oe.build.add_task(p, pdeps, d)
150 oe.data.setVar("FILE", oldfile, d)
153 def feeder(lineno, s, fn, d):
154 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, __oepath_found__, classes, oe
158 data.setVar(__infunc__, '\n'.join(__body__), d)
159 data.setVarFlag(__infunc__, "func", 1, d)
160 if __infunc__ == "__anonymous":
161 anonqueue = oe.data.getVar("__anonqueue", d) or []
163 anonitem["content"] = oe.data.getVar("__anonymous", d)
164 anonitem["flags"] = oe.data.getVarFlags("__anonymous", d)
165 anonqueue.append(anonitem)
166 oe.data.setVar("__anonqueue", anonqueue, d)
167 oe.data.delVarFlags("__anonymous", d)
168 oe.data.delVar("__anonymous", d)
176 m = __python_func_regexp__.match(s)
181 text = '\n'.join(__body__)
182 comp = compile(text, "<oe>", "exec")
183 exec comp in __builtins__
188 if s[0] == '#': return # skip comments
190 m = __func_start_regexp__.match(s)
192 __infunc__ = m.group("func") or "__anonymous"
194 if data.getVar(key, d):
195 # clean up old version of this piece of metadata, as its
196 # flags could cause problems
197 data.setVarFlag(key, 'python', None, d)
198 data.setVarFlag(key, 'fakeroot', None, d)
199 if m.group("py") is not None:
200 data.setVarFlag(key, "python", "1", d)
202 data.delVarFlag(key, "python", d)
203 if m.group("fr") is not None:
204 data.setVarFlag(key, "fakeroot", "1", d)
206 data.delVarFlag(key, "fakeroot", d)
209 m = __def_regexp__.match(s)
215 m = __export_func_regexp__.match(s)
218 n = __word__.findall(fns)
222 allvars.append(classes[-1] + "_" + f)
224 vars = [[ allvars[0], allvars[1] ]]
225 if len(classes) > 1 and classes[-2] is not None:
226 allvars.append(classes[-2] + "_" + f)
228 vars.append([allvars[2], allvars[1]])
229 vars.append([allvars[0], allvars[2]])
231 for (var, calledvar) in vars:
232 if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d):
235 if data.getVar(var, d):
236 data.setVarFlag(var, 'python', None, d)
237 data.setVarFlag(var, 'func', None, d)
239 for flag in [ "func", "python" ]:
240 if data.getVarFlag(calledvar, flag, d):
241 data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d)
242 for flag in [ "dirs" ]:
243 if data.getVarFlag(var, flag, d):
244 data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d)
246 if data.getVarFlag(calledvar, "python", d):
247 data.setVar(var, "\treturn oe.build.exec_func('" + calledvar + "', d)\n", d)
249 data.setVar(var, "\t" + calledvar + "\n", d)
250 data.setVarFlag(var, 'export_func', '1', d)
254 m = __addtask_regexp__.match(s)
256 func = m.group("func")
257 before = m.group("before")
258 after = m.group("after")
263 data.setVarFlag(var, "task", 1, d)
265 if after is not None:
266 # set up deps for function
267 data.setVarFlag(var, "deps", after.split(), d)
268 if before is not None:
269 # set up things that depend on this func
270 data.setVarFlag(var, "postdeps", before.split(), d)
273 m = __addhandler_regexp__.match(s)
276 hs = __word__.findall(fns)
278 data.setVarFlag(h, "handler", 1, d)
281 m = __inherit_regexp__.match(s)
285 n = __word__.findall(files)
289 from oe.parse import ConfHandler
290 return ConfHandler.feeder(lineno, s, fn, d)
292 __pkgsplit_cache__={}
293 def vars_from_file(mypkg, d):
295 return (None, None, None)
296 if mypkg in __pkgsplit_cache__:
297 return __pkgsplit_cache__[mypkg]
299 myfile = os.path.splitext(os.path.basename(mypkg))
300 parts = myfile[0].split('_')
301 __pkgsplit_cache__[mypkg] = parts
307 parts.extend(tmplist)
310 def set_additional_vars(file, d, include):
311 """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}"""
313 debug(2,"OE %s: set_additional_vars" % file)
315 src_uri = data.getVar('SRC_URI', d)
318 src_uri = data.expand(src_uri, d)
320 a = data.getVar('A', d)
322 a = data.expand(a, d).split()
328 fetch.init(src_uri.split())
329 except fetch.NoMethodError:
332 a += fetch.localpaths(d)
334 data.setVar('A', "".join(a), d)
337 # Add us to the handlers list
338 from oe.parse import handlers
339 handlers.append({'supports': supports, 'handle': handle, 'init': init})