1 """class for handling .oe files
3 Reads the file and obtains its metadata"""
5 import re, oe, string, os, sys
8 from oe import debug, data, fetch, fatal
10 from oe.parse.ConfHandler import include, localpath, obtain, init
12 __func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>\w+)?\s*\(\s*\)\s*{$" )
13 __inherit_regexp__ = re.compile( r"inherit\s+(.+)" )
14 __export_func_regexp__ = re.compile( r"EXPORT_FUNCTIONS\s+(.+)" )
15 __addtask_regexp__ = re.compile("addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*")
16 __addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" )
17 __word__ = re.compile(r"\S+")
26 localfn = localpath(fn, d)
27 return localfn[-3:] == ".oe" or localfn[-8:] == ".oeclass"
29 def inherit(files, d):
30 __inherit_cache = data.getVar('__inherit_cache', d) or ""
34 file = data.expand(f, d)
35 if file[0] != "/" and file[-8:] != ".oeclass":
36 file = "classes/%s.oeclass" % file
38 if not file in string.split(__inherit_cache):
39 debug(2, "OE %s:%d: inheriting %s" % (fn, lineno, file))
40 __inherit_cache += " %s" % file
42 data.setVar('__inherit_cache', __inherit_cache, d)
45 def handle(fn, d = {}, include = 0):
46 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __oepath_found__
53 debug(2, "OE " + fn + ": handle(data)")
55 debug(2, "OE " + fn + ": handle(data, include)")
57 (root, ext) = os.path.splitext(os.path.basename(fn))
60 classes.append(__classname__)
64 oldfile = data.getVar('FILE', d)
68 if not os.path.isabs(fn):
70 voepath = data.getVar("OEPATH", d)
72 oepath += voepath.split(":")
75 if os.access(os.path.join(p, fn), os.R_OK):
76 f = open(os.path.join(p, fn), 'r')
78 raise IOError("file not found")
83 data.setVar('FILE', fn, d)
85 i = string.split(data.getVar("INHERIT", d, 1) or "")
86 if not "base" in i and __classname__ != "base":
96 if not w: continue # skip empty lines
98 if s[0] == '#': continue # skip comments
100 s2 = f.readline()[:-1].strip()
102 feeder(lineno, s, fn, d)
103 if ext == ".oeclass":
104 classes.remove(__classname__)
109 set_additional_vars(fn, d, include)
110 anonqueue = data.getVar("__anonqueue", d, 1) or []
111 for anon in anonqueue:
112 data.setVar("__anonfunc", anon["content"], d)
113 data.setVarFlags("__anonfunc", anon["flags"], d)
116 t = data.getVar('T', d)
117 data.setVar('T', '${TMPDIR}/', d)
118 build.exec_func("__anonfunc", d)
121 data.setVar('T', t, d)
123 oe.error("executing anonymous function: %s" % e)
125 data.delVar("__anonqueue", d)
126 data.delVar("__anonfunc", d)
129 if data.getVarFlag(var, 'handler', d):
130 oe.event.register(data.getVar(var, d))
133 if not data.getVarFlag(var, 'task', d):
136 deps = data.getVarFlag(var, 'deps', d) or []
137 postdeps = data.getVarFlag(var, 'postdeps', d) or []
138 oe.build.add_task(var, deps, d)
140 pdeps = data.getVarFlag(p, 'deps', d) or []
142 data.setVarFlag(p, 'deps', pdeps, d)
143 oe.build.add_task(p, pdeps, d)
145 data.setVar('FILE', oldfile, d)
148 def feeder(lineno, s, fn, d):
149 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __oepath_found__, classes, oe
153 data.setVarFlag(__infunc__, "func", 1, d)
154 data.setVar(__infunc__, string.join(__body__, '\n'), d)
155 if __infunc__ == "__anonymous":
156 anonqueue = oe.data.getVar("__anonqueue", d) or []
158 anonitem["content"] = oe.data.getVar("__anonymous", d)
159 anonitem["flags"] = oe.data.getVarFlags("__anonymous", d)
160 anonqueue.append(anonitem)
161 oe.data.setVar("__anonqueue", anonqueue, d)
162 oe.data.delVarFlags("__anonymous", d)
163 oe.data.delVar("__anonymous", d)
170 m = __func_start_regexp__.match(s)
172 __infunc__ = m.group("func") or "__anonymous"
174 if data.getVar(key, d):
175 # clean up old version of this piece of metadata, as its
176 # flags could cause problems
177 data.setVarFlag(key, 'python', None, d)
178 data.setVarFlag(key, 'fakeroot', None, d)
179 if m.group("py") is not None:
180 data.setVarFlag(key, "python", "1", d)
182 data.setVarFlag(key, "python", None, d)
183 if m.group("fr") is not None:
184 data.setVarFlag(key, "fakeroot", "1", d)
186 data.setVarFlag(key, "fakeroot", None, d)
189 m = __export_func_regexp__.match(s)
192 n = __word__.findall(fns)
196 allvars.append(classes[-1] + "_" + f)
198 vars = [[ allvars[0], allvars[1] ]]
199 if len(classes) > 1 and classes[-2] is not None:
200 allvars.append(classes[-2] + "_" + f)
202 vars.append([allvars[2], allvars[1]])
203 vars.append([allvars[0], allvars[2]])
205 for (var, calledvar) in vars:
206 if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d):
209 if data.getVar(var, d):
210 data.setVarFlag(var, 'python', None, d)
211 data.setVarFlag(var, 'func', None, d)
213 for flag in [ "func", "python" ]:
214 if data.getVarFlag(calledvar, flag, d):
215 data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d)
216 for flag in [ "dirs" ]:
217 if data.getVarFlag(var, flag, d):
218 data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d)
220 if data.getVarFlag(calledvar, "python", d):
221 data.setVar(var, "\treturn oe.build.exec_func('" + calledvar + "', d)\n", d)
223 data.setVar(var, "\t" + calledvar + "\n", d)
224 data.setVarFlag(var, 'export_func', '1', d)
228 m = __addtask_regexp__.match(s)
230 func = m.group("func")
231 before = m.group("before")
232 after = m.group("after")
237 data.setVarFlag(var, "task", 1, d)
239 if after is not None:
240 # set up deps for function
241 data.setVarFlag(var, "deps", after.split(), d)
242 if before is not None:
243 # set up things that depend on this func
244 data.setVarFlag(var, "postdeps", before.split(), d)
247 m = __addhandler_regexp__.match(s)
250 hs = __word__.findall(fns)
252 data.setVarFlag(h, "handler", 1, d)
255 m = __inherit_regexp__.match(s)
259 n = __word__.findall(files)
263 from oe.parse import ConfHandler
264 return ConfHandler.feeder(lineno, s, fn, d)
266 __pkgsplit_cache__={}
267 def vars_from_file(mypkg, d):
269 return (None, None, None)
270 if mypkg in __pkgsplit_cache__:
271 return __pkgsplit_cache__[mypkg]
273 myfile = os.path.splitext(os.path.basename(mypkg))
274 parts = string.split(myfile[0], '_')
275 __pkgsplit_cache__[mypkg] = parts
281 parts.extend(tmplist)
284 def set_additional_vars(file, d, include):
285 """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}"""
287 debug(2,"OE %s: set_additional_vars" % file)
289 src_uri = data.getVar('SRC_URI', d)
292 src_uri = data.expand(src_uri, d)
294 a = data.getVar('A', d)
296 a = data.expand(a, d).split()
302 fetch.init(src_uri.split())
303 except fetch.NoMethodError:
306 a += fetch.localpaths(d)
308 data.setVar('A', string.join(a), d)
311 # Add us to the handlers list
312 from oe.parse import handlers
313 handlers.append({'supports': supports, 'handle': handle, 'init': init})