build_examples.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. RESULT_WARNINGS=22 # magic number result code for "warnings found"
  14. set -e
  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 -e
  28. make clean defconfig
  29. make all 2>&1 | tee $BUILDLOG
  30. ) || (RESULT=$?; make V=1) # only build verbose if there's an error
  31. popd
  32. EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
  33. if [ $RESULT -eq 0 ] && grep -q ": warning:" $BUILDLOG; then
  34. echo "Build will fail, due to warnings in this example"
  35. RESULT=$RESULT_WARNINGS
  36. fi
  37. rm -f $BUILDLOG
  38. done
  39. if [ $RESULT -eq $RESULT_WARNINGS ]; then
  40. echo "Build would have passed, except for warnings."
  41. fi
  42. exit $RESULT