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 re |
| 13 | import string |
| 14 | import logging |
| 15 | import bb |
| 16 | import itertools |
| 17 | from bb import methodpool |
| 18 | from bb.parse import logger |
| 19 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | class StatementGroup(list): |
| 21 | def eval(self, data): |
| 22 | for statement in self: |
| 23 | statement.eval(data) |
| 24 | |
| 25 | class AstNode(object): |
| 26 | def __init__(self, filename, lineno): |
| 27 | self.filename = filename |
| 28 | self.lineno = lineno |
| 29 | |
| 30 | class IncludeNode(AstNode): |
| 31 | def __init__(self, filename, lineno, what_file, force): |
| 32 | AstNode.__init__(self, filename, lineno) |
| 33 | self.what_file = what_file |
| 34 | self.force = force |
| 35 | |
| 36 | def eval(self, data): |
| 37 | """ |
| 38 | Include the file and evaluate the statements |
| 39 | """ |
| 40 | s = data.expand(self.what_file) |
| 41 | logger.debug(2, "CONF %s:%s: including %s", self.filename, self.lineno, s) |
| 42 | |
| 43 | # TODO: Cache those includes... maybe not here though |
| 44 | if self.force: |
| 45 | bb.parse.ConfHandler.include(self.filename, s, self.lineno, data, "include required") |
| 46 | else: |
| 47 | bb.parse.ConfHandler.include(self.filename, s, self.lineno, data, False) |
| 48 | |
| 49 | class ExportNode(AstNode): |
| 50 | def __init__(self, filename, lineno, var): |
| 51 | AstNode.__init__(self, filename, lineno) |
| 52 | self.var = var |
| 53 | |
| 54 | def eval(self, data): |
| 55 | data.setVarFlag(self.var, "export", 1, op = 'exported') |
| 56 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 57 | class UnsetNode(AstNode): |
| 58 | def __init__(self, filename, lineno, var): |
| 59 | AstNode.__init__(self, filename, lineno) |
| 60 | self.var = var |
| 61 | |
| 62 | def eval(self, data): |
| 63 | loginfo = { |
| 64 | 'variable': self.var, |
| 65 | 'file': self.filename, |
| 66 | 'line': self.lineno, |
| 67 | } |
| 68 | data.delVar(self.var,**loginfo) |
| 69 | |
| 70 | class UnsetFlagNode(AstNode): |
| 71 | def __init__(self, filename, lineno, var, flag): |
| 72 | AstNode.__init__(self, filename, lineno) |
| 73 | self.var = var |
| 74 | self.flag = flag |
| 75 | |
| 76 | def eval(self, data): |
| 77 | loginfo = { |
| 78 | 'variable': self.var, |
| 79 | 'file': self.filename, |
| 80 | 'line': self.lineno, |
| 81 | } |
| 82 | data.delVarFlag(self.var, self.flag, **loginfo) |
| 83 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | class DataNode(AstNode): |
| 85 | """ |
| 86 | Various data related updates. For the sake of sanity |
| 87 | we have one class doing all this. This means that all |
| 88 | this need to be re-evaluated... we might be able to do |
| 89 | that faster with multiple classes. |
| 90 | """ |
| 91 | def __init__(self, filename, lineno, groupd): |
| 92 | AstNode.__init__(self, filename, lineno) |
| 93 | self.groupd = groupd |
| 94 | |
| 95 | def getFunc(self, key, data): |
| 96 | if 'flag' in self.groupd and self.groupd['flag'] != None: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 97 | return data.getVarFlag(key, self.groupd['flag'], expand=False, noweakdefault=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 98 | else: |
| 99 | return data.getVar(key, False, noweakdefault=True, parsing=True) |
| 100 | |
| 101 | def eval(self, data): |
| 102 | groupd = self.groupd |
| 103 | key = groupd["var"] |
| 104 | loginfo = { |
| 105 | 'variable': key, |
| 106 | 'file': self.filename, |
| 107 | 'line': self.lineno, |
| 108 | } |
| 109 | if "exp" in groupd and groupd["exp"] != None: |
| 110 | data.setVarFlag(key, "export", 1, op = 'exported', **loginfo) |
| 111 | |
| 112 | op = "set" |
| 113 | if "ques" in groupd and groupd["ques"] != None: |
| 114 | val = self.getFunc(key, data) |
| 115 | op = "set?" |
| 116 | if val == None: |
| 117 | val = groupd["value"] |
| 118 | elif "colon" in groupd and groupd["colon"] != None: |
| 119 | e = data.createCopy() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 120 | op = "immediate" |
| 121 | val = e.expand(groupd["value"], key + "[:=]") |
| 122 | elif "append" in groupd and groupd["append"] != None: |
| 123 | op = "append" |
| 124 | val = "%s %s" % ((self.getFunc(key, data) or ""), groupd["value"]) |
| 125 | elif "prepend" in groupd and groupd["prepend"] != None: |
| 126 | op = "prepend" |
| 127 | val = "%s %s" % (groupd["value"], (self.getFunc(key, data) or "")) |
| 128 | elif "postdot" in groupd and groupd["postdot"] != None: |
| 129 | op = "postdot" |
| 130 | val = "%s%s" % ((self.getFunc(key, data) or ""), groupd["value"]) |
| 131 | elif "predot" in groupd and groupd["predot"] != None: |
| 132 | op = "predot" |
| 133 | val = "%s%s" % (groupd["value"], (self.getFunc(key, data) or "")) |
| 134 | else: |
| 135 | val = groupd["value"] |
| 136 | |
| 137 | flag = None |
| 138 | if 'flag' in groupd and groupd['flag'] != None: |
| 139 | flag = groupd['flag'] |
| 140 | elif groupd["lazyques"]: |
| 141 | flag = "_defaultval" |
| 142 | |
| 143 | loginfo['op'] = op |
| 144 | loginfo['detail'] = groupd["value"] |
| 145 | |
| 146 | if flag: |
| 147 | data.setVarFlag(key, flag, val, **loginfo) |
| 148 | else: |
| 149 | data.setVar(key, val, parsing=True, **loginfo) |
| 150 | |
| 151 | class MethodNode(AstNode): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 152 | tr_tbl = str.maketrans('/.+-@%&', '_______') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 153 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 154 | def __init__(self, filename, lineno, func_name, body, python, fakeroot): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | AstNode.__init__(self, filename, lineno) |
| 156 | self.func_name = func_name |
| 157 | self.body = body |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 158 | self.python = python |
| 159 | self.fakeroot = fakeroot |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 160 | |
| 161 | def eval(self, data): |
| 162 | text = '\n'.join(self.body) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 163 | funcname = self.func_name |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | if self.func_name == "__anonymous": |
| 165 | funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(MethodNode.tr_tbl))) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 166 | self.python = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 167 | text = "def %s(d):\n" % (funcname) + text |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 168 | 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] | 169 | anonfuncs = data.getVar('__BBANONFUNCS', False) or [] |
| 170 | anonfuncs.append(funcname) |
| 171 | data.setVar('__BBANONFUNCS', anonfuncs) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 172 | if data.getVar(funcname, False): |
| 173 | # clean up old version of this piece of metadata, as its |
| 174 | # flags could cause problems |
| 175 | data.delVarFlag(funcname, 'python') |
| 176 | data.delVarFlag(funcname, 'fakeroot') |
| 177 | if self.python: |
| 178 | data.setVarFlag(funcname, "python", "1") |
| 179 | if self.fakeroot: |
| 180 | data.setVarFlag(funcname, "fakeroot", "1") |
| 181 | data.setVarFlag(funcname, "func", 1) |
| 182 | data.setVar(funcname, text, parsing=True) |
| 183 | data.setVarFlag(funcname, 'filename', self.filename) |
| 184 | data.setVarFlag(funcname, 'lineno', str(self.lineno - len(self.body))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 185 | |
| 186 | class PythonMethodNode(AstNode): |
| 187 | def __init__(self, filename, lineno, function, modulename, body): |
| 188 | AstNode.__init__(self, filename, lineno) |
| 189 | self.function = function |
| 190 | self.modulename = modulename |
| 191 | self.body = body |
| 192 | |
| 193 | def eval(self, data): |
| 194 | # Note we will add root to parsedmethods after having parse |
| 195 | # 'this' file. This means we will not parse methods from |
| 196 | # bb classes twice |
| 197 | text = '\n'.join(self.body) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 198 | 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] | 199 | data.setVarFlag(self.function, "func", 1) |
| 200 | data.setVarFlag(self.function, "python", 1) |
| 201 | data.setVar(self.function, text, parsing=True) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 202 | data.setVarFlag(self.function, 'filename', self.filename) |
| 203 | data.setVarFlag(self.function, 'lineno', str(self.lineno - len(self.body) - 1)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 204 | |
| 205 | class ExportFuncsNode(AstNode): |
| 206 | def __init__(self, filename, lineno, fns, classname): |
| 207 | AstNode.__init__(self, filename, lineno) |
| 208 | self.n = fns.split() |
| 209 | self.classname = classname |
| 210 | |
| 211 | def eval(self, data): |
| 212 | |
| 213 | for func in self.n: |
| 214 | calledfunc = self.classname + "_" + func |
| 215 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 216 | 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] | 217 | continue |
| 218 | |
| 219 | if data.getVar(func, False): |
| 220 | data.setVarFlag(func, 'python', None) |
| 221 | data.setVarFlag(func, 'func', None) |
| 222 | |
| 223 | for flag in [ "func", "python" ]: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 224 | if data.getVarFlag(calledfunc, flag, False): |
| 225 | data.setVarFlag(func, flag, data.getVarFlag(calledfunc, flag, False)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | for flag in [ "dirs" ]: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 227 | if data.getVarFlag(func, flag, False): |
| 228 | data.setVarFlag(calledfunc, flag, data.getVarFlag(func, flag, False)) |
| 229 | data.setVarFlag(func, "filename", "autogenerated") |
| 230 | data.setVarFlag(func, "lineno", 1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 231 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 232 | if data.getVarFlag(calledfunc, "python", False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 233 | data.setVar(func, " bb.build.exec_func('" + calledfunc + "', d)\n", parsing=True) |
| 234 | else: |
| 235 | if "-" in self.classname: |
| 236 | 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)) |
| 237 | data.setVar(func, " " + calledfunc + "\n", parsing=True) |
| 238 | data.setVarFlag(func, 'export_func', '1') |
| 239 | |
| 240 | class AddTaskNode(AstNode): |
| 241 | def __init__(self, filename, lineno, func, before, after): |
| 242 | AstNode.__init__(self, filename, lineno) |
| 243 | self.func = func |
| 244 | self.before = before |
| 245 | self.after = after |
| 246 | |
| 247 | def eval(self, data): |
| 248 | bb.build.addtask(self.func, self.before, self.after, data) |
| 249 | |
| 250 | class DelTaskNode(AstNode): |
| 251 | def __init__(self, filename, lineno, func): |
| 252 | AstNode.__init__(self, filename, lineno) |
| 253 | self.func = func |
| 254 | |
| 255 | def eval(self, data): |
| 256 | bb.build.deltask(self.func, data) |
| 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): |
| 312 | func = m.group("func") |
| 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)) |
| 340 | bb.event.register(var, d.getVar(var, False), (d.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln) |
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) |
| 345 | runAnonFuncs(d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 346 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 347 | tasklist = d.getVar('__BBTASKS', False) or [] |
| 348 | bb.event.fire(bb.event.RecipeTaskPreProcess(fn, list(tasklist)), d) |
| 349 | bb.build.add_tasks(tasklist, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 350 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 351 | bb.parse.siggen.finalise(fn, d, variant) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 352 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 353 | d.setVar('BBINCLUDED', bb.parse.get_file_depends(d)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 354 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 355 | bb.event.fire(bb.event.RecipeParsed(fn), d) |
| 356 | finally: |
| 357 | bb.event.set_handlers(saved_handlers) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 358 | |
| 359 | def _create_variants(datastores, names, function, onlyfinalise): |
| 360 | def create_variant(name, orig_d, arg = None): |
| 361 | if onlyfinalise and name not in onlyfinalise: |
| 362 | return |
| 363 | new_d = bb.data.createCopy(orig_d) |
| 364 | function(arg or name, new_d) |
| 365 | datastores[name] = new_d |
| 366 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 367 | for variant in list(datastores.keys()): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 368 | for name in names: |
| 369 | if not variant: |
| 370 | # Based on main recipe |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 371 | create_variant(name, datastores[""]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 372 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 373 | create_variant("%s-%s" % (variant, name), datastores[variant], name) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 374 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 375 | def multi_finalize(fn, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 376 | appends = (d.getVar("__BBAPPEND") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 377 | for append in appends: |
| 378 | logger.debug(1, "Appending .bbappend file %s to %s", append, fn) |
| 379 | bb.parse.BBHandler.handle(append, d, True) |
| 380 | |
| 381 | onlyfinalise = d.getVar("__ONLYFINALISE", False) |
| 382 | |
| 383 | safe_d = d |
| 384 | d = bb.data.createCopy(safe_d) |
| 385 | try: |
| 386 | finalize(fn, d) |
| 387 | except bb.parse.SkipRecipe as e: |
| 388 | d.setVar("__SKIPPED", e.args[0]) |
| 389 | datastores = {"": safe_d} |
| 390 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 391 | extended = d.getVar("BBCLASSEXTEND") or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 392 | if extended: |
| 393 | # the following is to support bbextends with arguments, for e.g. multilib |
| 394 | # an example is as follows: |
| 395 | # BBCLASSEXTEND = "multilib:lib32" |
| 396 | # it will create foo-lib32, inheriting multilib.bbclass and set |
| 397 | # BBEXTENDCURR to "multilib" and BBEXTENDVARIANT to "lib32" |
| 398 | extendedmap = {} |
| 399 | variantmap = {} |
| 400 | |
| 401 | for ext in extended.split(): |
| 402 | eext = ext.split(':', 2) |
| 403 | if len(eext) > 1: |
| 404 | extendedmap[ext] = eext[0] |
| 405 | variantmap[ext] = eext[1] |
| 406 | else: |
| 407 | extendedmap[ext] = ext |
| 408 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 409 | pn = d.getVar("PN") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 410 | def extendfunc(name, d): |
| 411 | if name != extendedmap[name]: |
| 412 | d.setVar("BBEXTENDCURR", extendedmap[name]) |
| 413 | d.setVar("BBEXTENDVARIANT", variantmap[name]) |
| 414 | else: |
| 415 | d.setVar("PN", "%s-%s" % (pn, name)) |
| 416 | bb.parse.BBHandler.inherit(extendedmap[name], fn, 0, d) |
| 417 | |
| 418 | safe_d.setVar("BBCLASSEXTEND", extended) |
| 419 | _create_variants(datastores, extendedmap.keys(), extendfunc, onlyfinalise) |
| 420 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 421 | for variant in datastores.keys(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 422 | if variant: |
| 423 | try: |
| 424 | if not onlyfinalise or variant in onlyfinalise: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 425 | finalize(fn, datastores[variant], variant) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 426 | except bb.parse.SkipRecipe as e: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 427 | datastores[variant].setVar("__SKIPPED", e.args[0]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 428 | |
| 429 | datastores[""] = d |
| 430 | return datastores |