Skip to content

Commit 8f8f7de

Browse files
authored
feat(): Allow multiple targets selection
1 parent 0c297de commit 8f8f7de

File tree

1 file changed

+67
-28
lines changed

1 file changed

+67
-28
lines changed

build.sh

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ if [ -z $DEPLOY_OUT ]; then
2020
fi
2121

2222
function print_help() {
23-
echo "Usage: build.sh [-s] [-A <arduino_branch>] [-I <idf_branch>] [-i <idf_commit>] [-c <path>] [-t <target>] [-b <build|menuconfig|reconfigure|idf_libs|copy_bootloader|mem_variant>] [config ...]"
23+
echo "Usage: build.sh [-s] [-A <arduino_branch>] [-I <idf_branch>] [-i <idf_commit>] [-c <path>] [-t <target>] [-b <build|menuconfig|reconfigure|idf-libs|copy-bootloader|mem-variant>] [config ...]"
2424
echo " -s Skip installing/updating of ESP-IDF and all components"
2525
echo " -A Set which branch of arduino-esp32 to be used for compilation"
2626
echo " -I Set which branch of ESP-IDF to be used for compilation"
2727
echo " -i Set which commit of ESP-IDF to be used for compilation"
2828
echo " -e Archive the build to dist"
2929
echo " -d Deploy the build to github arduino-esp32"
30+
echo " -D Debug level to be set to ESP-IDF. One of default,none,error,warning,info,debug or verbose"
3031
echo " -c Set the arduino-esp32 folder to copy the result to. ex. '$HOME/Arduino/hardware/espressif/esp32'"
31-
echo " -t Set the build target(chip). ex. 'esp32s3'"
32+
echo " -t Set the build target(chip) ex. 'esp32s3' or select multiple targets(chips) by separating them with comma ex. 'esp32,esp32s3,esp32c3'"
3233
echo " -b Set the build type. ex. 'build' to build the project and prepare for uploading to a board"
3334
echo " ... Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash@80MHz. Requires -b"
3435
exit 1
@@ -59,16 +60,16 @@ while getopts ":A:I:i:c:t:b:sde" opt; do
5960
export IDF_COMMIT="$OPTARG"
6061
;;
6162
t )
62-
TARGET=$OPTARG
63+
IFS=',' read -ra TARGET <<< "$OPTARG"
6364
;;
6465
b )
6566
b=$OPTARG
66-
if [ "$b" != "build" ] &&
67-
[ "$b" != "menuconfig" ] &&
68-
[ "$b" != "reconfigure" ] &&
69-
[ "$b" != "idf_libs" ] &&
70-
[ "$b" != "copy_bootloader" ] &&
71-
[ "$b" != "mem_variant" ]; then
67+
if [ "$b" != "build" ] &&
68+
[ "$b" != "menuconfig" ] &&
69+
[ "$b" != "reconfigure" ] &&
70+
[ "$b" != "idf-libs" ] &&
71+
[ "$b" != "copy-bootloader" ] &&
72+
[ "$b" != "mem-variant" ]; then
7273
print_help
7374
fi
7475
BUILD_TYPE="$b"
@@ -86,6 +87,9 @@ done
8687
shift $((OPTIND -1))
8788
CONFIGS=$@
8889

90+
# Output the TARGET array
91+
echo "TARGET(s): ${TARGET[@]}"
92+
8993
mkdir -p dist
9094
rm -rf dependencies.lock
9195

@@ -113,27 +117,42 @@ if [ "$BUILD_TYPE" != "all" ]; then
113117
echo "ERROR: You need to specify target for non-default builds"
114118
print_help
115119
fi
116-
configs="configs/defconfig.common;configs/defconfig.$TARGET"
117120

118121
# Target Features Configs
119122
for target_json in `jq -c '.targets[]' configs/builds.json`; do
120123
target=$(echo "$target_json" | jq -c '.target' | tr -d '"')
121-
if [ "$TARGET" == "$target" ]; then
122-
for defconf in `echo "$target_json" | jq -c '.features[]' | tr -d '"'`; do
123-
configs="$configs;configs/defconfig.$defconf"
124-
done
124+
125+
# Check if $target is in the $TARGET array
126+
target_in_array=false
127+
for item in "${TARGET[@]}"; do
128+
if [ "$item" = "$target" ]; then
129+
target_in_array=true
130+
break
131+
fi
132+
done
133+
134+
if [ "$target_in_array" = false ]; then
135+
# Skip building for targets that are not in the $TARGET array
136+
continue
125137
fi
126-
done
138+
139+
configs="configs/defconfig.common;configs/defconfig.$target;configs/defconfig.debug_$BUILD_DEBUG"
140+
for defconf in `echo "$target_json" | jq -c '.features[]' | tr -d '"'`; do
141+
configs="$configs;configs/defconfig.$defconf"
142+
done
127143

128-
# Configs From Arguments
129-
for conf in $CONFIGS; do
130-
configs="$configs;configs/defconfig.$conf"
131-
done
144+
echo "* Building for $target"
132145

133-
echo "idf.py -DIDF_TARGET=\"$TARGET\" -DSDKCONFIG_DEFAULTS=\"$configs\" $BUILD_TYPE"
134-
rm -rf build sdkconfig
135-
idf.py -DIDF_TARGET="$TARGET" -DSDKCONFIG_DEFAULTS="$configs" $BUILD_TYPE
136-
if [ $? -ne 0 ]; then exit 1; fi
146+
# Configs From Arguments
147+
for conf in $CONFIGS; do
148+
configs="$configs;configs/defconfig.$conf"
149+
done
150+
151+
echo "idf.py -DIDF_TARGET=\"$target\" -DSDKCONFIG_DEFAULTS=\"$configs\" $BUILD_TYPE"
152+
rm -rf build sdkconfig
153+
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$configs" $BUILD_TYPE
154+
if [ $? -ne 0 ]; then exit 1; fi
155+
done
137156
exit 0
138157
fi
139158

@@ -152,16 +171,36 @@ echo "Framework built from
152171
#targets_count=`jq -c '.targets[] | length' configs/builds.json`
153172
for target_json in `jq -c '.targets[]' configs/builds.json`; do
154173
target=$(echo "$target_json" | jq -c '.target' | tr -d '"')
174+
target_skip=$(echo "$target_json" | jq -c '.skip // 0')
175+
176+
# Check if $target is in the $TARGET array if not "all"
177+
if [ "$TARGET" != "all" ]; then
178+
target_in_array=false
179+
for item in "${TARGET[@]}"; do
180+
if [ "$item" = "$target" ]; then
181+
target_in_array=true
182+
break
183+
fi
184+
done
155185

156-
if [ "$TARGET" != "all" ] && [ "$TARGET" != "$target" ]; then
186+
# If $target is not in the $TARGET array, skip processing
187+
if [ "$target_in_array" = false ]; then
188+
echo "* Skipping Target: $target"
189+
continue
190+
fi
191+
fi
192+
193+
# Skip chips that should not be a part of the final libs
194+
# WARNING!!! this logic needs to be updated when cron builds are split into jobs
195+
if [ "$TARGET" = "all" ] && [ $target_skip -eq 1 ]; then
157196
echo "* Skipping Target: $target"
158197
continue
159198
fi
160199

161200
echo "* Target: $target"
162201

163202
# Build Main Configs List
164-
main_configs="configs/defconfig.common;configs/defconfig.$target"
203+
main_configs="configs/defconfig.common;configs/defconfig.$target;configs/defconfig.debug_$BUILD_DEBUG"
165204
for defconf in `echo "$target_json" | jq -c '.features[]' | tr -d '"'`; do
166205
main_configs="$main_configs;configs/defconfig.$defconf"
167206
done
@@ -174,7 +213,7 @@ for target_json in `jq -c '.targets[]' configs/builds.json`; do
174213

175214
echo "* Build IDF-Libs: $idf_libs_configs"
176215
rm -rf build sdkconfig
177-
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" idf_libs
216+
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" idf-libs
178217
if [ $? -ne 0 ]; then exit 1; fi
179218

180219
# Build Bootloaders
@@ -186,7 +225,7 @@ for target_json in `jq -c '.targets[]' configs/builds.json`; do
186225

187226
echo "* Build BootLoader: $bootloader_configs"
188227
rm -rf build sdkconfig
189-
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$bootloader_configs" copy_bootloader
228+
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$bootloader_configs" copy-bootloader
190229
if [ $? -ne 0 ]; then exit 1; fi
191230
done
192231

@@ -199,7 +238,7 @@ for target_json in `jq -c '.targets[]' configs/builds.json`; do
199238

200239
echo "* Build Memory Variant: $mem_configs"
201240
rm -rf build sdkconfig
202-
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$mem_configs" mem_variant
241+
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$mem_configs" mem-variant
203242
if [ $? -ne 0 ]; then exit 1; fi
204243
done
205244
done

0 commit comments

Comments
 (0)