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 __word__ = re.compile(r"\S+")
25 localfn = localpath(fn, d)
26 return localfn[-3:] == ".oe" or localfn[-8:] == ".oeclass"
28 def inherit(files, d):
29 __inherit_cache = data.getVar('__inherit_cache', d) or ""
33 file = data.expand(f, d)
34 if file[0] != "/" and file[-8:] != ".oeclass":
35 file = "classes/%s.oeclass" % file
37 if not file in __inherit_cache.split():
38 debug(2, "OE %s:%d: inheriting %s" % (fn, lineno, file))
39 __inherit_cache += " %s" % file
41 data.setVar('__inherit_cache', __inherit_cache, d)
44 def handle(fn, d = {}, include = 0):
45 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __oepath_found__
52 debug(2, "OE " + fn + ": handle(data)")
54 debug(2, "OE " + fn + ": handle(data, include)")
56 (root, ext) = os.path.splitext(os.path.basename(fn))
59 classes.append(__classname__)
63 oldfile = data.getVar('FILE', d)
67 if not os.path.isabs(fn):
69 voepath = data.getVar("OEPATH", d)
71 oepath += voepath.split(":")
74 if os.access(os.path.join(p, fn), os.R_OK):
75 f = open(os.path.join(p, fn), 'r')
77 raise IOError("file not found")
82 data.setVar('FILE', fn, d)
83 i = (data.getVar("INHERIT", d, 1) or "").split()
84 if not "base" in i and __classname__ != "base":
94 if not w: continue # skip empty lines
96 if s[0] == '#': continue # skip comments
98 s2 = f.readline()[:-1].strip()
100 feeder(lineno, s, fn, d)
101 if ext == ".oeclass":
102 classes.remove(__classname__)
107 set_additional_vars(fn, d, include)
108 anonqueue = data.getVar("__anonqueue", d, 1) or []
109 for anon in anonqueue:
110 data.setVar("__anonfunc", anon["content"], d)
111 data.setVarFlags("__anonfunc", anon["flags"], d)
114 t = data.getVar('T', d)
115 data.setVar('T', '${TMPDIR}/', d)
116 build.exec_func("__anonfunc", d)
119 data.setVar('T', t, d)
121 oe.error("executing anonymous function: %s" % e)
123 data.delVar("__anonqueue", d)
124 data.delVar("__anonfunc", d)
127 if data.getVarFlag(var, 'handler', d):
128 oe.event.register(data.getVar(var, d))
131 if not data.getVarFlag(var, 'task', d):
134 deps = data.getVarFlag(var, 'deps', d) or []
135 postdeps = data.getVarFlag(var, 'postdeps', d) or []
136 oe.build.add_task(var, deps, d)
138 pdeps = data.getVarFlag(p, 'deps', d) or []
140 data.setVarFlag(p, 'deps', pdeps, d)
141 oe.build.add_task(p, pdeps, d)
143 data.setVar('FILE', oldfile, d)
146 def feeder(lineno, s, fn, d):
147 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __oepath_found__, classes, oe
151 data.setVar(__infunc__, '\n'.join(__body__), d)
152 data.setVarFlag(__infunc__, "func", 1, d)
153 data.setVar(__infunc__, string.join(__body__, '\n'), d)
154 if __infunc__ == "__anonymous":
155 anonqueue = oe.data.getVar("__anonqueue", d) or []
157 anonitem["content"] = oe.data.getVar("__anonymous", d)
158 anonitem["flags"] = oe.data.getVarFlags("__anonymous", d)
159 anonqueue.append(anonitem)
160 oe.data.setVar("__anonqueue", anonqueue, d)
161 oe.data.delVarFlags("__anonymous", d)
162 oe.data.delVar("__anonymous", d)
169 m = __func_start_regexp__.match(s)
171 __infunc__ = m.group("func") or "__anonymous"
173 if data.getVar(key, d):
174 # clean up old version of this piece of metadata, as its
175 # flags could cause problems
176 data.setVarFlag(key, 'python', None, d)
177 data.setVarFlag(key, 'fakeroot', None, d)
178 if m.group("py") is not None:
179 data.setVarFlag(key, "python", "1", d)
181 data.delVarFlag(key, "python", d)
182 if m.group("fr") is not None:
183 data.setVarFlag(key, "fakeroot", "1", d)
185 data.delVarFlag(key, "fakeroot", d)
188 m = __export_func_regexp__.match(s)
191 n = __word__.findall(fns)
195 allvars.append(classes[-1] + "_" + f)
197 vars = [[ allvars[0], allvars[1] ]]
198 if len(classes) > 1 and classes[-2] is not None:
199 allvars.append(classes[-2] + "_" + f)
201 vars.append([allvars[2], allvars[1]])
202 vars.append([allvars[0], allvars[2]])
204 for (var, calledvar) in vars:
205 if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d):
208 if data.getVar(var, d):
209 data.setVarFlag(var, 'python', None, d)
210 data.setVarFlag(var, 'func', None, d)
212 for flag in [ "func", "python" ]:
213 if data.getVarFlag(calledvar, flag, d):
214 data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d)
215 for flag in [ "dirs" ]:
216 if data.getVarFlag(var, flag, d):
217 data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d)
219 if data.getVarFlag(calledvar, "python", d):
220 data.setVar(var, "\treturn oe.build.exec_func('" + calledvar + "', d)\n", d)
222 data.setVar(var, "\t" + calledvar + "\n", d)
223 data.setVarFlag(var, 'export_func', '1', d)
227 m = __addtask_regexp__.match(s)
229 func = m.group("func")
230 before = m.group("before")
231 after = m.group("after")
236 data.setVarFlag(var, "task", 1, d)
238 if after is not None:
239 # set up deps for function
240 data.setVarFlag(var, "deps", after.split(), d)
241 if before is not None:
242 # set up things that depend on this func
243 data.setVarFlag(var, "postdeps", before.split(), d)
246 m = __addhandler_regexp__.match(s)
249 hs = __word__.findall(fns)
251 data.setVarFlag(h, "handler", 1, d)
254 m = __inherit_regexp__.match(s)
258 n = __word__.findall(files)
262 from oe.parse import ConfHandler
263 return ConfHandler.feeder(lineno, s, fn, d)
265 __pkgsplit_cache__={}
266 def vars_from_file(mypkg, d):
268 return (None, None, None)
269 if mypkg in __pkgsplit_cache__:
270 return __pkgsplit_cache__[mypkg]
272 myfile = os.path.splitext(os.path.basename(mypkg))
273 parts = myfile[0].split('_')
274 __pkgsplit_cache__[mypkg] = parts
280 parts.extend(tmplist)
283 def set_additional_vars(file, d, include):
284 """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}"""
286 debug(2,"OE %s: set_additional_vars" % file)
288 src_uri = data.getVar('SRC_URI', d)
291 src_uri = data.expand(src_uri, d)
293 a = data.getVar('A', d)
295 a = data.expand(a, d).split()
301 fetch.init(src_uri.split())
302 except fetch.NoMethodError:
305 a += fetch.localpaths(d)
307 data.setVar('A', "".join(a), d)
310 # Add us to the handlers list
311 from oe.parse import handlers
312 handlers.append({'supports': supports, 'handle': handle, 'init': init})