calamares/ci/calamaresstyle
Adriaan de Groot c4eee7bb11 CI: demand clang-format 12 or 13
- use clang-format12 or 13 or unversioned executable, only
- check it's actually 12 or 13
- set language standard explicitly to C++17, "Cpp11" is now
  an alias for "latest" which is weird

This change does lead to some thrashing when applying styles,
so I'm not going to do that across the board right now. Changes include:
- extra spaces in lambda-captures
- nicer alignment of lambda-bodies
2022-02-01 16:23:39 +01:00

89 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
#
# SPDX-FileCopyrightText: 2014 Aurélien Gâteau <agateau@kde.org>
# SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
# Calls astyle with settings matching Calamares coding style
# Requires astyle >= 2.04 and clang-format-8 or later
#
# You can pass in directory names, in which case the files
# in that directory (NOT below it) are processed.
#
LANG=C
LC_ALL=C
LC_NUMERIC=C
export LANG LC_ALL LC_NUMERIC
BASEDIR=$(dirname $0)
TOPDIR=$( cd $BASEDIR/.. && pwd -P )
test -d "$BASEDIR" || { echo "! Could not determine base for $0" ; exit 1 ; }
test -d "$TOPDIR" || { echo "! Cound not determine top-level source dir" ; exit 1 ; }
test -f "$TOPDIR/.clang-format" || { echo "! No .clang-format support files in $TOPDIR" ; exit 1 ; }
AS=$( which astyle )
# Allow specifying CF_VERSIONS outside already
CF_VERSIONS="$CF_VERSIONS clang-format13 clang-format12 clang-format"
for _cf in $CF_VERSIONS
do
# Not an error if this particular clang-format isn't found
CF=$( which $_cf 2> /dev/null || true )
test -n "$CF" && break
done
test -n "$AS" || { echo "! No astyle found in PATH"; exit 1 ; }
test -n "$CF" || { echo "! No clang-format ($CF_VERSIONS) found in PATH"; exit 1 ; }
test -x "$AS" || { echo "! $AS is not executable."; exit 1 ; }
test -x "$CF" || { echo "! $CF is not executable."; exit 1 ; }
### CLANG-FORMAT-WRANGLING
#
# Version 7 and earlier doesn't understand all the options we would like
# Version 12 handles lambdas nicely, so use that.
# Version 13 is also ok.
format_version=`"$CF" --version | tr -dc '[^.0-9]' | cut -d . -f 1`
case "$format_version" in
12|13 )
:
;;
* )
echo "! Clang-format version '$format_version' unsupported, version 12 required."
exit 1
;;
esac
### FILE PROCESSING
#
#
set -e
any_dirs=no
for d in "$@"
do
test -d "$d" && any_dirs=yes
done
style_some()
{
if test -n "$*" ; then
$AS --options=$BASEDIR/astylerc --quiet "$@"
$CF -i -style=file "$@"
fi
}
if test "x$any_dirs" = "xyes" ; then
for d in "$@"
do
if test -d "$d" ; then
style_some $( find "$d" -maxdepth 1 -type f -name '*.cpp' -o -name '*.h' )
else
style_some "$d"
fi
done
else
style_some "$@"
fi