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