2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4 """class for handling .oe files
6 Reads the file and obtains its metadata"""
9 import oe.fetch, oe.build
10 from oe import debug, data, fetch, fatal
12 from oe.parse.ConfHandler import include, localpath, obtain, init
13 from oe.parse import ParseError
15 __func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>[\w\-\+]+)?\s*\(\s*\)\s*{$" )
16 __inherit_regexp__ = re.compile( r"inherit\s+(.+)" )
17 __export_func_regexp__ = re.compile( r"EXPORT_FUNCTIONS\s+(.+)" )
18 __addtask_regexp__ = re.compile("addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*")
19 __addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" )
20 __def_regexp__ = re.compile( r"def\s+(\w+).*:" )
21 __python_func_regexp__ = re.compile( r"\s+.*" )
22 __word__ = re.compile(r"\S+")
32 localfn = localpath(fn, d)
33 return localfn[-3:] == ".oe" or localfn[-8:] == ".oeclass"
35 def inherit(files, d):
36 __inherit_cache = data.getVar('__inherit_cache', d) or ""
40 file = data.expand(f, d)
41 if file[0] != "/" and file[-8:] != ".oeclass":
42 file = "classes/%s.oeclass" % file
44 if not file in __inherit_cache.split():
45 debug(2, "OE %s:%d: inheriting %s" % (fn, lineno, file))
46 __inherit_cache += " %s" % file
48 data.setVar('__inherit_cache', __inherit_cache, d)
51 def handle(fn, d = {}, include = 0):
52 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __oepath_found__
59 debug(2, "OE " + fn + ": handle(data)")
61 debug(2, "OE " + fn + ": handle(data, include)")
63 (root, ext) = os.path.splitext(os.path.basename(fn))
68 classes.append(__classname__)
71 oldfile = data.getVar('FILE', d)
77 if not os.path.isabs(fn):
79 voepath = data.getVar("OEPATH", d)
81 oepath += voepath.split(":")
84 j = os.path.join(p, fn)
85 if os.access(j, os.R_OK):
90 raise IOError("file not found")
96 oe.parse.mark_dependency(d, abs_fn)
99 data.setVar('FILE', fn, d)
100 i = (data.getVar("INHERIT", d, 1) or "").split()
101 if not "base" in i and __classname__ != "base":
111 if not w: continue # skip empty lines
115 s2 = f.readline()[:-1].strip()
117 feeder(lineno, s, fn, d)
118 if ext == ".oeclass":
119 classes.remove(__classname__)
124 anonqueue = data.getVar("__anonqueue", d, 1) or []
125 for anon in anonqueue:
126 data.setVar("__anonfunc", anon["content"], d)
127 data.setVarFlags("__anonfunc", anon["flags"], d)
130 t = data.getVar('T', d)
131 data.setVar('T', '${TMPDIR}/', d)
132 build.exec_func("__anonfunc", d)
135 data.setVar('T', t, d)
137 oe.debug(1, "executing anonymous function: %s" % e)
139 data.delVar("__anonqueue", d)
140 data.delVar("__anonfunc", d)
141 set_additional_vars(fn, d, include)
145 if data.getVarFlag(var, 'handler', d):
146 oe.event.register(data.getVar(var, d))
149 if not data.getVarFlag(var, 'task', d):
152 deps = data.getVarFlag(var, 'deps', d) or []
153 postdeps = data.getVarFlag(var, 'postdeps', d) or []
154 oe.build.add_task(var, deps, d)
156 pdeps = data.getVarFlag(p, 'deps', d) or []
158 data.setVarFlag(p, 'deps', pdeps, d)
159 oe.build.add_task(p, pdeps, d)
161 oe.data.setVar("FILE", oldfile, d)
164 def feeder(lineno, s, fn, d):
165 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
169 data.setVar(__infunc__, '\n'.join(__body__), d)
170 data.setVarFlag(__infunc__, "func", 1, d)
171 if __infunc__ == "__anonymous":
172 anonqueue = oe.data.getVar("__anonqueue", d) or []
174 anonitem["content"] = oe.data.getVar("__anonymous", d)
175 anonitem["flags"] = oe.data.getVarFlags("__anonymous", d)
176 anonqueue.append(anonitem)
177 oe.data.setVar("__anonqueue", anonqueue, d)
178 oe.data.delVarFlags("__anonymous", d)
179 oe.data.delVar("__anonymous", d)
187 m = __python_func_regexp__.match(s)
192 text = '\n'.join(__body__)
193 comp = compile(text, "<oe>", "exec")
194 exec comp in __builtins__
197 funcs = data.getVar('__functions__', d) or ""
198 data.setVar('__functions__', "%s\n%s" % (funcs, text), d)
201 if s[0] == '#': return # skip comments
203 m = __func_start_regexp__.match(s)
205 __infunc__ = m.group("func") or "__anonymous"
207 if data.getVar(key, d):
208 # clean up old version of this piece of metadata, as its
209 # flags could cause problems
210 data.setVarFlag(key, 'python', None, d)
211 data.setVarFlag(key, 'fakeroot', None, d)
212 if m.group("py") is not None:
213 data.setVarFlag(key, "python", "1", d)
215 data.delVarFlag(key, "python", d)
216 if m.group("fr") is not None:
217 data.setVarFlag(key, "fakeroot", "1", d)
219 data.delVarFlag(key, "fakeroot", d)
222 m = __def_regexp__.match(s)
228 m = __export_func_regexp__.match(s)
231 n = __word__.findall(fns)
235 allvars.append(classes[-1] + "_" + f)
237 vars = [[ allvars[0], allvars[1] ]]
238 if len(classes) > 1 and classes[-2] is not None:
239 allvars.append(classes[-2] + "_" + f)
241 vars.append([allvars[2], allvars[1]])
242 vars.append([allvars[0], allvars[2]])
244 for (var, calledvar) in vars:
245 if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d):
248 if data.getVar(var, d):
249 data.setVarFlag(var, 'python', None, d)
250 data.setVarFlag(var, 'func', None, d)
252 for flag in [ "func", "python" ]:
253 if data.getVarFlag(calledvar, flag, d):
254 data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d)
255 for flag in [ "dirs" ]:
256 if data.getVarFlag(var, flag, d):
257 data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d)
259 if data.getVarFlag(calledvar, "python", d):
260 data.setVar(var, "\toe.build.exec_func('" + calledvar + "', d)\n", d)
262 data.setVar(var, "\t" + calledvar + "\n", d)
263 data.setVarFlag(var, 'export_func', '1', d)
267 m = __addtask_regexp__.match(s)
269 func = m.group("func")
270 before = m.group("before")
271 after = m.group("after")
276 data.setVarFlag(var, "task", 1, d)
278 if after is not None:
279 # set up deps for function
280 data.setVarFlag(var, "deps", after.split(), d)
281 if before is not None:
282 # set up things that depend on this func
283 data.setVarFlag(var, "postdeps", before.split(), d)
286 m = __addhandler_regexp__.match(s)
289 hs = __word__.findall(fns)
291 data.setVarFlag(h, "handler", 1, d)
294 m = __inherit_regexp__.match(s)
298 n = __word__.findall(files)
302 from oe.parse import ConfHandler
303 return ConfHandler.feeder(lineno, s, fn, d)
305 __pkgsplit_cache__={}
306 def vars_from_file(mypkg, d):
308 return (None, None, None)
309 if mypkg in __pkgsplit_cache__:
310 return __pkgsplit_cache__[mypkg]
312 myfile = os.path.splitext(os.path.basename(mypkg))
313 parts = myfile[0].split('_')
314 __pkgsplit_cache__[mypkg] = parts
320 parts.extend(tmplist)
323 def set_additional_vars(file, d, include):
324 """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}"""
326 debug(2,"OE %s: set_additional_vars" % file)
328 src_uri = data.getVar('SRC_URI', d)
331 src_uri = data.expand(src_uri, d)
333 a = data.getVar('A', d)
335 a = data.expand(a, d).split()
341 fetch.init(src_uri.split())
342 except fetch.NoMethodError:
344 except oe.MalformedUrl,e:
345 raise ParseError("Unable to generate local paths for SRC_URI due to malformed uri: %s" % e)
347 a += fetch.localpaths(d)
349 data.setVar('A', " ".join(a), d)
352 # Add us to the handlers list
353 from oe.parse import handlers
354 handlers.append({'supports': supports, 'handle': handle, 'init': init})