-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI: update formatting to match Calamares
- Loading branch information
1 parent
47cda51
commit 7bec3f6
Showing
2 changed files
with
32 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,14 @@ | |
# SPDX-FileCopyrightText: 2019 Adriaan de Groot <[email protected]> | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Calls astyle with settings matching Calamares coding style | ||
# Requires astyle >= 2.04 and clang-format-8 or later | ||
# Apply Calamares-style formatting to sources. Requires clang-format-15. | ||
# | ||
# You can pass in directory names, in which case the files | ||
# in that directory (NOT below it) are processed. | ||
# | ||
# If the environment variable CLANG_FORMAT is set to a (full path) and | ||
# that path is executable, it will be used if possible. | ||
# | ||
LANG=C | ||
LC_ALL=C | ||
LC_NUMERIC=C | ||
|
@@ -19,52 +21,53 @@ 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.base" || { echo "! No .clang-format support files in $TOPDIR" ; exit 1 ; } | ||
|
||
AS=$( which astyle ) | ||
test -f "$TOPDIR/.clang-format" || { echo "! No .clang-format support files in $TOPDIR" ; exit 1 ; } | ||
|
||
# Allow specifying CF_VERSIONS outside already | ||
CF_VERSIONS="$CF_VERSIONS clang-format-8 clang-format80 clang-format90 clang-format-9.0.1 clang-format" | ||
# Start with CLANG_FORMAT, if it is specified | ||
CF_VERSIONS="" | ||
if test -n "$CLANG_FORMAT" && test -x "$CLANG_FORMAT" ; then | ||
CF_VERSIONS="$CLANG_FORMAT" | ||
fi | ||
# And a bunch of other potential known versions of clang-format, newest first | ||
CF_VERSIONS="$CF_VERSIONS clang-format-17" | ||
CF_VERSIONS="$CF_VERSIONS clang-format-16 clang-format-16.0.6 " | ||
CF_VERSIONS="$CF_VERSIONS clang-format15 clang-format-15 " | ||
# Generic name of clang-format | ||
CF_VERSIONS="$CF_VERSIONS 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 8 is ok | ||
# Version 9 is ok | ||
# Later versions change some defaults so need extra wrangling. | ||
# .. there are extra files that are appended to the settings, per | ||
# .. clang-format version. | ||
# Version 7 and earlier doesn't understand all the options we would like. | ||
# Version 12 handled lambdas nicely and was the norm for Calamares 3.2. | ||
# Version 13 was also ok. | ||
# Version 14 behaves differently with short-functions-in-class, | ||
# spreading functions out that 13 keeps on one line. To avoid | ||
# ping-pong commits, forbid 14. | ||
# Version 15 is available on recent-ish Ubuntus and FreeBSD, pick it. | ||
# It also supports inserting braces, which is the one thing we kept | ||
# astyle around for. | ||
# Version 16 is available on openSUSE and is ok as well. | ||
# Version 17 is available on FreeBSD and KaOS and is ok as well. | ||
|
||
format_version=`"$CF" --version | tr -dc '[^.0-9]' | cut -d . -f 1` | ||
case "$format_version" in | ||
[0-7] ) | ||
echo "! Clang-format version 8+ required" | ||
exit 1 | ||
;; | ||
[89] ) | ||
15|16|17 ) | ||
: | ||
;; | ||
* ) | ||
echo "! Clang-format version '$format_version' unsupported." | ||
echo "! Clang-format version '$format_version' unsupported, versions 15-17 are ok." | ||
exit 1 | ||
;; | ||
esac | ||
_fmt="$TOPDIR/.clang-format" | ||
cp "$_fmt.base" "$_fmt" | ||
for f in "$extra_settings" ; do | ||
test -f "$_fmt.$f" && cat "$_fmt.$f" >> "$_fmt" | ||
done | ||
|
||
|
||
### FILE PROCESSING | ||
|
@@ -81,7 +84,6 @@ done | |
style_some() | ||
{ | ||
if test -n "$*" ; then | ||
$AS --options=$BASEDIR/astylerc --quiet "$@" | ||
$CF -i -style=file "$@" | ||
fi | ||
} | ||
|
@@ -98,8 +100,3 @@ if test "x$any_dirs" = "xyes" ; then | |
else | ||
style_some "$@" | ||
fi | ||
|
||
### CLANG-FORMAT-WRANGLING | ||
# | ||
# Restore the original .clang-format | ||
cp "$_fmt.base" "$_fmt" |