From dd10dc0d271c46e7c77e591d01778e677398d191 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Fri, 23 Nov 2018 11:18:37 -0500 Subject: [PATCH] Bug 21876: tweak the build script While trying to build following the instructions on the wiki, error after error was encountered, and frustration rose. Eventually, tcohen mentioned untracked files. So, all untracked files were purposefully deleted all, and then building succeeded again. To this end, the build script wa tweaked. 1) Sorry, a bunch of perlcritic things to get it perlcritic -2 clear were done. :) Proof: perlcritic -1 debian/build-git-snapshot -- fear the long scrolly output apply the patch repeat -- much shorter, and who cares about the print return value! perlcritic -2 debian/build-git-snapshot -- OK. YAY! 2) everything_is_committed was broken. It would always return 1 and keep going. Proof: touch foobar. add a blank line to Koha.pm now try to build. It will spend minutes and die miserably at the end. To address this, it was tweaked to check for two cases: uncommitted and untracked. You can test this with a combination of touch foobar and blank line to Koha.pm to see. 3) While not a huge issue, the version should be better determined rather than hard coded as 16.06~git. Logic was added to better determine something based on Koha.pm through grep'ing, so as to not need PERL5LIB set. Proof: Try checking out 17.11.x apply this patch (hopefully it does) try to build without a -v parameter. -- it should generate 17.11~git Feel free to repeat with 18.05 and master they should generate 18.05~git and 18.06~git As always run the qa test tools. ;) Oh wait, they don't run unless you rename this to a .pl file. I guess that's another bug. And if you do rename to test, it should only complain about Robin's last name. --- debian/build-git-snapshot | 155 ++++++++++++++++++++++++++++++---------------- 1 file changed, 102 insertions(+), 53 deletions(-) diff --git a/debian/build-git-snapshot b/debian/build-git-snapshot index 0ae2197355..f9ca54a949 100755 --- a/debian/build-git-snapshot +++ b/debian/build-git-snapshot @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl # Copyright 2010 Catalyst IT Ltd. # @@ -23,76 +23,98 @@ use Modern::Perl; +use Carp; +use English qw( -no_match_vars ); +use File::Basename qw/dirname/; +use File::Spec qw/rel2abs/; use Getopt::Long; use POSIX qw/strftime/; +our $VERSION = '1.1'; # Just to perlcritic -2 :) my $basetgz; my $buildresult; -my $distribution='squeeze-dev'; -my $git_checks='all'; -my $version='16.06~git'; -my $auto_version=1; +my $distribution = 'jessie'; +my $git_checks = 'all'; +my $version; +my $auto_version = 1; my $need_help; my $debug; GetOptions( 'basetgz|b=s' => \$basetgz, - '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, + '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; +if ($need_help) { + help_and_exit(); +} +if ( $git_checks ne 'all' + && $git_checks ne 'modified' + && $git_checks ne 'none' ) +{ + help_and_exit( +"$PROGRAM_NAME: --git-checks/-g must be one of 'all', 'modified', or 'none'" + ); +} sub sys_command_output { my ($command) = @_; - print "$command\n" if $debug; - my $command_output; - open($command_output, "-|", "$command ") - or die qq{Cannot execute "$command": $!"}; - return map { chomp; $_ } <$command_output>; + if ($debug) { + print "$command\n"; + } + open my $command_output, q{-|}, + "$command " || croak qq{Cannot execute "$command": $OS_ERROR}; + my @output = <$command_output>; + chomp @output; + close $command_output || croak 'Difficulty closing command handle'; + if ($debug) { + print "output: @output\n"; + } + return @output; } sub sys_command_output_screen { my ($command) = @_; - print "$command\n" if $debug; - system($command) == 0 or die "Command '$command' returns an error ($?)\n"; + if ($debug) { + print "$command\n"; + } + return system($command) == 0 + || croak "Command '$command' returns an error ($CHILD_ERROR)\n"; } sub everything_is_committed { + my ($check_type) = @_; + my %filters; my $filter; - for ($git_checks) { - $_ eq "none" - and return 1; - - $_ eq "modified" - and $filter = "no", - last; + $filters{'uncommitted'} = 'no'; + $filters{'untracked'} = 'normal'; + $filter = $filters{$check_type}; - $_ eq "all" - and $filter = "normal", - last; + # No header, so wc -l generates a count of the changes. + my ($has_changes) = + sys_command_output("git status --porcelain -u${filter} | wc -l"); - help_and_exit("$0: --git-checks/-g must be one of 'all', 'modified', or 'none'"); + if ($debug) { + print "has changes: $has_changes\n"; } - my $has_changes = grep /^xxx/, sys_command_output("git status --porcelain -u${filter}"); - return !$has_changes; } sub help_and_exit { - my $msg = shift; - if ($msg) { - print "$msg\n\n"; + my $msg = shift; + if ($msg) { + print "$msg\n\n"; } - print < "../koha_$newversion.orig.tar.gz"} ); - - my $pdebuildopts = $buildresult ? "--buildresult $buildresult" : ""; - my $pdebuildbasetgz = $basetgz ? "-- --basetgz /var/cache/pbuilder/" . $basetgz . ".tgz" : ""; - sys_command_output_screen( "pdebuild $pdebuildbasetgz $pdebuildopts" ); + sys_command_output( +qq{git archive --format=tar --prefix="koha-$newversion/" HEAD | gzip -9 > "../koha_$newversion.orig.tar.gz"} + ); + + my $pdebuildopts = $buildresult ? "--buildresult $buildresult" : q{}; + my $pdebuildbasetgz = + $basetgz ? '-- --basetgz /var/cache/pbuilder/' . $basetgz . '.tgz' : q{}; + sys_command_output_screen("pdebuild $pdebuildbasetgz $pdebuildopts"); + return; } -everything_is_committed() or die "cannot build: uncommited changes"; +# This logic doesn't require PERL5LIB set correctly. +my $path_name = File::Spec->rel2abs($PROGRAM_NAME); -my $newversion = $auto_version - ? sprintf ('%s%s.%s', $version, strftime("+%Y%m%d%H%M%S", localtime), latest_sha1()) +# Koha.pm is always up a directory from this script. +my $koha_file = dirname( dirname($path_name) ) . '/Koha.pm'; +($version) = sys_command_output( + qq{grep VERSION $koha_file | grep = | cut -f2 -d\\\" | cut -f1-2 -d.}); +$version .= '~git'; # YY.MM~git + +if ( $git_checks ne 'none' ) { + everything_is_committed('uncommitted') + || croak 'cannot build: uncommited changes'; +} +if ( $git_checks eq 'all' ) { + everything_is_committed('untracked') + || croak 'cannot build: untracked 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 ); +adjust_debian_changelog($newversion); +build_package($newversion); reset_debian_changelog(); - -- 2.11.0