mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-11-23 23:03:06 +05:00
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.
This commit is contained in:
1 parent
dc72966aca
commit
765508993a
1 file changed
+22
-4
+22
-4
@@ -3,6 +3,7 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
from SCons.Script import Return
|
from SCons.Script import Return
|
||||||
|
|
||||||
@@ -16,10 +17,27 @@ def checkout(repository, revision, directory):
|
|||||||
if not (directory / ".git").is_dir():
|
if not (directory / ".git").is_dir():
|
||||||
subprocess.run(["git", "clone", "--filter=blob:none", "--no-checkout",
|
subprocess.run(["git", "clone", "--filter=blob:none", "--no-checkout",
|
||||||
repository, str(directory)], check=True)
|
repository, str(directory)], check=True)
|
||||||
current = subprocess.run(["git", "-C", str(directory), "rev-parse", "HEAD"],
|
result = subprocess.run(["git", "-C", str(directory), "rev-parse", "--verify", revision + "^{commit}"],
|
||||||
check=True, capture_output=True, text=True).stdout.strip()
|
capture_output=True, text=True)
|
||||||
if not current.startswith(revision):
|
if result.returncode:
|
||||||
subprocess.run(["git", "-C", str(directory), "checkout", "--detach", revision], check=True)
|
# 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()
|
platform = env.PioPlatform()
|
||||||
|
|||||||
Reference in new issue
Block a user