build_examples.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. export BATCH_BUILD=1
  12. export V=0 # only build verbose if there's an error
  13. EXAMPLE_NUM=1
  14. RESULT=0
  15. FAILED_EXAMPLES=""
  16. RESULT_WARNINGS=22 # magic number result code for "warnings found"
  17. # traverse categories
  18. for category in ${IDF_PATH}/examples/*; do
  19. # traverse examples within each category
  20. for example in ${category}/*; do
  21. [ -f ${example}/Makefile ] || continue
  22. echo "Building ${example} as ${EXAMPLE_NUM}..."
  23. mkdir -p example_builds/${EXAMPLE_NUM}
  24. cp -r ${example} example_builds/${EXAMPLE_NUM}
  25. pushd example_builds/${EXAMPLE_NUM}/`basename ${example}`
  26. # be stricter in the CI build than the default IDF settings
  27. export EXTRA_CFLAGS="-Werror -Werror=deprecated-declarations"
  28. export EXTRA_CXXFLAGS=${EXTRA_CFLAGS}
  29. # build non-verbose first
  30. BUILDLOG=$(mktemp -t examplebuild.XXXX.log)
  31. (
  32. set -o pipefail # so result of make all isn't lost when piping to tee
  33. set -e
  34. make clean defconfig
  35. make $* all 2>&1 | tee $BUILDLOG
  36. ) || { RESULT=$?; FAILED_EXAMPLES+=" ${example}"; make V=1; } # verbose output for errors
  37. popd
  38. EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
  39. if grep -q ": warning:" $BUILDLOG; then
  40. [ $RESULT -eq 0 ] && RESULT=$RESULT_WARNINGS
  41. FAILED_EXAMPLES+=" ${example} (warnings)"
  42. fi
  43. rm -f $BUILDLOG
  44. done
  45. done
  46. if [ $RESULT -eq $RESULT_WARNINGS ]; then
  47. echo "Build would have passed, except for warnings."
  48. fi
  49. [ $RESULT -eq 0 ] || echo "Failed examples: $FAILED_EXAMPLES"
  50. exit $RESULT