|
13 | 13 | import pickle |
14 | 14 | import zipfile, tarfile |
15 | 15 | import sys |
| 16 | +import sysconfig |
16 | 17 | from unittest import mock, SkipTest, skipIf, skipUnless, expectedFailure |
17 | 18 | from contextlib import contextmanager |
18 | 19 | from glob import glob |
@@ -2981,6 +2982,88 @@ def test_pkg_config_libdir(self): |
2981 | 2982 | self.wipe() |
2982 | 2983 | self.init(testdir, extra_args=['-Dstart_native=true'], override_envvars=env) |
2983 | 2984 |
|
| 2985 | + @skipIf(is_windows(), 'POSIX only') |
| 2986 | + def test_python_build_config_extensions(self): |
| 2987 | + testdir = os.path.join(self.unit_test_dir, |
| 2988 | + '125 python extension') |
| 2989 | + |
| 2990 | + VERSION_INFO_KEYS = ('major', 'minor', 'micro', 'releaselevel', 'serial') |
| 2991 | + EXTENSION_SUFFIX = '.extension-suffix.so' |
| 2992 | + STABLE_ABI_SUFFIX = '.stable-abi-suffix.so' |
| 2993 | + |
| 2994 | + python_build_config = { |
| 2995 | + 'schema_version': '1.0', |
| 2996 | + 'base_interpreter': sys.executable, |
| 2997 | + 'base_prefix': '/usr', |
| 2998 | + 'platform': sysconfig.get_platform(), |
| 2999 | + 'language': { |
| 3000 | + 'version': sysconfig.get_python_version(), |
| 3001 | + 'version_info': {key: getattr(sys.version_info, key) for key in VERSION_INFO_KEYS} |
| 3002 | + }, |
| 3003 | + 'implementation': { |
| 3004 | + attr: ( |
| 3005 | + getattr(sys.implementation, attr) |
| 3006 | + if attr != 'version' else |
| 3007 | + {key: getattr(sys.implementation.version, key) for key in VERSION_INFO_KEYS} |
| 3008 | + ) |
| 3009 | + for attr in dir(sys.implementation) |
| 3010 | + if not attr.startswith('__') |
| 3011 | + }, |
| 3012 | + 'abi': { |
| 3013 | + 'flags': [], |
| 3014 | + 'extension_suffix': EXTENSION_SUFFIX, |
| 3015 | + 'stable_abi_suffix': STABLE_ABI_SUFFIX, |
| 3016 | + }, |
| 3017 | + 'suffixes': { |
| 3018 | + 'source': ['.py'], |
| 3019 | + 'bytecode': ['.pyc'], |
| 3020 | + 'optimized_bytecode': ['.pyc'], |
| 3021 | + 'debug_bytecode': ['.pyc'], |
| 3022 | + 'extensions': [EXTENSION_SUFFIX, STABLE_ABI_SUFFIX, '.so'], |
| 3023 | + }, |
| 3024 | + 'libpython': { |
| 3025 | + 'dynamic': sysconfig.get_config_var('LDLIBRARY'), |
| 3026 | + 'dynamic_stableabi': sysconfig.get_config_var('PY3LIBRARY'), |
| 3027 | + 'static': sysconfig.get_config_var('LIBRARY'), |
| 3028 | + 'link_extensions': True, |
| 3029 | + }, |
| 3030 | + 'c_api': { |
| 3031 | + 'headers': sysconfig.get_path('include'), |
| 3032 | + 'pkgconfig_path': sysconfig.get_config_var('LIBPC'), |
| 3033 | + } |
| 3034 | + } |
| 3035 | + with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as python_build_config_file: |
| 3036 | + json.dump(python_build_config, fp=python_build_config_file) |
| 3037 | + |
| 3038 | + with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as cross_file: |
| 3039 | + cross_file.write( |
| 3040 | + textwrap.dedent(f''' |
| 3041 | + [binaries] |
| 3042 | + pkg-config = 'pkg-config' |
| 3043 | +
|
| 3044 | + [built-in options] |
| 3045 | + python.build_config = '{python_build_config_file.name}' |
| 3046 | + '''.strip()) |
| 3047 | + ) |
| 3048 | + cross_file.flush() |
| 3049 | + |
| 3050 | + intro_installed_file = os.path.join(self.builddir, 'meson-info', 'intro-installed.json') |
| 3051 | + expected_files = [ |
| 3052 | + os.path.join(self.builddir, 'foo' + EXTENSION_SUFFIX), |
| 3053 | + os.path.join(self.builddir, 'foo_stable' + STABLE_ABI_SUFFIX), |
| 3054 | + ] |
| 3055 | + |
| 3056 | + for extra_args in ( |
| 3057 | + ['--python.build-config', python_build_config_file.name], |
| 3058 | + ['--cross-file', cross_file.name], |
| 3059 | + ): |
| 3060 | + with self.subTest(extra_args=extra_args): |
| 3061 | + self.init(testdir, extra_args=extra_args) |
| 3062 | + with open(intro_installed_file) as f: |
| 3063 | + intro_installed = json.load(f) |
| 3064 | + self.assertEqual(expected_files, list(intro_installed)) |
| 3065 | + self.wipe() |
| 3066 | + |
2984 | 3067 | def __reconfigure(self): |
2985 | 3068 | # Set an older version to force a reconfigure from scratch |
2986 | 3069 | filename = os.path.join(self.privatedir, 'coredata.dat') |
|
0 commit comments