Skip to content

Commit 7e0bae1

Browse files
committedMay 1, 2024·
Add build_examples.sh script
1 parent 54098b1 commit 7e0bae1

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed
 

‎.github/workflows/ci.yml

+3-10
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,9 @@ jobs:
3434
- uses: actions/setup-python@v4
3535
with:
3636
python-version: '3.9'
37+
- name: Install jq
38+
run: sudo apt-get install -yq jq
3739
- name: Install PlatformIO Core
3840
run: pip install --upgrade platformio
3941
- name: Build examples
40-
run: |
41-
for example in examples/*; do
42-
cd "$example"
43-
platformio init --board ${{ matrix.board }}
44-
grep -q ArduinoJson *.ino && echo "lib_deps = bblanchon/ArduinoJson" >> platformio.ini
45-
mv *.ino src/
46-
ln -s ../../../ lib/PicoMQTT
47-
pio run
48-
cd ../..
49-
done
42+
run: ./build_examples.sh ${{ matrix.board }}

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.pio
22
*.orig
33
*.tar.gz
4-
*.sh
4+
/examples.build
5+
/config.h

‎build_examples.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "$#" -ne 1 ]
4+
then
5+
echo "Usage: $0 <pio-board-name>"
6+
exit 1
7+
fi
8+
9+
set -e
10+
11+
cd "$(dirname "$0")"
12+
13+
mkdir -p examples.build
14+
ROOT_DIR=$PWD
15+
16+
BOARD="$1"
17+
PLATFORM="$(pio boards --json-output | jq -r ".[] | select(.id == \"$BOARD\") | .platform")"
18+
19+
if [ -z "$PLATFORM" ]
20+
then
21+
echo "Unknown board $BOARD"
22+
exit 2
23+
fi
24+
25+
find examples -mindepth 1 -type d | cut -d/ -f2 | sort | while read -r EXAMPLE
26+
do
27+
COMPATIBLE_PLATFORMS="$(grep -hoiE 'platform compatibility:.*' "$ROOT_DIR/examples/$EXAMPLE/"* | cut -d: -f2- | head -n1)"
28+
DEPENDENCIES="$(grep -hoiE 'dependencies:.*' "$ROOT_DIR/examples/$EXAMPLE/"* | cut -d: -f2- | head -n1)"
29+
echo "$EXAMPLE:$COMPATIBLE_PLATFORMS"
30+
if [ -n "$COMPATIBLE_PLATFORMS" ] && ! echo "$COMPATIBLE_PLATFORMS" | grep -qFiw "$PLATFORM"
31+
then
32+
echo "$EXAMPLE: This example is not compatible with this platform"
33+
continue
34+
fi
35+
36+
mkdir -p examples.build/$BOARD/$EXAMPLE
37+
pushd examples.build/$BOARD/$EXAMPLE
38+
if [ ! -f platformio.ini ]
39+
then
40+
pio init --board=$BOARD
41+
echo "monitor_speed = 115200" >> platformio.ini
42+
echo "upload_speed = 921600" >> platformio.ini
43+
if [ -n "$DEPENDENCIES" ]
44+
then
45+
echo "lib_deps = $DEPENDENCIES" >> platformio.ini
46+
fi
47+
fi
48+
ln -s -f -t src/ "$ROOT_DIR/examples/$EXAMPLE/"*
49+
ln -s -f -t lib/ "$ROOT_DIR"
50+
if [ -e "$ROOT_DIR/config.h" ]
51+
then
52+
ln -s -f -t src/ "$ROOT_DIR/config.h"
53+
fi
54+
pio run
55+
popd
56+
done

‎examples/arduinojson/arduinojson.ino

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// dependencies: bblanchon/ArduinoJson
12
#include <PicoMQTT.h>
23

34
#if __has_include("config.h")

0 commit comments

Comments
 (0)
Please sign in to comment.