From: Francesco Chemolli Date: Mon, 1 Jun 2020 23:23:09 +0000 (+0000) Subject: Maintenance: Support custom astyle versions (#644) X-Git-Tag: 4.15-20210522-snapshot~107 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=12e6d55e6ef19af2009162967c0fa3b480b965b1;p=thirdparty%2Fsquid.git Maintenance: Support custom astyle versions (#644) ... to override the astyle version used for official sources: $ ./scripts/source-maintenance.sh Astyle version problem. You have 3.1 instead of 2.04 $ ./scripts/source-maintenance.sh --enable-astyle 3.1 Found astyle 3.1. Formatting... --- diff --git a/scripts/formater.pl b/scripts/formater.pl index 3bed0966e6..686c56b80a 100755 --- a/scripts/formater.pl +++ b/scripts/formater.pl @@ -29,26 +29,10 @@ use strict; use IPC::Open2; -# -# NP: The Squid code requires astyle version 2.04 (exactly for now) -# -my $ASTYLE_BIN="/usr/local/bin/astyle"; -if (! -x $ASTYLE_BIN) { - $ASTYLE_BIN="/usr/bin/astyle"; -} -if (! -x $ASTYLE_BIN) { - $ASTYLE_BIN="/usr/local/src/astyle-2.04/bin/astyle"; -} - +my $ASTYLE_BIN = defined $ENV{'ASTYLE'} ? $ENV{'ASTYLE'} : 'astyle'; my $ASTYLE_ARGS ="--mode=c -s4 --convert-tabs --keep-one-line-blocks --lineend=linux"; #$ASTYLE_ARGS="--mode=c -s4 -O --break-blocks -l"; - -if(! -e $ASTYLE_BIN || ! -x $ASTYLE_BIN){ - print "\nFile $ASTYLE_BIN not found\n"; - print "Please fix the ASTYLE_BIN variable in this script!\n\n"; - exit -1; -} $ASTYLE_BIN=$ASTYLE_BIN." ".$ASTYLE_ARGS; my $INDENT = ""; @@ -89,8 +73,8 @@ while($out){ my $pid_style=open2(\*FROM_ASTYLE, \*TO_ASTYLE, $ASTYLE_BIN); if(!$pid_style){ - print "An error while open2\n"; - exit -1; + print "An error while running $ASTYLE_BIN\n"; + exit -1; } my $pid; diff --git a/scripts/source-maintenance.sh b/scripts/source-maintenance.sh index 55b922fd22..fa6e904cc9 100755 --- a/scripts/source-maintenance.sh +++ b/scripts/source-maintenance.sh @@ -26,6 +26,15 @@ KeepGoing="no" # the actual name of the directive that enabled keep-going mode KeepGoingDirective="" +# +# The script checks that the version of astyle is TargetAstyleVersion. +# if it isn't, the default behaviour is to not perform the formatting stage +# in order to avoid unexpected massive changes if the behaviour of astyle +# has changed in different releases. +# if --with-astyle /path/to/astyle is used, the check is still performed +# and a warning is printed, but the sources are reformatted +TargetAstyleVersion="2.04" +ASTYLE='astyle' # command-line options while [ $# -ge 1 ]; do @@ -35,6 +44,11 @@ while [ $# -ge 1 ]; do KeepGoingDirective=$1 shift ;; + --with-astyle) + ASTYLE=$2 + export ASTYLE + shift 2 + ;; *) echo "Usage: $0 [--keep-going|-k]" echo "Unsupported command-line option: $1" @@ -61,10 +75,22 @@ else MD5="md5sum" fi -ASVER=`astyle --version 2>&1 | grep -o -E "[0-9.]+"` -if test "${ASVER}" != "2.04" ; then - echo "Astyle version problem. You have ${ASVER} instead of 2.04" - ASVER="" +${ASTYLE} --version >/dev/null 2>/dev/null +result=$? +if test $result -gt 0 ; then + echo "ERROR: cannot run ${ASTYLE}" + exit 1 +fi +ASVER=`${ASTYLE} --version 2>&1 | grep -o -E "[0-9.]+"` +if test "${ASVER}" != "${TargetAstyleVersion}" ; then + if test "${ASTYLE}" = "astyle" ; then + echo "Astyle version problem. You have ${ASVER} instead of ${TargetAstyleVersion}" + echo "Formatting step skipped due to version mismatch" + ASVER="" + else + echo "WARNING: ${ASTYLE} is version ${ASVER} instead of ${TargetAstyleVersion}" + echo "Formatting anyway, please double check output before submitting" + fi else echo "Found astyle ${ASVER}. Formatting..." fi