summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse/parse_py/BBHandler.py
diff options
context:
space:
mode:
authorHolger Freyther <ich@tamarin.(none)>2010-02-12 14:14:49 +0000
committerRichard Purdie <rpurdie@linux.intel.com>2010-02-15 17:06:36 +0000
commit5bac3403d7e51f72ee16c8123c2c8607a1d93ca9 (patch)
treec1de610084eaee1f305b3ac60f0bb7cc1046ba90 /bitbake/lib/bb/parse/parse_py/BBHandler.py
parente9d8dd2abf220cc28c7346768516d847b257f532 (diff)
downloadpoky-5bac3403d7e51f72ee16c8123c2c8607a1d93ca9.tar.gz
bitbake: [parser] Move evaluating into the ast class...
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/parse/parse_py/BBHandler.py')
-rw-r--r--bitbake/lib/bb/parse/parse_py/BBHandler.py139
1 files changed, 11 insertions, 128 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py
index 76deb6b453..1343ec114f 100644
--- a/bitbake/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py
@@ -27,10 +27,10 @@
27 27
28import re, bb, os, sys, time, string 28import re, bb, os, sys, time, string
29import bb.fetch, bb.build, bb.utils 29import bb.fetch, bb.build, bb.utils
30from bb import data, fetch, methodpool 30from bb import data, fetch
31 31
32from ConfHandler import include, init 32from ConfHandler import include, init
33from bb.parse import ParseError, resolve_file 33from bb.parse import ParseError, resolve_file, ast
34 34
35__func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" ) 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+(.+)" ) 36__inherit_regexp__ = re.compile( r"inherit\s+(.+)" )
@@ -39,7 +39,7 @@ __addtask_regexp__ = re.compile("addtask\s+(?P<func>\w+)\s*((before\s*(?P<
39__addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" ) 39__addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" )
40__def_regexp__ = re.compile( r"def\s+(\w+).*:" ) 40__def_regexp__ = re.compile( r"def\s+(\w+).*:" )
41__python_func_regexp__ = re.compile( r"(\s+.*)|(^$)" ) 41__python_func_regexp__ = re.compile( r"(\s+.*)|(^$)" )
42__word__ = re.compile(r"\S+") 42
43 43
44__infunc__ = "" 44__infunc__ = ""
45__inpython__ = False 45__inpython__ = False
@@ -54,124 +54,7 @@ classes = [ None, ]
54# The two parts using it are tightly integrated anyway 54# The two parts using it are tightly integrated anyway
55IN_PYTHON_EOF = -9999999999999 55IN_PYTHON_EOF = -9999999999999
56 56
57__parsed_methods__ = methodpool.get_parsed_dict()
58 57
59# parsing routines, to be moved into AST classes
60def handleMethod(func_name, lineno, fn, body, d):
61 if func_name == "__anonymous":
62 funcname = ("__anon_%s_%s" % (lineno, fn.translate(string.maketrans('/.+-', '____'))))
63 if not funcname in methodpool._parsed_fns:
64 text = "def %s(d):\n" % (funcname) + '\n'.join(body)
65 methodpool.insert_method(funcname, text, fn)
66 anonfuncs = data.getVar('__BBANONFUNCS', d) or []
67 anonfuncs.append(funcname)
68 data.setVar('__BBANONFUNCS', anonfuncs, d)
69 else:
70 data.setVarFlag(func_name, "func", 1, d)
71 data.setVar(func_name, '\n'.join(body), d)
72
73def handlePythonMethod(root, body, fn):
74 # Note we will add root to parsedmethods after having parse
75 # 'this' file. This means we will not parse methods from
76 # bb classes twice
77 if not root in __parsed_methods__:
78 text = '\n'.join(body)
79 methodpool.insert_method(root, text, fn)
80
81def handleMethodFlags(key, m, d):
82 if data.getVar(key, d):
83 # Clean up old version of this piece of metadata, as its
84 # flags could cause problems
85 data.setVarFlag(key, 'python', None, d)
86 data.setVarFlag(key, 'fakeroot', None, d)
87 if m.group("py") is not None:
88 data.setVarFlag(key, "python", "1", d)
89 else:
90 data.delVarFlag(key, "python", d)
91 if m.group("fr") is not None:
92 data.setVarFlag(key, "fakeroot", "1", d)
93 else:
94 data.delVarFlag(key, "fakeroot", d)
95
96def handleExportFuncs(m, d):
97 fns = m.group(1)
98 n = __word__.findall(fns)
99 for f in n:
100 allvars = []
101 allvars.append(f)
102 allvars.append(classes[-1] + "_" + f)
103
104 vars = [[ allvars[0], allvars[1] ]]
105 if len(classes) > 1 and classes[-2] is not None:
106 allvars.append(classes[-2] + "_" + f)
107 vars = []
108 vars.append([allvars[2], allvars[1]])
109 vars.append([allvars[0], allvars[2]])
110
111 for (var, calledvar) in vars:
112 if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d):
113 continue
114
115 if data.getVar(var, d):
116 data.setVarFlag(var, 'python', None, d)
117 data.setVarFlag(var, 'func', None, d)
118
119 for flag in [ "func", "python" ]:
120 if data.getVarFlag(calledvar, flag, d):
121 data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d)
122 for flag in [ "dirs" ]:
123 if data.getVarFlag(var, flag, d):
124 data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d)
125
126 if data.getVarFlag(calledvar, "python", d):
127 data.setVar(var, "\tbb.build.exec_func('" + calledvar + "', d)\n", d)
128 else:
129 data.setVar(var, "\t" + calledvar + "\n", d)
130 data.setVarFlag(var, 'export_func', '1', d)
131
132def handleAddTask(m, d):
133 func = m.group("func")
134 before = m.group("before")
135 after = m.group("after")
136 if func is None:
137 return
138 if func[:3] != "do_":
139 var = "do_" + func
140
141 data.setVarFlag(var, "task", 1, d)
142
143 bbtasks = data.getVar('__BBTASKS', d) or []
144 if not var in bbtasks:
145 bbtasks.append(var)
146 data.setVar('__BBTASKS', bbtasks, d)
147
148 existing = data.getVarFlag(var, "deps", d) or []
149 if after is not None:
150 # set up deps for function
151 for entry in after.split():
152 if entry not in existing:
153 existing.append(entry)
154 data.setVarFlag(var, "deps", existing, d)
155 if before is not None:
156 # set up things that depend on this func
157 for entry in before.split():
158 existing = data.getVarFlag(entry, "deps", d) or []
159 if var not in existing:
160 data.setVarFlag(entry, "deps", [var] + existing, d)
161
162def handleBBHandlers(m, d):
163 fns = m.group(1)
164 hs = __word__.findall(fns)
165 bbhands = data.getVar('__BBHANDLERS', d) or []
166 for h in hs:
167 bbhands.append(h)
168 data.setVarFlag(h, "handler", 1, d)
169 data.setVar('__BBHANDLERS', bbhands, d)
170
171def handleInherit(m, d):
172 files = m.group(1)
173 n = __word__.findall(files)
174 inherit(n, d)
175 58
176def supports(fn, d): 59def supports(fn, d):
177 return fn[-3:] == ".bb" or fn[-8:] == ".bbclass" or fn[-4:] == ".inc" 60 return fn[-3:] == ".bb" or fn[-8:] == ".bbclass" or fn[-4:] == ".inc"
@@ -312,7 +195,7 @@ def handle(fn, d, include = 0):
312 195
313 # we have parsed the bb class now 196 # we have parsed the bb class now
314 if ext == ".bbclass" or ext == ".inc": 197 if ext == ".bbclass" or ext == ".inc":
315 __parsed_methods__[base_name] = 1 198 bb.methodpool.get_parsed_dict()[base_name] = 1
316 199
317 return d 200 return d
318 201
@@ -321,7 +204,7 @@ def feeder(lineno, s, fn, root, d):
321 if __infunc__: 204 if __infunc__:
322 if s == '}': 205 if s == '}':
323 __body__.append('') 206 __body__.append('')
324 handleMethod(__infunc__, lineno, fn, __body__, d) 207 ast.handleMethod(__infunc__, __body__, d)
325 __infunc__ = "" 208 __infunc__ = ""
326 __body__ = [] 209 __body__ = []
327 else: 210 else:
@@ -334,7 +217,7 @@ def feeder(lineno, s, fn, root, d):
334 __body__.append(s) 217 __body__.append(s)
335 return 218 return
336 else: 219 else:
337 handlePythonMethod(root, __body__, fn) 220 ast.handlePythonMethod(root, __body__, fn)
338 __body__ = [] 221 __body__ = []
339 __inpython__ = False 222 __inpython__ = False
340 223
@@ -355,7 +238,7 @@ def feeder(lineno, s, fn, root, d):
355 m = __func_start_regexp__.match(s) 238 m = __func_start_regexp__.match(s)
356 if m: 239 if m:
357 __infunc__ = m.group("func") or "__anonymous" 240 __infunc__ = m.group("func") or "__anonymous"
358 handleMethodFlags(__infunc__, m, d) 241 ast.handleMethodFlags(__infunc__, m, d)
359 return 242 return
360 243
361 m = __def_regexp__.match(s) 244 m = __def_regexp__.match(s)
@@ -366,22 +249,22 @@ def feeder(lineno, s, fn, root, d):
366 249
367 m = __export_func_regexp__.match(s) 250 m = __export_func_regexp__.match(s)
368 if m: 251 if m:
369 handleExportFuncs(m, d) 252 ast.handleExportFuncs(m, classes, d)
370 return 253 return
371 254
372 m = __addtask_regexp__.match(s) 255 m = __addtask_regexp__.match(s)
373 if m: 256 if m:
374 handleAddTask(m, d) 257 ast.handleAddTask(m, d )
375 return 258 return
376 259
377 m = __addhandler_regexp__.match(s) 260 m = __addhandler_regexp__.match(s)
378 if m: 261 if m:
379 handleBBHandlers(m, d) 262 ast.handleBBHandlers(m, d)
380 return 263 return
381 264
382 m = __inherit_regexp__.match(s) 265 m = __inherit_regexp__.match(s)
383 if m: 266 if m:
384 handleInherit(m, d) 267 ast.handleInherit(m, d)
385 return 268 return
386 269
387 from bb.parse import ConfHandler 270 from bb.parse import ConfHandler