summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorHolger Freyther <ich@tamarin.(none)>2009-05-19 12:10:37 +0200
committerRichard Purdie <rpurdie@linux.intel.com>2010-02-15 17:07:51 +0000
commit793c88dd92747890e910c598e19f1778865883d2 (patch)
treed34ec6e00aa689a985a0bb5f45050530c7234fd1 /bitbake/lib
parent3eb2e6cf02155c3fce0a49bd967545cacfc08fb3 (diff)
downloadpoky-793c88dd92747890e910c598e19f1778865883d2.tar.gz
bitbake: [parser] Remove the "data" from feeder, evaluate after parsing a file
Evaluate the statements after having parsed one file. This is referred to as "entwirren" and we can remove the direct evaluation and postpone a bit, in the future we can use a cached copy instead of parsing the original. Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/parse/__init__.py8
-rw-r--r--bitbake/lib/bb/parse/ast.py44
-rw-r--r--bitbake/lib/bb/parse/parse_py/BBHandler.py39
-rw-r--r--bitbake/lib/bb/parse/parse_py/ConfHandler.py24
4 files changed, 51 insertions, 64 deletions
diff --git a/bitbake/lib/bb/parse/__init__.py b/bitbake/lib/bb/parse/__init__.py
index b1308b3b04..6737e061ea 100644
--- a/bitbake/lib/bb/parse/__init__.py
+++ b/bitbake/lib/bb/parse/__init__.py
@@ -68,15 +68,11 @@ def supports(fn, data):
68 return 1 68 return 1
69 return 0 69 return 0
70 70
71def handle(fn, data, include = 0, statements = None): 71def handle(fn, data, include = 0):
72 """Call the handler that is appropriate for this file""" 72 """Call the handler that is appropriate for this file"""
73 if not statements:
74 import ast
75 statements = ast.StatementGroup()
76
77 for h in handlers: 73 for h in handlers:
78 if h['supports'](fn, data): 74 if h['supports'](fn, data):
79 return h['handle'](fn, data, include, statements) 75 return h['handle'](fn, data, include)
80 raise ParseError("%s is not a BitBake file" % fn) 76 raise ParseError("%s is not a BitBake file" % fn)
81 77
82def init(fn, data): 78def init(fn, data):
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py
index ed9c689afa..646a5b8d8e 100644
--- a/bitbake/lib/bb/parse/ast.py
+++ b/bitbake/lib/bb/parse/ast.py
@@ -56,13 +56,11 @@ class IncludeNode:
56 s = bb.data.expand(self.what_file, data) 56 s = bb.data.expand(self.what_file, data)
57 bb.msg.debug(3, bb.msg.domain.Parsing, "CONF %s:%d: including %s" % (self.from_fn, self.from_lineno, s)) 57 bb.msg.debug(3, bb.msg.domain.Parsing, "CONF %s:%d: including %s" % (self.from_fn, self.from_lineno, s))
58 58
59 # TODO: Cache those includes... 59 # TODO: Cache those includes... maybe not here though
60 statements = StatementGroup()
61 if self.force: 60 if self.force:
62 bb.parse.ConfHandler.include(statements, self.from_fn, s, data, "include required") 61 bb.parse.ConfHandler.include(self.from_fn, s, data, "include required")
63 else: 62 else:
64 bb.parse.ConfHandler.include(statements, self.from_fn, s, data, False) 63 bb.parse.ConfHandler.include(self.from_fn, s, data, False)
65 #statements.eval(data)
66 64
67class ExportNode: 65class ExportNode:
68 def __init__(self, var): 66 def __init__(self, var):
@@ -256,43 +254,30 @@ class InheritNode:
256 self.n = __word__.findall(files) 254 self.n = __word__.findall(files)
257 255
258 def eval(self, data): 256 def eval(self, data):
259 statements = StatementGroup() 257 bb.parse.BBHandler.inherit(self.n, data)
260 bb.parse.BBHandler.inherit(statements, self.n, data)
261 258
262def handleInclude(statements, m, fn, lineno, data, force): 259def handleInclude(statements, m, fn, lineno, force):
263 # AST handling
264 statements.append(IncludeNode(m.group(1), fn, lineno, force)) 260 statements.append(IncludeNode(m.group(1), fn, lineno, force))
265 statements[-1].eval(data)
266 261
267def handleExport(statements, m, data): 262def handleExport(statements, m):
268 # AST handling
269 statements.append(ExportNode(m.group(1))) 263 statements.append(ExportNode(m.group(1)))
270 statements[-1].eval(data)
271 264
272def handleData(statements, groupd, data): 265def handleData(statements, groupd):
273 # AST handling
274 statements.append(DataNode(groupd)) 266 statements.append(DataNode(groupd))
275 statements[-1].eval(data)
276 267
277def handleMethod(statements, func_name, lineno, fn, body, d): 268def handleMethod(statements, func_name, lineno, fn, body):
278 # AST handling
279 statements.append(MethodNode(func_name, body, lineno, fn)) 269 statements.append(MethodNode(func_name, body, lineno, fn))
280 statements[-1].eval(d)
281 270
282def handlePythonMethod(statements, root, body, fn): 271def handlePythonMethod(statements, root, body, fn):
283 # AST handling
284 statements.append(PythonMethodNode(root, body, fn)) 272 statements.append(PythonMethodNode(root, body, fn))
285 statements[-1].eval(None)
286 273
287def handleMethodFlags(statements, key, m, d): 274def handleMethodFlags(statements, key, m):
288 statements.append(MethodFlagsNode(key, m)) 275 statements.append(MethodFlagsNode(key, m))
289 statements[-1].eval(d)
290 276
291def handleExportFuncs(statements, m, classes, d): 277def handleExportFuncs(statements, m, classes):
292 statements.append(ExportFuncsNode(m.group(1), classes)) 278 statements.append(ExportFuncsNode(m.group(1), classes))
293 statements[-1].eval(d)
294 279
295def handleAddTask(statements, m, d): 280def handleAddTask(statements, m):
296 func = m.group("func") 281 func = m.group("func")
297 before = m.group("before") 282 before = m.group("before")
298 after = m.group("after") 283 after = m.group("after")
@@ -300,17 +285,14 @@ def handleAddTask(statements, m, d):
300 return 285 return
301 286
302 statements.append(AddTaskNode(func, before, after)) 287 statements.append(AddTaskNode(func, before, after))
303 statements[-1].eval(d)
304 288
305def handleBBHandlers(statements, m, d): 289def handleBBHandlers(statements, m):
306 statements.append(BBHandlerNode(m.group(1))) 290 statements.append(BBHandlerNode(m.group(1)))
307 statements[-1].eval(d)
308 291
309def handleInherit(statements, m, d): 292def handleInherit(statements, m):
310 files = m.group(1) 293 files = m.group(1)
311 n = __word__.findall(files) 294 n = __word__.findall(files)
312 statements.append(InheritNode(m.group(1))) 295 statements.append(InheritNode(m.group(1)))
313 statements[-1].eval(d)
314 296
315def finalise(fn, d): 297def finalise(fn, d):
316 bb.data.expandKeys(d) 298 bb.data.expandKeys(d)
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py
index 32e0901e25..f313009ab8 100644
--- a/bitbake/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py
@@ -62,7 +62,7 @@ IN_PYTHON_EOF = -9999999999999
62def supports(fn, d): 62def supports(fn, d):
63 return fn[-3:] == ".bb" or fn[-8:] == ".bbclass" or fn[-4:] == ".inc" 63 return fn[-3:] == ".bb" or fn[-8:] == ".bbclass" or fn[-4:] == ".inc"
64 64
65def inherit(statements, files, d): 65def inherit(files, d):
66 __inherit_cache = data.getVar('__inherit_cache', d) or [] 66 __inherit_cache = data.getVar('__inherit_cache', d) or []
67 fn = "" 67 fn = ""
68 lineno = 0 68 lineno = 0
@@ -75,10 +75,10 @@ def inherit(statements, files, d):
75 bb.msg.debug(2, bb.msg.domain.Parsing, "BB %s:%d: inheriting %s" % (fn, lineno, file)) 75 bb.msg.debug(2, bb.msg.domain.Parsing, "BB %s:%d: inheriting %s" % (fn, lineno, file))
76 __inherit_cache.append( file ) 76 __inherit_cache.append( file )
77 data.setVar('__inherit_cache', __inherit_cache, d) 77 data.setVar('__inherit_cache', __inherit_cache, d)
78 include(statements, fn, file, d, "inherit") 78 include(fn, file, d, "inherit")
79 __inherit_cache = data.getVar('__inherit_cache', d) or [] 79 __inherit_cache = data.getVar('__inherit_cache', d) or []
80 80
81def handle(fn, d, include, statements): 81def handle(fn, d, include):
82 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__ 82 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__
83 __body__ = [] 83 __body__ = []
84 __infunc__ = "" 84 __infunc__ = ""
@@ -113,19 +113,24 @@ def handle(fn, d, include, statements):
113 if include: 113 if include:
114 bb.parse.mark_dependency(d, abs_fn) 114 bb.parse.mark_dependency(d, abs_fn)
115 115
116 if ext != ".bbclass": 116 statements = ast.StatementGroup()
117 data.setVar('FILE', fn, d)
118
119 lineno = 0 117 lineno = 0
120 while 1: 118 while 1:
121 lineno = lineno + 1 119 lineno = lineno + 1
122 s = f.readline() 120 s = f.readline()
123 if not s: break 121 if not s: break
124 s = s.rstrip() 122 s = s.rstrip()
125 feeder(lineno, s, fn, base_name, d, statements) 123 feeder(lineno, s, fn, base_name, statements)
126 if __inpython__: 124 if __inpython__:
127 # add a blank line to close out any python definition 125 # add a blank line to close out any python definition
128 feeder(IN_PYTHON_EOF, "", fn, base_name, d, statements) 126 feeder(IN_PYTHON_EOF, "", fn, base_name, statements)
127
128 # DONE WITH PARSING... time to evaluate
129 if ext != ".bbclass":
130 data.setVar('FILE', fn, d)
131
132 statements.eval(d)
133
129 if ext == ".bbclass": 134 if ext == ".bbclass":
130 classes.remove(__classname__) 135 classes.remove(__classname__)
131 else: 136 else:
@@ -145,7 +150,7 @@ def handle(fn, d, include, statements):
145 pn = data.getVar('PN', d, True) 150 pn = data.getVar('PN', d, True)
146 based = bb.data.createCopy(d) 151 based = bb.data.createCopy(d)
147 data.setVar('PN', pn + '-' + cls, based) 152 data.setVar('PN', pn + '-' + cls, based)
148 inherit(statements, [cls], based) 153 inherit([cls], based)
149 try: 154 try:
150 ast.finalise(fn, based) 155 ast.finalise(fn, based)
151 except bb.parse.SkipPackage: 156 except bb.parse.SkipPackage:
@@ -162,12 +167,12 @@ def handle(fn, d, include, statements):
162 167
163 return d 168 return d
164 169
165def feeder(lineno, s, fn, root, d, statements): 170def feeder(lineno, s, fn, root, statements):
166 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, classes, bb, __residue__ 171 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, classes, bb, __residue__
167 if __infunc__: 172 if __infunc__:
168 if s == '}': 173 if s == '}':
169 __body__.append('') 174 __body__.append('')
170 ast.handleMethod(statements, __infunc__, lineno, fn, __body__, d) 175 ast.handleMethod(statements, __infunc__, lineno, fn, __body__)
171 __infunc__ = "" 176 __infunc__ = ""
172 __body__ = [] 177 __body__ = []
173 else: 178 else:
@@ -201,7 +206,7 @@ def feeder(lineno, s, fn, root, d, statements):
201 m = __func_start_regexp__.match(s) 206 m = __func_start_regexp__.match(s)
202 if m: 207 if m:
203 __infunc__ = m.group("func") or "__anonymous" 208 __infunc__ = m.group("func") or "__anonymous"
204 ast.handleMethodFlags(statements, __infunc__, m, d) 209 ast.handleMethodFlags(statements, __infunc__, m)
205 return 210 return
206 211
207 m = __def_regexp__.match(s) 212 m = __def_regexp__.match(s)
@@ -212,26 +217,26 @@ def feeder(lineno, s, fn, root, d, statements):
212 217
213 m = __export_func_regexp__.match(s) 218 m = __export_func_regexp__.match(s)
214 if m: 219 if m:
215 ast.handleExportFuncs(statements, m, classes, d) 220 ast.handleExportFuncs(statements, m, classes)
216 return 221 return
217 222
218 m = __addtask_regexp__.match(s) 223 m = __addtask_regexp__.match(s)
219 if m: 224 if m:
220 ast.handleAddTask(statements, m, d) 225 ast.handleAddTask(statements, m)
221 return 226 return
222 227
223 m = __addhandler_regexp__.match(s) 228 m = __addhandler_regexp__.match(s)
224 if m: 229 if m:
225 ast.handleBBHandlers(statements, m, d) 230 ast.handleBBHandlers(statements, m)
226 return 231 return
227 232
228 m = __inherit_regexp__.match(s) 233 m = __inherit_regexp__.match(s)
229 if m: 234 if m:
230 ast.handleInherit(statements, m, d) 235 ast.handleInherit(statements, m)
231 return 236 return
232 237
233 from bb.parse import ConfHandler 238 from bb.parse import ConfHandler
234 return ConfHandler.feeder(lineno, s, fn, d, statements) 239 return ConfHandler.feeder(lineno, s, fn, statements)
235 240
236# Add us to the handlers list 241# Add us to the handlers list
237from bb.parse import handlers 242from bb.parse import handlers
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
index 69f2eea1b3..839a662024 100644
--- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
@@ -49,7 +49,7 @@ def init(data):
49def supports(fn, d): 49def supports(fn, d):
50 return fn[-5:] == ".conf" 50 return fn[-5:] == ".conf"
51 51
52def include(statements, oldfn, fn, data, error_out): 52def include(oldfn, fn, data, error_out):
53 """ 53 """
54 54
55 error_out If True a ParseError will be reaised if the to be included 55 error_out If True a ParseError will be reaised if the to be included
@@ -70,13 +70,13 @@ def include(statements, oldfn, fn, data, error_out):
70 70
71 from bb.parse import handle 71 from bb.parse import handle
72 try: 72 try:
73 ret = handle(fn, data, True, statements) 73 ret = handle(fn, data, True)
74 except IOError: 74 except IOError:
75 if error_out: 75 if error_out:
76 raise ParseError("Could not %(error_out)s file %(fn)s" % vars() ) 76 raise ParseError("Could not %(error_out)s file %(fn)s" % vars() )
77 bb.msg.debug(2, bb.msg.domain.Parsing, "CONF file '%s' not found" % fn) 77 bb.msg.debug(2, bb.msg.domain.Parsing, "CONF file '%s' not found" % fn)
78 78
79def handle(fn, data, include, statements): 79def handle(fn, data, include):
80 init(data) 80 init(data)
81 81
82 if include == 0: 82 if include == 0:
@@ -89,8 +89,8 @@ def handle(fn, data, include, statements):
89 if include: 89 if include:
90 bb.parse.mark_dependency(data, abs_fn) 90 bb.parse.mark_dependency(data, abs_fn)
91 91
92 statements = ast.StatementGroup()
92 lineno = 0 93 lineno = 0
93 bb.data.setVar('FILE', fn, data)
94 while 1: 94 while 1:
95 lineno = lineno + 1 95 lineno = lineno + 1
96 s = f.readline() 96 s = f.readline()
@@ -103,32 +103,36 @@ def handle(fn, data, include, statements):
103 s2 = f.readline()[:-1].strip() 103 s2 = f.readline()[:-1].strip()
104 lineno = lineno + 1 104 lineno = lineno + 1
105 s = s[:-1] + s2 105 s = s[:-1] + s2
106 feeder(lineno, s, fn, data, statements) 106 feeder(lineno, s, fn, statements)
107 107
108 # DONE WITH PARSING... time to evaluate
109 bb.data.setVar('FILE', fn, data)
110 statements.eval(data)
108 if oldfile: 111 if oldfile:
109 bb.data.setVar('FILE', oldfile, data) 112 bb.data.setVar('FILE', oldfile, data)
113
110 return data 114 return data
111 115
112def feeder(lineno, s, fn, data, statements): 116def feeder(lineno, s, fn, statements):
113 m = __config_regexp__.match(s) 117 m = __config_regexp__.match(s)
114 if m: 118 if m:
115 groupd = m.groupdict() 119 groupd = m.groupdict()
116 ast.handleData(statements, groupd, data) 120 ast.handleData(statements, groupd)
117 return 121 return
118 122
119 m = __include_regexp__.match(s) 123 m = __include_regexp__.match(s)
120 if m: 124 if m:
121 ast.handleInclude(statements, m, fn, lineno, data, False) 125 ast.handleInclude(statements, m, fn, lineno, False)
122 return 126 return
123 127
124 m = __require_regexp__.match(s) 128 m = __require_regexp__.match(s)
125 if m: 129 if m:
126 ast.handleInclude(statements, m, fn, lineno, data, True) 130 ast.handleInclude(statements, m, fn, lineno, True)
127 return 131 return
128 132
129 m = __export_regexp__.match(s) 133 m = __export_regexp__.match(s)
130 if m: 134 if m:
131 ast.handleExport(statements, m, data) 135 ast.handleExport(statements, m)
132 return 136 return
133 137
134 raise ParseError("%s:%d: unparsed line: '%s'" % (fn, lineno, s)); 138 raise ParseError("%s:%d: unparsed line: '%s'" % (fn, lineno, s));