1From 6a2f229e74804f70f4419b2a1e6843aab059e098 Mon Sep 17 00:00:00 2001
2From: Changqing Li <changqing.li@windriver.com>
3Date: Tue, 25 Jun 2019 14:25:08 +0800
4Subject: [PATCH] do not import target module while cross compile
5
6Some modules such as dynamic library maybe cann't be imported
7while cross compile, we just check whether does the module exist.
8
9Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com>
10
11update to version 4.10.5, and switch to python3
12Signed-off-by: Changqing Li <changqing.li@windriver.com>
13
14Upstream-Status: Inappropriate [embedded specific]
15
16Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
17---
18 buildtools/wafsamba/samba_bundled.py | 27 +++++++++++++++++++--------
19 1 file changed, 19 insertions(+), 8 deletions(-)
20
21diff --git a/buildtools/wafsamba/samba_bundled.py b/buildtools/wafsamba/samba_bundled.py
22index 2300565..26d9e8c 100644
23--- a/buildtools/wafsamba/samba_bundled.py
24+++ b/buildtools/wafsamba/samba_bundled.py
25@@ -4,6 +4,7 @@ import sys
26 from waflib import Build, Options, Logs
27 from waflib.Configure import conf
28 from wafsamba import samba_utils
29+import importlib.util, os
30
31 def PRIVATE_NAME(bld, name):
32     '''possibly rename a library to include a bundled extension'''
33@@ -245,17 +246,27 @@ def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'):
34     # versions
35     minversion = minimum_library_version(conf, libname, minversion)
36
37-    try:
38-        m = __import__(modulename)
39-    except ImportError:
40-        found = False
41-    else:
42+    # Find module in PYTHONPATH
43+    spec = importlib.util._find_spec_from_path(modulename, [os.environ["PYTHONPATH"]])
44+    if spec:
45         try:
46-            version = m.__version__
47-        except AttributeError:
48+            module = importlib.util.module_from_spec(spec)
49+            spec.loader.load_module(module)
50+        except ImportError:
51             found = False
52+
53+            if conf.env.CROSS_COMPILE:
54+                # Some modules such as dynamic library maybe cann't be imported
55+                # while cross compile, we just check whether the module exist
56+                Logs.warn('Cross module[%s] has been found, but can not be loaded.' % (spec.name))
57+                found = True
58         else:
59-            found = tuplize_version(version) >= tuplize_version(minversion)
60+            try:
61+                version = module.__version__
62+            except AttributeError:
63+                found = False
64+            else:
65+                found = tuplize_version(version) >= tuplize_version(minversion)
66     if not found and not conf.LIB_MAY_BE_BUNDLED(libname):
67         Logs.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname, minversion))
68         sys.exit(1)
69--
702.25.1
71
72