]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Maintenance: Sort source file lists in Makefiles (#643)
authorFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 1 Jun 2020 16:28:33 +0000 (16:28 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 1 Jun 2020 16:28:37 +0000 (16:28 +0000)
Automate keeping files in Makefile.am SOURCES
directives in the appropriate order and apply to
current Makefile.am throughout the source

scripts/format-makefile-am.pl [new file with mode: 0755]
scripts/source-maintenance.sh

diff --git a/scripts/format-makefile-am.pl b/scripts/format-makefile-am.pl
new file mode 100755 (executable)
index 0000000..2b8efe6
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/perl
+#
+## Copyright (C) 1996-2020 The Squid Software Foundation and contributors
+##
+## Squid software is distributed under GPLv2+ license and includes
+## contributions from numerous individuals and organizations.
+## Please see the COPYING and CONTRIBUTORS files for details.
+##
+
+use strict;
+use warnings;
+
+my $current_source_section='';
+while (<>) {
+    chomp;
+    if (m!^#!) {
+        print "$_\n";
+        next;
+    }
+    # accumulate files and prep for sorting
+    my %files = ();
+    if (/^(\S+_SOURCES)\s*(\+?=)\s*(.*[^\\])$/ ) {
+        my @parts = split(/\s+/, $3);
+        if ($#parts == 0) { # one file only specified on same line as SOURCES
+            print "$1 $2 $3\n";
+            next;
+        }
+        foreach my $file (@parts) {
+            &addfile(\%files, $file, $1);
+        }
+        print "$1 $2 \\\n";
+        &print_files(\%files);
+        next;
+    }
+    if (/^(\S+_SOURCES)\s*(\+?=)\s*(.*?)\s*\\$/) {
+        $current_source_section=$1;
+        print "$1 $2 \\\n";
+        if (defined $3) {
+            foreach my $file (split(/\s+/, $3)) {
+                &addfile(\%files, $file, $current_source_section);
+            }
+        }
+    } else {
+        print "$_\n";
+        next;
+    }
+    while (<>) {
+        chomp;
+        m!^\s+(.*?)\s*\\?$!;
+        foreach my $file (split(/\s+/, $1)) {
+            &addfile(\%files, $file, $current_source_section) if (length $file);
+        }
+        if (! /\\$/ ) {  # last line in the list
+            &print_files(\%files);
+            last;
+        }
+    }
+}
+
+exit 0;
+
+# arg: ref to hash to add the file to, filename
+sub addfile
+{
+    my $files = shift @_;
+    my $fn = shift @_;
+    my $current_source_section = shift @_;
+
+    $fn =~ m!\s*(tests/stub_|tests/test)?(\S+)(\s+\\\s*)?$! || die "no parse";
+    my $prefix = (defined $1) ? $1 : '';
+    my $filename = (defined $2) ? $2 : '';
+
+    print STDERR "WARNING: duplicate $prefix$filename ".
+        "detected in $current_source_section\n"
+        if exists($files->{"$filename.$prefix"});
+
+    $files->{"$filename.$prefix"}="$prefix$filename";
+}
+
+# arg is hash ref, print values in order of key
+sub print_files
+{
+    my %files=%{$_[0]};
+    my @q=();
+    foreach my $k (sort keys %files) {
+        push @q, "\t".$files{$k};
+    }
+    print join(" \\\n", @q)."\n";
+}
index 4da788ee976bb6478932fa67e82d229a19366307..55b922fd2215f423ed8291321431960ab697dbd4 100755 (executable)
@@ -113,6 +113,17 @@ applyPlugin ()
                 updateIfChanged "$source" "$new" "by $script"
 }
 
+# updates the given source file using the given script(s)
+applyPluginsTo ()
+{
+        source="$1"
+        shift
+
+        for script in `git ls-files "$@"`; do
+                run_ applyPlugin $script $source || return
+        done
+}
+
 srcFormat ()
 {
 #
@@ -139,9 +150,7 @@ for FILENAME in `git ls-files`; do
        #
        # Code Style formatting maintenance
        #
-       for SCRIPT in `git ls-files scripts/maintenance/`; do
-               run_ applyPlugin ${SCRIPT} "${FILENAME}" || return
-       done
+       applyPluginsTo ${FILENAME} scripts/maintenance/ || return
        if test "${ASVER}"; then
                ./scripts/formater.pl ${FILENAME}
                if test -e $FILENAME -a -e "$FILENAME.astylebak"; then
@@ -232,10 +241,8 @@ for FILENAME in `git ls-files`; do
        chmod 755 ${FILENAME}
        ;;
 
-    Makefile.am)
-
-       perl -p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
-       mv ${FILENAME}.styled ${FILENAME}
+    *.am)
+               applyPluginsTo ${FILENAME} scripts/format-makefile-am.pl || return
        ;;
 
     ChangeLog|CREDITS|CONTRIBUTORS|COPYING|*.list|*.png|*.po|*.pot|rfcs/|*.txt|test-suite/squidconf/empty|.bzrignore)