refactor: split 'usage' subroutine in automake
authorStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 12 Jan 2011 00:06:33 +0000 (01:06 +0100)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Thu, 23 Jun 2011 08:47:29 +0000 (10:47 +0200)
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
automake.in
tests/Makefile.am
tests/Makefile.in
tests/autodist-no-duplicate.test [new file with mode: 0755]

index 7ef5077..2524e06 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-06-23   Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       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  <stefano.lattarini@gmail.com>
 
        tests: fix bug in 'autodist.test'
index 93f4ae4..77db7f6 100755 (executable)
@@ -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@>.
index 28196f8..b14ef77 100644 (file)
@@ -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 \
index ba57aa2..f9df782 100644 (file)
@@ -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 (executable)
index 0000000..36a9c9a
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+# 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
+
+: