build_unit_test.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/bash
  2. #
  3. # Build unit test app
  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 ${IDF_TARGET} ] && die "IDF_TARGET is not set"
  24. [ -d ${LOG_PATH} ] || mkdir -p ${LOG_PATH}
  25. # Relative to IDF_PATH
  26. # If changing the BUILD_PATH, remember to update the "artifacts" in gitlab-ci configs, and IDFApp.py.
  27. BUILD_PATH=${IDF_PATH}/tools/unit-test-app/builds
  28. OUTPUT_PATH=${IDF_PATH}/tools/unit-test-app/output
  29. mkdir -p ${BUILD_PATH}/${IDF_TARGET}
  30. mkdir -p ${OUTPUT_PATH}/${IDF_TARGET}
  31. if [ -z ${CI_NODE_TOTAL} ]; then
  32. CI_NODE_TOTAL=1
  33. echo "Assuming CI_NODE_TOTAL=${CI_NODE_TOTAL}"
  34. fi
  35. if [ -z ${CI_NODE_INDEX} ]; then
  36. # Gitlab uses a 1-based index
  37. CI_NODE_INDEX=1
  38. echo "Assuming CI_NODE_INDEX=${CI_NODE_INDEX}"
  39. fi
  40. set -o nounset # Exit if variable not set.
  41. # Convert LOG_PATH to relative, to make the json file less verbose.
  42. LOG_PATH=$(realpath --relative-to ${IDF_PATH} ${LOG_PATH})
  43. ALL_BUILD_LIST_JSON="${BUILD_PATH}/${IDF_TARGET}/list.json"
  44. JOB_BUILD_LIST_JSON="${BUILD_PATH}/${IDF_TARGET}/list_job_${CI_NODE_INDEX}.json"
  45. echo "build_unit_test running for target $IDF_TARGET"
  46. cd ${IDF_PATH}
  47. # This part of the script produces the same result for all the unit test app build jobs. It may be moved to a separate stage
  48. # (pre-build) later, then the build jobs will receive ${BUILD_LIST_JSON} file as an artifact.
  49. ${IDF_PATH}/tools/find_apps.py tools/unit-test-app \
  50. -vv \
  51. --format json \
  52. --build-system cmake \
  53. --target ${IDF_TARGET} \
  54. --recursive \
  55. --build-dir "builds/@t/@w" \
  56. --build-log "${LOG_PATH}/@w.txt" \
  57. --output ${ALL_BUILD_LIST_JSON} \
  58. --config 'configs/*='
  59. # The part below is where the actual builds happen
  60. ${IDF_PATH}/tools/build_apps.py \
  61. -vv \
  62. --format json \
  63. --keep-going \
  64. --parallel-count ${CI_NODE_TOTAL} \
  65. --parallel-index ${CI_NODE_INDEX} \
  66. --output-build-list ${JOB_BUILD_LIST_JSON} \
  67. ${ALL_BUILD_LIST_JSON}\
  68. # Copy build artifacts to output directory
  69. build_names=$(cd ${BUILD_PATH}/${IDF_TARGET}; find . -maxdepth 1 \! -name . -prune -type d | cut -c 3-)
  70. for build_name in $build_names; do
  71. src=${BUILD_PATH}/${IDF_TARGET}/${build_name}
  72. dst=${OUTPUT_PATH}/${IDF_TARGET}/${build_name}
  73. echo "Copying artifacts from ${src} to ${dst}"
  74. rm -rf ${dst}
  75. mkdir -p ${dst}
  76. cp ${src}/{*.bin,*.elf,*.map,sdkconfig,flasher_args.json} ${dst}/
  77. mkdir -p ${dst}/bootloader
  78. cp ${src}/bootloader/*.bin ${dst}/bootloader/
  79. mkdir -p ${dst}/partition_table
  80. cp ${src}/partition_table/*.bin ${dst}/partition_table/
  81. done
  82. # Check for build warnings
  83. ${IDF_PATH}/tools/ci/check_build_warnings.py -vv ${JOB_BUILD_LIST_JSON}