build_examples.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env bash
  2. #
  3. # Build all examples from the examples directory, in BUILD_PATH to
  4. # ensure they can run when copied to a new directory.
  5. #
  6. # Runs as part of CI process.
  7. #
  8. # -----------------------------------------------------------------------------
  9. # Safety settings (see https://gist.github.com/ilg-ul/383869cbb01f61a51c4d).
  10. if [[ ! -z ${DEBUG_SHELL} ]]
  11. then
  12. set -x # Activate the expand mode if DEBUG is anything but empty.
  13. fi
  14. set -o errexit # Exit if command failed.
  15. set -o pipefail # Exit if pipe failed.
  16. export PATH="$IDF_PATH/tools/ci:$IDF_PATH/tools:$PATH"
  17. # -----------------------------------------------------------------------------
  18. die() {
  19. echo "${1:-"Unknown Error"}" 1>&2
  20. exit 1
  21. }
  22. [ -z ${IDF_PATH} ] && die "IDF_PATH is not set"
  23. [ -z ${LOG_PATH} ] && die "LOG_PATH is not set"
  24. [ -z ${BUILD_PATH} ] && die "BUILD_PATH is not set"
  25. [ -z ${IDF_TARGET} ] && die "IDF_TARGET is not set"
  26. [ -z ${EXAMPLE_TEST_BUILD_SYSTEM} ] && die "EXAMPLE_TEST_BUILD_SYSTEM is not set"
  27. [ -d ${LOG_PATH} ] || mkdir -p ${LOG_PATH}
  28. [ -d ${BUILD_PATH} ] || mkdir -p ${BUILD_PATH}
  29. if [ -z ${CI_NODE_TOTAL} ]; then
  30. CI_NODE_TOTAL=1
  31. echo "Assuming CI_NODE_TOTAL=${CI_NODE_TOTAL}"
  32. fi
  33. if [ -z ${CI_NODE_INDEX} ]; then
  34. # Gitlab uses a 1-based index
  35. CI_NODE_INDEX=1
  36. echo "Assuming CI_NODE_INDEX=${CI_NODE_INDEX}"
  37. fi
  38. export EXTRA_CFLAGS="${PEDANTIC_CFLAGS:-}"
  39. export EXTRA_CXXFLAGS="${PEDANTIC_CXXFLAGS:-}"
  40. set -o nounset # Exit if variable not set.
  41. export REALPATH=realpath
  42. if [ "$(uname -s)" = "Darwin" ]; then
  43. export REALPATH=grealpath
  44. fi
  45. # Convert LOG_PATH and BUILD_PATH to relative, to make the json file less verbose.
  46. LOG_PATH=$(${REALPATH} --relative-to ${IDF_PATH} ${LOG_PATH})
  47. BUILD_PATH=$(${REALPATH} --relative-to ${IDF_PATH} ${BUILD_PATH})
  48. ALL_BUILD_LIST_JSON="${BUILD_PATH}/list.json"
  49. JOB_BUILD_LIST_JSON="${BUILD_PATH}/list_job_${CI_NODE_INDEX}.json"
  50. echo "build_examples running for target $IDF_TARGET"
  51. cd ${IDF_PATH}
  52. # This part of the script produces the same result for all the example build jobs. It may be moved to a separate stage
  53. # (pre-build) later, then the build jobs will receive ${BUILD_LIST_JSON} file as an artifact.
  54. # If changing the work-dir or build-dir format, remember to update the "artifacts" in gitlab-ci configs, and IDFApp.py.
  55. ${IDF_PATH}/tools/find_apps.py examples \
  56. -vv \
  57. --format json \
  58. --build-system ${EXAMPLE_TEST_BUILD_SYSTEM} \
  59. --target ${IDF_TARGET} \
  60. --recursive \
  61. --exclude examples/build_system/idf_as_lib \
  62. --work-dir "${BUILD_PATH}/@f/@w/@t" \
  63. --build-dir build \
  64. --build-log "${LOG_PATH}/@f_@w.txt" \
  65. --output ${ALL_BUILD_LIST_JSON} \
  66. --config 'sdkconfig.ci=default' \
  67. --config 'sdkconfig.ci.*=' \
  68. --config '=default' \
  69. # --config rules above explained:
  70. # 1. If sdkconfig.ci exists, use it build the example with configuration name "default"
  71. # 2. If sdkconfig.ci.* exists, use it to build the "*" configuration
  72. # 3. If none of the above exist, build the default configuration under the name "default"
  73. # The part below is where the actual builds happen
  74. ${IDF_PATH}/tools/build_apps.py \
  75. -vv \
  76. --format json \
  77. --keep-going \
  78. --parallel-count ${CI_NODE_TOTAL} \
  79. --parallel-index ${CI_NODE_INDEX} \
  80. --output-build-list ${JOB_BUILD_LIST_JSON} \
  81. ${ALL_BUILD_LIST_JSON}\
  82. # Check for build warnings
  83. ${IDF_PATH}/tools/ci/check_build_warnings.py -vv ${JOB_BUILD_LIST_JSON}