forked from espressif/esp32-arduino-lib-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·303 lines (267 loc) · 11.1 KB
/
build.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/bash
if ! [ -x "$(command -v python3)" ]; then
echo "ERROR: python is not installed! Please install python first."
exit 1
fi
if ! [ -x "$(command -v git)" ]; then
echo "ERROR: git is not installed! Please install git first."
exit 1
fi
TARGET="all"
BUILD_TYPE="all"
BUILD_DEBUG="default"
SKIP_ENV=0
COPY_OUT=0
ARCHIVE_OUT=0
if [ -z $DEPLOY_OUT ]; then
DEPLOY_OUT=0
fi
function print_help() {
echo "Usage: build.sh [-s] [-A <arduino_branch>] [-I <idf_branch>] [-D <debug_level>] [-i <idf_commit>] [-c <path>] [-t <target>] [-b <build|menuconfig|reconfigure|idf-libs|copy-bootloader|mem-variant>] [config ...]"
echo " -s Skip installing/updating of ESP-IDF and all components"
echo " -A Set which branch of arduino-esp32 to be used for compilation"
echo " -I Set which branch of ESP-IDF to be used for compilation"
echo " -i Set which commit of ESP-IDF to be used for compilation"
echo " -e Archive the build to dist"
echo " -d Deploy the build to github arduino-esp32"
echo " -D Debug level to be set to ESP-IDF. One of default,none,error,warning,info,debug or verbose"
echo " -c Set the arduino-esp32 folder to copy the result to. ex. '$HOME/Arduino/hardware/espressif/esp32'"
echo " -t Set the build target(chip). ex. 'esp32s3'"
echo " -b Set the build type. ex. 'build' to build the project and prepare for uploading to a board"
echo " ... Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash@80MHz. Requires -b"
exit 1
}
while getopts ":A:I:i:c:t:b:D:sde" opt; do
case ${opt} in
s )
SKIP_ENV=1
;;
d )
DEPLOY_OUT=1
;;
e )
ARCHIVE_OUT=1
;;
c )
export ESP32_ARDUINO="$OPTARG"
COPY_OUT=1
;;
A )
export AR_BRANCH="$OPTARG"
;;
I )
export IDF_BRANCH="$OPTARG"
;;
i )
export IDF_COMMIT="$OPTARG"
;;
D )
BUILD_DEBUG="$OPTARG"
;;
t )
TARGET=$OPTARG
;;
b )
b=$OPTARG
if [ "$b" != "build" ] &&
[ "$b" != "menuconfig" ] &&
[ "$b" != "reconfigure" ] &&
[ "$b" != "idf-libs" ] &&
[ "$b" != "copy-bootloader" ] &&
[ "$b" != "mem-variant" ]; then
print_help
fi
BUILD_TYPE="$b"
;;
\? )
echo "Invalid option: -$OPTARG" 1>&2
print_help
;;
: )
echo "Invalid option: -$OPTARG requires an argument" 1>&2
print_help
;;
esac
done
shift $((OPTIND -1))
CONFIGS=$@
mkdir -p dist
if [ $SKIP_ENV -eq 0 ]; then
echo "* Installing/Updating ESP-IDF and all components..."
# update components from git
./tools/update-components.sh
if [ $? -ne 0 ]; then exit 1; fi
# install arduino component
./tools/install-arduino.sh
if [ $? -ne 0 ]; then exit 1; fi
# install esp-idf
source ./tools/install-esp-idf.sh
if [ $? -ne 0 ]; then exit 1; fi
else
# $IDF_PATH/install.sh
# source $IDF_PATH/export.sh
source ./tools/config.sh
fi
if [ -f "$AR_MANAGED_COMPS/espressif__esp-sr/.component_hash" ]; then
rm -rf $AR_MANAGED_COMPS/espressif__esp-sr/.component_hash
fi
if [ "$BUILD_TYPE" != "all" ]; then
if [ "$TARGET" = "all" ]; then
echo "ERROR: You need to specify target for non-default builds"
print_help
fi
configs="configs/defconfig.common;configs/defconfig.$TARGET;configs/defconfig.debug_$BUILD_DEBUG"
# Target Features Configs
for target_json in `jq -c '.targets[]' configs/builds.json`; do
target=$(echo "$target_json" | jq -c '.target' | tr -d '"')
if [ "$TARGET" == "$target" ]; then
for defconf in `echo "$target_json" | jq -c '.features[]' | tr -d '"'`; do
configs="$configs;configs/defconfig.$defconf"
done
fi
done
# Configs From Arguments
for conf in $CONFIGS; do
configs="$configs;configs/defconfig.$conf"
done
echo "idf.py -DIDF_TARGET=\"$TARGET\" -DSDKCONFIG_DEFAULTS=\"$configs\" $BUILD_TYPE"
rm -rf build sdkconfig
idf.py -DIDF_TARGET="$TARGET" -DSDKCONFIG_DEFAULTS="$configs" $BUILD_TYPE
if [ $? -ne 0 ]; then exit 1; fi
exit 0
fi
rm -rf build sdkconfig out
mkdir -p "$AR_TOOLS/esp32-arduino-libs"
#targets_count=`jq -c '.targets[] | length' configs/builds.json`
for target_json in `jq -c '.targets[]' configs/builds.json`; do
target=$(echo "$target_json" | jq -c '.target' | tr -d '"')
target_skip=$(echo "$target_json" | jq -c '.skip // 0')
if [ "$TARGET" != "all" ] && [ "$TARGET" != "$target" ]; then
echo "* Skipping Target: $target"
continue
fi
# Skip chips that should not be a part of the final libs
# WARNING!!! this logic needs to be updated when cron builds are split into jobs
if [ "$TARGET" = "all" ] && [ $target_skip -eq 1 ]; then
echo "* Skipping Target: $target"
continue
fi
echo "* Target: $target"
# Build Main Configs List
main_configs="configs/defconfig.common;configs/defconfig.$target;configs/defconfig.debug_$BUILD_DEBUG"
for defconf in `echo "$target_json" | jq -c '.features[]' | tr -d '"'`; do
main_configs="$main_configs;configs/defconfig.$defconf"
done
# Build IDF Libs
idf_libs_configs="$main_configs"
for defconf in `echo "$target_json" | jq -c '.idf_libs[]' | tr -d '"'`; do
idf_libs_configs="$idf_libs_configs;configs/defconfig.$defconf"
done
if [ -f "$AR_MANAGED_COMPS/espressif__esp-sr/.component_hash" ]; then
rm -rf $AR_MANAGED_COMPS/espressif__esp-sr/.component_hash
fi
echo "* Build IDF-Libs: $idf_libs_configs"
rm -rf build sdkconfig
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" idf-libs
if [ $? -ne 0 ]; then exit 1; fi
if [ "$target" == "esp32s3" ]; then
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" srmodels_bin
if [ $? -ne 0 ]; then exit 1; fi
AR_SDK="$AR_TOOLS/esp32-arduino-libs/$target"
# sr model.bin
if [ -f "build/srmodels/srmodels.bin" ]; then
echo "$AR_SDK/esp_sr"
mkdir -p "$AR_SDK/esp_sr"
cp -f "build/srmodels/srmodels.bin" "$AR_SDK/esp_sr/"
cp -f "partitions.csv" "$AR_SDK/esp_sr/"
fi
fi
# Build Bootloaders
for boot_conf in `echo "$target_json" | jq -c '.bootloaders[]'`; do
bootloader_configs="$main_configs"
for defconf in `echo "$boot_conf" | jq -c '.[]' | tr -d '"'`; do
bootloader_configs="$bootloader_configs;configs/defconfig.$defconf";
done
if [ -f "$AR_MANAGED_COMPS/espressif__esp-sr/.component_hash" ]; then
rm -rf $AR_MANAGED_COMPS/espressif__esp-sr/.component_hash
fi
echo "* Build BootLoader: $bootloader_configs"
rm -rf build sdkconfig
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$bootloader_configs" copy-bootloader
if [ $? -ne 0 ]; then exit 1; fi
done
# Build Memory Variants
for mem_conf in `echo "$target_json" | jq -c '.mem_variants[]'`; do
mem_configs="$main_configs"
for defconf in `echo "$mem_conf" | jq -c '.[]' | tr -d '"'`; do
mem_configs="$mem_configs;configs/defconfig.$defconf";
done
if [ -f "$AR_MANAGED_COMPS/espressif__esp-sr/.component_hash" ]; then
rm -rf $AR_MANAGED_COMPS/espressif__esp-sr/.component_hash
fi
echo "* Build Memory Variant: $mem_configs"
rm -rf build sdkconfig
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$mem_configs" mem-variant
if [ $? -ne 0 ]; then exit 1; fi
done
done
#
# Add components version info
#
rm -rf "$AR_TOOLS/esp32-arduino-libs/versions.txt"
# The lib-builder version
component_version="lib-builder: "$(git -C "$AR_ROOT" symbolic-ref --short HEAD || git -C "$AR_ROOT" tag --points-at HEAD)" "$(git -C "$AR_ROOT" rev-parse --short HEAD)
echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt"
# ESP-IDF version
component_version="esp-idf: "$(git -C "$IDF_PATH" symbolic-ref --short HEAD || git -C "$IDF_PATH" tag --points-at HEAD)" "$(git -C "$IDF_PATH" rev-parse --short HEAD)
echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt"
# components version
for component in `ls "$AR_COMPS"`; do
if [ -d "$AR_COMPS/$component/.git" ]; then
component_version="$component: "$(git -C "$AR_COMPS/$component" symbolic-ref --short HEAD || git -C "$AR_COMPS/$component" tag --points-at HEAD)" "$(git -C "$AR_COMPS/$component" rev-parse --short HEAD)
echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt"
fi
done
# TinyUSB version
component_version="tinyusb: "$(git -C "$AR_COMPS/arduino_tinyusb/tinyusb" symbolic-ref --short HEAD || git -C "$AR_COMPS/arduino_tinyusb/tinyusb" tag --points-at HEAD)" "$(git -C "$AR_COMPS/arduino_tinyusb/tinyusb" rev-parse --short HEAD)
echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt"
# managed components version
for component in `ls "$AR_MANAGED_COMPS"`; do
if [ -d "$AR_MANAGED_COMPS/$component/.git" ]; then
component_version="$component: "$(git -C "$AR_MANAGED_COMPS/$component" symbolic-ref --short HEAD || git -C "$AR_MANAGED_COMPS/$component" tag --points-at HEAD)" "$(git -C "$AR_MANAGED_COMPS/$component" rev-parse --short HEAD)
echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt"
elif [ -f "$AR_MANAGED_COMPS/$component/idf_component.yml" ]; then
component_version="$component: "$(cat "$AR_MANAGED_COMPS/$component/idf_component.yml" | grep "^version: " | cut -d ' ' -f 2)
echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt"
fi
done
# update package_esp32_index.template.json
if [ "$BUILD_TYPE" = "all" ]; then
python3 ./tools/gen_tools_json.py -i "$IDF_PATH" -j "$AR_COMPS/arduino/package/package_esp32_index.template.json" -o "$AR_OUT/"
python3 ./tools/gen_tools_json.py -i "$IDF_PATH" -o "$TOOLS_JSON_OUT/"
if [ $? -ne 0 ]; then exit 1; fi
fi
# Generate PlatformIO manifest file
if [ "$BUILD_TYPE" = "all" ]; then
pushd $IDF_PATH
ibr=$(git describe --all --exact-match 2>/dev/null)
ic=$(git -C "$IDF_PATH" rev-parse --short HEAD)
popd
python3 ./tools/gen_platformio_manifest.py -o "$TOOLS_JSON_OUT/" -s "$ibr" -c "$ic"
if [ $? -ne 0 ]; then exit 1; fi
fi
# copy everything to arduino-esp32 installation
if [ $COPY_OUT -eq 1 ] && [ -d "$ESP32_ARDUINO" ]; then
./tools/copy-to-arduino.sh
if [ $? -ne 0 ]; then exit 1; fi
fi
# push changes to esp32-arduino-libs and create pull request into arduino-esp32
if [ $DEPLOY_OUT -eq 1 ]; then
./tools/push-to-arduino.sh
if [ $? -ne 0 ]; then exit 1; fi
fi
# archive the build
if [ $ARCHIVE_OUT -eq 1 ]; then
./tools/archive-build.sh "$TARGET"
if [ $? -ne 0 ]; then exit 1; fi
fi