summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse/parse_py/BBHandler.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/parse/parse_py/BBHandler.py')
-rw-r--r--bitbake/lib/bb/parse/parse_py/BBHandler.py50
1 files changed, 39 insertions, 11 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py
index 422ce6f9ef..c82090fec0 100644
--- a/bitbake/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py
@@ -21,9 +21,9 @@
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place, Suite 330, Boston, MA 02111-1307 USA.""" 22 Place, Suite 330, Boston, MA 02111-1307 USA."""
23 23
24import re, bb, os, sys 24import re, bb, os, sys, time
25import bb.fetch, bb.build, bb.utils 25import bb.fetch, bb.build, bb.utils
26from bb import debug, data, fetch, fatal 26from bb import debug, data, fetch, fatal, methodpool
27 27
28from ConfHandler import include, localpath, obtain, init 28from ConfHandler import include, localpath, obtain, init
29from bb.parse import ParseError 29from bb.parse import ParseError
@@ -44,6 +44,8 @@ __bbpath_found__ = 0
44__classname__ = "" 44__classname__ = ""
45classes = [ None, ] 45classes = [ None, ]
46 46
47__parsed_methods__ = methodpool.get_parsed_dict()
48
47def supports(fn, d): 49def supports(fn, d):
48 localfn = localpath(fn, d) 50 localfn = localpath(fn, d)
49 return localfn[-3:] == ".bb" or localfn[-8:] == ".bbclass" or localfn[-4:] == ".inc" 51 return localfn[-3:] == ".bb" or localfn[-8:] == ".bbclass" or localfn[-4:] == ".inc"
@@ -78,6 +80,7 @@ def handle(fn, d, include = 0):
78 debug(2, "BB " + fn + ": handle(data, include)") 80 debug(2, "BB " + fn + ": handle(data, include)")
79 81
80 (root, ext) = os.path.splitext(os.path.basename(fn)) 82 (root, ext) = os.path.splitext(os.path.basename(fn))
83 base_name = "%s%s" % (root,ext)
81 init(d) 84 init(d)
82 85
83 if ext == ".bbclass": 86 if ext == ".bbclass":
@@ -126,10 +129,10 @@ def handle(fn, d, include = 0):
126 s = f.readline() 129 s = f.readline()
127 if not s: break 130 if not s: break
128 s = s.rstrip() 131 s = s.rstrip()
129 feeder(lineno, s, fn, d) 132 feeder(lineno, s, fn, base_name, d)
130 if __inpython__: 133 if __inpython__:
131 # add a blank line to close out any python definition 134 # add a blank line to close out any python definition
132 feeder(lineno + 1, "", fn, d) 135 feeder(lineno + 1, "", fn, base_name, d)
133 if ext == ".bbclass": 136 if ext == ".bbclass":
134 classes.remove(__classname__) 137 classes.remove(__classname__)
135 else: 138 else:
@@ -156,9 +159,15 @@ def handle(fn, d, include = 0):
156 set_additional_vars(fn, d, include) 159 set_additional_vars(fn, d, include)
157 data.update_data(d) 160 data.update_data(d)
158 161
162 all_handlers = {}
159 for var in data.keys(d): 163 for var in data.keys(d):
164 # try to add the handler
165 # if we added it remember the choiche
160 if data.getVarFlag(var, 'handler', d): 166 if data.getVarFlag(var, 'handler', d):
161 bb.event.register(data.getVar(var, d)) 167 handler = data.getVar(var,d)
168 if bb.event.register(var,handler) == bb.event.Registered:
169 all_handlers[var] = handler
170
162 continue 171 continue
163 172
164 if not data.getVarFlag(var, 'task', d): 173 if not data.getVarFlag(var, 'task', d):
@@ -172,12 +181,22 @@ def handle(fn, d, include = 0):
172 pdeps.append(var) 181 pdeps.append(var)
173 data.setVarFlag(p, 'deps', pdeps, d) 182 data.setVarFlag(p, 'deps', pdeps, d)
174 bb.build.add_task(p, pdeps, d) 183 bb.build.add_task(p, pdeps, d)
184
185 # now add the handlers
186 if not len(all_handlers) == 0:
187 data.setVar('__all_handlers__', all_handlers, d)
188
175 bbpath.pop(0) 189 bbpath.pop(0)
176 if oldfile: 190 if oldfile:
177 bb.data.setVar("FILE", oldfile, d) 191 bb.data.setVar("FILE", oldfile, d)
192
193 # we have parsed the bb class now
194 if ext == ".bbclass" or ext == ".inc":
195 __parsed_methods__[base_name] = 1
196
178 return d 197 return d
179 198
180def feeder(lineno, s, fn, d): 199def feeder(lineno, s, fn, root, d):
181 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, __bbpath_found__, classes, bb, __residue__ 200 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, __bbpath_found__, classes, bb, __residue__
182 if __infunc__: 201 if __infunc__:
183 if s == '}': 202 if s == '}':
@@ -205,13 +224,22 @@ def feeder(lineno, s, fn, d):
205 __body__.append(s) 224 __body__.append(s)
206 return 225 return
207 else: 226 else:
208 text = '\n'.join(__body__) 227 # Note we will add root to parsedmethods after having parse
209 comp = bb.utils.better_compile(text, "<bb>", fn ) 228 # 'this' file. This means we will not parse methods from
210 bb.utils.better_exec(comp, __builtins__, text, fn) 229 # bb classes twice
230 if not root in __parsed_methods__:
231 text = '\n'.join(__body__)
232 methodpool.insert_method( root, text, fn )
233 funcs = data.getVar('__functions__', d) or {}
234 if not funcs.has_key( root ):
235 funcs[root] = text
236 else:
237 funcs[root] = "%s\n%s" % (funcs[root], text)
238
239 data.setVar('__functions__', funcs, d)
211 __body__ = [] 240 __body__ = []
212 __inpython__ = False 241 __inpython__ = False
213 funcs = data.getVar('__functions__', d) or "" 242
214 data.setVar('__functions__', "%s\n%s" % (funcs, text), d)
215# fall through 243# fall through
216 244
217 if s == '' or s[0] == '#': return # skip comments and empty lines 245 if s == '' or s[0] == '#': return # skip comments and empty lines