-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathathena-upstream-tarball
executable file
·192 lines (153 loc) · 6.79 KB
/
athena-upstream-tarball
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/python
"""
Create an Athena redistribution platform for the specified package.
Not Debian-specific, but relies on Debathena build system for working
with source checkouts.
"""
import dabuildsys
from dabuildsys import BuildError
import argparse
import os.path
import re
import shutil
import subprocess
import sys
import tempfile
# Globals
quiet = False
def get_version_by_autoconf(rev):
"""
Extract package version number from autoconf files.
Returns (program name, version) tuple.
"""
try:
text = rev.read_file("configure.ac")
except subprocess.CalledProcessError:
return None
lines = text.split("\n")
for line in lines:
match = re.match(r"^AC_INIT\(\[(.+?)\], \[(.+?)\]", line)
if match:
return (match.group(1), match.group(2))
# FIXME: the following code should be reenabled after we convert
# everything to automake
#
# raise dabuildsys.BuildError("configure.{ac,in} contains no version file it is supposed to contain")
return None
def get_version_by_python_distutils(rev):
"""
Extract the package version number from setup.py.
"""
try:
text = rev.read_file("setup.py")
except subprocess.CalledProcessError:
return None
root = rev.repo.root
rev.checkout()
cmd = ['python', 'setup.py', '--version']
return subprocess.check_output(cmd, cwd = root).strip()
def build_automake_tarball(package, version, rev, filename, generated_path, dest_path):
"""
Generate makefile and invoke automake in order to get
a redistributable tarball.
"""
root = tempfile.mkdtemp('upstream-tarball')
rev.extract_tree(root)
def run(*cmd):
# Append schroot command to all invocations
cmd = ('schroot', '-c', dabuildsys.upstream_tarball_chroot, '--') + cmd
kwargs = {'stderr' : subprocess.STDOUT} if quiet else {}
return subprocess.check_output(cmd, cwd = root, **kwargs)
run('autoreconf', '-fvi')
run('./configure')
run('make', 'distcheck')
shutil.move(os.path.join(root, filename), generated_path)
shutil.rmtree(root)
def do_git_archive(package, version, rev, filename, generated_path, dest_path):
"""
Create a redistributable tarball from the specified Git revision.
"""
fullname = "%s-%s" % (package, version)
rev.repo.git('archive', '--prefix=%s/' % fullname, '--output=%s' % filename, rev.hash)
def build_upstream_tarball(package, do_build = True, do_pristine_tar = False, allow_override = False, force_version = None):
"""
Build a correct redistributable release of non-Debian-specific package.
"""
# Set up the repo object and view on the lastest upstream version
repo = dabuildsys.PackageCheckout(package, full_clean=True)
root = repo.root
latest = repo.read_branch_head("master")
# Try to determine upstream version, using one of the following sources:
# autoconf, distutils, VERSION file
autoconf_version = get_version_by_autoconf(latest)
distutils_version = get_version_by_python_distutils(latest)
if autoconf_version:
ac_name, version = autoconf_version
# The following check is important, because the name of upstream tarball
# as generated depends on the name specified in configure.ac
if package != ac_name:
raise BuildError("Autoconf package name does not match the package name")
method = 'make distcheck'
elif distutils_version:
version = distutils_version
method = 'git archive'
else:
try:
version = latest.read_file("VERSION")
except subprocess.CalledProcessError:
raise BuildError("No VERSION file found, and no other way to determine current version was provided")
method = 'git archive'
if force_version is not None:
version = force_version
# The tag must exist in order for build to succeed
try:
tagged = repo.read_tag(version)
except subprocess.CalledProcessError:
raise BuildError("Unable to find the tag corresponding to version %s" % version)
# Determine the relevant filenames and paths
filename = '%s-%s.tar.gz' % (package, version)
generated_path = os.path.join(root, filename)
dest_path = os.path.join(dabuildsys.orig_tarball_dir, filename)
# Check if tarball is already checked-in
if not allow_override and filename.lower() in [s.lower() for s in repo.list_tarballs()]:
raise BuildError("Tarball %s is already checked-in" % filename)
if do_build:
print "Using `%s' to generate redistributable tarball for %s %s" % (method, package, version)
print "Used revision: %s" % tagged.hash
# Do not overwrite existing files
if os.path.isfile(dest_path):
raise BuildError("File %s already exists, aborting" % dest_path)
if method == 'make distcheck':
build_automake_tarball(package, version, tagged, filename, generated_path, dest_path)
if method == 'git archive':
do_git_archive(package, version, tagged, filename, generated_path, dest_path)
if not os.path.isfile(generated_path):
raise BuildError("Generation ran successfuly, but file %s was not found" % generated_path)
shutil.move(generated_path, dest_path)
print "Successfully created %s using `%s'." % (filename, method)
print "Full location: %s" % dest_path
if do_pristine_tar:
print "Importing %s into %s repository onto pristine-tar branch" % (dest_path, package)
repo.import_tarball(dest_path, tagged.hash)
def main():
argparser = argparse.ArgumentParser(description="Generate upstream tarballs")
argparser.add_argument("package", help="A package to generate tarball for")
argparser.add_argument("--quiet", "-q", action="store_true", help="Do not print autoconf output")
argparser.add_argument("--pristine-tar", "-p", action="store_true", help="Commit the tarball to the Git repo")
argparser.add_argument("--only-pristine-tar", "-P", action="store_true", help="Do not build the tarball, only commit it")
argparser.add_argument("--yes-please-do-override-my-pristine-tar", action="store_true", help="Do not quit if pristine-tar is checked in")
argparser.add_argument("--force-version", help="Override the detected version number")
args = argparser.parse_args()
global quiet
quiet = args.quiet
do_build = not args.only_pristine_tar
do_pristine_tar = args.pristine_tar or args.only_pristine_tar
build_upstream_tarball(args.package, do_build, do_pristine_tar, args.yes_please_do_override_my_pristine_tar, args.force_version)
if __name__ == '__main__':
if not dabuildsys.claim_lock():
print >>sys.stderr, "The lock is in place; unable to proceed"
sys.exit(1)
try:
main()
finally:
dabuildsys.release_lock()