forked from fhessel/esp32_https_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-example.sh
More file actions
executable file
·95 lines (82 loc) · 2.92 KB
/
Copy pathbuild-example.sh
File metadata and controls
executable file
·95 lines (82 loc) · 2.92 KB
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
#!/bin/bash
# This script verifies that every example in the examples directory can be built
# Check that PlatformIO is on the path
if [[ "$(which pio)" == "" ]]; then
echo "::error::PlatformIO executable (pio) not found on PATH. Stop."
echo "::error::PATH=$PATH"
exit 1
fi
# Parse parameters
BOARD="$1"
if [[ "$BOARD" == "" ]]; then
echo "::error::No board specified. Stop."
exit 1
fi
EXAMPLENAME="$2"
if [[ "$EXAMPLENAME" == "" ]]; then
echo "::error::No example specified. Stop."
exit 1
fi
# In general, we want the script to fail if something unexpected happens.
# This flag gets only revoked for the actual build process.
set -e
# Find the script and repository location based on the current script location
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
REPODIR=$(cd "$(dirname $SCRIPTDIR/../../../..)" && pwd)
# Some other directory definitions
TMPDIR="$REPODIR/tmp"
CIDIR="$REPODIR/extras/ci"
EXAMPLEDIR="$REPODIR/examples"
# Re-create build directory
if [ -d "$TMPDIR" ]; then
rm -r "$TMPDIR"
fi
mkdir -p "$TMPDIR"
# Check that an .ino file exists
if [ ! -d "$EXAMPLEDIR/$EXAMPLENAME" ]; then
echo "::error::Example directory does not exist: $EXAMPLENAME"
exit 1
fi
if [ ! -f "$EXAMPLEDIR/$EXAMPLENAME/$EXAMPLENAME.ino" ]; then
echo "::error::Example sketch does not exist: $EXAMPLENAME.ino"
exit 1
fi
# We take the .ino file, rename it as main.cpp and add an Arduino.h include at the top
PROJECTDIR="$TMPDIR/$EXAMPLENAME-$BOARD"
MAINCPP="$PROJECTDIR/src/main.cpp"
INOFILE="$PROJECTDIR/src/$EXAMPLENAME.ino"
# (re-)create the project directory under tmp/
if [ -d "$PROJECTDIR" ] && [ "$PROJECTDIR" != "" ]; then
rm -r "$PROJECTDIR"
fi
# Create the lib folder to link the current version of the library
mkdir -p "$PROJECTDIR/lib"
# Copy the project folder template from ci/templates/example-project
cp -r "$CIDIR/templates/example-project"/* "$PROJECTDIR/"
# Copy the source files
cp -r "$EXAMPLEDIR/$EXAMPLENAME/." "$PROJECTDIR/src"
# Create the library link
ln -s "$REPODIR" "$PROJECTDIR/lib/esp32_https_server"
# Convert .ino to main.cpp
echo "#include <Arduino.h>" > "$MAINCPP"
cat "$INOFILE" >> "$MAINCPP"
rm "$INOFILE"
# If the example has dependencies, rewrite platformio.ini
if [[ -f "$EXAMPLEDIR/$EXAMPLENAME/.ci_lib_deps" ]]; then
LIB_DEPS=$(head -n1 "$EXAMPLEDIR/$EXAMPLENAME/.ci_lib_deps")
sed "s#\\#lib_deps#lib_deps = $LIB_DEPS#" "$PROJECTDIR/platformio.ini" > "$PROJECTDIR/platformio.ini.tmp"
mv "$PROJECTDIR/platformio.ini.tmp" "$PROJECTDIR/platformio.ini"
fi
# Try building the application (+e as we want to test every example and get a
# summary on what is working)
set +e
pio --no-ansi run -d "$PROJECTDIR" -e "$BOARD" 2>&1 | \
"$CIDIR/scripts/pio-to-gh-log.py" \
"src/main.cpp:examples/$EXAMPLENAME/$EXAMPLENAME.ino:-1" \
"lib/esp32_https_server/:src/" \
"$REPODIR/:"
RC=${PIPESTATUS[0]}
if [[ "$RC" != "0" ]]; then
echo "::error::pio returned with RC=$RC"
fi
exit $RC