1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#!/usr/bin/python3
import argparse
import os
import subprocess
import sys
# we know that our relative path doesn't include the module
try:
# If __file__ is a symlink, resolve to where it points to. If the symlink
# target is relative, then we need to join that to the directory __file__
# is inside in order to resolve it correctly. If the symlink target is
# absolute, then os.path.join is defined to ignore the first parameter
# here.
realpath = os.path.join(os.path.dirname(__file__), os.readlink(__file__))
except OSError:
realpath = __file__
sys.path.insert(
0,
os.path.abspath(
os.path.join(os.path.dirname(realpath), os.path.pardir)
)
)
import gitubuntu, gitubuntu.exportorig, gitubuntu.git_repository
from gitubuntu.cache import CACHE_PATH
import gitubuntu.prepare_upload
separator_seen = False
dpkg_args = ['-i', '-I']
prepare_upload_args = []
for arg in sys.argv[1:]:
if arg == '--':
separator_seen = True
elif separator_seen:
dpkg_args.append(arg)
else:
prepare_upload_args.append(arg)
parser = argparse.ArgumentParser(
usage='gu-build [-h] [--remote REMOTE] [--branch BRANCH]\n'
' [-- DPKG_BUILDPACKAGE_ARGS]')
gitubuntu.prepare_upload._add_subparser_arguments(parser)
parsed_prepare_upload_args = parser.parse_args(prepare_upload_args)
repo = gitubuntu.git_repository.GitUbuntuRepository('.')
dl_cache = os.path.join(os.getcwd(), os.getenv('GIT_DIR', '.git'), CACHE_PATH)
search_list = gitubuntu.build.derive_orig_search_list_from_args(
repo, 'HEAD', False, False, dl_cache=dl_cache
)
# see what the upload target is to determine what base branch to check against
changelog = gitubuntu.git_repository.Changelog.from_path('debian/changelog')
dist = changelog.distribution.split('-')
target = 'pkg/ubuntu/%s' % dist[0]
if len(dist) > 1 and dist[1] == 'security':
# special case; this is the only pocket that doesn't get mapped
# to -devel on upload
target = target + '-security'
elif dist[0] != 'devel':
target = target + '-devel'
old_changelog = repo.get_changelog_from_treeish(target)
# if we haven't made any changes but just checked out, we shouldn't
# pass a nonsensical -v argument
if (old_changelog.version in changelog.all_versions
and changelog.version != old_changelog.version):
dpkg_args.append("-v%s" % old_changelog.version)
if old_changelog.upstream_version != changelog.upstream_version:
dpkg_args.append("-sa")
gitubuntu.exportorig.main(repo, 'HEAD', search_list)
parameters = gitubuntu.prepare_upload.establish_args(
repo,
remote_name=parsed_prepare_upload_args.remote,
branch_name=parsed_prepare_upload_args.branch,
force_push=parsed_prepare_upload_args.force_push,
)
# fixme: some minor duplication with gitubuntu.prepare_upload
for k,v in parameters.changes_file_headers.items():
dpkg_args.append("--changes-option=-D%s=%s" % (k,v))
result = subprocess.run(['dpkg-buildpackage'] + dpkg_args)
sys.exit(result.returncode)
|