2023-01-14 06:40:40 -05:00
|
|
|
import os
|
2021-08-04 19:27:54 -04:00
|
|
|
import sys
|
|
|
|
import time
|
2023-01-14 06:40:40 -05:00
|
|
|
import shlex
|
|
|
|
import pathlib
|
|
|
|
import subprocess
|
2021-08-04 19:27:54 -04:00
|
|
|
|
2023-01-14 00:28:04 -05:00
|
|
|
# Target will be a board, "test", "docs", "mpy-cross-mac", or "windows"
|
|
|
|
TARGET = sys.argv[1]
|
2021-08-04 19:27:54 -04:00
|
|
|
|
|
|
|
# Submodules needed by port builds outside of their ports directory.
|
|
|
|
# Should we try and detect these?
|
2023-01-14 00:28:04 -05:00
|
|
|
PORT_DEPS = {
|
2021-08-04 19:27:54 -04:00
|
|
|
"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("::endgroup::", flush=True)
|
2023-01-14 00:28:04 -05:00
|
|
|
print("Duration:", time.monotonic() - start, flush=True)
|
|
|
|
|
2021-08-04 19:27:54 -04:00
|
|
|
|
2023-01-14 06:40:40 -05:00
|
|
|
def set_output(name, value):
|
|
|
|
if "GITHUB_OUTPUT" in os.environ:
|
|
|
|
with open(os.environ["GITHUB_OUTPUT"], "at") as f:
|
|
|
|
print(f"{name}={value}", file=f)
|
|
|
|
else:
|
|
|
|
print(f"Would set GitHub actions output {name} to '{value}'")
|
|
|
|
|
|
|
|
|
2023-01-14 00:28:04 -05:00
|
|
|
def main():
|
|
|
|
submodules = []
|
2023-01-14 06:40:40 -05:00
|
|
|
submodules_tags = []
|
|
|
|
|
2023-01-14 00:28:04 -05:00
|
|
|
print("Target:", TARGET)
|
2021-08-04 19:27:54 -04:00
|
|
|
|
2023-02-10 09:17:51 -05:00
|
|
|
if TARGET == "scheduler":
|
|
|
|
# submodules = ["tools/"]
|
|
|
|
submodules = ["extmod/ulab", "lib/", "tools/"]
|
|
|
|
elif TARGET == "tests":
|
2023-01-14 00:28:04 -05:00
|
|
|
submodules = ["extmod/ulab", "lib/", "tools/"]
|
2023-03-04 00:02:19 -05:00
|
|
|
elif TARGET == "docs":
|
2023-01-14 00:28:04 -05:00
|
|
|
# used in .readthedocs.yml to generate RTD
|
2023-02-23 02:19:34 -05:00
|
|
|
submodules = ["extmod/ulab"]
|
|
|
|
submodules_tags = ["frozen/"]
|
2023-02-10 09:17:51 -05:00
|
|
|
elif TARGET == "mpy-cross" or TARGET == "mpy-cross-mac":
|
2023-01-14 00:28:04 -05:00
|
|
|
submodules = ["tools/"] # for huffman
|
2023-03-04 00:02:19 -05:00
|
|
|
elif TARGET == "windows":
|
2023-01-14 00:28:04 -05:00
|
|
|
# This builds one board from a number of ports so fill out a bunch of submodules
|
|
|
|
submodules = ["extmod/ulab", "lib/", "tools/", "ports/", "data/nvm.toml"]
|
|
|
|
elif TARGET == "website":
|
2023-02-23 02:19:34 -05:00
|
|
|
submodules = ["tools/adabot/"]
|
|
|
|
submodules_tags = ["frozen/"]
|
2023-01-20 23:54:08 -05:00
|
|
|
elif TARGET == "pre-commit":
|
|
|
|
submodules = ["extmod/ulab"]
|
2023-01-14 00:28:04 -05:00
|
|
|
else:
|
|
|
|
p = list(pathlib.Path(".").glob(f"ports/*/boards/{TARGET}/mpconfigboard.mk"))
|
|
|
|
if not p:
|
|
|
|
raise RuntimeError(f"Unsupported target: {TARGET}")
|
2021-08-04 19:27:54 -04:00
|
|
|
|
2023-01-14 00:28:04 -05:00
|
|
|
config = p[0]
|
|
|
|
# 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])
|
2023-01-14 06:40:40 -05:00
|
|
|
submodules_tags.append(lib_folder)
|
2021-08-04 19:27:54 -04:00
|
|
|
|
2023-01-14 06:40:40 -05:00
|
|
|
print("Submodule tags[Y]:", submodules_tags)
|
|
|
|
print("Submodule tags[N]:", submodules)
|
|
|
|
|
|
|
|
if submodules_tags:
|
|
|
|
run(
|
|
|
|
"Init the submodules with tags",
|
|
|
|
f"git submodule update --init {' '.join(submodules_tags)}",
|
|
|
|
)
|
2021-08-04 19:27:54 -04:00
|
|
|
|
2023-01-14 00:28:04 -05:00
|
|
|
if submodules:
|
2023-01-14 06:40:40 -05:00
|
|
|
run(
|
|
|
|
"Init the submodules without tags",
|
|
|
|
f"git submodule update --init --depth=1 {' '.join(submodules)}",
|
|
|
|
)
|
|
|
|
|
|
|
|
for submodule in submodules_tags:
|
|
|
|
if submodule.startswith("frozen"):
|
|
|
|
set_output("frozen_tags", True)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
set_output("frozen_tags", False)
|
2021-08-04 19:27:54 -04:00
|
|
|
|
|
|
|
|
2023-01-14 00:28:04 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|