build_examples.sh 1.8 KB

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