sponsor-patch: Support building with sbuild (LP: #681242).

This commit is contained in:
Benjamin Drung 2010-11-26 19:34:31 +01:00
parent 76f7079cb1
commit 15e5ef9a82
3 changed files with 97 additions and 29 deletions

3
debian/changelog vendored
View File

@ -18,8 +18,9 @@ ubuntu-dev-tools (0.107) UNRELEASED; urgency=low
[ Benjamin Drung ] [ Benjamin Drung ]
* wrap-and-sort: Remove duplicate items from sorted lists. * wrap-and-sort: Remove duplicate items from sorted lists.
* syncpackage: Fix error message for failed downloads. * syncpackage: Fix error message for failed downloads.
* sponsor-patch: Support building with sbuild (LP: #681242).
-- Stefano Rivera <stefanor@ubuntu.com> Fri, 26 Nov 2010 18:38:05 +0200 -- Benjamin Drung <bdrung@ubuntu.com> Fri, 26 Nov 2010 19:32:48 +0100
ubuntu-dev-tools (0.106) experimental; urgency=low ubuntu-dev-tools (0.106) experimental; urgency=low

View File

@ -11,9 +11,7 @@ test-build it, and upload.
.SH DESCRIPTION .SH DESCRIPTION
\fBsponsor\-patch\fR downloads the patch or Bazaar branch linked to an \fBsponsor\-patch\fR downloads the patch or Bazaar branch linked to an
Ubuntu bug, applies it, generates a review diff, (optionally) test Ubuntu bug, applies it, generates a review diff, (optionally) test
builds it with builds it, runs
.BR pbuilder (8),
runs
.BR lintian (1) .BR lintian (1)
and, after review and confirmation, can upload it. and, after review and confirmation, can upload it.
@ -50,33 +48,39 @@ the patched source and try building it again.
The sources and patches will be downloaded into the working directory The sources and patches will be downloaded into the working directory
(which defaults to the current directory). (which defaults to the current directory).
.BR pbuilder (8) The output of the build tool will be placed in
output will be placed in \fIworkdir\fR/\fIsourcepkg\fB\-buildresult/\fR. \fIworkdir\fR/\fIsourcepkg\fB\-buildresult/\fR.
.SH OPTIONS .SH OPTIONS
.TP .TP
.BR \-b ", " \-\-build .BR \-b ", " \-\-build
Build the package with \fBpbuilder\fR(1). This assumes the common Build the package with the specified builder. Note for \fBpbuilder\fR(8) users:
configuration, where the \fBDIST\fR environment is read by This assumes the common configuration, where the \fBDIST\fR environment is read
\fBpbuilderrc\fR(5) to select the correct base image. by \fBpbuilderrc\fR(5) to select the correct base image.
.TP
.B \-B \fIBUILDER\fR, \fB\-\-builder\fR=\fIBUILDER
Use the specify builder to build the package.
Supported are \fBpbuilder\fR(8) and \fBsbuild\fR(1).
This overrides \fBSPONSOR_PATCH_BUILDER\fR.
The default is \fBpbuilder\fR(8).
.TP .TP
.BR \-e ", " \-\-edit .BR \-e ", " \-\-edit
Launch a sub-shell to allow editing of the patched source before Launch a sub-shell to allow editing of the patched source before
building. building.
.TP .TP
.B \-k\fIKEY\fR, \fB\-\-key\fR=\fIKEY .B \-k \fIKEY\fR, \fB\-\-key\fR=\fIKEY
Specify a key ID for signing the upload. Specify a key ID for signing the upload.
.TP .TP
.BR \-s ", " \-\-sponsor .BR \-s ", " \-\-sponsor
Shortcut for sponsored uploads. Equivalent to \fB\-b \-u ubuntu\fR. Shortcut for sponsored uploads. Equivalent to \fB\-b \-u ubuntu\fR.
.TP .TP
.B \-u\fIDEST\fR, \fB\-\-upload\fR=\fIDEST .B \-u \fIDEST\fR, \fB\-\-upload\fR=\fIDEST
Upload to \fIDEST\fR with \fBdput\fR(1) (after confirmation). Upload to \fIDEST\fR with \fBdput\fR(1) (after confirmation).
.TP .TP
.BR \-v ", " \-\-verbose .BR \-v ", " \-\-verbose
Print more information. Print more information.
.TP .TP
.B \-w\fIDIR\fR, \fB\-\-workdir\fR=\fIDIR .B \-w \fIDIR\fR, \fB\-\-workdir\fR=\fIDIR
Use the specified working directory, creating it if necessary, instead Use the specified working directory, creating it if necessary, instead
of the current directory. This overrides \fBSPONSOR_PATCH_WORKDIR\fR. of the current directory. This overrides \fBSPONSOR_PATCH_WORKDIR\fR.
.TP .TP
@ -85,6 +89,12 @@ Display a help message and exit.
.SH ENVIRONMENT .SH ENVIRONMENT
.TP
.B SPONSOR_PATCH_BUILDER
The default builder for \fBsponsor\-patch\fR.
Supported are \fBpbuilder\fR(8) and \fBsbuild\fR(1).
If unset and not provided on the command line, \fBpbuilder\fR(8) is used.
.TP .TP
.B SPONSOR_PATCH_WORKDIR .B SPONSOR_PATCH_WORKDIR
The default working directory for \fBsponsor\-patch\fR. If unset and not The default working directory for \fBsponsor\-patch\fR. If unset and not
@ -112,6 +122,7 @@ Performing a test build of bug \fB1234\fR in your PPA:
.BR edit-patch (1), .BR edit-patch (1),
.BR lintian (1), .BR lintian (1),
.BR pbuilder (8), .BR pbuilder (8),
.BR sbuild (1),
.BR update\-maintainer (1) .BR update\-maintainer (1)
.SH AUTHORS .SH AUTHORS

View File

@ -148,6 +148,50 @@ class BugTask(object):
return self.project == "ubuntu" return self.project == "ubuntu"
class Builder(object):
def __init__(self, name):
self.name = name
cmd = ["dpkg-architecture", "-qDEB_BUILD_ARCH_CPU"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
self.architecture = process.communicate()[0].strip()
def get_architecture(self):
return self.architecture
def get_name(self):
return self.name
class Pbuilder(Builder):
def __init__(self):
Builder.__init__(self, "pbuilder")
def build(self, dsc_file, dist, result_directory):
# TODO: Do not rely on a specific pbuilder configuration.
cmd = ["sudo", "-E", "DIST=" + dist, "pbuilder", "--build",
"--distribution", dist, "--architecture", self.architecture,
"--buildresult", result_directory, dsc_file]
Print.command(cmd)
return subprocess.call(cmd)
class Sbuild(Builder):
def __init__(self):
Builder.__init__(self, "sbuild")
def build(self, dsc_file, dist, result_directory):
workdir = os.getcwd()
Print.command(["cd", result_directory])
os.chdir(result_directory)
cmd = ["sbuild", "--arch-all", "--dist=" + dist,
"--arch=" + self.architecture, dsc_file]
Print.command(cmd)
result = subprocess.call(cmd)
Print.command(["cd", workdir])
os.chdir(workdir)
return result
class Patch(object): class Patch(object):
def __init__(self, patch_file): def __init__(self, patch_file):
self.patch_file = patch_file self.patch_file = patch_file
@ -442,7 +486,7 @@ def apply_patch(task, patch):
edit = True edit = True
return edit return edit
def main(script_name, bug_number, build, edit, keyid, upload, workdir, def main(script_name, bug_number, build, edit, keyid, upload, workdir, builder,
verbose=False): verbose=False):
workdir = os.path.expanduser(workdir) workdir = os.path.expanduser(workdir)
if not os.path.isdir(workdir): if not os.path.isdir(workdir):
@ -634,27 +678,21 @@ def main(script_name, bug_number, build, edit, keyid, upload, workdir,
buildresult = os.path.join(workdir, task.package + "-buildresult") buildresult = os.path.join(workdir, task.package + "-buildresult")
if not os.path.isdir(buildresult): if not os.path.isdir(buildresult):
os.makedirs(buildresult) os.makedirs(buildresult)
cmd = ["dpkg-architecture", "-qDEB_BUILD_ARCH_CPU"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
architecture = process.communicate()[0].strip()
# build package # build package
dist = re.sub("-.*$", "", changelog.distributions) dist = re.sub("-.*$", "", changelog.distributions)
# TODO: Do not rely on a specific pbuilder configuration. result = builder.build(new_dsc_file, dist, buildresult)
cmd = ["sudo", "-E", "DIST=" + dist, "pbuilder", "--build", if result != 0:
"--distribution", dist, "--buildresult", buildresult, Print.error("Failed to build %s from source with %s." % \
"--architecture", architecture, new_dsc_file] (os.path.basename(new_dsc_file),
Print.command(cmd) builder.get_name()))
if subprocess.call(cmd) != 0:
Print.error("Failed to build %s from source." % \
(os.path.basename(new_dsc_file)))
# TODO: Add "retry" and "update" option # TODO: Add "retry" and "update" option
ask_for_manual_fixing() ask_for_manual_fixing()
continue continue
# Check lintian # Check lintian
changes_name = task.package + "_" + strip_epoch(new_version) + \ changes_name = task.package + "_" + strip_epoch(new_version) + \
"_" + architecture + ".changes" "_" + builder.get_architecture() + ".changes"
build_changes = os.path.join(buildresult, changes_name) build_changes = os.path.join(buildresult, changes_name)
assert os.path.isfile(build_changes), "%s does not exist." % \ assert os.path.isfile(build_changes), "%s does not exist." % \
(build_changes) (build_changes)
@ -674,7 +712,7 @@ def main(script_name, bug_number, build, edit, keyid, upload, workdir,
if upload: if upload:
if upload == "ubuntu": if upload == "ubuntu":
build_name = task.package + "_" + strip_epoch(new_version) + \ build_name = task.package + "_" + strip_epoch(new_version) + \
"_" + architecture + ".build" "_" + builder.get_architecture() + ".build"
build_log = os.path.join(buildresult, build_name) build_log = os.path.join(buildresult, build_name)
print "Please check %s %s carefully:\nfile://%s\nfile://%s\n" \ print "Please check %s %s carefully:\nfile://%s\nfile://%s\n" \
"file://%s" % (task.package, new_version, "file://%s" % (task.package, new_version,
@ -725,8 +763,17 @@ if __name__ == "__main__":
else: else:
default_workdir = os.getcwd() default_workdir = os.getcwd()
parser.add_option("-b", "--build", help="Build the package with pbuilder.", if "SPONSOR_PATCH_BUILDER" in os.environ:
dest="build", action="store_true", default=False) default_builder = os.environ["SPONSOR_PATCH_BUILDER"]
else:
default_builder = "pbuilder"
parser.add_option("-b", "--build", dest="build",
help="Build the package with the specified builder.",
action="store_true", default=False)
parser.add_option("-B", "--builder", dest="builder",
help="Specify the package builder (default pbuilder)",
default=default_builder)
parser.add_option("-e", "--edit", parser.add_option("-e", "--edit",
help="launch sub-shell to allow editing of the patch", help="launch sub-shell to allow editing of the patch",
dest="edit", action="store_true", default=False) dest="edit", action="store_true", default=False)
@ -759,9 +806,18 @@ if __name__ == "__main__":
Print.error("Invalid bug number specified: %s" % (bug_number)) Print.error("Invalid bug number specified: %s" % (bug_number))
sys.exit(1) sys.exit(1)
if options.builder == "pbuilder":
builder = Pbuilder()
elif options.builder == "sbuild":
builder = Sbuild()
else:
Print.error("Unsupported builder specified: %s. Only pbuilder and "
"sbuild are supported." % (options.builder))
sys.exit(1)
if options.sponsoring: if options.sponsoring:
options.build = True options.build = True
options.upload = "ubuntu" options.upload = "ubuntu"
main(script_name, bug_number, options.build, options.edit, options.keyid, main(script_name, bug_number, options.build, options.edit, options.keyid,
options.upload, options.workdir, options.verbose) options.upload, options.workdir, builder, options.verbose)