|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +import re |
| 4 | + |
| 5 | + |
| 6 | +def target_version(): |
| 7 | + with open('src/cffi/recompiler.py', encoding='UTF-8') as f: |
| 8 | + for line in f: |
| 9 | + m = re.match(r'^VERSION_BASE = (0x[0-9A-F]+)$', line) |
| 10 | + if m: |
| 11 | + return int(m.group(1), 16) |
| 12 | + raise Exception('Version not found') |
| 13 | + |
| 14 | + |
| 15 | +def backend_supported_versions(): |
| 16 | + versions = {} |
| 17 | + with open('src/c/cffi1_module.c', encoding='UTF-8') as f: |
| 18 | + for line in f: |
| 19 | + m = re.match(r'^#define CFFI_VERSION_(MIN|MAX) *(0x[0-9A-F]+)$', |
| 20 | + line) |
| 21 | + if m: |
| 22 | + versions[m.group(1)] = int(m.group(2), 16) |
| 23 | + if len(versions) == 2: |
| 24 | + return versions['MIN'], versions['MAX'] |
| 25 | + raise Exception('Versions not found') |
| 26 | + |
| 27 | + |
| 28 | +versions = backend_supported_versions() |
| 29 | +target = target_version() |
| 30 | +for pkg in ('python-cffi', 'python3-cffi'): |
| 31 | + subst = { |
| 32 | + 'pkg': pkg, |
| 33 | + 'min': versions[0], |
| 34 | + 'max': versions[1], |
| 35 | + 'target': target, |
| 36 | + } |
| 37 | + with open('debian/{0}-backend.substvars'.format(pkg), 'a', |
| 38 | + encoding='UTF-8') as f: |
| 39 | + f.write('cffi:Provides={pkg}-backend-api-min (= {min}), ' |
| 40 | + '{pkg}-backend-api-max (= {max}), ' |
| 41 | + '{pkg}-backend-api-{target}\n'.format(**subst)) |
| 42 | + with open('debian/{0}.pydist'.format(pkg), 'w', encoding='UTF-8') as f: |
| 43 | + f.write('cffi {pkg}-backend-api-min (<= {target}), ' |
| 44 | + '{pkg}-backend-api-max (>= {target})\n' |
| 45 | + .format(**subst)) |
0 commit comments