blob: b0ad5c4142472c57db53d7eb5d445a71f79004c3 [file] [log] [blame]
Patrick Williams705982a2024-01-12 09:51:57 -06001From ba492aead265edfd1da2a6c45dd7661c248309cb Mon Sep 17 00:00:00 2001
Brad Bishop26bdd442019-08-16 17:08:17 -04002From: 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.
Patrick Williamsb48b7b42016-08-17 15:04:38 -05008
Patrick Williams705982a2024-01-12 09:51:57 -06009Upstream-Status: Pending
10
Patrick Williamsb48b7b42016-08-17 15:04:38 -050011Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com>
12
Brad Bishop26bdd442019-08-16 17:08:17 -040013update 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 +++++++++++++++++++--------
Andrew Geissler69721092021-07-23 12:57:00 -040017 1 file changed, 19 insertions(+), 8 deletions(-)
Brad Bishop26bdd442019-08-16 17:08:17 -040018
19diff --git a/buildtools/wafsamba/samba_bundled.py b/buildtools/wafsamba/samba_bundled.py
Patrick Williams705982a2024-01-12 09:51:57 -060020index 2300565..26d9e8c 100644
Brad Bishop26bdd442019-08-16 17:08:17 -040021--- 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
Patrick Williamsb48b7b42016-08-17 15:04:38 -050028
Andrew Geissler517393d2023-01-13 08:55:19 -060029 def PRIVATE_NAME(bld, name):
Brad Bishop26bdd442019-08-16 17:08:17 -040030 '''possibly rename a library to include a bundled extension'''
Patrick Williams705982a2024-01-12 09:51:57 -060031@@ -245,17 +246,27 @@ def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'):
Patrick Williamsb48b7b42016-08-17 15:04:38 -050032 # 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
Brad Bishop26bdd442019-08-16 17:08:17 -040041+ spec = importlib.util._find_spec_from_path(modulename, [os.environ["PYTHONPATH"]])
42+ if spec:
Patrick Williamsb48b7b42016-08-17 15:04:38 -050043 try:
44- version = m.__version__
45- except AttributeError:
Brad Bishop26bdd442019-08-16 17:08:17 -040046+ module = importlib.util.module_from_spec(spec)
47+ spec.loader.load_module(module)
Patrick Williamsb48b7b42016-08-17 15:04:38 -050048+ 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
Brad Bishop26bdd442019-08-16 17:08:17 -040054+ Logs.warn('Cross module[%s] has been found, but can not be loaded.' % (spec.name))
Patrick Williamsb48b7b42016-08-17 15:04:38 -050055+ found = True
56 else:
57- found = tuplize_version(version) >= tuplize_version(minversion)
58+ try:
Brad Bishop26bdd442019-08-16 17:08:17 -040059+ version = module.__version__
Patrick Williamsb48b7b42016-08-17 15:04:38 -050060+ except AttributeError:
61+ found = False
62+ else:
63+ found = tuplize_version(version) >= tuplize_version(minversion)
Patrick Williamsb48b7b42016-08-17 15:04:38 -050064 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)
Brad Bishop26bdd442019-08-16 17:08:17 -040067--
Andrew Geissler517393d2023-01-13 08:55:19 -0600682.25.1
Brad Bishop26bdd442019-08-16 17:08:17 -040069