From: Francesco Chemolli Date: Mon, 1 Jun 2020 16:28:33 +0000 (+0000) Subject: Maintenance: Sort source file lists in Makefiles (#643) X-Git-Tag: 4.15-20210522-snapshot~109 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2a06115;p=thirdparty%2Fsquid.git Maintenance: Sort source file lists in Makefiles (#643) Automate keeping files in Makefile.am SOURCES directives in the appropriate order and apply to current Makefile.am throughout the source --- diff --git a/scripts/format-makefile-am.pl b/scripts/format-makefile-am.pl new file mode 100755 index 0000000000..2b8efe654d --- /dev/null +++ b/scripts/format-makefile-am.pl @@ -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"; +} diff --git a/scripts/source-maintenance.sh b/scripts/source-maintenance.sh index 4da788ee97..55b922fd22 100755 --- a/scripts/source-maintenance.sh +++ b/scripts/source-maintenance.sh @@ -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)