From 765508993ac03632dc6678b1e160c65d6e945163 Mon Sep 17 00:00:00 2001 From: Yurii Date: Mon, 23 Nov 2026 17:52:07 +0300 Subject: [PATCH] fix: recover missing source revisions in S2 TinyUSB builds Resolve missing SDK revisions to their full GitHub commit IDs and fetch those commits explicitly before checkout. Keep using the matching source revision when upstream branches no longer expose it. Always materialize the requested checkout, including fresh no-checkout clones whose HEAD already matches the pinned revision. Cached commits continue to work without API requests. --- tools/tinyusb_s2.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/tinyusb_s2.py b/tools/tinyusb_s2.py index e5d4422..a081e3d 100644 --- a/tools/tinyusb_s2.py +++ b/tools/tinyusb_s2.py @@ -3,6 +3,7 @@ from pathlib import Path import shutil import subprocess +from urllib.request import Request, urlopen from SCons.Script import Return @@ -16,10 +17,27 @@ def checkout(repository, revision, directory): if not (directory / ".git").is_dir(): subprocess.run(["git", "clone", "--filter=blob:none", "--no-checkout", repository, str(directory)], check=True) - current = subprocess.run(["git", "-C", str(directory), "rev-parse", "HEAD"], - check=True, capture_output=True, text=True).stdout.strip() - if not current.startswith(revision): - subprocess.run(["git", "-C", str(directory), "checkout", "--detach", revision], check=True) + result = subprocess.run(["git", "-C", str(directory), "rev-parse", "--verify", revision + "^{commit}"], + capture_output=True, text=True) + if result.returncode: + # SDK metadata can reference commits no longer reachable from upstream branches. + api = repository.removesuffix(".git").replace("https://github.com/", "https://api.github.com/repos/", 1) + request = Request(api + "/commits/" + revision, headers={ + "Accept": "application/vnd.github.sha", + "User-Agent": "OTGateway" + }) + with urlopen(request, timeout=30) as response: + commit = response.read().decode("ascii").strip() + if (len(commit) != 40 or not commit.startswith(revision) + or any(char not in "0123456789abcdef" for char in commit)): + raise RuntimeError("Unexpected GitHub commit for SDK revision " + revision) + subprocess.run(["git", "-C", str(directory), "fetch", "--depth=1", "origin", commit], check=True) + + else: + commit = result.stdout.strip() + + # A fresh --no-checkout clone can have the correct HEAD and still lack its files. + subprocess.run(["git", "-C", str(directory), "checkout", "--detach", commit], check=True) platform = env.PioPlatform()