|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script verifies that every example in the examples directory can be built |
| 4 | + |
| 5 | +# Check that PlatformIO is on the path |
| 6 | +if [[ "$(which pio)" == "" ]]; then |
| 7 | + echo "::error::PlatformIO executable (pio) not found on PATH. Stop." |
| 8 | + echo "::error::PATH=$PATH" |
| 9 | + exit 1 |
| 10 | +fi |
| 11 | + |
| 12 | +# Parse parameters |
| 13 | +BOARD="$1" |
| 14 | +if [[ "$BOARD" == "" ]]; then |
| 15 | + echo "::error::No board specified. Stop." |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | +EXAMPLENAME="$2" |
| 19 | +if [[ "$EXAMPLENAME" == "" ]]; then |
| 20 | + echo "::error::No example specified. Stop." |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# In general, we want the script to fail if something unexpected happens. |
| 25 | +# This flag gets only revoked for the actual build process. |
| 26 | +set -e |
| 27 | + |
| 28 | +# Find the script and repository location based on the current script location |
| 29 | +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
| 30 | +REPODIR=$(cd "$(dirname $SCRIPTDIR/../../../..)" && pwd) |
| 31 | + |
| 32 | +# Some other directory definitions |
| 33 | +TMPDIR="$REPODIR/tmp" |
| 34 | +CIDIR="$REPODIR/extras/ci" |
| 35 | +EXAMPLEDIR="$REPODIR/examples" |
| 36 | + |
| 37 | +# Re-create build directory |
| 38 | +if [ -d "$TMPDIR" ]; then |
| 39 | + rm -r "$TMPDIR" |
| 40 | +fi |
| 41 | +mkdir -p "$TMPDIR" |
| 42 | + |
| 43 | +# Check that an .ino file exists |
| 44 | +if [ ! -d "$EXAMPLEDIR/$EXAMPLENAME" ]; then |
| 45 | + echo "::error::Example directory does not exist: $EXAMPLENAME" |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | +if [ ! -f "$EXAMPLEDIR/$EXAMPLENAME/$EXAMPLENAME.ino" ]; then |
| 49 | + echo "::error::Example sketch does not exist: $EXAMPLENAME.ino" |
| 50 | + exit 1 |
| 51 | +fi |
| 52 | + |
| 53 | +# We take the .ino file, rename it as main.cpp and add an Arduino.h include at the top |
| 54 | +PROJECTDIR="$TMPDIR/$EXAMPLENAME-$BOARD" |
| 55 | +MAINCPP="$PROJECTDIR/src/main.cpp" |
| 56 | +INOFILE="$PROJECTDIR/src/$EXAMPLENAME.ino" |
| 57 | + |
| 58 | +# (re-)create the project directory under tmp/ |
| 59 | +if [ -d "$PROJECTDIR" ] && [ "$PROJECTDIR" != "" ]; then |
| 60 | + rm -r "$PROJECTDIR" |
| 61 | +fi |
| 62 | + |
| 63 | +# Create the lib folder to link the current version of the library |
| 64 | +mkdir -p "$PROJECTDIR/lib" |
| 65 | +# Copy the project folder template from ci/templates/example-project |
| 66 | +cp -r "$CIDIR/templates/example-project"/* "$PROJECTDIR/" |
| 67 | +# Copy the source files |
| 68 | +cp -r "$EXAMPLEDIR/$EXAMPLENAME/." "$PROJECTDIR/src" |
| 69 | +# Create the library link |
| 70 | +ln -s "$REPODIR" "$PROJECTDIR/lib/esp32_https_server" |
| 71 | +# Convert .ino to main.cpp |
| 72 | +echo "#include <Arduino.h>" > "$MAINCPP" |
| 73 | +cat "$INOFILE" >> "$MAINCPP" |
| 74 | +rm "$INOFILE" |
| 75 | + |
| 76 | +# If the example has dependencies, rewrite platformio.ini |
| 77 | +if [[ -f "$EXAMPLEDIR/$EXAMPLENAME/.ci_lib_deps" ]]; then |
| 78 | + LIB_DEPS=$(head -n1 "$EXAMPLEDIR/$EXAMPLENAME/.ci_lib_deps") |
| 79 | + sed "s#\\#lib_deps#lib_deps = $LIB_DEPS#" "$PROJECTDIR/platformio.ini" > "$PROJECTDIR/platformio.ini.tmp" |
| 80 | + mv "$PROJECTDIR/platformio.ini.tmp" "$PROJECTDIR/platformio.ini" |
| 81 | +fi |
| 82 | + |
| 83 | +# Try building the application (+e as we want to test every example and get a |
| 84 | +# summary on what is working) |
| 85 | +set +e |
| 86 | +pio --no-ansi run -d "$PROJECTDIR" -e "$BOARD" 2>&1 | \ |
| 87 | + "$CIDIR/scripts/pio-to-gh-log.py" \ |
| 88 | + "src/main.cpp:examples/$EXAMPLENAME/$EXAMPLENAME.ino:-1" \ |
| 89 | + "lib/esp32_https_server/:src/" \ |
| 90 | + "$REPODIR/:" |
| 91 | +RC=${PIPESTATUS[0]} |
| 92 | +if [[ "$RC" != "0" ]]; then |
| 93 | + echo "::error::pio returned with RC=$RC" |
| 94 | +fi |
| 95 | +exit $RC |
0 commit comments