build_template_app.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. # -O2 makes the bootloader too large to fit in the default space, otherwise(!)
  23. echo "CONFIG_PARTITION_TABLE_OFFSET=0x10000" >> esp-idf-template/sdkconfig.ci.O2
  24. # This part will be built in earlier stage (pre_build job) with only cmake. Built with make in later stage
  25. # CONFIG_COMPILER_OPTIMIZATION_DEBUG with flag -Og
  26. echo "CONFIG_COMPILER_OPTIMIZATION_DEBUG=y" > esp-idf-template/sdkconfig.ci2.Og
  27. echo "CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG=y" >> esp-idf-template/sdkconfig.ci2.Og
  28. # -Og makes the bootloader too large to fit in the default space, otherwise(!)
  29. echo "CONFIG_PARTITION_TABLE_OFFSET=0x10000" >> esp-idf-template/sdkconfig.ci2.Og
  30. # Needs to be built with specific extra flags
  31. # Same as O2, but also disable assertions.
  32. cp esp-idf-template/sdkconfig.ci.O2 esp-idf-template/sdkconfig.ci3.no_assert
  33. echo "CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y" >> esp-idf-template/sdkconfig.ci3.no_assert
  34. }
  35. get_config_str() {
  36. CONFIG_STR=
  37. until [ $# -eq 0 ]
  38. do
  39. CONFIG_STR+=" --config $1"
  40. shift
  41. done
  42. echo ${CONFIG_STR}
  43. }
  44. build_stage2() {
  45. CONFIG_STR=$(get_config_str sdkconfig.ci.*=)
  46. # Override EXTRA_CFLAGS and EXTRA_CXXFLAGS in the environment
  47. export EXTRA_CFLAGS=${PEDANTIC_CFLAGS/-Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function/}
  48. export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS/-Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function/}
  49. python -m idf_build_apps build -vv \
  50. -p esp-idf-template \
  51. -t all \
  52. ${CONFIG_STR} \
  53. --work-dir ${BUILD_PATH}/cmake \
  54. --build-dir ${BUILD_DIR} \
  55. --build-log ${BUILD_LOG_CMAKE} \
  56. --size-file size.json \
  57. --collect-size-info size_info.txt \
  58. --default-build-targets esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 esp32h2 esp32p4
  59. }
  60. build_stage1() {
  61. CONFIG_STR=$(get_config_str sdkconfig.ci2.*=)
  62. python -m idf_build_apps build -vv \
  63. -p esp-idf-template \
  64. -t all \
  65. ${CONFIG_STR} \
  66. --work-dir ${BUILD_PATH}/cmake \
  67. --build-dir ${BUILD_DIR} \
  68. --build-log ${BUILD_LOG_CMAKE} \
  69. --size-file size.json \
  70. --collect-size-info size_info.txt \
  71. --default-build-targets esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 esp32h2 esp32p4
  72. }
  73. # Default arguments
  74. # STAGE:
  75. # 1 (-p): fast build, 2 (default): regular build
  76. STAGE=2
  77. # Parse arguments: -p for STAGE
  78. for arg in $*
  79. do
  80. if [ ${arg} = "-p" ]; then
  81. STAGE=1
  82. fi
  83. done
  84. mkdir -p ${BUILD_PATH}/cmake
  85. mkdir -p ${LOG_PATH}
  86. rm -f scan.json
  87. gen_configs
  88. if [ ${STAGE} = 1 ]
  89. then
  90. build_stage1
  91. else
  92. build_stage2
  93. fi