build_esp32sx.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import os
  2. import glob
  3. import sys
  4. import subprocess
  5. import time
  6. import build_utils
  7. SUCCEEDED = "\033[32msucceeded\033[0m"
  8. FAILED = "\033[31mfailed\033[0m"
  9. SKIPPED = "\033[33mskipped\033[0m"
  10. success_count = 0
  11. fail_count = 0
  12. skip_count = 0
  13. exit_status = 0
  14. total_time = time.monotonic()
  15. build_format = '| {:23} | {:30} | {:18} | {:7} | {:6} | {:6} |'
  16. build_separator = '-' * 100
  17. def filter_with_input(mylist):
  18. if len(sys.argv) > 1:
  19. input_args = list(set(mylist).intersection(sys.argv))
  20. if len(input_args) > 0:
  21. mylist[:] = input_args
  22. # Build all examples if not specified
  23. all_examples = []
  24. for entry in os.scandir("examples/device"):
  25. # Only includes example with CMakeLists.txt for esp32s, and skip board_test to speed up ci
  26. if entry.is_dir() and os.path.exists(entry.path + "/sdkconfig.defaults") and entry.name != 'board_test':
  27. all_examples.append(entry.name)
  28. filter_with_input(all_examples)
  29. all_examples.sort()
  30. # Build all boards if not specified
  31. all_boards = []
  32. for entry in os.scandir("hw/bsp/esp32s2/boards"):
  33. if entry.is_dir():
  34. all_boards.append(entry.name)
  35. for entry in os.scandir("hw/bsp/esp32s3/boards"):
  36. if entry.is_dir():
  37. all_boards.append(entry.name)
  38. filter_with_input(all_boards)
  39. all_boards.sort()
  40. def build_board(example, board):
  41. global success_count, fail_count, skip_count, exit_status
  42. start_time = time.monotonic()
  43. flash_size = "-"
  44. sram_size = "-"
  45. # Check if board is skipped
  46. if build_utils.skip_example(example, board):
  47. success = SKIPPED
  48. skip_count += 1
  49. print(build_format.format(example, board, success, '-', flash_size, sram_size))
  50. else:
  51. subprocess.run("make -C examples/device/{} BOARD={} clean".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  52. build_result = subprocess.run("make -j -C examples/device/{} BOARD={} all".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  53. if build_result.returncode == 0:
  54. success = SUCCEEDED
  55. success_count += 1
  56. (flash_size, sram_size) = build_size(example, board)
  57. else:
  58. exit_status = build_result.returncode
  59. success = FAILED
  60. fail_count += 1
  61. build_duration = time.monotonic() - start_time
  62. print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size))
  63. if build_result.returncode != 0:
  64. print(build_result.stdout.decode("utf-8"))
  65. def build_size(example, board):
  66. #elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board)
  67. elf_file = 'examples/device/{}/_build/{}/*.elf'.format(example, board)
  68. size_output = subprocess.run('size {}'.format(elf_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8")
  69. size_list = size_output.split('\n')[1].split('\t')
  70. flash_size = int(size_list[0])
  71. sram_size = int(size_list[1]) + int(size_list[2])
  72. return (flash_size, sram_size)
  73. print(build_separator)
  74. print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
  75. print(build_separator)
  76. for example in all_examples:
  77. for board in all_boards:
  78. build_board(example, board)
  79. total_time = time.monotonic() - total_time
  80. print(build_separator)
  81. print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, total_time))
  82. print(build_separator)
  83. sys.exit(exit_status)