Skip to content

Commit 676f1a2

Browse files
committed
Make gen_wrapper.sh ShellCheck compliant
ShellCheck is a static analysis tool for shell scripts. https://www.shellcheck.net/ Signed-off-by: Frederic Pillon <[email protected]>
1 parent 23dc07a commit 676f1a2

File tree

1 file changed

+55
-48
lines changed

1 file changed

+55
-48
lines changed

CI/utils/gen_wrapper.sh

+55-48
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,30 @@ LLoutInc_path=$Core_path/cores/arduino/stm32/LL
2323
CMSIS_Startupfile=$Core_path/cores/arduino/stm32/stm32_def_build.h
2424

2525
# Variables
26-
series=(`ls -d $HALDrivers_path/STM32*/ | sed -e "s#$HALDrivers_path/STM32##g" | sed -e "s#xx_HAL_Driver/##g"`)
26+
series=($(find $HALDrivers_path -maxdepth 1 -type d -name "STM32*" | sed -e "s#$HALDrivers_path/STM32##g" -e "s#xx_HAL_Driver##g"))
27+
2728
all_LL_file=stm32yyxx_ll.h
2829

2930
# Create the file
3031
print_C_header() {
3132
if [[ $1 = *"template"* ]]; then
32-
echo "#if 0" > $1
33+
echo "#if 0" > "$1"
3334
else
34-
touch $1
35+
touch "$1"
3536
fi
3637
}
3738

3839
# Add some pragma to ll header files to avoid several warnings
3940
# which will be corrected along Cube update
4041
print_LL_header() {
41-
upper=`echo $1 | awk '{print toupper($1)}' | sed -e "s/\./_/g"`
42+
upper=$(echo "$1" | awk '{print toupper($1)}' | sed -e "s/\./_/g")
4243
echo "#ifndef _${upper}_
4344
#define _${upper}_
4445
/* LL raised several warnings, ignore them */
4546
#pragma GCC diagnostic push
4647
#pragma GCC diagnostic ignored \"-Wunused-parameter\"
4748
#pragma GCC diagnostic ignored \"-Wstrict-aliasing\"
48-
" > $LLoutInc_path/$1
49+
" > $LLoutInc_path/"$1"
4950
}
5051

5152
print_CMSIS_Startup_header() {
@@ -68,17 +69,19 @@ echo "#else
6869
print_CMSIS_Startup_list() {
6970
# Handle first elements
7071
# File name
71-
local f=`echo ${list[0]} | awk -F/ '{print $NF}'`
72-
local upper=`echo $f | awk -F'[_.]' '{print toupper($2)}' | tr X x`
72+
local f
73+
local upper
74+
f=$(echo "${list[0]}" | awk -F/ '{print $NF}')
75+
upper=$(echo "$f" | awk -F'[_.]' '{print toupper($2)}' | tr X x)
7376
echo "#if defined($upper)
7477
#define CMSIS_STARTUP_FILE \"$f\"" >> $CMSIS_Startupfile
7578

7679
if [ ${#list[@]} -gt 1 ]; then
77-
for fp in ${list[@]:1}
80+
for fp in "${list[@]:1}"
7881
do
7982
# File name
80-
f=`echo $fp | awk -F/ '{print $NF}'`
81-
upper=`echo $f | awk -F'[_.]' '{print toupper($2)}' | tr X x`
83+
f=$(echo "$fp" | awk -F/ '{print $NF}')
84+
upper=$(echo "$f" | awk -F'[_.]' '{print toupper($2)}' | tr X x)
8285
echo "#elif defined($upper)
8386
#define CMSIS_STARTUP_FILE \"$f\"" >> $CMSIS_Startupfile
8487
done
@@ -88,7 +91,7 @@ fi
8891
# main
8992
# Check if this is the right place
9093
if [ ! -d $HALDrivers_path ]; then
91-
echo "Could not find $HAL_outSrcpath!"
94+
echo "Could not find $HALDrivers_path!"
9295
echo "Launch $0 from scripts folder!"
9396
exit 1
9497
fi
@@ -97,51 +100,55 @@ fi
97100
rm -f $HALoutSrc_path/* $LLoutSrc_path/* $LLoutInc_path/* $CMSIS_Startupfile
98101

99102
# Search all files for each series
100-
for serie in ${series[@]}
103+
for serie in "${series[@]}"
101104
do
102-
if [ -d $HALDrivers_path/STM32${serie}xx_HAL_Driver/Src ]; then
103-
lower=`echo $serie | awk '{print tolower($0)}'`
105+
if [ -d $HALDrivers_path/STM32"${serie}"xx_HAL_Driver/Src ]; then
106+
lower=$(echo "$serie" | awk '{print tolower($0)}')
104107
echo -n "Generating for $serie..."
105108

106109
# Generate stm32yyxx_[hal|ll]*.c file
107-
filelist=(`find $HALDrivers_path/STM32${serie}xx_HAL_Driver/Src -maxdepth 1 -name "stm32${lower}xx_*.c"`)
108-
for fp in ${filelist[@]}
110+
filelist=($(find $HALDrivers_path/STM32"${serie}"xx_HAL_Driver/Src -maxdepth 1 -name "stm32${lower}xx_*.c"))
111+
for fp in "${filelist[@]}"
109112
do
110113
outp=$HALoutSrc_path
111114
# File name
112-
f=`echo $fp | awk -F/ '{print $NF}'`
115+
f=$(echo "$fp" | awk -F/ '{print $NF}')
113116
# Compute generic file name
114-
g=`echo $f | sed -e "s/$lower/yy/g"`
117+
g="${f//$lower/yy}"
115118
if [[ $f = *"_ll_"* ]]; then
116119
outp=$LLoutSrc_path
117120
fi
118-
if [ ! -f $outp/$g ]; then
119-
print_C_header $outp/$g
121+
if [ ! -f $outp/"$g" ]; then
122+
print_C_header $outp/"$g"
120123
fi
121124
# Amend file name under serie switch
122-
echo "#ifdef STM32${serie}xx" >> $outp/$g
123-
echo "#include \"$f\"" >> $outp/$g
124-
echo "#endif" >> $outp/$g
125+
{
126+
echo "#ifdef STM32${serie}xx"
127+
echo "#include \"$f\""
128+
echo "#endif"
129+
} >> $outp/"$g"
125130
done
126131

127132
# Generate stm32yyxx_ll_*.h file
128-
filelist=(`find $HALDrivers_path/STM32${serie}xx_HAL_Driver/Inc -maxdepth 2 -name "stm32${lower}xx_ll_*.h"`)
129-
for fp in ${filelist[@]}
133+
filelist=($(find $HALDrivers_path/STM32"${serie}"xx_HAL_Driver/Inc -maxdepth 2 -name "stm32${lower}xx_ll_*.h"))
134+
for fp in "${filelist[@]}"
130135
do
131136
# File name
132-
f=`echo $fp | awk -F/ '{print $NF}'`
137+
f=$(echo "$fp" | awk -F/ '{print $NF}')
133138
# Compute generic file name
134-
g=`echo $f | sed -e "s/$lower/yy/g"`
139+
g="${f//$lower/yy}"
135140

136-
if [ ! -f $LLoutInc_path/$g ]; then
137-
print_LL_header $g
141+
if [ ! -f $LLoutInc_path/"$g" ]; then
142+
print_LL_header "$g"
138143
fi
139144
# Amend full LL header file
140145
echo "#include \"$g\"" >> $LLoutInc_path/${all_LL_file}.tmp
141146
# Amend file name under serie switch
142-
echo "#ifdef STM32${serie}xx" >> $LLoutInc_path/$g
143-
echo "#include \"$f\"" >> $LLoutInc_path/$g
144-
echo "#endif" >> $LLoutInc_path/$g
147+
{
148+
echo "#ifdef STM32${serie}xx"
149+
echo "#include \"$f\""
150+
echo "#endif"
151+
} >> $LLoutInc_path/"$g"
145152
done
146153
echo "done"
147154
fi
@@ -156,23 +163,23 @@ sort -u $LLoutInc_path/${all_LL_file}.tmp >> $LLoutInc_path/${all_LL_file}
156163
rm -f $LLoutInc_path/${all_LL_file}.tmp
157164

158165
# Search all template file to end "#if 0"
159-
filelist=(`find $HALoutSrc_path -maxdepth 1 -name "stm32*_template.c"`)
160-
for fp in ${filelist[@]}
166+
filelist=($(find $HALoutSrc_path -maxdepth 1 -name "stm32*_template.c"))
167+
for fp in "${filelist[@]}"
161168
do
162-
echo "#endif /* 0 */" >> $fp
169+
echo "#endif /* 0 */" >> "$fp"
163170
done
164171

165172
# Search all LL header files to end guard
166-
filelist=(`find $LLoutInc_path -maxdepth 1 -name "stm32yyxx_ll*.h"`)
167-
for fp in ${filelist[@]}
173+
filelist=($(find $LLoutInc_path -maxdepth 1 -name "stm32yyxx_ll*.h"))
174+
for fp in "${filelist[@]}"
168175
do
169-
upper=`basename $fp | awk '{print toupper($1)}' | sed -e "s/\./_/g"`
170-
echo "#pragma GCC diagnostic pop" >> $fp
171-
echo "#endif /* _${upper}_ */" >> $fp
176+
upper=$(basename "$fp" | awk '{print toupper($1)}' | sed -e "s/\./_/g")
177+
echo "#pragma GCC diagnostic pop" >> "$fp"
178+
echo "#endif /* _${upper}_ */" >> "$fp"
172179
done
173180

174181
# CMSIS startup files
175-
list=(`find $CMSIS_Device_ST_path -name "startup_*.s" | grep gcc | sort -u`)
182+
list=($(find $CMSIS_Device_ST_path -name "startup_*.s" | grep gcc | sort -du))
176183
if [ ${#list[@]} -ne 0 ]; then
177184
echo "Number of startup files: ${#list[@]}"
178185
print_CMSIS_Startup_header
@@ -189,16 +196,16 @@ if [ ! -d $CMSIS_DSPSrc_path ]; then
189196
echo "Skip CMSIS DSP generation."
190197
else
191198
# Remove old file
192-
rm -fr $CMSIS_DSP_outSrc_path/*/
199+
rm -fr "${CMSIS_DSP_outSrc_path:?}"/*/
193200

194-
filelist=(`find $CMSIS_DSPSrc_path -name "*.c" | sed -e "s#$CMSIS_DSPSrc_path/##g" | sort -u`)
195-
for fp in ${filelist[@]}
201+
filelist=($(find $CMSIS_DSPSrc_path -name "*.c" | sed -e "s#$CMSIS_DSPSrc_path/##g" | sort -u))
202+
for fp in "${filelist[@]}"
196203
do
197204
# Directory name
198-
d=`echo $fp | awk -F/ '{print $(NF-1)}'`
199-
if [ ! -d $CMSIS_DSP_outSrc_path/$d ]; then
200-
mkdir $CMSIS_DSP_outSrc_path/$d
201-
echo "#include \"../Source/$d/$d.c\"" > $CMSIS_DSP_outSrc_path/$d/$d.c
205+
d=$(echo "$fp" | awk -F/ '{print $(NF-1)}')
206+
if [ ! -d $CMSIS_DSP_outSrc_path/"$d" ]; then
207+
mkdir $CMSIS_DSP_outSrc_path/"$d"
208+
echo "#include \"../Source/$d/$d.c\"" > $CMSIS_DSP_outSrc_path/"$d"/"$d".c
202209
fi
203210
done
204211
fi

0 commit comments

Comments
 (0)