diff options
Diffstat (limited to 'bitbake/lib/bb/parse/ast.py')
-rw-r--r-- | bitbake/lib/bb/parse/ast.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index 9e0a0f5c98..862087c77d 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py | |||
@@ -9,6 +9,7 @@ | |||
9 | # SPDX-License-Identifier: GPL-2.0-only | 9 | # SPDX-License-Identifier: GPL-2.0-only |
10 | # | 10 | # |
11 | 11 | ||
12 | import sys | ||
12 | import bb | 13 | import bb |
13 | from bb import methodpool | 14 | from bb import methodpool |
14 | from bb.parse import logger | 15 | from bb.parse import logger |
@@ -269,6 +270,29 @@ class BBHandlerNode(AstNode): | |||
269 | data.setVarFlag(h, "handler", 1) | 270 | data.setVarFlag(h, "handler", 1) |
270 | data.setVar('__BBHANDLERS', bbhands) | 271 | data.setVar('__BBHANDLERS', bbhands) |
271 | 272 | ||
273 | class PyLibNode(AstNode): | ||
274 | def __init__(self, filename, lineno, libdir, namespace): | ||
275 | AstNode.__init__(self, filename, lineno) | ||
276 | self.libdir = libdir | ||
277 | self.namespace = namespace | ||
278 | |||
279 | def eval(self, data): | ||
280 | global_mods = (data.getVar("BB_GLOBAL_PYMODULES") or "").split() | ||
281 | for m in global_mods: | ||
282 | if m not in bb.utils._context: | ||
283 | bb.utils._context[m] = __import__(m) | ||
284 | |||
285 | libdir = data.expand(self.libdir) | ||
286 | if libdir not in sys.path: | ||
287 | sys.path.append(libdir) | ||
288 | try: | ||
289 | bb.utils._context[self.namespace] = __import__(self.namespace) | ||
290 | toimport = getattr(bb.utils._context[self.namespace], "BBIMPORTS", []) | ||
291 | for i in toimport: | ||
292 | bb.utils._context[self.namespace] = __import__(self.namespace + "." + i) | ||
293 | except AttributeError as e: | ||
294 | bb.error("Error importing OE modules: %s" % str(e)) | ||
295 | |||
272 | class InheritNode(AstNode): | 296 | class InheritNode(AstNode): |
273 | def __init__(self, filename, lineno, classes): | 297 | def __init__(self, filename, lineno, classes): |
274 | AstNode.__init__(self, filename, lineno) | 298 | AstNode.__init__(self, filename, lineno) |
@@ -320,6 +344,9 @@ def handleDelTask(statements, filename, lineno, m): | |||
320 | def handleBBHandlers(statements, filename, lineno, m): | 344 | def handleBBHandlers(statements, filename, lineno, m): |
321 | statements.append(BBHandlerNode(filename, lineno, m.group(1))) | 345 | statements.append(BBHandlerNode(filename, lineno, m.group(1))) |
322 | 346 | ||
347 | def handlePyLib(statements, filename, lineno, m): | ||
348 | statements.append(PyLibNode(filename, lineno, m.group(1), m.group(2))) | ||
349 | |||
323 | def handleInherit(statements, filename, lineno, m): | 350 | def handleInherit(statements, filename, lineno, m): |
324 | classes = m.group(1) | 351 | classes = m.group(1) |
325 | statements.append(InheritNode(filename, lineno, classes)) | 352 | statements.append(InheritNode(filename, lineno, classes)) |