build_examples.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. #
  3. # Build all examples from the examples directory, out of tree to
  4. # ensure they can run when copied to a new directory.
  5. #
  6. # Runs as part of CI process.
  7. #
  8. # Assumes CWD is an out-of-tree build directory, and will copy examples to individual subdirectories, one by one.
  9. #
  10. [ -z ${IDF_PATH} ] && echo "IDF_PATH is not set" && exit 1
  11. EXAMPLE_NUM=1
  12. RESULT=0
  13. FAILED_EXAMPLES=""
  14. RESULT_WARNINGS=22 # magic number result code for "warnings found"
  15. for example in ${IDF_PATH}/examples/*; do
  16. [ -f ${example}/Makefile ] || continue
  17. echo "Building ${example} as ${EXAMPLE_NUM}..."
  18. mkdir -p example_builds/${EXAMPLE_NUM}
  19. cp -r ${example} example_builds/${EXAMPLE_NUM}
  20. pushd example_builds/${EXAMPLE_NUM}/`basename ${example}`
  21. # be stricter in the CI build than the default IDF settings
  22. export EXTRA_CFLAGS="-Werror -Werror=deprecated-declarations"
  23. export EXTRA_CXXFLAGS=${EXTRA_CFLAGS}
  24. # build non-verbose first
  25. BUILDLOG=$(mktemp -t examplebuild.XXXX.log)
  26. (
  27. set -o pipefail # so result of make all isn't lost when piping to tee
  28. set -e
  29. make clean defconfig
  30. make $* all 2>&1 | tee $BUILDLOG
  31. ) || { RESULT=$?; FAILED_EXAMPLES+=" ${example}"; make V=1; } # only build verbose if there's an error
  32. popd
  33. EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
  34. if grep -q ": warning:" $BUILDLOG; then
  35. [ $RESULT -eq 0 ] && RESULT=$RESULT_WARNINGS
  36. FAILED_EXAMPLES+=" ${example} (warnings)"
  37. fi
  38. rm -f $BUILDLOG
  39. done
  40. if [ $RESULT -eq $RESULT_WARNINGS ]; then
  41. echo "Build would have passed, except for warnings."
  42. fi
  43. [ $RESULT -eq 0 ] || echo "Failed examples: $FAILED_EXAMPLES"
  44. exit $RESULT