]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Maintenance: Support custom astyle versions (#644)
authorFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 1 Jun 2020 23:23:09 +0000 (23:23 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 1 Jun 2020 23:23:14 +0000 (23:23 +0000)
... 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...

scripts/formater.pl
scripts/source-maintenance.sh

index 3bed0966e6ff6c498efda8b169f2700a4099bf82..686c56b80a65a3e02217408917a737abc8663dc1 100755 (executable)
 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;
index 55b922fd2215f423ed8291321431960ab697dbd4..fa6e904cc90dc381832039df1bfd3bcf5f9c9d63 100755 (executable)
 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