Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 1 | From f4cda3a71311e4496b725bc5f46af93413ec7a1c Mon Sep 17 00:00:00 2001 |
| 2 | From: Bian Naimeng <biannm@cn.fujitsu.com> |
| 3 | Date: Fri, 17 Jul 2015 11:58:49 +0800 |
| 4 | Subject: [PATCH] libldb: add new recipe |
| 5 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 6 | Some modules such as dynamic library maybe cann't be imported while cross compile, |
| 7 | we just check whether does the module exist. |
| 8 | |
| 9 | Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com> |
| 10 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 11 | --- |
| 12 | buildtools/wafsamba/samba_bundled.py | 32 ++++++++++++++++++++++++-------- |
| 13 | 1 file changed, 24 insertions(+), 8 deletions(-) |
| 14 | |
| 15 | diff --git a/buildtools/wafsamba/samba_bundled.py b/buildtools/wafsamba/samba_bundled.py |
| 16 | index 253d604..398cc6a 100644 |
| 17 | --- a/buildtools/wafsamba/samba_bundled.py |
| 18 | +++ b/buildtools/wafsamba/samba_bundled.py |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 19 | @@ -2,6 +2,7 @@ |
| 20 | |
| 21 | import sys |
| 22 | import Build, Options, Logs |
| 23 | +import imp, os |
| 24 | from Configure import conf |
| 25 | from samba_utils import TO_LIST |
| 26 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 27 | @@ -249,17 +250,32 @@ def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'): |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 28 | # versions |
| 29 | minversion = minimum_library_version(conf, libname, minversion) |
| 30 | |
| 31 | - try: |
| 32 | - m = __import__(modulename) |
| 33 | - except ImportError: |
| 34 | - found = False |
| 35 | - else: |
| 36 | + # Find module in PYTHONPATH |
| 37 | + stuff = imp.find_module(modulename, [os.environ["PYTHONPATH"]]) |
| 38 | + if stuff: |
| 39 | try: |
| 40 | - version = m.__version__ |
| 41 | - except AttributeError: |
| 42 | + m = imp.load_module(modulename, stuff[0], stuff[1], stuff[2]) |
| 43 | + except ImportError: |
| 44 | found = False |
| 45 | + |
| 46 | + if conf.env.CROSS_COMPILE: |
| 47 | + # Some modules such as dynamic library maybe cann't be imported |
| 48 | + # while cross compile, we just check whether the module exist |
| 49 | + Logs.warn('Cross module[%s] has been found, but can not be loaded.' % (stuff[1])) |
| 50 | + found = True |
| 51 | else: |
| 52 | - found = tuplize_version(version) >= tuplize_version(minversion) |
| 53 | + try: |
| 54 | + version = m.__version__ |
| 55 | + except AttributeError: |
| 56 | + found = False |
| 57 | + else: |
| 58 | + found = tuplize_version(version) >= tuplize_version(minversion) |
| 59 | + finally: |
| 60 | + if stuff[0]: |
| 61 | + stuff[0].close() |
| 62 | + else: |
| 63 | + found = False |
| 64 | + |
| 65 | if not found and not conf.LIB_MAY_BE_BUNDLED(libname): |
| 66 | Logs.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname, minversion)) |
| 67 | sys.exit(1) |