| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Converts a release tarball to a Debian package. |
| 4 |
|
| 5 |
# This script only works on Jussi's private release machine. |
| 6 |
|
| 7 |
import os, sys, subprocess, re, shutil |
| 8 |
import tarfile |
| 9 |
from glob import glob |
| 10 |
import pathlib |
| 11 |
|
| 12 |
assert(os.getcwd() == '/home/jpakkane') |
| 13 |
|
| 14 |
packdir = 'mesonpackaging' |
| 15 |
relfile = packdir + '/releases' |
| 16 |
|
| 17 |
files = glob('meson/dist/*.tar.gz') |
| 18 |
assert(len(files) == 1) |
| 19 |
infile = files[0] |
| 20 |
|
| 21 |
with tarfile.open(infile , 'r') as tf: |
| 22 |
for e in tf.getmembers(): |
| 23 |
if '__pycache__' in e.name or e.name.endswith('.pyc'): |
| 24 |
sys.exit('Source archive has Python binary files:' + str(e.name)) |
| 25 |
|
| 26 |
fname = os.path.split(infile)[1] |
| 27 |
tmp = fname.replace('-', '_') |
| 28 |
|
| 29 |
assert fname.endswith('.tar.gz') |
| 30 |
version_part = fname.split('-', 1)[1][:-7] |
| 31 |
|
| 32 |
if 'rc' in version_part: |
| 33 |
base_version, rcnum = version_part.split('rc') |
| 34 |
version = base_version + 'rc' + rcnum |
| 35 |
extension = tmp[-7:] |
| 36 |
dchversion = base_version + '~rc' + rcnum |
| 37 |
origname = tmp.split('rc', 1)[0] + '~rc' + rcnum + '.orig' + extension |
| 38 |
else: |
| 39 |
origname = tmp[:-7] + '.orig.' + tmp[-6:] |
| 40 |
version = version_part |
| 41 |
dchversion = version |
| 42 |
version_lines = pathlib.Path(relfile).read_text().split('\n')[:-1] |
| 43 |
prev_ver = version_lines[-1] |
| 44 |
version_lines.append(version) |
| 45 |
print('Deb orig name is', origname) |
| 46 |
print('Version is', version) |
| 47 |
print('Previous version is', prev_ver) |
| 48 |
assert(prev_ver) |
| 49 |
outdir = os.path.join(packdir, version) |
| 50 |
origfile = os.path.join(packdir, version, origname) |
| 51 |
if not os.path.exists(outdir): |
| 52 |
os.mkdir(outdir) |
| 53 |
shutil.copyfile(infile, origfile) |
| 54 |
subprocess.check_call(['tar', 'xf', origname], cwd=outdir) |
| 55 |
extractdir = glob(os.path.join(packdir, version, 'meson-*'))[0] |
| 56 |
fromdeb = glob(os.path.join(packdir, prev_ver, 'meson-*/debian'))[0] |
| 57 |
todeb = os.path.join(extractdir, 'debian') |
| 58 |
shutil.copytree(fromdeb, todeb) |
| 59 |
myenv = os.environ.copy() |
| 60 |
myenv['EDITOR'] = 'emacs' |
| 61 |
subprocess.check_call(['dch', '-v', dchversion + '-1'], cwd=extractdir, env=myenv) |
| 62 |
pathlib.Path(relfile).write_text('\n'.join(version_lines) + '\n') |
| 63 |
else: |
| 64 |
extractdir = glob(os.path.join(packdir, version, 'meson-*'))[0] |
| 65 |
print('Outdir already exists') |
| 66 |
|
| 67 |
subprocess.check_call(['debuild', '-S'], cwd=extractdir) |
| 68 |
|
| 69 |
subprocess.call(['sudo rm -rf /var/cache/pbuilder/result/*'], shell=True) |
| 70 |
subprocess.check_call('sudo pbuilder --build *.dsc 2>&1 | tee buildlog.txt', |
| 71 |
shell=True, |
| 72 |
cwd=outdir) |
| 73 |
subprocess.check_call('sudo dpkg -i /var/cache/pbuilder/result/meson*all.deb', |
| 74 |
shell=True) |
| 75 |
|
| 76 |
if os.path.exists('smoke/build'): |
| 77 |
shutil.rmtree('smoke/build') |
| 78 |
if os.path.exists('smoke/buildcross'): |
| 79 |
shutil.rmtree('smoke/buildcross') |
| 80 |
subprocess.check_call(['meson', 'setup', 'build'], cwd='smoke') |
| 81 |
subprocess.check_call(['ninja', 'test'], cwd='smoke/build') |
| 82 |
subprocess.check_call(['ninja', 'reconfigure'], cwd='smoke/build') |
| 83 |
subprocess.check_call(['ninja', 'test'], cwd='smoke/build') |
| 84 |
#subprocess.check_call(['/usr/bin/meson', |
| 85 |
# 'env2mfile', |
| 86 |
# '--cross', |
| 87 |
# '--debarch', |
| 88 |
# 'armhf', |
| 89 |
# '-o', |
| 90 |
# 'cross-file.txt'], cwd='smoke') |
| 91 |
subprocess.check_call(['/usr/share/meson/debcrossgen', |
| 92 |
'--arch', |
| 93 |
'armhf', |
| 94 |
'-o', |
| 95 |
'cross-file.txt'], cwd='smoke') |
| 96 |
subprocess.check_call(['meson', |
| 97 |
'setup', |
| 98 |
'buildcross', |
| 99 |
'--cross-file', |
| 100 |
'cross-file.txt'], cwd='smoke') |
| 101 |
subprocess.check_call(['ninja', 'test'], cwd='smoke/buildcross') |
| 102 |
subprocess.check_call(['sudo', 'apt-get', '-y', 'remove', 'meson']) |
| 103 |
subprocess.call('rm meson-*tar.gz*', shell=True) |
| 104 |
subprocess.check_call(['cp', infile, '.']) |
| 105 |
subprocess.check_call(['gpg', '--detach-sign', '--armor', fname]) |