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.py72
1 files changed, 48 insertions, 24 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py
index f8988b8631..c13e4b9755 100644
--- a/bitbake/lib/bb/parse/parse_py/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py
@@ -19,11 +19,9 @@ from . import ConfHandler
19from .. import resolve_file, ast, logger, ParseError 19from .. import resolve_file, ast, logger, ParseError
20from .ConfHandler import include, init 20from .ConfHandler import include, init
21 21
22# For compatibility 22__func_start_regexp__ = re.compile(r"(((?P<py>python(?=(\s|\()))|(?P<fr>fakeroot(?=\s)))\s*)*(?P<func>[\w\.\-\+\{\}\$:]+)?\s*\(\s*\)\s*{$" )
23bb.deprecate_import(__name__, "bb.parse", ["vars_from_file"])
24
25__func_start_regexp__ = re.compile(r"(((?P<py>python(?=(\s|\()))|(?P<fr>fakeroot(?=\s)))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" )
26__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+(.+)" )
27__export_func_regexp__ = re.compile(r"EXPORT_FUNCTIONS\s+(.+)" ) 25__export_func_regexp__ = re.compile(r"EXPORT_FUNCTIONS\s+(.+)" )
28__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+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*")
29__deltask_regexp__ = re.compile(r"deltask\s+(.+)") 27__deltask_regexp__ = re.compile(r"deltask\s+(.+)")
@@ -36,6 +34,7 @@ __infunc__ = []
36__inpython__ = False 34__inpython__ = False
37__body__ = [] 35__body__ = []
38__classname__ = "" 36__classname__ = ""
37__residue__ = []
39 38
40cached_statements = {} 39cached_statements = {}
41 40
@@ -43,31 +42,46 @@ def supports(fn, d):
43 """Return True if fn has a supported extension""" 42 """Return True if fn has a supported extension"""
44 return os.path.splitext(fn)[-1] in [".bb", ".bbclass", ".inc"] 43 return os.path.splitext(fn)[-1] in [".bb", ".bbclass", ".inc"]
45 44
46def inherit(files, fn, lineno, d): 45def inherit(files, fn, lineno, d, deferred=False):
47 __inherit_cache = d.getVar('__inherit_cache', False) or [] 46 __inherit_cache = d.getVar('__inherit_cache', False) or []
47 #if "${" in files and not deferred:
48 # bb.warn("%s:%s has non deferred conditional inherit" % (fn, lineno))
48 files = d.expand(files).split() 49 files = d.expand(files).split()
49 for file in files: 50 for file in files:
50 if not os.path.isabs(file) and not file.endswith(".bbclass"): 51 classtype = d.getVar("__bbclasstype", False)
51 file = os.path.join('classes', '%s.bbclass' % file) 52 origfile = file
52 53 for t in ["classes-" + classtype, "classes"]:
53 if not os.path.isabs(file): 54 file = origfile
54 bbpath = d.getVar("BBPATH") 55 if not os.path.isabs(file) and not file.endswith(".bbclass"):
55 abs_fn, attempts = bb.utils.which(bbpath, file, history=True) 56 file = os.path.join(t, '%s.bbclass' % file)
56 for af in attempts: 57
57 if af != abs_fn: 58 if not os.path.isabs(file):
58 bb.parse.mark_dependency(d, af) 59 bbpath = d.getVar("BBPATH")
59 if abs_fn: 60 abs_fn, attempts = bb.utils.which(bbpath, file, history=True)
60 file = abs_fn 61 for af in attempts:
62 if af != abs_fn:
63 bb.parse.mark_dependency(d, af)
64 if abs_fn:
65 file = abs_fn
66
67 if os.path.exists(file):
68 break
69
70 if not os.path.exists(file):
71 raise ParseError("Could not inherit file %s" % (file), fn, lineno)
61 72
62 if not file in __inherit_cache: 73 if not file in __inherit_cache:
63 logger.debug("Inheriting %s (from %s:%d)" % (file, fn, lineno)) 74 logger.debug("Inheriting %s (from %s:%d)" % (file, fn, lineno))
64 __inherit_cache.append( file ) 75 __inherit_cache.append( file )
65 d.setVar('__inherit_cache', __inherit_cache) 76 d.setVar('__inherit_cache', __inherit_cache)
66 include(fn, file, lineno, d, "inherit") 77 try:
78 bb.parse.handle(file, d, True)
79 except (IOError, OSError) as exc:
80 raise ParseError("Could not inherit file %s: %s" % (fn, exc.strerror), fn, lineno)
67 __inherit_cache = d.getVar('__inherit_cache', False) or [] 81 __inherit_cache = d.getVar('__inherit_cache', False) or []
68 82
69def get_statements(filename, absolute_filename, base_name): 83def get_statements(filename, absolute_filename, base_name):
70 global cached_statements 84 global cached_statements, __residue__, __body__
71 85
72 try: 86 try:
73 return cached_statements[absolute_filename] 87 return cached_statements[absolute_filename]
@@ -87,12 +101,17 @@ def get_statements(filename, absolute_filename, base_name):
87 # add a blank line to close out any python definition 101 # add a blank line to close out any python definition
88 feeder(lineno, "", filename, base_name, statements, eof=True) 102 feeder(lineno, "", filename, base_name, statements, eof=True)
89 103
104 if __residue__:
105 raise ParseError("Unparsed lines %s: %s" % (filename, str(__residue__)), filename, lineno)
106 if __body__:
107 raise ParseError("Unparsed lines from unclosed function %s: %s" % (filename, str(__body__)), filename, lineno)
108
90 if filename.endswith(".bbclass") or filename.endswith(".inc"): 109 if filename.endswith(".bbclass") or filename.endswith(".inc"):
91 cached_statements[absolute_filename] = statements 110 cached_statements[absolute_filename] = statements
92 return statements 111 return statements
93 112
94def handle(fn, d, include): 113def handle(fn, d, include, baseconfig=False):
95 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__, __classname__ 114 global __infunc__, __body__, __residue__, __classname__
96 __body__ = [] 115 __body__ = []
97 __infunc__ = [] 116 __infunc__ = []
98 __classname__ = "" 117 __classname__ = ""
@@ -144,7 +163,7 @@ def handle(fn, d, include):
144 return d 163 return d
145 164
146def feeder(lineno, s, fn, root, statements, eof=False): 165def feeder(lineno, s, fn, root, statements, eof=False):
147 global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__, __infunc__, __body__, bb, __residue__, __classname__ 166 global __inpython__, __infunc__, __body__, __residue__, __classname__
148 167
149 # Check tabs in python functions: 168 # Check tabs in python functions:
150 # - def py_funcname(): covered by __inpython__ 169 # - def py_funcname(): covered by __inpython__
@@ -181,10 +200,10 @@ def feeder(lineno, s, fn, root, statements, eof=False):
181 200
182 if s and s[0] == '#': 201 if s and s[0] == '#':
183 if len(__residue__) != 0 and __residue__[0][0] != "#": 202 if len(__residue__) != 0 and __residue__[0][0] != "#":
184 bb.fatal("There is a comment on line %s of file %s (%s) which is in the middle of a multiline expression.\nBitbake used to ignore these but no longer does so, please fix your metadata as errors are likely as a result of this change." % (lineno, fn, s)) 203 bb.fatal("There is a comment on line %s of file %s:\n'''\n%s\n'''\nwhich is in the middle of a multiline expression. This syntax is invalid, please correct it." % (lineno, fn, s))
185 204
186 if len(__residue__) != 0 and __residue__[0][0] == "#" and (not s or s[0] != "#"): 205 if len(__residue__) != 0 and __residue__[0][0] == "#" and (not s or s[0] != "#"):
187 bb.fatal("There is a confusing multiline, partially commented expression on line %s of file %s (%s).\nPlease clarify whether this is all a comment or should be parsed." % (lineno, fn, s)) 206 bb.fatal("There is a confusing multiline partially commented expression on line %s of file %s:\n%s\nPlease clarify whether this is all a comment or should be parsed." % (lineno - len(__residue__), fn, "\n".join(__residue__)))
188 207
189 if s and s[-1] == '\\': 208 if s and s[-1] == '\\':
190 __residue__.append(s[:-1]) 209 __residue__.append(s[:-1])
@@ -255,7 +274,12 @@ def feeder(lineno, s, fn, root, statements, eof=False):
255 ast.handleInherit(statements, fn, lineno, m) 274 ast.handleInherit(statements, fn, lineno, m)
256 return 275 return
257 276
258 return ConfHandler.feeder(lineno, s, fn, statements) 277 m = __inherit_def_regexp__.match(s)
278 if m:
279 ast.handleInheritDeferred(statements, fn, lineno, m)
280 return
281
282 return ConfHandler.feeder(lineno, s, fn, statements, conffile=False)
259 283
260# Add us to the handlers list 284# Add us to the handlers list
261from .. import handlers 285from .. import handlers