Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame^] | 1 | From 69c409195ede704ed7e9298ed4942cc70a52e099 Mon Sep 17 00:00:00 2001 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 2 | From: Changqing Li <changqing.li@windriver.com> |
| 3 | Date: Tue, 25 Jun 2019 14:25:08 +0800 |
| 4 | Subject: [PATCH] do not import target module while cross compile |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 5 | |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 6 | Some modules such as dynamic library maybe cann't be imported |
| 7 | while cross compile, we just check whether does the module exist. |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 8 | |
| 9 | Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com> |
| 10 | |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 11 | update to version 4.10.5, and switch to python3 |
| 12 | Signed-off-by: Changqing Li <changqing.li@windriver.com> |
Andrew Geissler | 6972109 | 2021-07-23 12:57:00 -0400 | [diff] [blame] | 13 | |
| 14 | Upstream-Status: Inappropriate [embedded specific] |
| 15 | |
| 16 | Signed-off-by: Yi Zhao <yi.zhao@windriver.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 17 | --- |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 18 | buildtools/wafsamba/samba_bundled.py | 27 +++++++++++++++++++-------- |
Andrew Geissler | 6972109 | 2021-07-23 12:57:00 -0400 | [diff] [blame] | 19 | 1 file changed, 19 insertions(+), 8 deletions(-) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 20 | |
| 21 | diff --git a/buildtools/wafsamba/samba_bundled.py b/buildtools/wafsamba/samba_bundled.py |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame^] | 22 | index 7d2d855..01dcb56 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 23 | --- a/buildtools/wafsamba/samba_bundled.py |
| 24 | +++ b/buildtools/wafsamba/samba_bundled.py |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 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 |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 30 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame^] | 31 | def PRIVATE_NAME(bld, name): |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 32 | '''possibly rename a library to include a bundled extension''' |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame^] | 33 | @@ -241,17 +242,27 @@ def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'): |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 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 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 43 | + spec = importlib.util._find_spec_from_path(modulename, [os.environ["PYTHONPATH"]]) |
| 44 | + if spec: |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 45 | try: |
| 46 | - version = m.__version__ |
| 47 | - except AttributeError: |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 48 | + module = importlib.util.module_from_spec(spec) |
| 49 | + spec.loader.load_module(module) |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 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 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 56 | + Logs.warn('Cross module[%s] has been found, but can not be loaded.' % (spec.name)) |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 57 | + found = True |
| 58 | else: |
| 59 | - found = tuplize_version(version) >= tuplize_version(minversion) |
| 60 | + try: |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 61 | + version = module.__version__ |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 62 | + except AttributeError: |
| 63 | + found = False |
| 64 | + else: |
| 65 | + found = tuplize_version(version) >= tuplize_version(minversion) |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 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) |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 69 | -- |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame^] | 70 | 2.25.1 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 71 | |