|
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 |
@@ -2929,6 +2930,88 @@ def test_pkg_config_libdir(self): |
2929 | 2930 | self.wipe() |
2930 | 2931 | self.init(testdir, extra_args=['-Dstart_native=true'], override_envvars=env) |
2931 | 2932 |
|
| 2933 | + @skipIf(is_windows(), 'POSIX only') |
| 2934 | + def test_python_build_config_extensions(self): |
| 2935 | + testdir = os.path.join(self.unit_test_dir, |
| 2936 | + '125 python extension') |
| 2937 | + |
| 2938 | + VERSION_INFO_KEYS = ('major', 'minor', 'micro', 'releaselevel', 'serial') |
| 2939 | + EXTENSION_SUFFIX = '.extension-suffix.so' |
| 2940 | + STABLE_ABI_SUFFIX = '.stable-abi-suffix.so' |
| 2941 | + |
| 2942 | + python_build_config = { |
| 2943 | + 'schema_version': '1.0', |
| 2944 | + 'base_interpreter': sys.executable, |
| 2945 | + 'base_prefix': '/usr', |
| 2946 | + 'platform': sysconfig.get_platform(), |
| 2947 | + 'language': { |
| 2948 | + 'version': sysconfig.get_python_version(), |
| 2949 | + 'version_info': {key: getattr(sys.version_info, key) for key in VERSION_INFO_KEYS} |
| 2950 | + }, |
| 2951 | + 'implementation': { |
| 2952 | + attr: ( |
| 2953 | + getattr(sys.implementation, attr) |
| 2954 | + if attr != 'version' else |
| 2955 | + {key: getattr(sys.implementation.version, key) for key in VERSION_INFO_KEYS} |
| 2956 | + ) |
| 2957 | + for attr in dir(sys.implementation) |
| 2958 | + if not attr.startswith('__') |
| 2959 | + }, |
| 2960 | + 'abi': { |
| 2961 | + 'flags': [], |
| 2962 | + 'extension_suffix': EXTENSION_SUFFIX, |
| 2963 | + 'stable_abi_suffix': STABLE_ABI_SUFFIX, |
| 2964 | + }, |
| 2965 | + 'suffixes': { |
| 2966 | + 'source': ['.py'], |
| 2967 | + 'bytecode': ['.pyc'], |
| 2968 | + 'optimized_bytecode': ['.pyc'], |
| 2969 | + 'debug_bytecode': ['.pyc'], |
| 2970 | + 'extensions': [EXTENSION_SUFFIX, STABLE_ABI_SUFFIX, '.so'], |
| 2971 | + }, |
| 2972 | + 'libpython': { |
| 2973 | + 'dynamic': sysconfig.get_config_var('LDLIBRARY'), |
| 2974 | + 'dynamic_stableabi': sysconfig.get_config_var('PY3LIBRARY'), |
| 2975 | + 'static': sysconfig.get_config_var('LIBRARY'), |
| 2976 | + 'link_extensions': True, |
| 2977 | + }, |
| 2978 | + 'c_api': { |
| 2979 | + 'headers': sysconfig.get_path('include'), |
| 2980 | + 'pkgconfig_path': sysconfig.get_config_var('LIBPC'), |
| 2981 | + } |
| 2982 | + } |
| 2983 | + with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as python_build_config_file: |
| 2984 | + json.dump(python_build_config, fp=python_build_config_file) |
| 2985 | + |
| 2986 | + with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as cross_file: |
| 2987 | + cross_file.write( |
| 2988 | + textwrap.dedent(f''' |
| 2989 | + [binaries] |
| 2990 | + pkg-config = 'pkg-config' |
| 2991 | +
|
| 2992 | + [built-in options] |
| 2993 | + python.build_config = '{python_build_config_file.name}' |
| 2994 | + '''.strip()) |
| 2995 | + ) |
| 2996 | + cross_file.flush() |
| 2997 | + |
| 2998 | + intro_installed_file = os.path.join(self.builddir, 'meson-info', 'intro-installed.json') |
| 2999 | + expected_files = [ |
| 3000 | + os.path.join(self.builddir, 'foo' + EXTENSION_SUFFIX), |
| 3001 | + os.path.join(self.builddir, 'foo_stable' + STABLE_ABI_SUFFIX), |
| 3002 | + ] |
| 3003 | + |
| 3004 | + for extra_args in ( |
| 3005 | + ['--python.build-config', python_build_config_file.name], |
| 3006 | + ['--cross-file', cross_file.name], |
| 3007 | + ): |
| 3008 | + with self.subTest(extra_args=extra_args): |
| 3009 | + self.init(testdir, extra_args=extra_args) |
| 3010 | + with open(intro_installed_file) as f: |
| 3011 | + intro_installed = json.load(f) |
| 3012 | + self.assertEqual(expected_files, list(intro_installed)) |
| 3013 | + self.wipe() |
| 3014 | + |
2932 | 3015 | def __reconfigure(self): |
2933 | 3016 | # Set an older version to force a reconfigure from scratch |
2934 | 3017 | filename = os.path.join(self.privatedir, 'coredata.dat') |
|
0 commit comments