build_board.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import os
  2. import sys
  3. import time
  4. import subprocess
  5. from multiprocessing import Pool
  6. import build_utils
  7. SUCCEEDED = "\033[32msucceeded\033[0m"
  8. FAILED = "\033[31mfailed\033[0m"
  9. SKIPPED = "\033[33mskipped\033[0m"
  10. build_separator = '-' * 106
  11. def filter_with_input(mylist):
  12. if len(sys.argv) > 1:
  13. input_args = list(set(mylist).intersection(sys.argv))
  14. if len(input_args) > 0:
  15. mylist[:] = input_args
  16. if __name__ == '__main__':
  17. # If examples are not specified in arguments, build all
  18. all_examples = []
  19. for dir1 in os.scandir("examples"):
  20. if dir1.is_dir():
  21. for entry in os.scandir(dir1.path):
  22. if entry.is_dir():
  23. all_examples.append(dir1.name + '/' + entry.name)
  24. filter_with_input(all_examples)
  25. all_examples.sort()
  26. # If boards are not specified in arguments, build all
  27. all_boards = []
  28. for entry in os.scandir("hw/bsp"):
  29. if entry.is_dir() and os.path.exists(entry.path + "/board.mk"):
  30. all_boards.append(entry.name)
  31. filter_with_input(all_boards)
  32. all_boards.sort()
  33. # Get dependencies
  34. for b in all_boards:
  35. subprocess.run("make -C examples/device/board_test BOARD={} get-deps".format(b), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  36. print(build_separator)
  37. print(build_utils.build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
  38. total_time = time.monotonic()
  39. # succeeded, failed, skipped
  40. total_result = [0, 0, 0]
  41. for example in all_examples:
  42. print(build_separator)
  43. with Pool(processes=os.cpu_count()) as pool:
  44. pool_args = list((map(lambda b, e=example: [e, b], all_boards)))
  45. result = pool.starmap(build_utils.build_example, pool_args)
  46. # sum all element of same index (column sum)
  47. result = list(map(sum, list(zip(*result))))
  48. # add to total result
  49. total_result = list(map(lambda x, y: x + y, total_result, result))
  50. total_time = time.monotonic() - total_time
  51. print(build_separator)
  52. print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(total_result[0], SUCCEEDED, total_result[1],
  53. FAILED, total_result[2], SKIPPED, total_time))
  54. print(build_separator)
  55. sys.exit(total_result[1])