From 3b3bd39db33bbe7366f410f6ede343a9f91d0f9a Mon Sep 17 00:00:00 2001 From: Srdjan Jankovic Date: Wed, 27 Apr 2011 19:23:59 +1200 Subject: [Signed Off] [PATCH 1/2] bug 5602: Rewriting the package making script Now it is a perl script. Various pdebuild flexibility. Signed-off-by: Chris Cormack --- debian/README.build | 13 ++++ debian/build-git-snapshot | 171 +++++++++++++++++++++++++++++++++------------ 2 files changed, 138 insertions(+), 46 deletions(-) create mode 100644 debian/README.build diff --git a/debian/README.build b/debian/README.build new file mode 100644 index 0000000..32a0f5d --- /dev/null +++ b/debian/README.build @@ -0,0 +1,13 @@ +In order to build .deb packages, following debian packages need to be present (installed): +devscripts +pbuilder +dh-make +fakeroot + +As root (or sudo) execute: +pbuilder create + +Executing build-git-snapshot without any arguments will leave package and the rest in some pbuilder dir, eg. /var/cache/pbuilder/result +It is highly recommended that --buildresult option is used. + +The script requires sudo. diff --git a/debian/build-git-snapshot b/debian/build-git-snapshot index 3847024..c3140e7 100755 --- a/debian/build-git-snapshot +++ b/debian/build-git-snapshot @@ -1,64 +1,143 @@ -#!/bin/sh +#!/usr/bin/perl + +# Copyright 2010 Catalyst IT Ltd. +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. # -# This script will build a .deb from a git snapshot of koha. -# Don't use it for building actual versions for uploading to Debian. +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# To use: -# - commit any changes into git -# - run this script +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Written by Robin Sheat +# Based on an sh version by Lars Wirzenius. + +use strict; +use warnings; + +use Getopt::Long; +use POSIX qw/strftime/; + +my $buildresult; +my $distribution='squeeze-dev'; +my $git_checks='all'; +my $version='3.3-1~git'; +my $auto_version=1; +my $need_help; +my $debug; + +GetOptions( + 'buildresult|r=s' => \$buildresult, + 'distribution|D=s' => \$distribution, + 'git-checks|g=s' => \$git_checks, + 'version|v=s' => \$version, + 'autoversion!' => \$auto_version, + 'help|h' => \$need_help, + 'debug|d' => \$debug, +); + +help_and_exit() if $need_help; + -set -e +sub sys_command_output { + my ($command) = @_; -die() -{ - echo "$@" - exit 1 + print "$command\n" if $debug; + open COMMAND, "$command |" + or die qq{Cannot execute "$command": $!"}; + return map { chomp; $_ } ; } -everything_is_commited() -{ - if git status --short | grep -q '^' - then - return 1 - else - return 0 - fi +sub everything_is_committed { + my $filter; + for ($git_checks) { + $_ eq "none" + and return 1; + + $_ eq "modified" + and $filter = "no", + last; + + $_ eq "all" + and $filter = "normal", + last; + + help_and_exit("$0: --git-checks/-g must be one of 'all', 'modified', or 'none'"); + } + my $has_changes = grep /^xxx/, sys_command_output("git status --porcelain -u${filter}"); + + return !$has_changes; } -latest_sha1() { - git rev-parse --short=8 HEAD +sub help_and_exit { + my $msg = shift; + if ($msg) { + print "$msg\n\n"; + } + print < "../koha_$1.tar.gz" - pdebuild $2 +sub build_package { + my ($newversion) = @_; + sys_command_output( qq{git archive --format=tar --prefix="koha-$newversion/" HEAD | gzip -9 > "../koha_$newversion.tar.gz"} ); + + my $pdebuildopts = $buildresult ? "--buildresult $buildresult" : ""; + sys_command_output( "pdebuild $pdebuildopts" ); } -if ! everything_is_commited -then - die "cannot build: uncommited changes" -fi - -version="$(newversion)" -if [ -n "$1" ] -then - pdebuildopts="--buildresult $1" -fi -adjust_debian_changelog "$version" -build_package "$version" "$pdebuildopts" -reset_debian_changelog +everything_is_committed() or die "cannot build: uncommited changes"; + +my $newversion = $auto_version + ? sprintf ('%s%s.%s', $version, strftime("+%Y%m%d%H%M%S", localtime), latest_sha1()) + : $version; + +adjust_debian_changelog( $newversion ); +build_package( $newversion ); +reset_debian_changelog(); + -- 1.7.2.2