build_esp32sx.py 3.5 KB

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