build_esp32s2.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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
  25. if entry.is_dir() and os.path.exists(entry.path + "/sdkconfig.defaults"):
  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. filter_with_input(all_boards)
  35. all_boards.sort()
  36. def build_board(example, board):
  37. global success_count, fail_count, skip_count, exit_status
  38. start_time = time.monotonic()
  39. flash_size = "-"
  40. sram_size = "-"
  41. # Check if board is skipped
  42. if skip_example(example, board):
  43. success = SKIPPED
  44. skip_count += 1
  45. print(build_format.format(example, board, success, '-', flash_size, sram_size))
  46. else:
  47. subprocess.run("make -C examples/device/{} BOARD={} clean".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  48. build_result = subprocess.run("make -j -C examples/device/{} BOARD={} all".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  49. if build_result.returncode == 0:
  50. success = SUCCEEDED
  51. success_count += 1
  52. (flash_size, sram_size) = build_size(example, board)
  53. else:
  54. exit_status = build_result.returncode
  55. success = FAILED
  56. fail_count += 1
  57. build_duration = time.monotonic() - start_time
  58. print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size))
  59. if build_result.returncode != 0:
  60. print(build_result.stdout.decode("utf-8"))
  61. def build_size(example, board):
  62. #elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board)
  63. elf_file = 'examples/device/{}/_build/{}/*.elf'.format(example, board)
  64. size_output = subprocess.run('size {}'.format(elf_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8")
  65. size_list = size_output.split('\n')[1].split('\t')
  66. flash_size = int(size_list[0])
  67. sram_size = int(size_list[1]) + int(size_list[2])
  68. return (flash_size, sram_size)
  69. def skip_example(example, board):
  70. return 0
  71. print(build_separator)
  72. print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
  73. print(build_separator)
  74. for example in all_examples:
  75. for board in all_boards:
  76. build_board(example, board)
  77. total_time = time.monotonic() - total_time
  78. print(build_separator)
  79. print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, total_time))
  80. print(build_separator)
  81. sys.exit(exit_status)