build_test_apps.sh 3.2 KB

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