2019-05-24 15:32:24 -04:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
2020-06-03 18:40:05 -04:00
|
|
|
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2018-11-28 19:58:44 -05:00
|
|
|
import os
|
2020-07-24 23:44:55 -04:00
|
|
|
import multiprocessing
|
2018-11-28 19:58:44 -05:00
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import shutil
|
|
|
|
import build_board_info as build_info
|
|
|
|
import time
|
|
|
|
|
2022-05-13 05:38:03 -04:00
|
|
|
sys.path.append("../docs")
|
|
|
|
from shared_bindings_matrix import get_settings_from_makefile
|
|
|
|
|
2018-11-28 19:58:44 -05:00
|
|
|
for port in build_info.SUPPORTED_PORTS:
|
2019-05-24 15:32:24 -04:00
|
|
|
result = subprocess.run("rm -rf ../ports/{port}/build*".format(port=port), shell=True)
|
2018-11-28 19:58:44 -05:00
|
|
|
|
|
|
|
PARALLEL = "-j 5"
|
2019-08-15 03:07:29 -04:00
|
|
|
if "GITHUB_ACTION" in os.environ:
|
2021-03-15 09:57:36 -04:00
|
|
|
PARALLEL = "-j 2"
|
2018-11-28 19:58:44 -05:00
|
|
|
|
|
|
|
all_boards = build_info.get_board_mapping()
|
|
|
|
build_boards = list(all_boards.keys())
|
2019-08-15 03:07:29 -04:00
|
|
|
if "BOARDS" in os.environ:
|
|
|
|
build_boards = os.environ["BOARDS"].split()
|
2018-11-28 19:58:44 -05:00
|
|
|
|
|
|
|
sha, version = build_info.get_version_info()
|
|
|
|
|
|
|
|
languages = build_info.get_languages()
|
2021-03-24 18:39:47 -04:00
|
|
|
|
|
|
|
all_languages = build_info.get_languages(list_all=True)
|
|
|
|
|
|
|
|
print("Note: Not building languages", set(all_languages) - set(languages))
|
2021-03-01 16:28:58 -05:00
|
|
|
|
2018-11-28 19:58:44 -05:00
|
|
|
exit_status = 0
|
2020-07-24 23:44:55 -04:00
|
|
|
cores = multiprocessing.cpu_count()
|
2021-03-15 09:57:36 -04:00
|
|
|
print("building boards with parallelism {}".format(cores))
|
2018-11-28 19:58:44 -05:00
|
|
|
for board in build_boards:
|
|
|
|
bin_directory = "../bin/{}/".format(board)
|
|
|
|
os.makedirs(bin_directory, exist_ok=True)
|
|
|
|
board_info = all_boards[board]
|
2022-05-13 05:38:03 -04:00
|
|
|
board_settings = get_settings_from_makefile("../ports/" + board_info["port"], board)
|
2018-11-28 19:58:44 -05:00
|
|
|
|
2021-03-24 18:39:47 -04:00
|
|
|
for language in languages:
|
2019-01-14 21:35:21 -05:00
|
|
|
bin_directory = "../bin/{board}/{language}".format(board=board, language=language)
|
2019-01-14 21:21:48 -05:00
|
|
|
os.makedirs(bin_directory, exist_ok=True)
|
2018-11-28 19:58:44 -05:00
|
|
|
start_time = time.monotonic()
|
2019-05-24 15:32:24 -04:00
|
|
|
|
|
|
|
# Normally different language builds are all done based on the same set of compiled sources.
|
|
|
|
# But sometimes a particular language needs to be built from scratch, if, for instance,
|
|
|
|
# CFLAGS_INLINE_LIMIT is set for a particular language to make it fit.
|
|
|
|
clean_build_check_result = subprocess.run(
|
2020-07-24 23:44:55 -04:00
|
|
|
"make -C ../ports/{port} TRANSLATION={language} BOARD={board} check-release-needs-clean-build -j {cores} | fgrep 'RELEASE_NEEDS_CLEAN_BUILD = 1'".format(
|
2021-03-15 09:57:36 -04:00
|
|
|
port=board_info["port"], language=language, board=board, cores=cores
|
|
|
|
),
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
)
|
2019-05-24 15:32:24 -04:00
|
|
|
clean_build = clean_build_check_result.returncode == 0
|
|
|
|
|
|
|
|
build_dir = "build-{board}".format(board=board)
|
|
|
|
if clean_build:
|
|
|
|
build_dir += "-{language}".format(language=language)
|
|
|
|
|
2022-07-30 01:09:49 -04:00
|
|
|
extensions = [
|
|
|
|
extension.strip()
|
|
|
|
for extension in board_settings["CIRCUITPY_BUILD_EXTENSIONS"].split(",")
|
|
|
|
]
|
|
|
|
|
|
|
|
artifacts = [os.path.join(build_dir, "firmware." + extension) for extension in extensions]
|
2019-05-24 15:32:24 -04:00
|
|
|
make_result = subprocess.run(
|
2022-07-30 01:09:49 -04:00
|
|
|
"make -C ../ports/{port} TRANSLATION={language} BOARD={board} BUILD={build} -j {cores} {artifacts}".format(
|
2021-03-15 09:57:36 -04:00
|
|
|
port=board_info["port"],
|
|
|
|
language=language,
|
|
|
|
board=board,
|
|
|
|
build=build_dir,
|
|
|
|
cores=cores,
|
2022-07-30 01:09:49 -04:00
|
|
|
artifacts=" ".join(artifacts),
|
2021-03-15 09:57:36 -04:00
|
|
|
),
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
)
|
2019-05-24 15:32:24 -04:00
|
|
|
|
2018-11-28 19:58:44 -05:00
|
|
|
build_duration = time.monotonic() - start_time
|
|
|
|
success = "\033[32msucceeded\033[0m"
|
|
|
|
if make_result.returncode != 0:
|
|
|
|
exit_status = make_result.returncode
|
|
|
|
success = "\033[31mfailed\033[0m"
|
|
|
|
|
2018-11-30 13:58:27 -05:00
|
|
|
other_output = ""
|
|
|
|
|
2022-05-13 05:38:03 -04:00
|
|
|
for extension in extensions:
|
2019-05-24 15:32:24 -04:00
|
|
|
temp_filename = "../ports/{port}/{build}/firmware.{extension}".format(
|
2021-03-15 09:57:36 -04:00
|
|
|
port=board_info["port"], build=build_dir, extension=extension
|
|
|
|
)
|
2019-04-11 14:25:04 -04:00
|
|
|
for alias in board_info["aliases"] + [board]:
|
2021-03-15 09:57:36 -04:00
|
|
|
bin_directory = "../bin/{alias}/{language}".format(alias=alias, language=language)
|
2019-04-11 14:25:04 -04:00
|
|
|
os.makedirs(bin_directory, exist_ok=True)
|
2021-04-30 16:30:13 -04:00
|
|
|
final_filename = (
|
|
|
|
"adafruit-circuitpython-{alias}-{language}-{version}.{extension}".format(
|
|
|
|
alias=alias, language=language, version=version, extension=extension
|
|
|
|
)
|
2021-03-15 09:57:36 -04:00
|
|
|
)
|
2019-04-11 14:25:04 -04:00
|
|
|
final_filename = os.path.join(bin_directory, final_filename)
|
|
|
|
try:
|
|
|
|
shutil.copyfile(temp_filename, final_filename)
|
|
|
|
except FileNotFoundError:
|
|
|
|
other_output = "Cannot find file {}".format(temp_filename)
|
|
|
|
if exit_status == 0:
|
|
|
|
exit_status = 1
|
2018-11-28 19:58:44 -05:00
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
print(
|
|
|
|
"Build {board} for {language}{clean_build} took {build_duration:.2f}s and {success}".format(
|
|
|
|
board=board,
|
|
|
|
language=language,
|
|
|
|
clean_build=(" (clean_build)" if clean_build else ""),
|
|
|
|
build_duration=build_duration,
|
|
|
|
success=success,
|
|
|
|
)
|
|
|
|
)
|
2019-08-15 03:07:29 -04:00
|
|
|
|
|
|
|
print(make_result.stdout.decode("utf-8"))
|
|
|
|
print(other_output)
|
|
|
|
|
|
|
|
# Flush so we will see something before 10 minutes has passed.
|
2018-12-05 15:01:58 -05:00
|
|
|
print(flush=True)
|
2018-11-28 19:58:44 -05:00
|
|
|
|
|
|
|
sys.exit(exit_status)
|