common.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. function build_examples()
  3. {
  4. excludes=("$@")
  5. # track the exit code for this platform
  6. local exit_code=0
  7. # loop through results and add them to the array
  8. examples=($(find $PWD/examples/ -name "*.pde" -o -name "*.ino"))
  9. # get the last example in the array
  10. local last="${examples[@]:(-1)}"
  11. # loop through example sketches
  12. for example in "${examples[@]}"; do
  13. # store the full path to the example's sketch directory
  14. local example_dir=$(dirname $example)
  15. # store the filename for the example without the path
  16. local example_file=$(basename $example)
  17. # skip files listed as excludes
  18. for exclude in "${excludes[@]}"; do
  19. if [ "${example_file}" == "${exclude}" ] ; then
  20. echo ">>>>>>>>>>>>>>>>>>>>>>>> Skipping ${example_file} <<<<<<<<<<<<<<<<<<<<<<<<<<"
  21. continue 2
  22. fi
  23. done
  24. echo "$example_file: "
  25. local sketch="$example_dir/$example_file"
  26. echo "$sketch"
  27. #arduino -v --verbose-build --verify $sketch
  28. # verify the example, and save stdout & stderr to a variable
  29. # we have to avoid reading the exit code of local:
  30. # "when declaring a local variable in a function, the local acts as a command in its own right"
  31. local build_stdout
  32. build_stdout=$(arduino --verify $sketch 2>&1)
  33. # echo output if the build failed
  34. if [ $? -ne 0 ]; then
  35. # heavy X
  36. echo -e "\xe2\x9c\x96"
  37. echo -e "----------------------------- DEBUG OUTPUT -----------------------------\n"
  38. echo "$build_stdout"
  39. echo -e "\n------------------------------------------------------------------------\n"
  40. # mark as fail
  41. exit_code=1
  42. else
  43. # heavy checkmark
  44. echo -e "\xe2\x9c\x93"
  45. fi
  46. done
  47. return $exit_code
  48. }