Skip to content

Commit b9fd19e

Browse files
committed
Remove hard-coded version from scripts/run_astyle.sh
This script now works the same way as cppcheck. The version to be used is specified once in the github CI action
1 parent 4c2a7e8 commit b9fd19e

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,6 @@ jobs:
213213
- run: sudo scripts/install_astyle_dependencies_with_apt.sh
214214
- run: scripts/install_astyle.sh $ASTYLE_REPO $ASTYLE_VER
215215
- name: Format code with astyle
216-
run: scripts/run_astyle.sh
216+
run: scripts/run_astyle.sh -v $ASTYLE_VER
217217
- name: Check code formatting
218218
run: git diff --exit-code

scripts/run_astyle.sh

+46-28
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,82 @@
22

33
# Script to run astyle on the code
44
#
5-
# Usage: /path/to/run_astyle.sh
5+
# Usage: /path/to/run_astyle.sh [ -v ASTYLE_VER]
66
#
7+
# - If -v ASTYLE_VER is specified, that version of astyle is run from
8+
# ~/astyle.local (whether or not it's there!). Use install_astyle.sh
9+
# to install a new version.
10+
711
# Note: the script must be run from the root directory of the xrdp repository
812

913
INSTALL_ROOT=~/astyle.local
10-
ASTYLE_FROM_XRDP=$INSTALL_ROOT/3.4.12/usr/bin/astyle
1114
MIN_ASTYLE_VER="3.1"
1215

1316
# ----------------------------------------------------------------------------
1417
# U S A G E
1518
# ----------------------------------------------------------------------------
1619
usage()
1720
{
18-
echo "** Usage: $0"
19-
echo " e.g. $0"
21+
echo "** Usage: $0 [ -v version]"
22+
echo " e.g. $0 -v 3.4.12"
2023
} >&2
2124

2225
# ----------------------------------------------------------------------------
2326
# M A I N
2427
# ----------------------------------------------------------------------------
28+
# Figure out ASTYLE setting, if any. Currently '-v' must be the first
29+
# argument on the command line.
30+
case "$1" in
31+
-v) # Version is separate parameter
32+
if [ $# -ge 2 ]; then
33+
ASTYLE="$INSTALL_ROOT/$2/usr/bin/astyle"
34+
shift 2
35+
else
36+
echo "** ignoring '-v' with no arg" >&2
37+
shift 1
38+
fi
39+
;;
40+
-v*) # Version is in same parameter
41+
# ${parameter#word} is not supported by classic Bourne shell,
42+
# but it is on bash, dash, etc. If it doesn't work on your shell,
43+
# don't use this form!
44+
ASTYLE="$INSTALL_ROOT/${1#-v}/usr/bin/astyle"
45+
shift 1
46+
esac
47+
48+
if [ -z "$ASTYLE" ]; then
49+
ASTYLE=astyle
50+
fi
51+
2552
if [ $# -ne 0 ]; then
2653
usage
2754
exit 1
2855
fi
2956

30-
# check if the built-in astyle meets the minimum requrements
31-
ASTYLE_FROM_OS_VER_OUTPUT=`astyle --version | grep "Artistic Style Version" | cut -d' ' -f4`
3257

33-
ASTYLE=""
34-
ERROR_MESSAGE=""
35-
if [ ! -z "$ASTYLE_FROM_OS_VER_OUTPUT" ]; then
36-
# astyle is installed, so check if it's version meets the minimum requirements
37-
LOWEST_VERSION=`echo -e "$MIN_ASTYLE_VER\n$ASTYLE_FROM_OS_VER_OUTPUT" | sort -V | head -n1`
38-
if [ "$MIN_ASTYLE_VER" = "$LOWEST_VERSION" ]; then
39-
ASTYLE=astyle
40-
else
58+
# check if the selected astyle meets the minimum requrements
59+
ASTYLE_VER_OUTPUT=`$ASTYLE --version 2>/dev/null | grep "Artistic Style Version" | cut -d' ' -f4`
60+
61+
if [ ! -z "$ASTYLE_VER_OUTPUT" ]; then
62+
# Check the version meets the minimum requirements
63+
LOWEST_VERSION=`{ echo "$MIN_ASTYLE_VER" ; echo "$ASTYLE_VER_OUTPUT"; } | sort -V | head -n1`
64+
if [ "$MIN_ASTYLE_VER" != "$LOWEST_VERSION" ]; then
4165
ERROR_MESSAGE="The version of astyle installed does not meet the minimum version requirement: >= $MIN_ASTYLE_VER "
4266
fi
43-
else
67+
elif [ "$ASTYLE" = astyle ]; then
4468
ERROR_MESSAGE="astyle is not installed on the system path"
45-
fi
46-
47-
if [ -z "$ASTYLE" ]; then
48-
# astyle from the os is invlid, fallback to the xrdp version if it is installed
49-
if [ -x "$ASTYLE_FROM_XRDP" ]; then
50-
ASTYLE="$ASTYLE_FROM_XRDP"
51-
ERROR_MESSAGE=""
52-
else
53-
ERROR_MESSAGE="${ERROR_MESSAGE}\nastyle $MIN_ASTYLE_VER is not installed at the expected path: $ASTYLE_FROM_XRDP"
54-
fi
69+
else
70+
ERROR_MESSAGE="Can't find $ASTYLE"
5571
fi
5672

5773
if [ ! -z "$ERROR_MESSAGE" ]; then
58-
echo "$ERROR_MESSAGE"
74+
echo "$ERROR_MESSAGE" >&2
5975
exit 1
6076
fi
6177

6278
if [ ! -f "astyle_config.as" ]; then
63-
echo "$0 must be run from the root xrdp repository directory which "
64-
echo "contains the 'astyle_config.as' file."
79+
echo "$0 must be run from the root xrdp repository directory which " >&2
80+
echo "contains the 'astyle_config.as' file." >&2
6581
exit 2
6682
fi
6783

@@ -72,3 +88,5 @@ ASTYLE_FLAGS="--options=astyle_config.as --exclude=third_party ./\*.c ./\*.h"
7288
echo "Command: $ASTYLE $ASTYLE_FLAGS"
7389
"$ASTYLE" $ASTYLE_FLAGS
7490
}
91+
92+
exit $?

0 commit comments

Comments
 (0)