build_template_app.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env bash
  2. #
  3. # Usage: build_template_app.sh [-p]
  4. # -p: optional, if specified, do a fast build for every chip target with cmake and only the default
  5. # config. Otherwise permutations of (chip target, build system, configs) which were not built in
  6. # the fast build will be built.
  7. #
  8. # Needs to be called under IDF root folder
  9. set -euo pipefail
  10. gen_configs() {
  11. # CONFIG_COMPILER_OPTIMIZATION_NONE with flag -O0
  12. echo "CONFIG_COMPILER_OPTIMIZATION_NONE=y" > esp-idf-template/sdkconfig.ci.O0
  13. echo "CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE=y" >> esp-idf-template/sdkconfig.ci.O0
  14. # -O0 makes the bootloader too large to fit in the default space, otherwise(!)
  15. echo "CONFIG_PARTITION_TABLE_OFFSET=0x10000" >> esp-idf-template/sdkconfig.ci.O0
  16. # CONFIG_COMPILER_OPTIMIZATION_SIZE with flag -Os
  17. echo "CONFIG_COMPILER_OPTIMIZATION_SIZE=y" > esp-idf-template/sdkconfig.ci.Os
  18. echo "CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y" >> esp-idf-template/sdkconfig.ci.Os
  19. # CONFIG_COMPILER_OPTIMIZATION_PERF with flag -O2
  20. echo "CONFIG_COMPILER_OPTIMIZATION_PERF=y" > esp-idf-template/sdkconfig.ci.O2
  21. echo "CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF=y" >> esp-idf-template/sdkconfig.ci.O2
  22. # This part will be built in earlier stage (pre_build job) with only cmake. Built with make in later stage
  23. # CONFIG_COMPILER_OPTIMIZATION_DEFAULT with flag -Og
  24. echo "CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y" > esp-idf-template/sdkconfig.ci2.Og
  25. echo "CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG=y" >> esp-idf-template/sdkconfig.ci2.Og
  26. # -Og makes the bootloader too large to fit in the default space, otherwise(!)
  27. echo "CONFIG_PARTITION_TABLE_OFFSET=0x10000" >> esp-idf-template/sdkconfig.ci2.Og
  28. # Needs to be built with specific extra flags
  29. # Same as O2, but also disable assertions.
  30. cp esp-idf-template/sdkconfig.ci.O2 esp-idf-template/sdkconfig.ci3.no_assert
  31. echo "CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y" >> esp-idf-template/sdkconfig.ci3.no_assert
  32. }
  33. get_config_str() {
  34. CONFIG_STR=
  35. until [ $# -eq 0 ]
  36. do
  37. CONFIG_STR+=" --config $1"
  38. shift
  39. done
  40. echo ${CONFIG_STR}
  41. }
  42. build_stage2() {
  43. CONFIG_STR=$(get_config_str sdkconfig.ci.*=)
  44. # Override EXTRA_CFLAGS and EXTRA_CXXFLAGS in the environment
  45. export EXTRA_CFLAGS=${PEDANTIC_CFLAGS/-Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function/}
  46. export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS/-Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function/}
  47. python -m idf_build_apps build -vv \
  48. -p esp-idf-template \
  49. -t all \
  50. ${CONFIG_STR} \
  51. --work-dir ${BUILD_PATH}/cmake \
  52. --build-dir ${BUILD_DIR} \
  53. --build-log ${BUILD_LOG_CMAKE} \
  54. --size-file size.json \
  55. --collect-size-info size_info.txt \
  56. --default-build-targets esp32,esp32s2,esp32s3,esp32c2,esp32c3 # add esp32h2 back after IDF-5541
  57. }
  58. build_stage1() {
  59. CONFIG_STR=$(get_config_str sdkconfig.ci2.*=)
  60. python -m idf_build_apps build -vv \
  61. -p esp-idf-template \
  62. -t all \
  63. ${CONFIG_STR} \
  64. --work-dir ${BUILD_PATH}/cmake \
  65. --build-dir ${BUILD_DIR} \
  66. --build-log ${BUILD_LOG_CMAKE} \
  67. --size-file size.json \
  68. --collect-size-info size_info.txt \
  69. --default-build-targets esp32,esp32s2,esp32s3,esp32c2,esp32c3,esp32h2
  70. }
  71. # Default arguments
  72. # STAGE:
  73. # 1 (-p): fast build, 2 (default): regular build
  74. STAGE=2
  75. # Parse arguments: -p for STAGE
  76. for arg in $*
  77. do
  78. if [ ${arg} = "-p" ]; then
  79. STAGE=1
  80. fi
  81. done
  82. mkdir -p ${BUILD_PATH}/cmake
  83. mkdir -p ${LOG_PATH}
  84. rm -f scan.json
  85. gen_configs
  86. if [ ${STAGE} = 1 ]
  87. then
  88. build_stage1
  89. else
  90. build_stage2
  91. fi