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.py61
1 files changed, 43 insertions, 18 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py
index cd1c998f8f..008fec2308 100644
--- a/bitbake/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py
@@ -23,8 +23,8 @@ __func_start_regexp__ = re.compile(r"(((?P<py>python(?=(\s|\()))|(?P<fr>faker
23__inherit_regexp__ = re.compile(r"inherit\s+(.+)" ) 23__inherit_regexp__ = re.compile(r"inherit\s+(.+)" )
24__inherit_def_regexp__ = re.compile(r"inherit_defer\s+(.+)" ) 24__inherit_def_regexp__ = re.compile(r"inherit_defer\s+(.+)" )
25__export_func_regexp__ = re.compile(r"EXPORT_FUNCTIONS\s+(.+)" ) 25__export_func_regexp__ = re.compile(r"EXPORT_FUNCTIONS\s+(.+)" )
26__addtask_regexp__ = re.compile(r"addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*") 26__addtask_regexp__ = re.compile(r"addtask\s+([^#\n]+)(?P<comment>#.*|.*?)")
27__deltask_regexp__ = re.compile(r"deltask\s+(.+)") 27__deltask_regexp__ = re.compile(r"deltask\s+([^#\n]+)(?P<comment>#.*|.*?)")
28__addhandler_regexp__ = re.compile(r"addhandler\s+(.+)" ) 28__addhandler_regexp__ = re.compile(r"addhandler\s+(.+)" )
29__def_regexp__ = re.compile(r"def\s+(\w+).*:" ) 29__def_regexp__ = re.compile(r"def\s+(\w+).*:" )
30__python_func_regexp__ = re.compile(r"(\s+.*)|(^$)|(^#)" ) 30__python_func_regexp__ = re.compile(r"(\s+.*)|(^$)|(^#)" )
@@ -34,6 +34,7 @@ __infunc__ = []
34__inpython__ = False 34__inpython__ = False
35__body__ = [] 35__body__ = []
36__classname__ = "" 36__classname__ = ""
37__residue__ = []
37 38
38cached_statements = {} 39cached_statements = {}
39 40
@@ -41,12 +42,22 @@ def supports(fn, d):
41 """Return True if fn has a supported extension""" 42 """Return True if fn has a supported extension"""
42 return os.path.splitext(fn)[-1] in [".bb", ".bbclass", ".inc"] 43 return os.path.splitext(fn)[-1] in [".bb", ".bbclass", ".inc"]
43 44
45def inherit_defer(expression, fn, lineno, d):
46 inherit = (expression, fn, lineno)
47 inherits = d.getVar('__BBDEFINHERITS', False) or []
48 inherits.append(inherit)
49 d.setVar('__BBDEFINHERITS', inherits)
50
44def inherit(files, fn, lineno, d, deferred=False): 51def inherit(files, fn, lineno, d, deferred=False):
45 __inherit_cache = d.getVar('__inherit_cache', False) or [] 52 __inherit_cache = d.getVar('__inherit_cache', False) or []
46 #if "${" in files and not deferred: 53 #if "${" in files and not deferred:
47 # bb.warn("%s:%s has non deferred conditional inherit" % (fn, lineno)) 54 # bb.warn("%s:%s has non deferred conditional inherit" % (fn, lineno))
48 files = d.expand(files).split() 55 files = d.expand(files).split()
49 for file in files: 56 for file in files:
57 defer = (d.getVar("BB_DEFER_BBCLASSES") or "").split()
58 if not deferred and file in defer:
59 inherit_defer(file, fn, lineno, d)
60 continue
50 classtype = d.getVar("__bbclasstype", False) 61 classtype = d.getVar("__bbclasstype", False)
51 origfile = file 62 origfile = file
52 for t in ["classes-" + classtype, "classes"]: 63 for t in ["classes-" + classtype, "classes"]:
@@ -80,7 +91,7 @@ def inherit(files, fn, lineno, d, deferred=False):
80 __inherit_cache = d.getVar('__inherit_cache', False) or [] 91 __inherit_cache = d.getVar('__inherit_cache', False) or []
81 92
82def get_statements(filename, absolute_filename, base_name): 93def get_statements(filename, absolute_filename, base_name):
83 global cached_statements 94 global cached_statements, __residue__, __body__
84 95
85 try: 96 try:
86 return cached_statements[absolute_filename] 97 return cached_statements[absolute_filename]
@@ -100,6 +111,11 @@ def get_statements(filename, absolute_filename, base_name):
100 # add a blank line to close out any python definition 111 # add a blank line to close out any python definition
101 feeder(lineno, "", filename, base_name, statements, eof=True) 112 feeder(lineno, "", filename, base_name, statements, eof=True)
102 113
114 if __residue__:
115 raise ParseError("Unparsed lines %s: %s" % (filename, str(__residue__)), filename, lineno)
116 if __body__:
117 raise ParseError("Unparsed lines from unclosed function %s: %s" % (filename, str(__body__)), filename, lineno)
118
103 if filename.endswith(".bbclass") or filename.endswith(".inc"): 119 if filename.endswith(".bbclass") or filename.endswith(".inc"):
104 cached_statements[absolute_filename] = statements 120 cached_statements[absolute_filename] = statements
105 return statements 121 return statements
@@ -233,29 +249,38 @@ def feeder(lineno, s, fn, root, statements, eof=False):
233 249
234 m = __addtask_regexp__.match(s) 250 m = __addtask_regexp__.match(s)
235 if m: 251 if m:
236 if len(m.group().split()) == 2: 252 after = ""
237 # Check and warn for "addtask task1 task2" 253 before = ""
238 m2 = re.match(r"addtask\s+(?P<func>\w+)(?P<ignores>.*)", s) 254
239 if m2 and m2.group('ignores'): 255 # This code splits on 'before' and 'after' instead of on whitespace so we can defer
240 logger.warning('addtask ignored: "%s"' % m2.group('ignores')) 256 # evaluation to as late as possible.
241 257 tasks = m.group(1).split(" before ")[0].split(" after ")[0]
242 # Check and warn for "addtask task1 before task2 before task3", the
243 # similar to "after"
244 taskexpression = s.split()
245 for word in ('before', 'after'):
246 if taskexpression.count(word) > 1:
247 logger.warning("addtask contained multiple '%s' keywords, only one is supported" % word)
248 258
249 # Check and warn for having task with exprssion as part of task name 259 for exp in m.group(1).split(" before "):
260 exp2 = exp.split(" after ")
261 if len(exp2) > 1:
262 after = after + " ".join(exp2[1:])
263
264 for exp in m.group(1).split(" after "):
265 exp2 = exp.split(" before ")
266 if len(exp2) > 1:
267 before = before + " ".join(exp2[1:])
268
269 # Check and warn for having task with a keyword as part of task name
270 taskexpression = s.split()
250 for te in taskexpression: 271 for te in taskexpression:
251 if any( ( "%s_" % keyword ) in te for keyword in bb.data_smart.__setvar_keyword__ ): 272 if any( ( "%s_" % keyword ) in te for keyword in bb.data_smart.__setvar_keyword__ ):
252 raise ParseError("Task name '%s' contains a keyword which is not recommended/supported.\nPlease rename the task not to include the keyword.\n%s" % (te, ("\n".join(map(str, bb.data_smart.__setvar_keyword__)))), fn) 273 raise ParseError("Task name '%s' contains a keyword which is not recommended/supported.\nPlease rename the task not to include the keyword.\n%s" % (te, ("\n".join(map(str, bb.data_smart.__setvar_keyword__)))), fn)
253 ast.handleAddTask(statements, fn, lineno, m) 274
275 if tasks is not None:
276 ast.handleAddTask(statements, fn, lineno, tasks, before, after)
254 return 277 return
255 278
256 m = __deltask_regexp__.match(s) 279 m = __deltask_regexp__.match(s)
257 if m: 280 if m:
258 ast.handleDelTask(statements, fn, lineno, m) 281 task = m.group(1)
282 if task is not None:
283 ast.handleDelTask(statements, fn, lineno, task)
259 return 284 return
260 285
261 m = __addhandler_regexp__.match(s) 286 m = __addhandler_regexp__.match(s)