From 9478566087f83d1fac2c9a7629898a3d39a05fdd Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Wed, 12 Jan 2011 01:06:33 +0100 Subject: [PATCH] refactor: split 'usage' subroutine in automake This change is related to automake bug#7819. * automake.in (print_autodist_files): New subroutine, extracted from ... (usage): ... this, which now uses it. * tests/autodist-no-duplicate.test: New test. * tests/Makefile.am (TESTS): Update. --- ChangeLog | 10 +++++ automake.in | 89 ++++++++++++++++++++-------------------- tests/Makefile.am | 1 + tests/Makefile.in | 1 + tests/autodist-no-duplicate.test | 39 ++++++++++++++++++ 5 files changed, 96 insertions(+), 44 deletions(-) create mode 100755 tests/autodist-no-duplicate.test diff --git a/ChangeLog b/ChangeLog index 7ef5077..2524e06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-06-23 Stefano Lattarini + + refactor: split 'usage' subroutine in automake + This change is related to automake bug#7819. + * automake.in (print_autodist_files): New subroutine, + extracted from ... + (usage): ... this, which now uses it. + * tests/autodist-no-duplicate.test: New test. + * tests/Makefile.am (TESTS): Update. + 2011-06-23 Stefano Lattarini tests: fix bug in 'autodist.test' diff --git a/automake.in b/automake.in index 93f4ae4..77db7f6 100755 --- a/automake.in +++ b/automake.in @@ -8323,6 +8323,50 @@ sub generate_makefile ($$) ################################################################ +# Helper function for usage(). +sub print_autodist_files (@) +{ + my @lcomm = sort (&uniq (@_)); + + my @four; + format USAGE_FORMAT = + @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< + $four[0], $four[1], $four[2], $four[3] +. + local $~ = "USAGE_FORMAT"; + + my $cols = 4; + my $rows = int(@lcomm / $cols); + my $rest = @lcomm % $cols; + + if ($rest) + { + $rows++; + } + else + { + $rest = $cols; + } + + for (my $y = 0; $y < $rows; $y++) + { + @four = ("", "", "", ""); + for (my $x = 0; $x < $cols; $x++) + { + last if $y + 1 == $rows && $x == $rest; + + my $idx = (($x > $rest) + ? ($rows * $rest + ($rows - 1) * ($x - $rest)) + : ($rows * $x)); + + $idx += $y; + $four[$x] = $lcomm[$idx]; + } + write; + } +} + + # Print usage information. sub usage () { @@ -8356,51 +8400,8 @@ Library files: "; Automake::ChannelDefs::usage; - my ($last, @lcomm); - $last = ''; - foreach my $iter (sort ((@common_files, @common_sometimes))) - { - push (@lcomm, $iter) unless $iter eq $last; - $last = $iter; - } - - my @four; print "\nFiles which are automatically distributed, if found:\n"; - format USAGE_FORMAT = - @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< - $four[0], $four[1], $four[2], $four[3] -. - $~ = "USAGE_FORMAT"; - - my $cols = 4; - my $rows = int(@lcomm / $cols); - my $rest = @lcomm % $cols; - - if ($rest) - { - $rows++; - } - else - { - $rest = $cols; - } - - for (my $y = 0; $y < $rows; $y++) - { - @four = ("", "", "", ""); - for (my $x = 0; $x < $cols; $x++) - { - last if $y + 1 == $rows && $x == $rest; - - my $idx = (($x > $rest) - ? ($rows * $rest + ($rows - 1) * ($x - $rest)) - : ($rows * $x)); - - $idx += $y; - $four[$x] = $lcomm[$idx]; - } - write; - } + print_autodist_files (@common_files, @common_sometimes); print ' Report bugs to <@PACKAGE_BUGREPORT@>. diff --git a/tests/Makefile.am b/tests/Makefile.am index 28196f8..b14ef77 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -113,6 +113,7 @@ autodist-acconfig-no-subdir.test \ autodist-aclocal-m4.test \ autodist-config-headers.test \ autodist-configure-no-subdir.test \ +autodist-no-duplicate.test \ autodist-stamp-vti.test \ autohdr.test \ autohdr2.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index ba57aa2..f9df782 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -390,6 +390,7 @@ autodist-acconfig-no-subdir.test \ autodist-aclocal-m4.test \ autodist-config-headers.test \ autodist-configure-no-subdir.test \ +autodist-no-duplicate.test \ autodist-stamp-vti.test \ autohdr.test \ autohdr2.test \ diff --git a/tests/autodist-no-duplicate.test b/tests/autodist-no-duplicate.test new file mode 100755 index 0000000..36a9c9a --- /dev/null +++ b/tests/autodist-no-duplicate.test @@ -0,0 +1,39 @@ +#! /bin/sh +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# This program 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, or (at your option) +# any later version. +# +# This program 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. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that there are no duplicates in the list of files automatically +# distributed by automake. + +. ./defs || Exit 1 + +set -e + +# The automake manual states that the list of automatically-distributed +# files should be given by `automake --help'. +list=`$AUTOMAKE --help \ + | sed -n '/^Files .*automatically distributed.*if found/,/^ *$/p' \ + | sed 1d` +list=`echo $list` +test -n "$list" + +for f in $list; do echo $f; done | sort > files.lst +uniq files.lst > files.uniq + +cat files.lst +cat files.uniq +diff files.lst files.uniq + +: -- 2.7.4