Last active
March 27, 2017 20:27
-
-
Save tomasbasham/e9ace873c23f8f0f00cd31b22f141111 to your computer and use it in GitHub Desktop.
Arduino Library Test Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# The MIT License (MIT) | |
# | |
# Copyright (c) 2015 Adafruit Industries | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
# Project name | |
IFS='/' read -r -a array <<< "${TRAVIS_REPO_SLUG}" | |
export LIBRARY_NAME=${array[@]: -1:1} | |
# Arduino version and IDE path | |
export ARDUINO_VERSION=1.8.2 | |
export ARDUINO_IDE=$HOME/arduino | |
# add the arduino CLI to our PATH | |
export PATH="${ARDUINO_IDE}:${PATH}" | |
# download and install arduino | |
wget https://downloads.arduino.cc/arduino-${ARDUINO_VERSION}-linux64.tar.xz | |
tar xf arduino-${ARDUINO_VERSION}-linux64.tar.xz | |
mv arduino-${ARDUINO_VERSION} ${ARDUINO_IDE} | |
rm arduino-${ARDUINO_VERSION}-linux64.tar.xz | |
# move this library to the arduino libraries folder | |
ln -s ${TRAVIS_BUILD_DIR} ${ARDUINO_IDE}/libraries/${LIBRARY_NAME} | |
echo "" | |
echo "########################################################################" | |
echo "INSTALLING DEPENDENCIES" | |
echo "########################################################################" | |
echo -n "DUE: " | |
DEPENDENCY_OUTPUT=$(arduino --install-boards arduino:sam 2>&1) | |
if [ $? -ne 0 ]; then echo -e "\xe2\x9c\x96"; else echo -e "\xe2\x9c\x93"; fi | |
echo -n "ZERO: " | |
DEPENDENCY_OUTPUT=$(arduino --install-boards arduino:samd 2>&1) | |
if [ $? -ne 0 ]; then echo -e "\xe2\x9c\x96"; else echo -e "\xe2\x9c\x93"; fi | |
# install random lib so the arduino IDE grabs a new library index | |
# see: https://github.com/arduino/Arduino/issues/3535 | |
echo -n "UPDATE LIBRARY INDEX: " | |
DEPENDENCY_OUTPUT=$(arduino --install-library USBHost > /dev/null 2>&1) | |
if [ $? -ne 0 ]; then echo -e "\xe2\x9c\x96"; else echo -e "\xe2\x9c\x93"; fi | |
# set the maximal compiler warning level | |
echo -n "SET BUILD PREFERENCES: " | |
DEPENDENCY_OUTPUT=$(arduino --pref "compiler.warning_level=all" --save-prefs 2>&1) | |
if [ $? -ne 0 ]; then echo -e "\xe2\x9c\x96"; else echo -e "\xe2\x9c\x93"; fi | |
# Build all examples for the library | |
function build_examples() { | |
# placeholder for platform | |
local platform=${PLATFORM} | |
# Track the number of successfully build examples | |
local pass_count=0 | |
# Track the number of examples failed to build | |
local fail_count=0 | |
# Track exit code | |
local exit_code=0 | |
# Grab all pde and ino example sketches | |
declare -a examples | |
# Loop through results and add them to the array | |
examples=($(find $PWD -name "*.pde" -o -name "*.ino")) | |
echo "" | |
echo "########################################################################" | |
echo -n "SWITCHING TO ${platform}: " | |
# Switch to the requested board. | |
# We have to avoid reading the exit code of local: | |
# "when declaring a local variable in a function, the local acts as a command in its own right" | |
local platform_stdout | |
platform_stdout=$(arduino --board $platform --save-prefs 2>&1) | |
# Grab the exit status of the arduino board change | |
local platform_switch=$? | |
# Notify if the platform switch failed | |
if [ $platform_switch -ne 0 ]; then print_failure; else print_success; fi | |
echo "########################################################################" | |
# Bail if the platform switch failed | |
if [ $platform_switch -ne 0 ]; then | |
echo $platform_stdout | |
exit_code=1 | |
print_results $exit_code $platform $pass_count $fail_count | |
exit 1 | |
fi | |
# Loop through example sketches | |
for example in "${examples[@]}"; do | |
# Store the filename for the example without the path | |
local example_file=$(basename $example) | |
# Print the current example | |
echo -n "${example_file}: " | |
# Verify the example, and save stdout & stderr to a variable | |
# We have to avoid reading the exit code of local: | |
# "when declaring a local variable in a function, the local acts as a command in its own right" | |
local build_stdout | |
build_stdout=$(arduino --verify $example 2>&1) | |
# Echo output if the build failed | |
if [ $? -ne 0 ]; then | |
print_failure | |
echo -e "----------------------------- DEBUG OUTPUT -----------------------------\n" | |
echo "${build_stdout}" | |
echo -e "\n------------------------------------------------------------------------\n" | |
# Increment fails | |
fail_count=$((fail_count + 1)) | |
# Mark as fail | |
exit_code=1 | |
else | |
print_success | |
# Increment passes | |
pass_count=$((pass_count + 1)) | |
fi | |
done | |
# Print results and exit | |
print_results $exit_code $platform $pass_count $fail_count | |
return $exit_code | |
} | |
# Print a heavy checkmark | |
function print_success() { | |
echo -e "\xe2\x9c\x93" | |
} | |
# Print a heavy X | |
function print_failure() { | |
echo -e "\xe2\x9c\x96" | |
} | |
# Generate final output | |
function print_results() { | |
# 0: failed, 1: passed | |
local status_number=$1 | |
# The platform | |
local platform=$2 | |
# The number of successfully built examples | |
local pass_count=$3 | |
# The number of examples failed to build | |
local fail_count=$4 | |
# The project origin URL | |
local repo=$(git config --get remote.origin.url) | |
echo -e "\n||||||||||||||||||||||||||||| JSON STATUS ||||||||||||||||||||||||||||||" | |
echo "repo: ${repo}" | |
echo "platform: ${platform}" | |
echo "status: ${status_number}" | |
echo "passed: ${pass_count}" | |
echo "failed: ${fail_count}" | |
echo -e "||||||||||||||||||||||||||||| JSON STATUS ||||||||||||||||||||||||||||||\n" | |
} |
Author
tomasbasham
commented
Mar 27, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment