| 1 |
|
| 2 |
|
| 3 |
import os |
| 4 |
import re |
| 5 |
import subprocess |
| 6 |
|
| 7 |
|
| 8 |
def cffi_version(): |
| 9 |
with open('lib_pypy/cffi/__init__.py', encoding='UTF-8') as f: |
| 10 |
for line in f: |
| 11 |
m = re.match(r'^__version__ = "([0-9.]+)(?:\.dev\d+)?"$', line) |
| 12 |
if m: |
| 13 |
return m.group(1) |
| 14 |
raise Exception('Version not found') |
| 15 |
|
| 16 |
|
| 17 |
def target_version(): |
| 18 |
with open('lib_pypy/cffi/recompiler.py', encoding='UTF-8') as f: |
| 19 |
for line in f: |
| 20 |
m = re.match(r'^VERSION_CHAR16CHAR32 = (0x[0-9A-F]+)$', line) |
| 21 |
if m: |
| 22 |
return int(m.group(1), 16) |
| 23 |
raise Exception('Version not found') |
| 24 |
|
| 25 |
|
| 26 |
def backend_supported_versions(): |
| 27 |
versions = {} |
| 28 |
with open('pypy/module/_cffi_backend/cffi1_module.py', |
| 29 |
encoding='UTF-8') as f: |
| 30 |
for line in f: |
| 31 |
m = re.match(r'^VERSION_(MIN|MAX) *= (0x[0-9A-F]+)$', |
| 32 |
line) |
| 33 |
if m: |
| 34 |
versions[m.group(1)] = int(m.group(2), 16) |
| 35 |
if len(versions) == 2: |
| 36 |
return versions['MIN'], versions['MAX'] |
| 37 |
raise Exception('Versions not found') |
| 38 |
|
| 39 |
|
| 40 |
def pypy_abi(): |
| 41 |
if 'pypy3' not in subprocess.check_output(('dh_listpackages',)).split(): |
| 42 |
return '' |
| 43 |
soabi = subprocess.check_output(( |
| 44 |
'pypy/goal/pypy3.11-c', '-c', |
| 45 |
'import sysconfig; print(sysconfig.get_config_var("SOABI"))')) |
| 46 |
return soabi.strip().replace('-', '-abi-') |
| 47 |
|
| 48 |
|
| 49 |
cffi = cffi_version() |
| 50 |
versions = backend_supported_versions() |
| 51 |
target = target_version() |
| 52 |
|
| 53 |
subst = { |
| 54 |
'cffi': cffi, |
| 55 |
'min': versions[0], |
| 56 |
'max': versions[1], |
| 57 |
'target': target, |
| 58 |
} |
| 59 |
with open('debian/pypy3-lib.substvars', 'a', encoding='UTF-8') as f: |
| 60 |
f.write('cffi:Provides=pypy3-cffi (= {cffi}), ' |
| 61 |
'pypy3-cffi-backend-api-min (= {min}), ' |
| 62 |
'pypy3-cffi-backend-api-max (= {max}), ' |
| 63 |
'pypy3-cffi-backend-api-{target}\n'.format(**subst)) |
| 64 |
|
| 65 |
with open('debian/pypy3.substvars', 'a', encoding='UTF-8') as f: |
| 66 |
f.write('pypy3-abi={}\n'.format(pypy_abi())) |
| 67 |
|
| 68 |
path = 'debian/pypy3-lib/usr/share/python3/dist' |
| 69 |
os.makedirs(path) |
| 70 |
with open(os.path.join(path, 'pypy3-cffi'), 'w', encoding='UTF-8') as f: |
| 71 |
f.write('cffi pypy3-cffi-backend-api-min (<= {target}), ' |
| 72 |
'pypy3-cffi-backend-api-max (>= {target})\n' |
| 73 |
.format(**subst)) |