diff options
Diffstat (limited to 'bitbake/lib/bb/parse/parse_py/BBHandler.py')
| -rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.py | 263 |
1 files changed, 0 insertions, 263 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py deleted file mode 100644 index f8988b8631..0000000000 --- a/bitbake/lib/bb/parse/parse_py/BBHandler.py +++ /dev/null | |||
| @@ -1,263 +0,0 @@ | |||
| 1 | """ | ||
| 2 | class for handling .bb files | ||
| 3 | |||
| 4 | Reads a .bb file and obtains its metadata | ||
| 5 | |||
| 6 | """ | ||
| 7 | |||
| 8 | |||
| 9 | # Copyright (C) 2003, 2004 Chris Larson | ||
| 10 | # Copyright (C) 2003, 2004 Phil Blundell | ||
| 11 | # | ||
| 12 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 13 | # | ||
| 14 | |||
| 15 | import re, bb, os | ||
| 16 | import bb.build, bb.utils, bb.data_smart | ||
| 17 | |||
| 18 | from . import ConfHandler | ||
| 19 | from .. import resolve_file, ast, logger, ParseError | ||
| 20 | from .ConfHandler import include, init | ||
| 21 | |||
| 22 | # For compatibility | ||
| 23 | bb.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+(.+)" ) | ||
| 27 | __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))|(.*)))))*") | ||
| 29 | __deltask_regexp__ = re.compile(r"deltask\s+(.+)") | ||
| 30 | __addhandler_regexp__ = re.compile(r"addhandler\s+(.+)" ) | ||
| 31 | __def_regexp__ = re.compile(r"def\s+(\w+).*:" ) | ||
| 32 | __python_func_regexp__ = re.compile(r"(\s+.*)|(^$)|(^#)" ) | ||
| 33 | __python_tab_regexp__ = re.compile(r" *\t") | ||
| 34 | |||
| 35 | __infunc__ = [] | ||
| 36 | __inpython__ = False | ||
| 37 | __body__ = [] | ||
| 38 | __classname__ = "" | ||
| 39 | |||
| 40 | cached_statements = {} | ||
| 41 | |||
| 42 | def supports(fn, d): | ||
| 43 | """Return True if fn has a supported extension""" | ||
| 44 | return os.path.splitext(fn)[-1] in [".bb", ".bbclass", ".inc"] | ||
| 45 | |||
| 46 | def inherit(files, fn, lineno, d): | ||
| 47 | __inherit_cache = d.getVar('__inherit_cache', False) or [] | ||
| 48 | files = d.expand(files).split() | ||
| 49 | for file in files: | ||
| 50 | if not os.path.isabs(file) and not file.endswith(".bbclass"): | ||
| 51 | file = os.path.join('classes', '%s.bbclass' % file) | ||
| 52 | |||
| 53 | if not os.path.isabs(file): | ||
| 54 | bbpath = d.getVar("BBPATH") | ||
| 55 | abs_fn, attempts = bb.utils.which(bbpath, file, history=True) | ||
| 56 | for af in attempts: | ||
| 57 | if af != abs_fn: | ||
| 58 | bb.parse.mark_dependency(d, af) | ||
| 59 | if abs_fn: | ||
| 60 | file = abs_fn | ||
| 61 | |||
| 62 | if not file in __inherit_cache: | ||
| 63 | logger.debug("Inheriting %s (from %s:%d)" % (file, fn, lineno)) | ||
| 64 | __inherit_cache.append( file ) | ||
| 65 | d.setVar('__inherit_cache', __inherit_cache) | ||
| 66 | include(fn, file, lineno, d, "inherit") | ||
| 67 | __inherit_cache = d.getVar('__inherit_cache', False) or [] | ||
| 68 | |||
| 69 | def get_statements(filename, absolute_filename, base_name): | ||
| 70 | global cached_statements | ||
| 71 | |||
| 72 | try: | ||
| 73 | return cached_statements[absolute_filename] | ||
| 74 | except KeyError: | ||
| 75 | with open(absolute_filename, 'r') as f: | ||
| 76 | statements = ast.StatementGroup() | ||
| 77 | |||
| 78 | lineno = 0 | ||
| 79 | while True: | ||
| 80 | lineno = lineno + 1 | ||
| 81 | s = f.readline() | ||
| 82 | if not s: break | ||
| 83 | s = s.rstrip() | ||
| 84 | feeder(lineno, s, filename, base_name, statements) | ||
| 85 | |||
| 86 | if __inpython__: | ||
| 87 | # add a blank line to close out any python definition | ||
| 88 | feeder(lineno, "", filename, base_name, statements, eof=True) | ||
| 89 | |||
| 90 | if filename.endswith(".bbclass") or filename.endswith(".inc"): | ||
| 91 | cached_statements[absolute_filename] = statements | ||
| 92 | return statements | ||
| 93 | |||
| 94 | def handle(fn, d, include): | ||
| 95 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __residue__, __classname__ | ||
| 96 | __body__ = [] | ||
| 97 | __infunc__ = [] | ||
| 98 | __classname__ = "" | ||
| 99 | __residue__ = [] | ||
| 100 | |||
| 101 | base_name = os.path.basename(fn) | ||
| 102 | (root, ext) = os.path.splitext(base_name) | ||
| 103 | init(d) | ||
| 104 | |||
| 105 | if ext == ".bbclass": | ||
| 106 | __classname__ = root | ||
| 107 | __inherit_cache = d.getVar('__inherit_cache', False) or [] | ||
| 108 | if not fn in __inherit_cache: | ||
| 109 | __inherit_cache.append(fn) | ||
| 110 | d.setVar('__inherit_cache', __inherit_cache) | ||
| 111 | |||
| 112 | if include != 0: | ||
| 113 | oldfile = d.getVar('FILE', False) | ||
| 114 | else: | ||
| 115 | oldfile = None | ||
| 116 | |||
| 117 | abs_fn = resolve_file(fn, d) | ||
| 118 | |||
| 119 | # actual loading | ||
| 120 | statements = get_statements(fn, abs_fn, base_name) | ||
| 121 | |||
| 122 | # DONE WITH PARSING... time to evaluate | ||
| 123 | if ext != ".bbclass" and abs_fn != oldfile: | ||
| 124 | d.setVar('FILE', abs_fn) | ||
| 125 | |||
| 126 | try: | ||
| 127 | statements.eval(d) | ||
| 128 | except bb.parse.SkipRecipe: | ||
| 129 | d.setVar("__SKIPPED", True) | ||
| 130 | if include == 0: | ||
| 131 | return { "" : d } | ||
| 132 | |||
| 133 | if __infunc__: | ||
| 134 | raise ParseError("Shell function %s is never closed" % __infunc__[0], __infunc__[1], __infunc__[2]) | ||
| 135 | if __residue__: | ||
| 136 | raise ParseError("Leftover unparsed (incomplete?) data %s from %s" % __residue__, fn) | ||
| 137 | |||
| 138 | if ext != ".bbclass" and include == 0: | ||
| 139 | return ast.multi_finalize(fn, d) | ||
| 140 | |||
| 141 | if ext != ".bbclass" and oldfile and abs_fn != oldfile: | ||
| 142 | d.setVar("FILE", oldfile) | ||
| 143 | |||
| 144 | return d | ||
| 145 | |||
| 146 | def 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__ | ||
| 148 | |||
| 149 | # Check tabs in python functions: | ||
| 150 | # - def py_funcname(): covered by __inpython__ | ||
| 151 | # - python(): covered by '__anonymous' == __infunc__[0] | ||
| 152 | # - python funcname(): covered by __infunc__[3] | ||
| 153 | if __inpython__ or (__infunc__ and ('__anonymous' == __infunc__[0] or __infunc__[3])): | ||
| 154 | tab = __python_tab_regexp__.match(s) | ||
| 155 | if tab: | ||
| 156 | bb.warn('python should use 4 spaces indentation, but found tabs in %s, line %s' % (root, lineno)) | ||
| 157 | |||
| 158 | if __infunc__: | ||
| 159 | if s == '}': | ||
| 160 | __body__.append('') | ||
| 161 | ast.handleMethod(statements, fn, lineno, __infunc__[0], __body__, __infunc__[3], __infunc__[4]) | ||
| 162 | __infunc__ = [] | ||
| 163 | __body__ = [] | ||
| 164 | else: | ||
| 165 | __body__.append(s) | ||
| 166 | return | ||
| 167 | |||
| 168 | if __inpython__: | ||
| 169 | m = __python_func_regexp__.match(s) | ||
| 170 | if m and not eof: | ||
| 171 | __body__.append(s) | ||
| 172 | return | ||
| 173 | else: | ||
| 174 | ast.handlePythonMethod(statements, fn, lineno, __inpython__, | ||
| 175 | root, __body__) | ||
| 176 | __body__ = [] | ||
| 177 | __inpython__ = False | ||
| 178 | |||
| 179 | if eof: | ||
| 180 | return | ||
| 181 | |||
| 182 | if s and s[0] == '#': | ||
| 183 | 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)) | ||
| 185 | |||
| 186 | 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)) | ||
| 188 | |||
| 189 | if s and s[-1] == '\\': | ||
| 190 | __residue__.append(s[:-1]) | ||
| 191 | return | ||
| 192 | |||
| 193 | s = "".join(__residue__) + s | ||
| 194 | __residue__ = [] | ||
| 195 | |||
| 196 | # Skip empty lines | ||
| 197 | if s == '': | ||
| 198 | return | ||
| 199 | |||
| 200 | # Skip comments | ||
| 201 | if s[0] == '#': | ||
| 202 | return | ||
| 203 | |||
| 204 | m = __func_start_regexp__.match(s) | ||
| 205 | if m: | ||
| 206 | __infunc__ = [m.group("func") or "__anonymous", fn, lineno, m.group("py") is not None, m.group("fr") is not None] | ||
| 207 | return | ||
| 208 | |||
| 209 | m = __def_regexp__.match(s) | ||
| 210 | if m: | ||
| 211 | __body__.append(s) | ||
| 212 | __inpython__ = m.group(1) | ||
| 213 | |||
| 214 | return | ||
| 215 | |||
| 216 | m = __export_func_regexp__.match(s) | ||
| 217 | if m: | ||
| 218 | ast.handleExportFuncs(statements, fn, lineno, m, __classname__) | ||
| 219 | return | ||
| 220 | |||
| 221 | m = __addtask_regexp__.match(s) | ||
| 222 | if m: | ||
| 223 | if len(m.group().split()) == 2: | ||
| 224 | # Check and warn for "addtask task1 task2" | ||
| 225 | m2 = re.match(r"addtask\s+(?P<func>\w+)(?P<ignores>.*)", s) | ||
| 226 | if m2 and m2.group('ignores'): | ||
| 227 | logger.warning('addtask ignored: "%s"' % m2.group('ignores')) | ||
| 228 | |||
| 229 | # Check and warn for "addtask task1 before task2 before task3", the | ||
| 230 | # similar to "after" | ||
| 231 | taskexpression = s.split() | ||
| 232 | for word in ('before', 'after'): | ||
| 233 | if taskexpression.count(word) > 1: | ||
| 234 | logger.warning("addtask contained multiple '%s' keywords, only one is supported" % word) | ||
| 235 | |||
| 236 | # Check and warn for having task with exprssion as part of task name | ||
| 237 | for te in taskexpression: | ||
| 238 | if any( ( "%s_" % keyword ) in te for keyword in bb.data_smart.__setvar_keyword__ ): | ||
| 239 | 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) | ||
| 240 | ast.handleAddTask(statements, fn, lineno, m) | ||
| 241 | return | ||
| 242 | |||
| 243 | m = __deltask_regexp__.match(s) | ||
| 244 | if m: | ||
| 245 | ast.handleDelTask(statements, fn, lineno, m) | ||
| 246 | return | ||
| 247 | |||
| 248 | m = __addhandler_regexp__.match(s) | ||
| 249 | if m: | ||
| 250 | ast.handleBBHandlers(statements, fn, lineno, m) | ||
| 251 | return | ||
| 252 | |||
| 253 | m = __inherit_regexp__.match(s) | ||
| 254 | if m: | ||
| 255 | ast.handleInherit(statements, fn, lineno, m) | ||
| 256 | return | ||
| 257 | |||
| 258 | return ConfHandler.feeder(lineno, s, fn, statements) | ||
| 259 | |||
| 260 | # Add us to the handlers list | ||
| 261 | from .. import handlers | ||
| 262 | handlers.append({'supports': supports, 'handle': handle, 'init': init}) | ||
| 263 | del handlers | ||
