2021-08-04 19:27:54 -04:00
|
|
|
import pathlib
|
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
# target will be a board, "test", "docs", "mpy-cross-mac", or "windows"
|
|
|
|
|
|
|
|
target = sys.argv[1]
|
|
|
|
ref = sys.argv[2]
|
|
|
|
|
|
|
|
print(target, ref)
|
|
|
|
|
|
|
|
# Submodules needed by port builds outside of their ports directory.
|
|
|
|
# Should we try and detect these?
|
|
|
|
port_deps = {
|
|
|
|
"atmel-samd": [
|
|
|
|
"extmod/ulab/",
|
2022-02-02 11:14:19 -05:00
|
|
|
"lib/adafruit_floppy/",
|
2021-08-04 19:27:54 -04:00
|
|
|
"lib/mp3/",
|
|
|
|
"lib/protomatter/",
|
|
|
|
"lib/quirc/",
|
|
|
|
"lib/tinyusb/",
|
|
|
|
"data/nvm.toml/",
|
|
|
|
],
|
2021-12-15 13:56:27 -05:00
|
|
|
"broadcom": ["extmod/ulab/", "lib/tinyusb/"],
|
2021-08-04 19:27:54 -04:00
|
|
|
"cxd56": ["extmod/ulab/", "lib/tinyusb/"],
|
2022-10-05 17:17:58 -04:00
|
|
|
"espressif": [
|
|
|
|
"extmod/ulab/",
|
|
|
|
"lib/certificates/nina-fw/",
|
|
|
|
"lib/protomatter/",
|
|
|
|
"lib/quirc/",
|
|
|
|
"lib/tinyusb/",
|
|
|
|
],
|
2021-08-04 19:27:54 -04:00
|
|
|
"litex": ["extmod/ulab/", "lib/tinyusb/"],
|
|
|
|
"mimxrt10xx": ["extmod/ulab/", "lib/tinyusb/", "data/nvm.toml/"],
|
|
|
|
"nrf": ["extmod/ulab/", "lib/mp3/", "lib/protomatter/", "lib/tinyusb/", "data/nvm.toml/"],
|
|
|
|
"raspberrypi": [
|
|
|
|
"extmod/ulab/",
|
2022-02-02 11:14:19 -05:00
|
|
|
"lib/adafruit_floppy/",
|
2022-09-29 10:08:28 -04:00
|
|
|
"lib/mbedtls/",
|
2021-08-04 19:27:54 -04:00
|
|
|
"lib/mp3/",
|
2022-10-05 17:17:58 -04:00
|
|
|
"lib/certificates/nina-fw/",
|
2021-08-04 19:27:54 -04:00
|
|
|
"lib/protomatter/",
|
|
|
|
"lib/quirc/",
|
|
|
|
"lib/tinyusb/",
|
|
|
|
"data/nvm.toml/",
|
|
|
|
],
|
|
|
|
"stm": ["extmod/ulab/", "lib/mp3/", "lib/protomatter/", "lib/tinyusb/", "data/nvm.toml/"]
|
|
|
|
# omit unix which is part of the "test" target below
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-14 16:16:28 -04:00
|
|
|
def run(title, command, check=True):
|
2021-08-04 19:27:54 -04:00
|
|
|
print("::group::" + title, flush=True)
|
|
|
|
print(command, flush=True)
|
|
|
|
start = time.monotonic()
|
2022-07-13 15:53:25 -04:00
|
|
|
try:
|
2022-07-14 16:16:28 -04:00
|
|
|
subprocess.run(shlex.split(command), stderr=subprocess.STDOUT, check=check)
|
2022-07-13 15:53:25 -04:00
|
|
|
finally:
|
|
|
|
print("Duration:", time.monotonic() - start, flush=True)
|
|
|
|
print("::endgroup::", flush=True)
|
2021-08-04 19:27:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
run(
|
|
|
|
"Fetch back to the start of 2021 to get tag history",
|
|
|
|
'git fetch --tags --recurse-submodules=no --shallow-since="2021-07-01" https://github.com/adafruit/circuitpython HEAD',
|
|
|
|
)
|
|
|
|
run(
|
|
|
|
"Fetch back to the start of 2021 to get commit history",
|
|
|
|
f'git fetch --recurse-submodules=no --shallow-since="2021-07-01" origin {ref}',
|
|
|
|
)
|
2023-01-07 07:22:33 -05:00
|
|
|
# See https://stackoverflow.com/questions/63878612/git-fatal-error-in-object-unshallow-sha-1#comment118418373_63879454
|
2023-01-07 08:30:54 -05:00
|
|
|
run('Fix for bug "fatal: error in object: unshallow"', "git repack -d")
|
2021-08-04 19:27:54 -04:00
|
|
|
run("Init submodules", "git submodule init")
|
|
|
|
run("Submodule status", "git submodule status")
|
|
|
|
|
|
|
|
submodules = []
|
|
|
|
|
|
|
|
if target == "test":
|
2022-02-16 11:31:43 -05:00
|
|
|
submodules = ["extmod/", "lib/", "tools/", "extmod/ulab", "lib/berkeley-db-1.xx"]
|
2021-08-04 19:27:54 -04:00
|
|
|
elif target == "docs":
|
2022-05-14 10:46:09 -04:00
|
|
|
# used in .readthedocs.yml to generate RTD
|
2022-05-11 08:49:29 -04:00
|
|
|
submodules = ["extmod/ulab/", "frozen/"]
|
2021-08-04 19:27:54 -04:00
|
|
|
elif target == "mpy-cross-mac":
|
|
|
|
submodules = ["tools/"] # for huffman
|
|
|
|
elif target == "windows":
|
|
|
|
# This builds one board from a number of ports so fill out a bunch of submodules
|
|
|
|
submodules = ["extmod/", "lib/", "tools/", "ports/", "data/nvm.toml/"]
|
2021-11-30 15:49:20 -05:00
|
|
|
elif target == "website":
|
2022-05-11 08:49:29 -04:00
|
|
|
submodules = ["tools/adabot/", "frozen/"]
|
2021-08-04 19:27:54 -04:00
|
|
|
else:
|
2021-11-30 15:49:20 -05:00
|
|
|
p = list(pathlib.Path(".").glob(f"ports/*/boards/{target}/mpconfigboard.mk"))
|
2021-08-04 19:27:54 -04:00
|
|
|
if not p:
|
|
|
|
raise RuntimeError(f"Unsupported target: {target}")
|
|
|
|
|
2021-11-30 15:49:20 -05:00
|
|
|
config = p[0]
|
2021-08-04 19:27:54 -04:00
|
|
|
# Add the ports folder to init submodules
|
|
|
|
port_folder = config.parents[2]
|
|
|
|
port = port_folder.name
|
|
|
|
submodules.append(str(port_folder))
|
|
|
|
submodules.append("tools/") # for huffman
|
|
|
|
submodules.extend(port_deps[port])
|
|
|
|
with config.open() as f:
|
|
|
|
for line in f.readlines():
|
|
|
|
prefix = "FROZEN_MPY_DIRS += $(TOP)/"
|
|
|
|
if line.startswith(prefix):
|
|
|
|
lib_folder = line.strip()[len(prefix) :]
|
|
|
|
# Drop everything after the second folder because the frozen
|
|
|
|
# folder may be inside the submodule.
|
|
|
|
if lib_folder.count("/") > 1:
|
|
|
|
lib_folder = lib_folder.split("/", maxsplit=2)
|
|
|
|
lib_folder = "/".join(lib_folder[:2])
|
|
|
|
submodules.append(lib_folder)
|
|
|
|
|
|
|
|
print(submodules)
|
|
|
|
if submodules:
|
|
|
|
submodules = " ".join(submodules)
|
|
|
|
# This line will fail because the submodule's need different commits than the tip of the branch. We
|
|
|
|
# fix it later.
|
2022-07-14 16:16:28 -04:00
|
|
|
run(
|
|
|
|
"Init the submodules we'll need",
|
|
|
|
f"git submodule update --init -N --depth 1 {submodules}",
|
|
|
|
check=False,
|
|
|
|
)
|
2021-08-04 19:27:54 -04:00
|
|
|
|
|
|
|
run(
|
|
|
|
"Fetch the submodule sha",
|
|
|
|
"git submodule foreach 'git fetch --tags --depth 1 origin $sha1 && git checkout -q $sha1'",
|
|
|
|
)
|