-
Notifications
You must be signed in to change notification settings - Fork 29
/
build_examples.sh
executable file
·56 lines (48 loc) · 1.35 KB
/
build_examples.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
#!/usr/bin/env bash
if [ "$#" -ne 1 ]
then
echo "Usage: $0 <pio-board-name>"
exit 1
fi
set -e
cd "$(dirname "$0")"
mkdir -p examples.build
ROOT_DIR=$PWD
BOARD="$1"
PLATFORM="$(pio boards --json-output | jq -r ".[] | select(.id == \"$BOARD\") | .platform")"
if [ -z "$PLATFORM" ]
then
echo "Unknown board $BOARD"
exit 2
fi
find examples -mindepth 1 -type d | cut -d/ -f2 | sort | while read -r EXAMPLE
do
COMPATIBLE_PLATFORMS="$(grep -hoiE 'platform compatibility:.*' "$ROOT_DIR/examples/$EXAMPLE/"* | cut -d: -f2- | head -n1)"
DEPENDENCIES="$(grep -hoiE 'dependencies:.*' "$ROOT_DIR/examples/$EXAMPLE/"* | cut -d: -f2- | head -n1)"
echo "$EXAMPLE:$COMPATIBLE_PLATFORMS"
if [ -n "$COMPATIBLE_PLATFORMS" ] && ! echo "$COMPATIBLE_PLATFORMS" | grep -qFiw "$PLATFORM"
then
echo "$EXAMPLE: This example is not compatible with this platform"
continue
fi
mkdir -p examples.build/$BOARD/$EXAMPLE
pushd examples.build/$BOARD/$EXAMPLE
if [ ! -f platformio.ini ]
then
pio init --board=$BOARD
echo "monitor_speed = 115200" >> platformio.ini
echo "upload_speed = 921600" >> platformio.ini
if [ -n "$DEPENDENCIES" ]
then
echo "lib_deps = $DEPENDENCIES" >> platformio.ini
fi
fi
ln -s -f -t src/ "$ROOT_DIR/examples/$EXAMPLE/"*
ln -s -f -t lib/ "$ROOT_DIR"
if [ -e "$ROOT_DIR/config.h" ]
then
ln -s -f -t src/ "$ROOT_DIR/config.h"
fi
pio run
popd
done