Skip to content
Snippets Groups Projects
Commit f85351d3 authored by Simon McVittie's avatar Simon McVittie
Browse files

build-relocatable-install: Add an option to just check for source code

parent 6e89e606
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
import argparse import argparse
import glob import glob
import logging
import os import os
import re import re
import shutil import shutil
...@@ -44,6 +45,9 @@ except ImportError: ...@@ -44,6 +45,9 @@ except ImportError:
from pipes import quote # noqa from pipes import quote # noqa
logger = logging.getLogger('pressure-vessel-build-relocatable-install')
class Architecture: class Architecture:
def __init__( def __init__(
self, self,
...@@ -170,6 +174,17 @@ def main(): ...@@ -170,6 +174,17 @@ def main():
"pressure-vessel's own source code" "pressure-vessel's own source code"
), ),
) )
parser.add_argument(
'--check-source-directory', default=None, metavar='DIR',
help=(
'Instead of building a binary + source release tarball, check '
'that all required source code is available in DIR'
),
)
parser.add_argument(
'--allow-missing-sources', action='store_true',
help='Missing source code is only a warning [default: error]',
)
parser.add_argument( parser.add_argument(
'--set-version', dest='version', default=None, '--set-version', dest='version', default=None,
help='Assume that pressure-vessel is version VERSION', help='Assume that pressure-vessel is version VERSION',
...@@ -387,7 +402,7 @@ def main(): ...@@ -387,7 +402,7 @@ def main():
+ list(PRIMARY_ARCH_DEPENDENCIES.items()) + list(PRIMARY_ARCH_DEPENDENCIES.items())
) )
if args.apt_get_source: if args.apt_get_source or args.check_source_directory is not None:
get_source.append( get_source.append(
('pressure-vessel-relocatable', 'pressure-vessel'), ('pressure-vessel-relocatable', 'pressure-vessel'),
) )
...@@ -454,16 +469,6 @@ def main(): ...@@ -454,16 +469,6 @@ def main():
os.path.join(installation, 'sources'), os.path.join(installation, 'sources'),
) )
v_check_call(
[
'apt-get',
'--download-only',
'--only-source',
'source',
] + list(source_to_download),
cwd=os.path.join(installation, 'sources'),
)
with open( with open(
os.path.join(installation, 'sources', 'sources.txt'), 'w' os.path.join(installation, 'sources', 'sources.txt'), 'w'
) as writer: ) as writer:
...@@ -473,50 +478,93 @@ def main(): ...@@ -473,50 +478,93 @@ def main():
for source in sorted(source_to_download): for source in sorted(source_to_download):
writer.write(source.replace('=', '\t') + '\n') writer.write(source.replace('=', '\t') + '\n')
if not args.apt_get_source: if args.check_source_directory is None:
os.makedirs( try:
os.path.join(installation, 'sources', 'pressure-vessel'), v_check_call(
exist_ok=True, [
) 'apt-get',
'--download-only',
'--only-source',
'source',
] + list(source_to_download),
cwd=os.path.join(installation, 'sources'),
)
except subprocess.CalledProcessError:
if args.allow_missing_sources:
logger.warning(
'Some source packages could not be downloaded')
with open(
os.path.join(installation, 'sources', 'INCOMPLETE'),
'w',
) as writer:
# nothing to write, just create the file
pass
else:
raise
if not args.apt_get_source:
os.makedirs(
os.path.join(installation, 'sources', 'pressure-vessel'),
exist_ok=True,
)
tar = subprocess.Popen([ tar = subprocess.Popen([
'tar', 'tar',
'-C', args.srcdir, '-C', args.srcdir,
'--exclude=.*.sw?', '--exclude=.*.sw?',
'--exclude=./.git', '--exclude=./.git',
'--exclude=./.mypy_cache', '--exclude=./.mypy_cache',
'--exclude=./_build', '--exclude=./_build',
'--exclude=./debian', '--exclude=./debian',
'--exclude=./relocatable-install', '--exclude=./relocatable-install',
'-cf-', '-cf-',
'.', '.',
], stdout=subprocess.PIPE) ], stdout=subprocess.PIPE)
subprocess.check_call([ subprocess.check_call([
'tar', 'tar',
'-C', os.path.join( '-C', os.path.join(
installation, installation,
'sources', 'sources',
'pressure-vessel', 'pressure-vessel',
), ),
'-xvf-', '-xvf-',
], stdin=tar.stdout) ], stdin=tar.stdout)
if tar.wait() != 0: if tar.wait() != 0:
raise subprocess.CalledProcessError( raise subprocess.CalledProcessError(
returncode=tar.returncode, returncode=tar.returncode,
cmd=tar.args, cmd=tar.args,
) )
with open( with open(
os.path.join( os.path.join(
installation, installation,
'sources', 'sources',
'pressure-vessel', 'pressure-vessel',
'.tarball-version', '.tarball-version',
), ),
'w', 'w',
) as writer: ) as writer:
writer.write('{}\n'.format(args.version)) writer.write('{}\n'.format(args.version))
else: # args.check_source_directory is not None
for source in sorted(source_to_download):
package, version = source.split('=')
if ':' in version:
version = version.split(':', 1)[1]
filename = os.path.join(
args.check_source_directory,
'{}_{}.dsc'.format(package, version),
)
if not os.path.exists(filename):
if args.allow_missing_sources:
logger.warning(
'Source code not found in %s', filename)
else:
raise RuntimeError(
'Source code not found in %s', filename)
if args.archive: if args.archive:
if args.archive_versions: if args.archive_versions:
...@@ -528,21 +576,25 @@ def main(): ...@@ -528,21 +576,25 @@ def main():
args.archive, args.archive,
'pressure-vessel{}-bin.tar.gz'.format(tail), 'pressure-vessel{}-bin.tar.gz'.format(tail),
) )
src_tar = os.path.join(
args.archive,
'pressure-vessel{}-bin+src.tar.gz'.format(tail),
)
subprocess.check_call([ if args.check_source_directory is None:
'tar', src_tar = os.path.join(
r'--transform=s,^\(\.\(/\|$\)\)\?,pressure-vessel{}/,'.format( args.archive,
tail, 'pressure-vessel{}-bin+src.tar.gz'.format(tail),
), )
'--exclude=metadata', # this is all duplicated in sources/ subprocess.check_call([
'-zcvf', src_tar + '.tmp', 'tar',
'-C', installation, r'--transform=s,^\(\.\(/\|$\)\)\?,pressure-vessel{}/,'.format(
'.', tail,
]) ),
'--exclude=metadata', # this is all duplicated in sources/
'-zcvf', src_tar + '.tmp',
'-C', installation,
'.',
])
else:
src_tar = ''
subprocess.check_call([ subprocess.check_call([
'tar', 'tar',
r'--transform=s,^\(\.\(/\|$\)\)\?,pressure-vessel{}/,'.format( r'--transform=s,^\(\.\(/\|$\)\)\?,pressure-vessel{}/,'.format(
...@@ -554,12 +606,15 @@ def main(): ...@@ -554,12 +606,15 @@ def main():
'.', '.',
]) ])
os.rename(bin_tar + '.tmp', bin_tar) os.rename(bin_tar + '.tmp', bin_tar)
os.rename(src_tar + '.tmp', src_tar)
print('Generated {}'.format(os.path.abspath(bin_tar))) print('Generated {}'.format(os.path.abspath(bin_tar)))
print('Generated {}'.format(os.path.abspath(src_tar)))
if src_tar:
os.rename(src_tar + '.tmp', src_tar)
print('Generated {}'.format(os.path.abspath(src_tar)))
if __name__ == '__main__': if __name__ == '__main__':
logging.basicConfig()
main() main()
# vim:set sw=4 sts=4 et: # vim:set sw=4 sts=4 et:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment