|
| 1 | +""" |
| 2 | +This is a helper script for merging in new versions of MicroPython. You *must* |
| 3 | +evaluate it's correctness and adapt it for each MP version. This is committed |
| 4 | +in the repo more for reference than "fire and forget" use. |
| 5 | +""" |
| 6 | + |
| 7 | +import sh |
| 8 | +from sh import git |
| 9 | +from io import StringIO |
| 10 | + |
| 11 | +out_buf = StringIO() |
| 12 | + |
| 13 | +ports_to_delete = [ |
| 14 | + "mimxrt", |
| 15 | + "powerpc", |
| 16 | + "samd", |
| 17 | + "javascript", |
| 18 | + "stm32", |
| 19 | + "esp32", |
| 20 | + "cc3200", |
| 21 | + "teensy", |
| 22 | + "windows", |
| 23 | + "zephyr", |
| 24 | + "minimal", |
| 25 | + "esp8266", |
| 26 | + "pic16bit", |
| 27 | + "qemu-arm", |
| 28 | + "bare-arm", |
| 29 | + "rp2", |
| 30 | +] |
| 31 | +for p in ports_to_delete: |
| 32 | + try: |
| 33 | + git.rm("-rf", "ports/" + p) |
| 34 | + except sh.ErrorReturnCode_128: |
| 35 | + pass |
| 36 | + |
| 37 | +# We inherit stm32 changes into stm because we did a git rename. |
| 38 | +git.status("--porcelain=1", "ports/stm", _out=out_buf) |
| 39 | +out_buf.seek(0) |
| 40 | +line = out_buf.readline() |
| 41 | +while line: |
| 42 | + state, path = line.split() |
| 43 | + if state == "UU": |
| 44 | + git.checkout("--ours", path) |
| 45 | + git.add(path) |
| 46 | + elif state == "UA": |
| 47 | + git.rm(path) |
| 48 | + line = out_buf.readline() |
| 49 | + |
| 50 | +# MicroPython added their nrf code in ports/nrf too. So, we always take our version. |
| 51 | +out_buf = StringIO() |
| 52 | +git.status("--porcelain=1", "ports/nrf", _out=out_buf) |
| 53 | +out_buf.seek(0) |
| 54 | +line = out_buf.readline() |
| 55 | +while line: |
| 56 | + state, path = line.split() |
| 57 | + if state == "UU": |
| 58 | + git.checkout("--ours", path) |
| 59 | + git.add(path) |
| 60 | + elif state == "UA": |
| 61 | + git.rm(path) |
| 62 | + elif state == "AA": |
| 63 | + git.rm("-f", path) |
| 64 | + elif state == "A": |
| 65 | + git.rm("-f", path) |
| 66 | + elif state == "DU": |
| 67 | + git.rm(path) |
| 68 | + elif state == "DD": |
| 69 | + git.rm(path) |
| 70 | + else: |
| 71 | + print(state, path) |
| 72 | + line = out_buf.readline() |
| 73 | + |
| 74 | + |
| 75 | +# MicroPython has their own CI settings. Let's not use them now. |
| 76 | +out_buf = StringIO() |
| 77 | +git.status("--porcelain=1", ".github/workflows", _out=out_buf) |
| 78 | +out_buf.seek(0) |
| 79 | +line = out_buf.readline() |
| 80 | +while line: |
| 81 | + state, path = line.split() |
| 82 | + if state == "A": |
| 83 | + git.rm("-f", path) |
| 84 | + else: |
| 85 | + print(state, path) |
| 86 | + line = out_buf.readline() |
| 87 | + |
| 88 | +# Delete docs and tests for things we don't need anymore |
| 89 | +docs_to_delete = [ |
| 90 | + "conf.py", |
| 91 | + "pyboard", |
| 92 | + "library/pyb.*", |
| 93 | + "library/esp*", |
| 94 | + "library/lcd160cr.rst", |
| 95 | + "esp8266", |
| 96 | + "wipy", |
| 97 | + "esp32", |
| 98 | + "library/machine.*", |
| 99 | + "library/network.*", |
| 100 | + "library/ubluetooth.rst", |
| 101 | + "library/ucryptolib.rst", |
| 102 | + "library/uos.rst", |
| 103 | + "library/usocket.rst", |
| 104 | + "library/ussl.rst", |
| 105 | + "library/ustruct.rst", |
| 106 | + "develop", |
| 107 | + "reference", |
| 108 | + "make.bat", |
| 109 | + "templates/topindex.html", |
| 110 | +] |
| 111 | +for d in docs_to_delete: |
| 112 | + try: |
| 113 | + git.rm("-rf", "docs/" + d) |
| 114 | + except sh.ErrorReturnCode_128: |
| 115 | + pass |
| 116 | + |
| 117 | +tests_to_delete = [ |
| 118 | + "wipy", |
| 119 | + "pyb", |
| 120 | + "multi_net", |
| 121 | + "net_inet", |
| 122 | + "multi_bluetooth", |
| 123 | + "esp32", |
| 124 | + "net_hosted", |
| 125 | +] |
| 126 | +for t in tests_to_delete: |
| 127 | + try: |
| 128 | + git.rm("-rf", "tests/" + t) |
| 129 | + except sh.ErrorReturnCode_128: |
| 130 | + pass |
| 131 | + |
| 132 | + |
| 133 | +libs_to_delete = [ |
| 134 | + "mynewt-nimble", |
| 135 | + "nxp_driver", |
| 136 | + "mbedtls", |
| 137 | + "mbedtls_errors", |
| 138 | + "asf4", |
| 139 | + "btstack", |
| 140 | +] |
| 141 | +for l in libs_to_delete: |
| 142 | + try: |
| 143 | + git.rm("-rf", "lib/" + l) |
| 144 | + except sh.ErrorReturnCode_128: |
| 145 | + pass |
| 146 | + |
| 147 | +extmod_to_delete = [ |
| 148 | + "machine_*", |
| 149 | + "webrepl", |
| 150 | + "uzlib", |
| 151 | + "ussl*", |
| 152 | + "modlwip.c", |
| 153 | + "moducryptolib.c", |
| 154 | + "modbluetooth*", |
| 155 | + "network*", |
| 156 | + "nimble", |
| 157 | + "btstack", |
| 158 | + "mpbthci*", |
| 159 | +] |
| 160 | +for e in extmod_to_delete: |
| 161 | + try: |
| 162 | + git.rm("-rf", "extmod/" + e) |
| 163 | + except sh.ErrorReturnCode_128 as error: |
| 164 | + print(error) |
| 165 | + pass |
| 166 | + |
| 167 | +top_delete = [ |
| 168 | + "drivers", |
| 169 | + ".travis.yml", |
| 170 | + ".github/FUNDING.yml", |
| 171 | + ".github/workflows/docs.yml", |
| 172 | + "README.md", |
| 173 | + "CODEOFCONDUCT.md", |
| 174 | + "CODECONVENTIONS.md", |
| 175 | + "examples", |
| 176 | +] |
| 177 | +for t in top_delete: |
| 178 | + try: |
| 179 | + git.rm("-rf", t) |
| 180 | + except sh.ErrorReturnCode_128: |
| 181 | + pass |
| 182 | + |
| 183 | +# Always ours: |
| 184 | +always_ours = [ |
| 185 | + "devices", |
| 186 | + "supervisor", |
| 187 | + "shared-bindings", |
| 188 | + "shared-module", |
| 189 | + "ports/atmel-samd", |
| 190 | + "ports/cxd56", |
| 191 | + "ports/esp32s2", |
| 192 | + "ports/mimxrt10xx", |
| 193 | + "ports/raspberrypi", |
| 194 | + "ports/stm", |
| 195 | +] |
| 196 | +for ours in always_ours: |
| 197 | + out_buf = StringIO() |
| 198 | + git.status("--porcelain=1", ours, _out=out_buf) |
| 199 | + out_buf.seek(0) |
| 200 | + line = out_buf.readline() |
| 201 | + while line: |
| 202 | + state, path = line.split() |
| 203 | + if state == "UU": |
| 204 | + print("ours", path) |
| 205 | + git.checkout("--ours", path) |
| 206 | + git.add(path) |
| 207 | + else: |
| 208 | + print(state, path) |
| 209 | + line = out_buf.readline() |
| 210 | + |
| 211 | +# Check to see if any files changed only in formatting |
| 212 | +out_buf = StringIO() |
| 213 | +git.status("--porcelain=1", ".", _out=out_buf) |
| 214 | +out_buf.seek(0) |
| 215 | +line = out_buf.readline() |
| 216 | +while line: |
| 217 | + state = line.split()[0] |
| 218 | + if state in ("D", "R", "DD"): |
| 219 | + line = out_buf.readline() |
| 220 | + continue |
| 221 | + state, path = line.split() |
| 222 | + log_buf = StringIO() |
| 223 | + git.log("--pretty=tformat:%H", "25ae98f..HEAD", path, _out=log_buf, _tty_out=False) |
| 224 | + log_buf.seek(0) |
| 225 | + commits = [] |
| 226 | + for line in log_buf.readlines(): |
| 227 | + commits.append(line.strip()) |
| 228 | + if state in ["UU", "M"] and commits == ["a52eb88031620a81521b937f2a0651dbac2bb350"]: |
| 229 | + git.checkout("--theirs", path) |
| 230 | + git.add(path) |
| 231 | + line = out_buf.readline() |
0 commit comments