|
12 | 12 | import pickle |
13 | 13 | import zipfile, tarfile |
14 | 14 | import sys |
| 15 | +import sysconfig |
15 | 16 | from unittest import mock, SkipTest, skipIf, skipUnless |
16 | 17 | from contextlib import contextmanager |
17 | 18 | from glob import glob |
@@ -2948,6 +2949,88 @@ def test_pkg_config_libdir(self): |
2948 | 2949 | self.wipe() |
2949 | 2950 | self.init(testdir, extra_args=['-Dstart_native=true'], override_envvars=env) |
2950 | 2951 |
|
| 2952 | + @skipIf(is_windows(), 'POSIX only') |
| 2953 | + def test_python_build_config_extensions(self): |
| 2954 | + testdir = os.path.join(self.unit_test_dir, |
| 2955 | + '125 python extension') |
| 2956 | + |
| 2957 | + VERSION_INFO_KEYS = ('major', 'minor', 'micro', 'releaselevel', 'serial') |
| 2958 | + EXTENSION_SUFFIX = '.extension-suffix.so' |
| 2959 | + STABLE_ABI_SUFFIX = '.stable-abi-suffix.so' |
| 2960 | + |
| 2961 | + python_build_config = { |
| 2962 | + 'schema_version': '1.0', |
| 2963 | + 'base_interpreter': sys.executable, |
| 2964 | + 'base_prefix': '/usr', |
| 2965 | + 'platform': sysconfig.get_platform(), |
| 2966 | + 'language': { |
| 2967 | + 'version': sysconfig.get_python_version(), |
| 2968 | + 'version_info': {key: getattr(sys.version_info, key) for key in VERSION_INFO_KEYS} |
| 2969 | + }, |
| 2970 | + 'implementation': { |
| 2971 | + attr: ( |
| 2972 | + getattr(sys.implementation, attr) |
| 2973 | + if attr != 'version' else |
| 2974 | + {key: getattr(sys.implementation.version, key) for key in VERSION_INFO_KEYS} |
| 2975 | + ) |
| 2976 | + for attr in dir(sys.implementation) |
| 2977 | + if not attr.startswith('__') |
| 2978 | + }, |
| 2979 | + 'abi': { |
| 2980 | + 'flags': [], |
| 2981 | + 'extension_suffix': EXTENSION_SUFFIX, |
| 2982 | + 'stable_abi_suffix': STABLE_ABI_SUFFIX, |
| 2983 | + }, |
| 2984 | + 'suffixes': { |
| 2985 | + 'source': ['.py'], |
| 2986 | + 'bytecode': ['.pyc'], |
| 2987 | + 'optimized_bytecode': ['.pyc'], |
| 2988 | + 'debug_bytecode': ['.pyc'], |
| 2989 | + 'extensions': [EXTENSION_SUFFIX, STABLE_ABI_SUFFIX, '.so'], |
| 2990 | + }, |
| 2991 | + 'libpython': { |
| 2992 | + 'dynamic': sysconfig.get_config_var('LDLIBRARY'), |
| 2993 | + 'dynamic_stableabi': sysconfig.get_config_var('PY3LIBRARY'), |
| 2994 | + 'static': sysconfig.get_config_var('LIBRARY'), |
| 2995 | + 'link_extensions': True, |
| 2996 | + }, |
| 2997 | + 'c_api': { |
| 2998 | + 'headers': sysconfig.get_path('include'), |
| 2999 | + 'pkgconfig_path': sysconfig.get_config_var('LIBPC'), |
| 3000 | + } |
| 3001 | + } |
| 3002 | + with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as python_build_config_file: |
| 3003 | + json.dump(python_build_config, fp=python_build_config_file) |
| 3004 | + |
| 3005 | + with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as cross_file: |
| 3006 | + cross_file.write( |
| 3007 | + textwrap.dedent(f''' |
| 3008 | + [binaries] |
| 3009 | + pkg-config = 'pkg-config' |
| 3010 | +
|
| 3011 | + [built-in options] |
| 3012 | + python.build_config = '{python_build_config_file.name}' |
| 3013 | + '''.strip()) |
| 3014 | + ) |
| 3015 | + cross_file.flush() |
| 3016 | + |
| 3017 | + intro_installed_file = os.path.join(self.builddir, 'meson-info', 'intro-installed.json') |
| 3018 | + expected_files = [ |
| 3019 | + os.path.join(self.builddir, 'foo' + EXTENSION_SUFFIX), |
| 3020 | + os.path.join(self.builddir, 'foo_stable' + STABLE_ABI_SUFFIX), |
| 3021 | + ] |
| 3022 | + |
| 3023 | + for extra_args in ( |
| 3024 | + ['--python.build-config', python_build_config_file.name], |
| 3025 | + ['--cross-file', cross_file.name], |
| 3026 | + ): |
| 3027 | + with self.subTest(extra_args=extra_args): |
| 3028 | + self.init(testdir, extra_args=extra_args) |
| 3029 | + with open(intro_installed_file) as f: |
| 3030 | + intro_installed = json.load(f) |
| 3031 | + self.assertEqual(expected_files, list(intro_installed)) |
| 3032 | + self.wipe() |
| 3033 | + |
2951 | 3034 | def __reconfigure(self): |
2952 | 3035 | # Set an older version to force a reconfigure from scratch |
2953 | 3036 | filename = os.path.join(self.privatedir, 'coredata.dat') |
|
0 commit comments