Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | """ |
| 2 | AbstractSyntaxTree classes for the Bitbake language |
| 3 | """ |
| 4 | |
| 5 | # Copyright (C) 2003, 2004 Chris Larson |
| 6 | # Copyright (C) 2003, 2004 Phil Blundell |
| 7 | # Copyright (C) 2009 Holger Hans Peter Freyther |
| 8 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 9 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 11 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | import bb |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | from bb import methodpool |
| 14 | from bb.parse import logger |
| 15 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 16 | class StatementGroup(list): |
| 17 | def eval(self, data): |
| 18 | for statement in self: |
| 19 | statement.eval(data) |
| 20 | |
| 21 | class AstNode(object): |
| 22 | def __init__(self, filename, lineno): |
| 23 | self.filename = filename |
| 24 | self.lineno = lineno |
| 25 | |
| 26 | class IncludeNode(AstNode): |
| 27 | def __init__(self, filename, lineno, what_file, force): |
| 28 | AstNode.__init__(self, filename, lineno) |
| 29 | self.what_file = what_file |
| 30 | self.force = force |
| 31 | |
| 32 | def eval(self, data): |
| 33 | """ |
| 34 | Include the file and evaluate the statements |
| 35 | """ |
| 36 | s = data.expand(self.what_file) |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 37 | logger.debug2("CONF %s:%s: including %s", self.filename, self.lineno, s) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | |
| 39 | # TODO: Cache those includes... maybe not here though |
| 40 | if self.force: |
| 41 | bb.parse.ConfHandler.include(self.filename, s, self.lineno, data, "include required") |
| 42 | else: |
| 43 | bb.parse.ConfHandler.include(self.filename, s, self.lineno, data, False) |
| 44 | |
| 45 | class ExportNode(AstNode): |
| 46 | def __init__(self, filename, lineno, var): |
| 47 | AstNode.__init__(self, filename, lineno) |
| 48 | self.var = var |
| 49 | |
| 50 | def eval(self, data): |
| 51 | data.setVarFlag(self.var, "export", 1, op = 'exported') |
| 52 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 53 | class UnsetNode(AstNode): |
| 54 | def __init__(self, filename, lineno, var): |
| 55 | AstNode.__init__(self, filename, lineno) |
| 56 | self.var = var |
| 57 | |
| 58 | def eval(self, data): |
| 59 | loginfo = { |
| 60 | 'variable': self.var, |
| 61 | 'file': self.filename, |
| 62 | 'line': self.lineno, |
| 63 | } |
| 64 | data.delVar(self.var,**loginfo) |
| 65 | |
| 66 | class UnsetFlagNode(AstNode): |
| 67 | def __init__(self, filename, lineno, var, flag): |
| 68 | AstNode.__init__(self, filename, lineno) |
| 69 | self.var = var |
| 70 | self.flag = flag |
| 71 | |
| 72 | def eval(self, data): |
| 73 | loginfo = { |
| 74 | 'variable': self.var, |
| 75 | 'file': self.filename, |
| 76 | 'line': self.lineno, |
| 77 | } |
| 78 | data.delVarFlag(self.var, self.flag, **loginfo) |
| 79 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 80 | class DataNode(AstNode): |
| 81 | """ |
| 82 | Various data related updates. For the sake of sanity |
| 83 | we have one class doing all this. This means that all |
| 84 | this need to be re-evaluated... we might be able to do |
| 85 | that faster with multiple classes. |
| 86 | """ |
| 87 | def __init__(self, filename, lineno, groupd): |
| 88 | AstNode.__init__(self, filename, lineno) |
| 89 | self.groupd = groupd |
| 90 | |
| 91 | def getFunc(self, key, data): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 92 | if 'flag' in self.groupd and self.groupd['flag'] is not None: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 93 | return data.getVarFlag(key, self.groupd['flag'], expand=False, noweakdefault=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 94 | else: |
| 95 | return data.getVar(key, False, noweakdefault=True, parsing=True) |
| 96 | |
| 97 | def eval(self, data): |
| 98 | groupd = self.groupd |
| 99 | key = groupd["var"] |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 100 | key = key.replace(":", "_") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 101 | loginfo = { |
| 102 | 'variable': key, |
| 103 | 'file': self.filename, |
| 104 | 'line': self.lineno, |
| 105 | } |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 106 | if "exp" in groupd and groupd["exp"] is not None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 107 | data.setVarFlag(key, "export", 1, op = 'exported', **loginfo) |
| 108 | |
| 109 | op = "set" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 110 | if "ques" in groupd and groupd["ques"] is not None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 111 | val = self.getFunc(key, data) |
| 112 | op = "set?" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 113 | if val is None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | val = groupd["value"] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 115 | elif "colon" in groupd and groupd["colon"] is not None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 116 | e = data.createCopy() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | op = "immediate" |
| 118 | val = e.expand(groupd["value"], key + "[:=]") |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 119 | elif "append" in groupd and groupd["append"] is not None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 120 | op = "append" |
| 121 | val = "%s %s" % ((self.getFunc(key, data) or ""), groupd["value"]) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 122 | elif "prepend" in groupd and groupd["prepend"] is not None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 123 | op = "prepend" |
| 124 | val = "%s %s" % (groupd["value"], (self.getFunc(key, data) or "")) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 125 | elif "postdot" in groupd and groupd["postdot"] is not None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | op = "postdot" |
| 127 | val = "%s%s" % ((self.getFunc(key, data) or ""), groupd["value"]) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 128 | elif "predot" in groupd and groupd["predot"] is not None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 129 | op = "predot" |
| 130 | val = "%s%s" % (groupd["value"], (self.getFunc(key, data) or "")) |
| 131 | else: |
| 132 | val = groupd["value"] |
| 133 | |
| 134 | flag = None |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 135 | if 'flag' in groupd and groupd['flag'] is not None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | flag = groupd['flag'] |
| 137 | elif groupd["lazyques"]: |
| 138 | flag = "_defaultval" |
| 139 | |
| 140 | loginfo['op'] = op |
| 141 | loginfo['detail'] = groupd["value"] |
| 142 | |
| 143 | if flag: |
| 144 | data.setVarFlag(key, flag, val, **loginfo) |
| 145 | else: |
| 146 | data.setVar(key, val, parsing=True, **loginfo) |
| 147 | |
| 148 | class MethodNode(AstNode): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 149 | tr_tbl = str.maketrans('/.+-@%&', '_______') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 151 | def __init__(self, filename, lineno, func_name, body, python, fakeroot): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 152 | AstNode.__init__(self, filename, lineno) |
| 153 | self.func_name = func_name |
| 154 | self.body = body |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 155 | self.python = python |
| 156 | self.fakeroot = fakeroot |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 157 | |
| 158 | def eval(self, data): |
| 159 | text = '\n'.join(self.body) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 160 | funcname = self.func_name |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 161 | if self.func_name == "__anonymous": |
| 162 | funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(MethodNode.tr_tbl))) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 163 | self.python = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | text = "def %s(d):\n" % (funcname) + text |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 165 | bb.methodpool.insert_method(funcname, text, self.filename, self.lineno - len(self.body) - 1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 166 | anonfuncs = data.getVar('__BBANONFUNCS', False) or [] |
| 167 | anonfuncs.append(funcname) |
| 168 | data.setVar('__BBANONFUNCS', anonfuncs) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 169 | if data.getVar(funcname, False): |
| 170 | # clean up old version of this piece of metadata, as its |
| 171 | # flags could cause problems |
| 172 | data.delVarFlag(funcname, 'python') |
| 173 | data.delVarFlag(funcname, 'fakeroot') |
| 174 | if self.python: |
| 175 | data.setVarFlag(funcname, "python", "1") |
| 176 | if self.fakeroot: |
| 177 | data.setVarFlag(funcname, "fakeroot", "1") |
| 178 | data.setVarFlag(funcname, "func", 1) |
| 179 | data.setVar(funcname, text, parsing=True) |
| 180 | data.setVarFlag(funcname, 'filename', self.filename) |
| 181 | data.setVarFlag(funcname, 'lineno', str(self.lineno - len(self.body))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 182 | |
| 183 | class PythonMethodNode(AstNode): |
| 184 | def __init__(self, filename, lineno, function, modulename, body): |
| 185 | AstNode.__init__(self, filename, lineno) |
| 186 | self.function = function |
| 187 | self.modulename = modulename |
| 188 | self.body = body |
| 189 | |
| 190 | def eval(self, data): |
| 191 | # Note we will add root to parsedmethods after having parse |
| 192 | # 'this' file. This means we will not parse methods from |
| 193 | # bb classes twice |
| 194 | text = '\n'.join(self.body) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 195 | bb.methodpool.insert_method(self.modulename, text, self.filename, self.lineno - len(self.body) - 1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | data.setVarFlag(self.function, "func", 1) |
| 197 | data.setVarFlag(self.function, "python", 1) |
| 198 | data.setVar(self.function, text, parsing=True) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 199 | data.setVarFlag(self.function, 'filename', self.filename) |
| 200 | data.setVarFlag(self.function, 'lineno', str(self.lineno - len(self.body) - 1)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 201 | |
| 202 | class ExportFuncsNode(AstNode): |
| 203 | def __init__(self, filename, lineno, fns, classname): |
| 204 | AstNode.__init__(self, filename, lineno) |
| 205 | self.n = fns.split() |
| 206 | self.classname = classname |
| 207 | |
| 208 | def eval(self, data): |
| 209 | |
| 210 | for func in self.n: |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 211 | func = func.replace(":", "_") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 212 | calledfunc = self.classname + "_" + func |
| 213 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 214 | if data.getVar(func, False) and not data.getVarFlag(func, 'export_func', False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 215 | continue |
| 216 | |
| 217 | if data.getVar(func, False): |
| 218 | data.setVarFlag(func, 'python', None) |
| 219 | data.setVarFlag(func, 'func', None) |
| 220 | |
| 221 | for flag in [ "func", "python" ]: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 222 | if data.getVarFlag(calledfunc, flag, False): |
| 223 | data.setVarFlag(func, flag, data.getVarFlag(calledfunc, flag, False)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | for flag in [ "dirs" ]: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 225 | if data.getVarFlag(func, flag, False): |
| 226 | data.setVarFlag(calledfunc, flag, data.getVarFlag(func, flag, False)) |
| 227 | data.setVarFlag(func, "filename", "autogenerated") |
| 228 | data.setVarFlag(func, "lineno", 1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 229 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 230 | if data.getVarFlag(calledfunc, "python", False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 231 | data.setVar(func, " bb.build.exec_func('" + calledfunc + "', d)\n", parsing=True) |
| 232 | else: |
| 233 | if "-" in self.classname: |
| 234 | bb.fatal("The classname %s contains a dash character and is calling an sh function %s using EXPORT_FUNCTIONS. Since a dash is illegal in sh function names, this cannot work, please rename the class or don't use EXPORT_FUNCTIONS." % (self.classname, calledfunc)) |
| 235 | data.setVar(func, " " + calledfunc + "\n", parsing=True) |
| 236 | data.setVarFlag(func, 'export_func', '1') |
| 237 | |
| 238 | class AddTaskNode(AstNode): |
| 239 | def __init__(self, filename, lineno, func, before, after): |
| 240 | AstNode.__init__(self, filename, lineno) |
| 241 | self.func = func |
| 242 | self.before = before |
| 243 | self.after = after |
| 244 | |
| 245 | def eval(self, data): |
| 246 | bb.build.addtask(self.func, self.before, self.after, data) |
| 247 | |
| 248 | class DelTaskNode(AstNode): |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 249 | def __init__(self, filename, lineno, tasks): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 250 | AstNode.__init__(self, filename, lineno) |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 251 | self.tasks = tasks |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | |
| 253 | def eval(self, data): |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 254 | tasks = data.expand(self.tasks).split() |
| 255 | for task in tasks: |
| 256 | bb.build.deltask(task, data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 257 | |
| 258 | class BBHandlerNode(AstNode): |
| 259 | def __init__(self, filename, lineno, fns): |
| 260 | AstNode.__init__(self, filename, lineno) |
| 261 | self.hs = fns.split() |
| 262 | |
| 263 | def eval(self, data): |
| 264 | bbhands = data.getVar('__BBHANDLERS', False) or [] |
| 265 | for h in self.hs: |
| 266 | bbhands.append(h) |
| 267 | data.setVarFlag(h, "handler", 1) |
| 268 | data.setVar('__BBHANDLERS', bbhands) |
| 269 | |
| 270 | class InheritNode(AstNode): |
| 271 | def __init__(self, filename, lineno, classes): |
| 272 | AstNode.__init__(self, filename, lineno) |
| 273 | self.classes = classes |
| 274 | |
| 275 | def eval(self, data): |
| 276 | bb.parse.BBHandler.inherit(self.classes, self.filename, self.lineno, data) |
| 277 | |
| 278 | def handleInclude(statements, filename, lineno, m, force): |
| 279 | statements.append(IncludeNode(filename, lineno, m.group(1), force)) |
| 280 | |
| 281 | def handleExport(statements, filename, lineno, m): |
| 282 | statements.append(ExportNode(filename, lineno, m.group(1))) |
| 283 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 284 | def handleUnset(statements, filename, lineno, m): |
| 285 | statements.append(UnsetNode(filename, lineno, m.group(1))) |
| 286 | |
| 287 | def handleUnsetFlag(statements, filename, lineno, m): |
| 288 | statements.append(UnsetFlagNode(filename, lineno, m.group(1), m.group(2))) |
| 289 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 290 | def handleData(statements, filename, lineno, groupd): |
| 291 | statements.append(DataNode(filename, lineno, groupd)) |
| 292 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 293 | def handleMethod(statements, filename, lineno, func_name, body, python, fakeroot): |
| 294 | statements.append(MethodNode(filename, lineno, func_name, body, python, fakeroot)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 295 | |
| 296 | def handlePythonMethod(statements, filename, lineno, funcname, modulename, body): |
| 297 | statements.append(PythonMethodNode(filename, lineno, funcname, modulename, body)) |
| 298 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 299 | def handleExportFuncs(statements, filename, lineno, m, classname): |
| 300 | statements.append(ExportFuncsNode(filename, lineno, m.group(1), classname)) |
| 301 | |
| 302 | def handleAddTask(statements, filename, lineno, m): |
| 303 | func = m.group("func") |
| 304 | before = m.group("before") |
| 305 | after = m.group("after") |
| 306 | if func is None: |
| 307 | return |
| 308 | |
| 309 | statements.append(AddTaskNode(filename, lineno, func, before, after)) |
| 310 | |
| 311 | def handleDelTask(statements, filename, lineno, m): |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 312 | func = m.group(1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 313 | if func is None: |
| 314 | return |
| 315 | |
| 316 | statements.append(DelTaskNode(filename, lineno, func)) |
| 317 | |
| 318 | def handleBBHandlers(statements, filename, lineno, m): |
| 319 | statements.append(BBHandlerNode(filename, lineno, m.group(1))) |
| 320 | |
| 321 | def handleInherit(statements, filename, lineno, m): |
| 322 | classes = m.group(1) |
| 323 | statements.append(InheritNode(filename, lineno, classes)) |
| 324 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 325 | def runAnonFuncs(d): |
| 326 | code = [] |
| 327 | for funcname in d.getVar("__BBANONFUNCS", False) or []: |
| 328 | code.append("%s(d)" % funcname) |
| 329 | bb.utils.better_exec("\n".join(code), {"d": d}) |
| 330 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 331 | def finalize(fn, d, variant = None): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 332 | saved_handlers = bb.event.get_handlers().copy() |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 333 | try: |
| 334 | for var in d.getVar('__BBHANDLERS', False) or []: |
| 335 | # try to add the handler |
| 336 | handlerfn = d.getVarFlag(var, "filename", False) |
| 337 | if not handlerfn: |
| 338 | bb.fatal("Undefined event handler function '%s'" % var) |
| 339 | handlerln = int(d.getVarFlag(var, "lineno", False)) |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 340 | bb.event.register(var, d.getVar(var, False), (d.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln, data=d) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 341 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 342 | bb.event.fire(bb.event.RecipePreFinalise(fn), d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 343 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 344 | bb.data.expandKeys(d) |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 345 | |
| 346 | bb.event.fire(bb.event.RecipePostKeyExpansion(fn), d) |
| 347 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 348 | runAnonFuncs(d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 349 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 350 | tasklist = d.getVar('__BBTASKS', False) or [] |
| 351 | bb.event.fire(bb.event.RecipeTaskPreProcess(fn, list(tasklist)), d) |
| 352 | bb.build.add_tasks(tasklist, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 353 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 354 | bb.parse.siggen.finalise(fn, d, variant) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 355 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 356 | d.setVar('BBINCLUDED', bb.parse.get_file_depends(d)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 357 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 358 | bb.event.fire(bb.event.RecipeParsed(fn), d) |
| 359 | finally: |
| 360 | bb.event.set_handlers(saved_handlers) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 361 | |
| 362 | def _create_variants(datastores, names, function, onlyfinalise): |
| 363 | def create_variant(name, orig_d, arg = None): |
| 364 | if onlyfinalise and name not in onlyfinalise: |
| 365 | return |
| 366 | new_d = bb.data.createCopy(orig_d) |
| 367 | function(arg or name, new_d) |
| 368 | datastores[name] = new_d |
| 369 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 370 | for variant in list(datastores.keys()): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 371 | for name in names: |
| 372 | if not variant: |
| 373 | # Based on main recipe |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 374 | create_variant(name, datastores[""]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 375 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 376 | create_variant("%s-%s" % (variant, name), datastores[variant], name) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 377 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 378 | def multi_finalize(fn, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 379 | appends = (d.getVar("__BBAPPEND") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 380 | for append in appends: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 381 | logger.debug("Appending .bbappend file %s to %s", append, fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 382 | bb.parse.BBHandler.handle(append, d, True) |
| 383 | |
| 384 | onlyfinalise = d.getVar("__ONLYFINALISE", False) |
| 385 | |
| 386 | safe_d = d |
| 387 | d = bb.data.createCopy(safe_d) |
| 388 | try: |
| 389 | finalize(fn, d) |
| 390 | except bb.parse.SkipRecipe as e: |
| 391 | d.setVar("__SKIPPED", e.args[0]) |
| 392 | datastores = {"": safe_d} |
| 393 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 394 | extended = d.getVar("BBCLASSEXTEND") or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 395 | if extended: |
| 396 | # the following is to support bbextends with arguments, for e.g. multilib |
| 397 | # an example is as follows: |
| 398 | # BBCLASSEXTEND = "multilib:lib32" |
| 399 | # it will create foo-lib32, inheriting multilib.bbclass and set |
| 400 | # BBEXTENDCURR to "multilib" and BBEXTENDVARIANT to "lib32" |
| 401 | extendedmap = {} |
| 402 | variantmap = {} |
| 403 | |
| 404 | for ext in extended.split(): |
| 405 | eext = ext.split(':', 2) |
| 406 | if len(eext) > 1: |
| 407 | extendedmap[ext] = eext[0] |
| 408 | variantmap[ext] = eext[1] |
| 409 | else: |
| 410 | extendedmap[ext] = ext |
| 411 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 412 | pn = d.getVar("PN") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 413 | def extendfunc(name, d): |
| 414 | if name != extendedmap[name]: |
| 415 | d.setVar("BBEXTENDCURR", extendedmap[name]) |
| 416 | d.setVar("BBEXTENDVARIANT", variantmap[name]) |
| 417 | else: |
| 418 | d.setVar("PN", "%s-%s" % (pn, name)) |
| 419 | bb.parse.BBHandler.inherit(extendedmap[name], fn, 0, d) |
| 420 | |
| 421 | safe_d.setVar("BBCLASSEXTEND", extended) |
| 422 | _create_variants(datastores, extendedmap.keys(), extendfunc, onlyfinalise) |
| 423 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 424 | for variant in datastores.keys(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 425 | if variant: |
| 426 | try: |
| 427 | if not onlyfinalise or variant in onlyfinalise: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 428 | finalize(fn, datastores[variant], variant) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 429 | except bb.parse.SkipRecipe as e: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 430 | datastores[variant].setVar("__SKIPPED", e.args[0]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 431 | |
| 432 | datastores[""] = d |
| 433 | return datastores |