Skip to content

Instantly share code, notes, and snippets.

@kergoth
Last active October 29, 2018 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kergoth/a60046871dfc94a8d7db27f15e5299fd to your computer and use it in GitHub Desktop.
Save kergoth/a60046871dfc94a8d7db27f15e5299fd to your computer and use it in GitHub Desktop.
From 9ed4b5c60eb5bd643ae0270e8f4ccb82a00f4ed7 Mon Sep 17 00:00:00 2001
From: Christopher Larson <chris_larson@mentor.com>
Date: Mon, 29 Oct 2018 23:32:01 +0500
Subject: [PATCH] external-common.bbclass: fix long standing oe.external import
issue
bitbake-layers and devtool both fail to run commands with
meta-external-toolchain included, as it fails to import oe.external. It
turns out that oe_import in base.bbclass is not entirely sufficient to
get the needed modules imported when namespace packages are involved,
and those packages have already been imported. Re-import such packages
after the sys.path change to ensure the new __init__.py files are
parsed, and the new __path__ changes picked up.
JIRA: SB-11904
Signed-off-by: Christopher Larson <chris_larson@mentor.com>
---
classes/external-common.bbclass | 48 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 46 insertions(+), 2 deletions(-)
diff --git a/classes/external-common.bbclass b/classes/external-common.bbclass
index 71b9039..a18bdbb 100644
--- a/classes/external-common.bbclass
+++ b/classes/external-common.bbclass
@@ -1,5 +1,49 @@
-OE_IMPORTS += "oe.external"
-OE_IMPORTED := "${@oe_import(d)}"
+def fixed_oe_import(d, modules=None):
+ import importlib
+ import sys
+
+ def inject(name, value):
+ """Make a python object accessible from the metadata"""
+ if hasattr(bb.utils, "_context"):
+ bb.utils._context[name] = value
+ else:
+ __builtins__[name] = value
+
+ bbpath = d.getVar("BBPATH").split(":")
+ layerpaths = [os.path.join(dir, "lib") for dir in bbpath]
+ sys.path[0:0] = layerpaths
+
+ if modules is None:
+ import oe.data
+ modules = oe.data.typed_value("OE_IMPORTS", d)
+
+ has_reloaded = set()
+ for toimport in modules:
+ # If we're importing something in a namespace package, and it's
+ # already been imported, reload it, to ensure any namespace package
+ # extensions to __path__ are picked up
+ imp_project = toimport
+ while True:
+ try:
+ imp_project, _ = imp_project.rsplit(".", 1)
+ except ValueError:
+ break
+ if imp_project in sys.modules and imp_project not in has_reloaded:
+ mod = sys.modules[imp_project]
+ if hasattr(mod, '__path__'):
+ bb.debug(1, 'Reloading %s' % imp_project)
+ importlib.reload(mod)
+ has_reloaded.add(imp_project)
+
+ project = toimport.split(".", 1)[0]
+ imported = importlib.import_module(toimport)
+ sys.modules[toimport] = imported
+ inject(project, sys.modules[project])
+ bb.debug(1, 'Imported and injected %s' % toimport)
+
+ return ""
+
+EXTERNAL_IMPORTED := "${@fixed_oe_import(d, ['oe.external'])}"
EXTERNAL_TOOLCHAIN_SYSROOT ?= "${@external_run(d, 'gcc', *(TARGET_CC_ARCH.split() + ['-print-sysroot'])).rstrip()}"
EXTERNAL_TOOLCHAIN_LIBROOT ?= "${@external_run(d, 'gcc', *(TARGET_CC_ARCH.split() + ['-print-file-name=crtbegin.o'])).rstrip().replace('/crtbegin.o', '')}"
--
2.11.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment