]> 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)
committerAmos Jeffries <yadij@users.noreply.github.com>
Thu, 17 Jun 2021 10:13:51 +0000 (22:13 +1200)
... 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 85b3eca12705311a9a7e999ad40f549d53e9326e..d77579bca709af2fdad7dd1067b65485d230bcfd 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 = "";
@@ -90,8 +74,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 fae8891b5bfbeda69b4aaf01b493a40498823397..8b4426f5177f33f6455b83a532aacc7917519b0e 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