simmel-bootloader/tools/build_all.py

74 lines
2.2 KiB
Python
Raw Permalink Normal View History

import os
import shutil
2020-03-24 09:04:21 +00:00
import glob
import sys
import subprocess
import time
2020-03-24 15:47:15 +00:00
subprocess.run("rm -rf _build/", shell=True)
subprocess.run("rm -rf bin/", shell=True)
2019-09-25 05:54:26 +00:00
success_count = 0
fail_count = 0
exit_status = 0
2020-03-24 09:04:21 +00:00
build_format = '| {:32} | {:9} | {:5} | {:6} | {:6} |'
build_separator = '-' * 74
2019-09-25 05:54:26 +00:00
2020-03-24 09:04:21 +00:00
# All supported boards
all_boards = []
for entry in os.scandir("src/boards"):
2019-04-24 05:03:26 +00:00
all_boards.append(entry.name)
2020-03-24 09:04:21 +00:00
all_boards.sort()
#sha, version = build_info.get_version_info()
2019-05-03 07:05:14 +00:00
total_time = time.monotonic()
2019-09-25 05:54:26 +00:00
print(build_separator)
2020-03-24 09:04:21 +00:00
print(build_format.format('Board', 'Result', 'Time', 'Flash', 'SRAM'))
2019-09-25 05:54:26 +00:00
print(build_separator)
for board in all_boards:
bin_directory = "bin/{}/".format(board)
os.makedirs(bin_directory, exist_ok=True)
start_time = time.monotonic()
make_result = subprocess.run("make -j 4 BOARD={} all genpkg".format(board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
build_duration = time.monotonic() - start_time
2019-09-25 05:54:26 +00:00
2020-03-24 17:31:27 +00:00
flash_size = "-"
sram_size = "-"
2019-09-25 05:54:26 +00:00
if make_result.returncode == 0:
success = "\033[32msucceeded\033[0m"
success_count += 1
2020-03-24 17:31:27 +00:00
out_file = glob.glob('_build/build-{}/*.out'.format(board))[0]
size_output = subprocess.run('size {}'.format(out_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8")
size_list = size_output.split('\n')[1].split('\t')
flash_size = int(size_list[0])
sram_size = int(size_list[1]) + int(size_list[2])
2019-09-25 05:54:26 +00:00
else:
exit_status = make_result.returncode
2019-09-25 05:54:26 +00:00
success = "\033[31mfailed\033[0m "
fail_count += 1
2020-03-24 15:47:15 +00:00
for entry in os.scandir("_build/build-{}".format(board)):
for extension in ["zip", "hex"]:
2018-12-05 00:03:33 +00:00
if entry.name.endswith(extension) and "nosd" not in entry.name:
shutil.copy(entry.path, bin_directory)
2020-03-24 09:04:21 +00:00
print(build_format.format(board, success, "{:.2f}s".format(build_duration), flash_size, sram_size))
2019-09-25 05:54:26 +00:00
if make_result.returncode != 0:
print(make_result.stdout.decode("utf-8"))
2019-09-25 05:54:26 +00:00
# Build Summary
2019-05-03 07:05:14 +00:00
total_time = time.monotonic() - total_time
2019-09-25 05:54:26 +00:00
print(build_separator)
print("Build Sumamary: {} \033[32msucceeded\033[0m, {} \033[31mfailed\033[0m and took {:.2f}s".format(success_count, fail_count, total_time))
print(build_separator)
2019-05-03 07:05:14 +00:00
sys.exit(exit_status)