Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7a6dae0

Browse files
authoredJan 31, 2022
Refactor the CI scripts (espressif#6191)
The reason behind this refactoring is that all of the sketch related functions can (and will) be used for other purposes. Build in the sketch directory: This will make it easy to handle artifacts after the build. Separate sketch related functions from IDE installation script. This is the main commit. Create a separate job for the Cmake check. This check was part of one of the Linux build. I believe that it's not the best place for such a check. Checking for the skip landmarks and validity of the the sketch directory were already done by count_sketches.
1 parent 9f08cf4 commit 7a6dae0

File tree

4 files changed

+245
-202
lines changed

4 files changed

+245
-202
lines changed
 

‎.github/scripts/install-arduino-ide.sh

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ else
3434
fi
3535
export OS_NAME
3636

37-
ARDUINO_BUILD_DIR="$HOME/.arduino/build.tmp"
38-
ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
39-
4037
if [ "$OS_IS_MACOS" == "1" ]; then
4138
export ARDUINO_IDE_PATH="/Applications/Arduino.app/Contents/Java"
4239
export ARDUINO_USR_PATH="$HOME/Documents/Arduino"
@@ -81,156 +78,3 @@ if [ ! -d "$ARDUINO_IDE_PATH" ]; then
8178
echo ""
8279
fi
8380

84-
function build_sketch(){ # build_sketch <fqbn> <path-to-ino> [extra-options]
85-
if [ "$#" -lt 2 ]; then
86-
echo "ERROR: Illegal number of parameters"
87-
echo "USAGE: build_sketch <fqbn> <path-to-ino> [extra-options]"
88-
return 1
89-
fi
90-
91-
local fqbn="$1"
92-
local sketch="$2"
93-
local xtra_opts="$3"
94-
local win_opts=""
95-
if [ "$OS_IS_WINDOWS" == "1" ]; then
96-
local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"`
97-
local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"`
98-
win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version -prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version"
99-
fi
100-
101-
#echo ""
102-
#echo "Compiling '"$(basename "$sketch")"' ..."
103-
mkdir -p "$ARDUINO_BUILD_DIR"
104-
mkdir -p "$ARDUINO_CACHE_DIR"
105-
$ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=10810 \
106-
-fqbn=$fqbn \
107-
-warnings="all" \
108-
-tools "$ARDUINO_IDE_PATH/tools-builder" \
109-
-tools "$ARDUINO_IDE_PATH/tools" \
110-
-built-in-libraries "$ARDUINO_IDE_PATH/libraries" \
111-
-hardware "$ARDUINO_IDE_PATH/hardware" \
112-
-hardware "$ARDUINO_USR_PATH/hardware" \
113-
-libraries "$ARDUINO_USR_PATH/libraries" \
114-
-build-cache "$ARDUINO_CACHE_DIR" \
115-
-build-path "$ARDUINO_BUILD_DIR" \
116-
$win_opts $xtra_opts "$sketch"
117-
}
118-
119-
function count_sketches(){ # count_sketches <examples-path> <target-mcu>
120-
local examples="$1"
121-
local target="$2"
122-
rm -rf sketches.txt
123-
if [ ! -d "$examples" ]; then
124-
touch sketches.txt
125-
return 0
126-
fi
127-
local sketches=$(find $examples -name *.ino)
128-
local sketchnum=0
129-
for sketch in $sketches; do
130-
local sketchdir=$(dirname $sketch)
131-
local sketchdirname=$(basename $sketchdir)
132-
local sketchname=$(basename $sketch)
133-
if [[ "$sketchdirname.ino" != "$sketchname" ]]; then
134-
continue
135-
elif [[ -f "$sketchdir/.skip.$target" ]]; then
136-
continue
137-
else
138-
echo $sketch >> sketches.txt
139-
sketchnum=$(($sketchnum + 1))
140-
fi
141-
done
142-
return $sketchnum
143-
}
144-
145-
function build_sketches(){ # build_sketches <fqbn> <target-mcu> <examples-path> <chunk> <total-chunks> [extra-options]
146-
local fqbn=$1
147-
local target="$2"
148-
local examples=$3
149-
local chunk_idex=$4
150-
local chunks_num=$5
151-
local xtra_opts=$6
152-
153-
if [ "$#" -lt 3 ]; then
154-
echo "ERROR: Illegal number of parameters"
155-
echo "USAGE: build_sketches <fqbn> <target-mcu <examples-path> [<chunk> <total-chunks>] [extra-options]"
156-
return 1
157-
fi
158-
159-
if [ "$#" -lt 5 ]; then
160-
chunk_idex="0"
161-
chunks_num="1"
162-
xtra_opts=$4
163-
fi
164-
165-
if [ "$chunks_num" -le 0 ]; then
166-
echo "ERROR: Chunks count must be positive number"
167-
return 1
168-
fi
169-
if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then
170-
echo "ERROR: Chunk index must be less than chunks count"
171-
return 1
172-
fi
173-
174-
set +e
175-
count_sketches "$examples" "$target"
176-
local sketchcount=$?
177-
set -e
178-
local sketches=$(cat sketches.txt)
179-
rm -rf sketches.txt
180-
181-
local chunk_size=$(( $sketchcount / $chunks_num ))
182-
local all_chunks=$(( $chunks_num * $chunk_size ))
183-
if [ "$all_chunks" -lt "$sketchcount" ]; then
184-
chunk_size=$(( $chunk_size + 1 ))
185-
fi
186-
187-
local start_index=0
188-
local end_index=0
189-
if [ "$chunk_idex" -ge "$chunks_num" ]; then
190-
start_index=$chunk_idex
191-
end_index=$sketchcount
192-
else
193-
start_index=$(( $chunk_idex * $chunk_size ))
194-
if [ "$sketchcount" -le "$start_index" ]; then
195-
echo "Skipping job"
196-
return 0
197-
fi
198-
199-
end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
200-
if [ "$end_index" -gt "$sketchcount" ]; then
201-
end_index=$sketchcount
202-
fi
203-
fi
204-
205-
local start_num=$(( $start_index + 1 ))
206-
echo "Found $sketchcount Sketches for target '$target'";
207-
echo "Chunk Index : $chunk_idex"
208-
echo "Chunk Count : $chunks_num"
209-
echo "Chunk Size : $chunk_size"
210-
echo "Start Sketch: $start_num"
211-
echo "End Sketch : $end_index"
212-
213-
local sketchnum=0
214-
for sketch in $sketches; do
215-
local sketchdir=$(dirname $sketch)
216-
local sketchdirname=$(basename $sketchdir)
217-
local sketchname=$(basename $sketch)
218-
if [ "${sketchdirname}.ino" != "$sketchname" ] \
219-
|| [ -f "$sketchdir/.skip.$target" ]; then
220-
continue
221-
fi
222-
sketchnum=$(($sketchnum + 1))
223-
if [ "$sketchnum" -le "$start_index" ] \
224-
|| [ "$sketchnum" -gt "$end_index" ]; then
225-
continue
226-
fi
227-
echo ""
228-
echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname"
229-
build_sketch "$fqbn" "$sketch" "$xtra_opts"
230-
local result=$?
231-
if [ $result -ne 0 ]; then
232-
return $result
233-
fi
234-
done
235-
return 0
236-
}

‎.github/scripts/on-push.sh

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,40 @@
22

33
set -e
44

5+
function build(){
6+
local target=$1
7+
local fqbn=$2
8+
local chunk_index=$3
9+
local chunks_cnt=$4
10+
local sketches=$5
11+
12+
local BUILD_SKETCH="${SCRIPTS_DIR}/sketch_utils.sh build"
13+
local BUILD_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh chunk_build"
14+
15+
local args="$ARDUINO_IDE_PATH $ARDUINO_USR_PATH"
16+
17+
args+=" \"$fqbn\""
18+
19+
if [ "$OS_IS_LINUX" == "1" ]; then
20+
args+=" $target"
21+
args+=" $ARDUINO_ESP32_PATH/libraries"
22+
args+=" $chunk_index $chunks_cnt"
23+
${BUILD_SKETCHES} ${args}
24+
else
25+
if [ "$OS_IS_WINDOWS" == "1" ]; then
26+
local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"`
27+
local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"`
28+
win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version
29+
-prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version"
30+
args+=" ${win_opts}"
31+
fi
32+
33+
for sketch in ${sketches}; do
34+
${BUILD_SKETCH} ${args} ${sketch}
35+
done
36+
fi
37+
}
38+
539
if [ -z "$GITHUB_WORKSPACE" ]; then
640
export GITHUB_WORKSPACE="$PWD"
741
export GITHUB_REPOSITORY="espressif/arduino-esp32"
@@ -22,57 +56,31 @@ fi
2256
#echo "Updating submodules ..."
2357
#git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1
2458

59+
SCRIPTS_DIR="./.github/scripts"
2560
if [ "$BUILD_PIO" -eq 0 ]; then
26-
# ArduinoIDE ESP32 Test
27-
TARGET="esp32"
28-
FQBN="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app"
2961
source ./.github/scripts/install-arduino-ide.sh
30-
source ./.github/scripts/install-arduino-core-esp32.sh
31-
if [ "$OS_IS_WINDOWS" == "1" ]; then
32-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
33-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
34-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
35-
elif [ "$OS_IS_MACOS" == "1" ]; then
36-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \
37-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
38-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \
39-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
40-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
41-
else
42-
# CMake Test
43-
if [ "$CHUNK_INDEX" -eq 0 ]; then
44-
bash "$ARDUINO_ESP32_PATH/.github/scripts/check-cmakelists.sh"
45-
fi
46-
build_sketches "$FQBN" "$TARGET" "$ARDUINO_ESP32_PATH/libraries" "$CHUNK_INDEX" "$CHUNKS_CNT"
47-
fi
62+
source ${SCRIPTS_DIR}/install-arduino-core-esp32.sh
4863

49-
# ArduinoIDE ESP32S2 Test
50-
TARGET="esp32s2"
51-
FQBN="espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app"
52-
if [ "$OS_IS_WINDOWS" == "1" ]; then
53-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \
54-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino"
55-
elif [ "$OS_IS_MACOS" == "1" ]; then
56-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \
57-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino"
58-
else
59-
build_sketches "$FQBN" "$TARGET" "$ARDUINO_ESP32_PATH/libraries" "$CHUNK_INDEX" "$CHUNKS_CNT"
60-
fi
64+
FQBN_ESP32="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app"
65+
FQBN_ESP32S2="espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app"
66+
FQBN_ESP32C3="espressif:esp32:esp32c3:PartitionScheme=huge_app"
6167

62-
# ArduinoIDE ESP32C3 Test
63-
TARGET="esp32c3"
64-
FQBN="espressif:esp32:esp32c3:PartitionScheme=huge_app"
65-
if [ "$OS_IS_WINDOWS" == "1" ]; then
66-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \
67-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino"
68-
elif [ "$OS_IS_MACOS" == "1" ]; then
69-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \
70-
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino"
71-
else
72-
build_sketches "$FQBN" "$TARGET" "$ARDUINO_ESP32_PATH/libraries" "$CHUNK_INDEX" "$CHUNKS_CNT"
73-
fi
68+
SKETCHES_ESP32="\
69+
$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino\
70+
$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino\
71+
$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino\
72+
"
73+
74+
SKETCHES_ESP32XX="\
75+
$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino\
76+
$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino\
77+
"
78+
79+
build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
80+
build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX
81+
build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX
7482
else
75-
source ./.github/scripts/install-platformio-esp32.sh
83+
source ./${SCRIPTS_DIR}/install-platformio-esp32.sh
7684
# PlatformIO ESP32 Test
7785
BOARD="esp32dev"
7886
OPTIONS="board_build.partitions = huge_app.csv"

‎.github/scripts/sketch_utils.sh

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#!/bin/bash
2+
3+
function build_sketch(){ # build_sketch <ide_path> <user_path> <fqbn> <path-to-ino> [extra-options]
4+
if [ "$#" -lt 4 ]; then
5+
echo "ERROR: Illegal number of parameters"
6+
echo "USAGE: ${0} build <ide_path> <user_path> <fqbn> <path-to-ino> [extra-options]"
7+
return 1
8+
fi
9+
10+
ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
11+
local ide_path=$1
12+
local usr_path=$2
13+
local fqbn=$3
14+
local sketch=$4
15+
local xtra_opts=$5
16+
local win_opts=$6
17+
18+
build_dir="$(dirname $sketch)/build"
19+
mkdir -p "$build_dir"
20+
mkdir -p "$ARDUINO_CACHE_DIR"
21+
$ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \
22+
-fqbn=$fqbn \
23+
-warnings="all" \
24+
-tools "$ide_path/tools-builder" \
25+
-tools "$ide_path/tools" \
26+
-built-in-libraries "$ide_path/libraries" \
27+
-hardware "$ide_path/hardware" \
28+
-hardware "$usr_path/hardware" \
29+
-libraries "$usr_path/libraries" \
30+
-build-cache "$ARDUINO_CACHE_DIR" \
31+
-build-path "$build_dir" \
32+
$win_opts $xtra_opts "$sketch"
33+
}
34+
35+
function count_sketches(){ # count_sketches <path> <target>
36+
local path=$1
37+
local target=$2
38+
39+
if [ $# -lt 2 ]; then
40+
echo "ERROR: Illegal number of parameters"
41+
echo "USAGE: ${0} count <path> <target>"
42+
fi
43+
44+
rm -rf sketches.txt
45+
if [ ! -d "$path" ]; then
46+
touch sketches.txt
47+
return 0
48+
fi
49+
50+
local sketches=$(find $path -name *.ino)
51+
local sketchnum=0
52+
for sketch in $sketches; do
53+
local sketchdir=$(dirname $sketch)
54+
local sketchdirname=$(basename $sketchdir)
55+
local sketchname=$(basename $sketch)
56+
if [[ "$sketchdirname.ino" != "$sketchname" ]]; then
57+
continue
58+
elif [[ -f "$sketchdir/.skip.$target" ]]; then
59+
continue
60+
else
61+
echo $sketch >> sketches.txt
62+
sketchnum=$(($sketchnum + 1))
63+
fi
64+
done
65+
return $sketchnum
66+
}
67+
68+
function build_sketches(){ # build_sketches <ide_path> <user_path> <fqbn> <target> <path> <chunk> <total-chunks> [extra-options]
69+
local ide_path=$1
70+
local usr_path=$2
71+
local fqbn=$3
72+
local target=$4
73+
local path=$5
74+
local chunk_idex=$6
75+
local chunks_num=$7
76+
local xtra_opts=$8
77+
78+
if [ "$#" -lt 7 ]; then
79+
echo "ERROR: Illegal number of parameters"
80+
echo "USAGE: ${0} chunk_build <ide_path> <user_path> <fqbn> <target> <path> [<chunk> <total-chunks>] [extra-options]"
81+
return 1
82+
fi
83+
84+
if [ "$chunks_num" -le 0 ]; then
85+
echo "ERROR: Chunks count must be positive number"
86+
return 1
87+
fi
88+
if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then
89+
echo "ERROR: Chunk index must be less than chunks count"
90+
return 1
91+
fi
92+
93+
set +e
94+
count_sketches "$path" "$target"
95+
local sketchcount=$?
96+
set -e
97+
local sketches=$(cat sketches.txt)
98+
rm -rf sketches.txt
99+
100+
local chunk_size=$(( $sketchcount / $chunks_num ))
101+
local all_chunks=$(( $chunks_num * $chunk_size ))
102+
if [ "$all_chunks" -lt "$sketchcount" ]; then
103+
chunk_size=$(( $chunk_size + 1 ))
104+
fi
105+
106+
local start_index=0
107+
local end_index=0
108+
if [ "$chunk_idex" -ge "$chunks_num" ]; then
109+
start_index=$chunk_idex
110+
end_index=$sketchcount
111+
else
112+
start_index=$(( $chunk_idex * $chunk_size ))
113+
if [ "$sketchcount" -le "$start_index" ]; then
114+
echo "Skipping job"
115+
return 0
116+
fi
117+
118+
end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
119+
if [ "$end_index" -gt "$sketchcount" ]; then
120+
end_index=$sketchcount
121+
fi
122+
fi
123+
124+
local start_num=$(( $start_index + 1 ))
125+
echo "Found $sketchcount Sketches for target '$target'";
126+
echo "Chunk Index : $chunk_idex"
127+
echo "Chunk Count : $chunks_num"
128+
echo "Chunk Size : $chunk_size"
129+
echo "Start Sketch: $start_num"
130+
echo "End Sketch : $end_index"
131+
132+
local sketchnum=0
133+
for sketch in $sketches; do
134+
local sketchdir=$(dirname $sketch)
135+
local sketchdirname=$(basename $sketchdir)
136+
local sketchname=$(basename $sketch)
137+
sketchnum=$(($sketchnum + 1))
138+
if [ "$sketchnum" -le "$start_index" ] \
139+
|| [ "$sketchnum" -gt "$end_index" ]; then
140+
continue
141+
fi
142+
echo ""
143+
echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname"
144+
build_sketch "$ide_path" "$usr_path" "$fqbn" "$sketch" "$xtra_opts"
145+
local result=$?
146+
if [ $result -ne 0 ]; then
147+
return $result
148+
fi
149+
done
150+
return 0
151+
}
152+
153+
USAGE="
154+
USAGE: ${0} [command] [options]
155+
Available commands:
156+
count: Count sketches.
157+
build: Build a sketch.
158+
chunk_build: Build a chunk of sketches.
159+
"
160+
161+
cmd=$1
162+
shift
163+
if [ -z $cmd ]; then
164+
echo "ERROR: No command supplied"
165+
echo "$USAGE"
166+
exit 2
167+
fi
168+
169+
case "$cmd" in
170+
"count")
171+
count_sketches $*
172+
;;
173+
"build")
174+
build_sketch $*
175+
;;
176+
"chunk_build")
177+
build_sketches $*
178+
;;
179+
*)
180+
echo "ERROR: Unrecognized command"
181+
echo "$USAGE"
182+
exit 2
183+
esac
184+

‎.github/workflows/push.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ concurrency:
1414

1515
jobs:
1616

17+
cmake-check:
18+
name: Check cmake file
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v2
22+
- run: bash ./.github/scripts/check-cmakelists.sh
23+
1724
# Ubuntu
1825
build-arduino-linux:
1926
name: Arduino ${{ matrix.chunk }} on ubuntu-latest

0 commit comments

Comments
 (0)
Please sign in to comment.