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