build_template_app.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #
  10. # This script will call find_apps.py with the following arguments:
  11. # - CMake build arguments: --work-dir {BUILD_PATH}/cmake --build-dir ${BUILD_DIR} --build-log ${BUILD_LOG_CMAKE}
  12. # - Make build arguments: --work-dir {BUILD_PATH}/make/${BUILD_DIR} --build-dir build --build-log ${BUILD_LOG_MAKE}
  13. set -euo pipefail
  14. gen_configs() {
  15. # CONFIG_COMPILER_OPTIMIZATION_NONE with flag -O0
  16. echo "CONFIG_COMPILER_OPTIMIZATION_NONE=y" > esp-idf-template/sdkconfig.ci.O0
  17. echo "CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE=y" >> esp-idf-template/sdkconfig.ci.O0
  18. # -O0 makes the bootloader too large to fit in the default space, otherwise(!)
  19. echo "CONFIG_PARTITION_TABLE_OFFSET=0x10000" >> esp-idf-template/sdkconfig.ci.O0
  20. # CONFIG_COMPILER_OPTIMIZATION_SIZE with flag -Os
  21. echo "CONFIG_COMPILER_OPTIMIZATION_SIZE=y" > esp-idf-template/sdkconfig.ci.Os
  22. echo "CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y" >> esp-idf-template/sdkconfig.ci.Os
  23. # CONFIG_COMPILER_OPTIMIZATION_PERF with flag -O2
  24. echo "CONFIG_COMPILER_OPTIMIZATION_PERF=y" > esp-idf-template/sdkconfig.ci.O2
  25. echo "CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF=y" >> esp-idf-template/sdkconfig.ci.O2
  26. # This part will be built in earlier stage (pre_build job) with only cmake. Built with make in later stage
  27. # CONFIG_COMPILER_OPTIMIZATION_DEFAULT with flag -Og
  28. echo "CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y" > esp-idf-template/sdkconfig.ci2.Og
  29. echo "CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG=y" >> 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. search_cmake() {
  45. TARGET=$1
  46. shift
  47. CONFIG_STR=$*
  48. tools/find_apps.py -vv --format json --work-dir ${BUILD_PATH}/cmake --build-dir ${BUILD_DIR} --build-log ${BUILD_LOG_CMAKE} -p esp-idf-template --build-system cmake ${CONFIG_STR} --target ${TARGET} --output scan_temp.json
  49. cat scan_temp.json >> scan.json
  50. rm scan_temp.json
  51. }
  52. search_make() {
  53. TARGET=$1
  54. shift
  55. CONFIG_STR=$*
  56. tools/find_apps.py -vv --format json --work-dir ${BUILD_PATH}/make/${BUILD_DIR} --build-dir build --build-log ${BUILD_LOG_MAKE} -p esp-idf-template --build-system make ${CONFIG_STR} --target ${TARGET} --output scan_temp.json
  57. cat scan_temp.json >> scan.json
  58. rm scan_temp.json
  59. }
  60. build() {
  61. tools/build_apps.py -vv --format json --keep-going --parallel-count 1 --parallel-index 1 --size-info ${SIZE_INFO_LOCATION} scan.json
  62. rm scan.json
  63. }
  64. build_stage2() {
  65. CONFIG_STR=$(get_config_str sdkconfig.ci.*=)
  66. search_cmake esp32 ${CONFIG_STR}
  67. search_cmake esp32s2 ${CONFIG_STR}
  68. search_cmake esp32s3 ${CONFIG_STR}
  69. search_cmake esp32c3 ${CONFIG_STR}
  70. search_cmake esp32h2 ${CONFIG_STR}
  71. CONFIG_STR=$(get_config_str sdkconfig.ci.*= sdkconfig.ci2.*=)
  72. search_make esp32 ${CONFIG_STR}
  73. build build_list_1.json
  74. CONFIG_STR=$(get_config_str sdkconfig.ci3.*=)
  75. search_make esp32 ${CONFIG_STR}
  76. search_cmake esp32 ${CONFIG_STR}
  77. search_cmake esp32s2 ${CONFIG_STR}
  78. search_cmake esp32s3 ${CONFIG_STR}
  79. search_cmake esp32c3 ${CONFIG_STR}
  80. search_cmake esp32h2 ${CONFIG_STR}
  81. # Override EXTRA_CFLAGS and EXTRA_CXXFLAGS in the environment
  82. export EXTRA_CFLAGS=${PEDANTIC_CFLAGS/-Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function/}
  83. export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS/-Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function/}
  84. build
  85. }
  86. build_stage1() {
  87. CONFIG_STR=$(get_config_str sdkconfig.ci2.*=)
  88. search_cmake esp32 ${CONFIG_STR}
  89. search_cmake esp32s2 ${CONFIG_STR}
  90. search_cmake esp32s3 ${CONFIG_STR}
  91. search_cmake esp32c3 ${CONFIG_STR}
  92. search_cmake esp32h2 ${CONFIG_STR}
  93. build
  94. }
  95. # Default arguments
  96. # STAGE:
  97. # 1 (-p): fast build, 2 (default): regular build
  98. STAGE=2
  99. # Parse arguments: -p for STAGE
  100. for arg in $*
  101. do
  102. if [ ${arg} = "-p" ]; then
  103. STAGE=1
  104. fi
  105. done
  106. mkdir -p ${BUILD_PATH}/make
  107. mkdir -p ${BUILD_PATH}/cmake
  108. mkdir -p ${LOG_PATH}
  109. rm -f scan.json
  110. gen_configs
  111. if [ ${STAGE} = 1 ]
  112. then
  113. build_stage1
  114. else
  115. build_stage2
  116. fi