-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-format.sh
executable file
·101 lines (90 loc) · 2.93 KB
/
update-format.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: Copyright © 2020-2023 Serpent OS Developers
#
# SPDX-License-Identifier: Zlib
#
function noisyFail ()
{
if [[ -z "$1" ]]; then
echo ""
echo "\033[1;31mERROR:\033[0m\033[1m No message parameter specified for noisyFail?\033[0m"
echo ""
exit 1
fi
# set up terminal colours
BOLDRED="\033[1;31m"
BOLD="\033[1m"
RESET="\033[0m"
ERRMSG="${BOLDRED}ERROR:${RESET}${BOLD} ${1}${RESET}"
echo ""
echo -e "${ERRMSG}"
echo ""
exit 1
}
function checkDirPrerequisites ()
{
if [[ ! -d .git/ ]]; then
MSG="${PWD} does not contain a .git/ directory?\n\
- please ensure that this script is run from the root of a git repository."
noisyFail "${MSG}"
fi
if [[ ! -d source/ ]]; then
MSG="${PWD} does not contain a source/ directory?"
noisyFail "${MSG}"
fi
}
function checkExePrerequisites ()
{
command -v iconv 2>&1 > /dev/null
if [[ ! $? -eq 0 ]]; then
MSG="'iconv' character set conversion tool not found in your $PATH?\n\
- please ensure that you are using a glibc-enabled distribution compiled with locale support."
noisyFail "${MSG}"
fi
command -v xargs 2>&1 > /dev/null
if [[ ! $? -eq 0 ]]; then
MSG="'xargs' utility (part of GNU findutils) not found in your $PATH?\n\
- please install GNU findutils using your distribution's package manager."
noisyFail "${MSG}"
fi
command -v dfmt 2>&1 > /dev/null
if [[ ! $? -eq 0 ]]; then
MSG="'dfmt' utility not found in your $PATH\n\
- please install 'dfmt'.\n\
- (git clone https://github.com/dlang-community/dfmt and consult the included README.md)"
noisyFail "${MSG}"
fi
command -v codespell 2>&1 > /dev/null
if [[ ! $? -eq 0 ]]; then
MSG="'codespell' spell checking tool not found in your \$PATH?\n\
- please install 'codespell' using your distribution's package manager."
noisyFail "${MSG}"
fi
}
D_FILES=""
# Autoformat the code and check spelling
function autoFormat ()
{
local D_FILES=""
if [[ -d tests/ ]]; then
D_FILES="$(find source/ tests/ -name '*.d' -type f 2>/dev/null)"
else
D_FILES="$(find source/ -name '*.d' -type f 2>/dev/null)"
fi
if [[ -n "${D_FILES}" ]]; then
echo "Testing that Dlang files can be converted to utf-8..."
echo "${D_FILES}" | xargs -n1 --verbose iconv -t utf8 > /dev/null || noisyFail "Failed to convert *.d files to utf-8? Please encode *.d files to utf-8."
echo "Running Dlang files through 'dfmt'..."
echo "${D_FILES}" | xargs -n1 --verbose dfmt -i
echo "Running Dlang files through 'codespell'..."
codespell "${D_FILES}"
else
MSG="No '*.d' Dlang source files found in ${PWD}/source/ or ${PWD}/tests/) ?"
noisyFail "${MSG}"
fi
}
# main ()
checkDirPrerequisites
checkExePrerequisites
autoFormat