Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | Some modules such as dynamic library maybe cann't be imported while cross compile, |
| 2 | we just check whether does the module exist. |
| 3 | |
| 4 | Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com> |
| 5 | |
| 6 | Index: ldb-1.1.26/buildtools/wafsamba/samba_bundled.py |
| 7 | =================================================================== |
| 8 | --- ldb-1.1.26.orig/buildtools/wafsamba/samba_bundled.py |
| 9 | +++ ldb-1.1.26/buildtools/wafsamba/samba_bundled.py |
| 10 | @@ -2,6 +2,7 @@ |
| 11 | |
| 12 | import sys |
| 13 | import Build, Options, Logs |
| 14 | +import imp, os |
| 15 | from Configure import conf |
| 16 | from samba_utils import TO_LIST |
| 17 | |
| 18 | @@ -230,17 +231,32 @@ def CHECK_BUNDLED_SYSTEM_PYTHON(conf, li |
| 19 | # versions |
| 20 | minversion = minimum_library_version(conf, libname, minversion) |
| 21 | |
| 22 | - try: |
| 23 | - m = __import__(modulename) |
| 24 | - except ImportError: |
| 25 | - found = False |
| 26 | - else: |
| 27 | + # Find module in PYTHONPATH |
| 28 | + stuff = imp.find_module(modulename, [os.environ["PYTHONPATH"]]) |
| 29 | + if stuff: |
| 30 | try: |
| 31 | - version = m.__version__ |
| 32 | - except AttributeError: |
| 33 | + m = imp.load_module(modulename, stuff[0], stuff[1], stuff[2]) |
| 34 | + except ImportError: |
| 35 | found = False |
| 36 | + |
| 37 | + if conf.env.CROSS_COMPILE: |
| 38 | + # Some modules such as dynamic library maybe cann't be imported |
| 39 | + # while cross compile, we just check whether the module exist |
| 40 | + Logs.warn('Cross module[%s] has been found, but can not be loaded.' % (stuff[1])) |
| 41 | + found = True |
| 42 | else: |
| 43 | - found = tuplize_version(version) >= tuplize_version(minversion) |
| 44 | + try: |
| 45 | + version = m.__version__ |
| 46 | + except AttributeError: |
| 47 | + found = False |
| 48 | + else: |
| 49 | + found = tuplize_version(version) >= tuplize_version(minversion) |
| 50 | + finally: |
| 51 | + if stuff[0]: |
| 52 | + stuff[0].close() |
| 53 | + else: |
| 54 | + found = False |
| 55 | + |
| 56 | if not found and not conf.LIB_MAY_BE_BUNDLED(libname): |
| 57 | Logs.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname, minversion)) |
| 58 | sys.exit(1) |