aboutsummaryrefslogtreecommitdiff
path: root/circuitpython/tools/ci_fetch_deps.py
blob: 491d8da0e5496401179b370d1f47fcd2b76986cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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/",
        "lib/adafruit_floppy/",
        "lib/mp3/",
        "lib/protomatter/",
        "lib/quirc/",
        "lib/tinyusb/",
        "data/nvm.toml/",
    ],
    "broadcom": ["extmod/ulab/", "lib/tinyusb/"],
    "cxd56": ["extmod/ulab/", "lib/tinyusb/"],
    "espressif": ["extmod/ulab/", "lib/tinyusb/", "lib/protomatter/", "lib/quirc/"],
    "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/",
        "lib/adafruit_floppy/",
        "lib/mp3/",
        "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
}


def run(title, command):
    print("::group::" + title, flush=True)
    print(command, flush=True)
    start = time.monotonic()
    subprocess.run(shlex.split(command), stderr=subprocess.STDOUT)
    print("Duration:", time.monotonic() - start, flush=True)
    print("::endgroup::", flush=True)


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}',
)
run("Init submodules", "git submodule init")
run("Submodule status", "git submodule status")

submodules = []

if target == "test":
    submodules = ["extmod/", "lib/", "tools/", "extmod/ulab", "lib/berkeley-db-1.xx"]
elif target == "docs":
    # used in .readthedocs.yml to generate RTD
    submodules = ["extmod/ulab/", "frozen/"]
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/"]
elif target == "website":
    submodules = ["tools/adabot/", "frozen/"]
else:
    p = list(pathlib.Path(".").glob(f"ports/*/boards/{target}/mpconfigboard.mk"))
    if not p:
        raise RuntimeError(f"Unsupported target: {target}")

    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])
                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.
    run("Init the submodules we'll need", f"git submodule update --init -N --depth 1 {submodules}")

    run(
        "Fetch the submodule sha",
        "git submodule foreach 'git fetch --tags --depth 1 origin $sha1 && git checkout -q $sha1'",
    )