Skip to content

Commit e0f7781

Browse files
committed
Use shfmt to format the gen_wrapper.sh script
Using shfmt https://github.com/mvdan/sh Signed-off-by: Frederic Pillon <[email protected]>
1 parent 676f1a2 commit e0f7781

File tree

1 file changed

+44
-51
lines changed

1 file changed

+44
-51
lines changed

CI/utils/gen_wrapper.sh

+44-51
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash -
2-
set -o nounset # Treat unset variables as an error
2+
set -o nounset # Treat unset variables as an error
33

44
# Base path
55
Core_path=../..
@@ -23,24 +23,24 @@ 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=($(find $HALDrivers_path -maxdepth 1 -type d -name "STM32*" | sed -e "s#$HALDrivers_path/STM32##g" -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" | sort))
2727

2828
all_LL_file=stm32yyxx_ll.h
2929

3030
# Create the file
3131
print_C_header() {
32-
if [[ $1 = *"template"* ]]; then
33-
echo "#if 0" > "$1"
34-
else
35-
touch "$1"
36-
fi
32+
if [[ $1 = *"template"* ]]; then
33+
echo "#if 0" > "$1"
34+
else
35+
touch "$1"
36+
fi
3737
}
3838

3939
# Add some pragma to ll header files to avoid several warnings
4040
# which will be corrected along Cube update
4141
print_LL_header() {
42-
upper=$(echo "$1" | awk '{print toupper($1)}' | sed -e "s/\./_/g")
43-
echo "#ifndef _${upper}_
42+
upper=$(echo "$1" | awk '{print toupper($1)}' | sed -e "s/\./_/g")
43+
echo "#ifndef _${upper}_
4444
#define _${upper}_
4545
/* LL raised several warnings, ignore them */
4646
#pragma GCC diagnostic push
@@ -50,14 +50,14 @@ echo "#ifndef _${upper}_
5050
}
5151

5252
print_CMSIS_Startup_header() {
53-
echo "#ifndef _STM32_DEF_BUILD_
53+
echo "#ifndef _STM32_DEF_BUILD_
5454
#define _STM32_DEF_BUILD_
5555
5656
#if !defined(CMSIS_STARTUP_FILE) && !defined(CUSTOM_STARTUP_FILE)" > $CMSIS_Startupfile
5757
}
5858

5959
print_CMSIS_Startup_footer() {
60-
echo "#else
60+
echo "#else
6161
#error UNKNOWN CHIP
6262
#endif
6363
#else
@@ -67,25 +67,24 @@ echo "#else
6767
}
6868

6969
print_CMSIS_Startup_list() {
70-
# Handle first elements
71-
# File name
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)
76-
echo "#if defined($upper)
70+
# Handle first elements
71+
# File name
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)
76+
echo "#if defined($upper)
7777
#define CMSIS_STARTUP_FILE \"$f\"" >> $CMSIS_Startupfile
7878

79-
if [ ${#list[@]} -gt 1 ]; then
80-
for fp in "${list[@]:1}"
81-
do
82-
# File name
83-
f=$(echo "$fp" | awk -F/ '{print $NF}')
84-
upper=$(echo "$f" | awk -F'[_.]' '{print toupper($2)}' | tr X x)
85-
echo "#elif defined($upper)
79+
if [ ${#list[@]} -gt 1 ]; then
80+
for fp in "${list[@]:1}"; do
81+
# File name
82+
f=$(echo "$fp" | awk -F/ '{print $NF}')
83+
upper=$(echo "$f" | awk -F'[_.]' '{print toupper($2)}' | tr X x)
84+
echo "#elif defined($upper)
8685
#define CMSIS_STARTUP_FILE \"$f\"" >> $CMSIS_Startupfile
87-
done
88-
fi
86+
done
87+
fi
8988
}
9089

9190
# main
@@ -100,22 +99,20 @@ fi
10099
rm -f $HALoutSrc_path/* $LLoutSrc_path/* $LLoutInc_path/* $CMSIS_Startupfile
101100

102101
# Search all files for each series
103-
for serie in "${series[@]}"
104-
do
102+
for serie in "${series[@]}"; do
105103
if [ -d $HALDrivers_path/STM32"${serie}"xx_HAL_Driver/Src ]; then
106104
lower=$(echo "$serie" | awk '{print tolower($0)}')
107105
echo -n "Generating for $serie..."
108106

109107
# Generate stm32yyxx_[hal|ll]*.c file
110108
filelist=($(find $HALDrivers_path/STM32"${serie}"xx_HAL_Driver/Src -maxdepth 1 -name "stm32${lower}xx_*.c"))
111-
for fp in "${filelist[@]}"
112-
do
109+
for fp in "${filelist[@]}"; do
113110
outp=$HALoutSrc_path
114111
# File name
115112
f=$(echo "$fp" | awk -F/ '{print $NF}')
116113
# Compute generic file name
117114
g="${f//$lower/yy}"
118-
if [[ $f = *"_ll_"* ]]; then
115+
if [[ $f = *"_ll_"* ]]; then
119116
outp=$LLoutSrc_path
120117
fi
121118
if [ ! -f $outp/"$g" ]; then
@@ -126,13 +123,12 @@ do
126123
echo "#ifdef STM32${serie}xx"
127124
echo "#include \"$f\""
128125
echo "#endif"
129-
} >> $outp/"$g"
126+
} >> $outp/"$g"
130127
done
131128

132129
# Generate stm32yyxx_ll_*.h file
133130
filelist=($(find $HALDrivers_path/STM32"${serie}"xx_HAL_Driver/Inc -maxdepth 2 -name "stm32${lower}xx_ll_*.h"))
134-
for fp in "${filelist[@]}"
135-
do
131+
for fp in "${filelist[@]}"; do
136132
# File name
137133
f=$(echo "$fp" | awk -F/ '{print $NF}')
138134
# Compute generic file name
@@ -145,10 +141,10 @@ do
145141
echo "#include \"$g\"" >> $LLoutInc_path/${all_LL_file}.tmp
146142
# Amend file name under serie switch
147143
{
148-
echo "#ifdef STM32${serie}xx"
149-
echo "#include \"$f\""
150-
echo "#endif"
151-
} >> $LLoutInc_path/"$g"
144+
echo "#ifdef STM32${serie}xx"
145+
echo "#include \"$f\""
146+
echo "#endif"
147+
} >> $LLoutInc_path/"$g"
152148
done
153149
echo "done"
154150
fi
@@ -164,15 +160,13 @@ rm -f $LLoutInc_path/${all_LL_file}.tmp
164160

165161
# Search all template file to end "#if 0"
166162
filelist=($(find $HALoutSrc_path -maxdepth 1 -name "stm32*_template.c"))
167-
for fp in "${filelist[@]}"
168-
do
169-
echo "#endif /* 0 */" >> "$fp"
163+
for fp in "${filelist[@]}"; do
164+
echo "#endif /* 0 */" >> "$fp"
170165
done
171166

172167
# Search all LL header files to end guard
173168
filelist=($(find $LLoutInc_path -maxdepth 1 -name "stm32yyxx_ll*.h"))
174-
for fp in "${filelist[@]}"
175-
do
169+
for fp in "${filelist[@]}"; do
176170
upper=$(basename "$fp" | awk '{print toupper($1)}' | sed -e "s/\./_/g")
177171
echo "#pragma GCC diagnostic pop" >> "$fp"
178172
echo "#endif /* _${upper}_ */" >> "$fp"
@@ -181,12 +175,12 @@ done
181175
# CMSIS startup files
182176
list=($(find $CMSIS_Device_ST_path -name "startup_*.s" | grep gcc | sort -du))
183177
if [ ${#list[@]} -ne 0 ]; then
184-
echo "Number of startup files: ${#list[@]}"
185-
print_CMSIS_Startup_header
186-
print_CMSIS_Startup_list
187-
print_CMSIS_Startup_footer
178+
echo "Number of startup files: ${#list[@]}"
179+
print_CMSIS_Startup_header
180+
print_CMSIS_Startup_list
181+
print_CMSIS_Startup_footer
188182
else
189-
echo "No startup files found!"
183+
echo "No startup files found!"
190184
fi
191185

192186
# CMSIS DSP C source files
@@ -199,8 +193,7 @@ else
199193
rm -fr "${CMSIS_DSP_outSrc_path:?}"/*/
200194

201195
filelist=($(find $CMSIS_DSPSrc_path -name "*.c" | sed -e "s#$CMSIS_DSPSrc_path/##g" | sort -u))
202-
for fp in "${filelist[@]}"
203-
do
196+
for fp in "${filelist[@]}"; do
204197
# Directory name
205198
d=$(echo "$fp" | awk -F/ '{print $(NF-1)}')
206199
if [ ! -d $CMSIS_DSP_outSrc_path/"$d" ]; then

0 commit comments

Comments
 (0)