mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-11-23 23:03:06 +05:00
fix: download TinyUSB sources using SDK revisions
Download lib-builder and TinyUSB source snapshots directly using the revisions in the installed SDK versions.txt. Avoid the GitHub REST lookup without maintaining a separate set of commit pins. Check the archive commit ID, extract the required files and reuse completed downloads. Incomplete extraction is retried on the next invocation.
This commit is contained in:
1 parent
765508993a
commit
39a0f34798
1 file changed
+28
-28
+28
-28
@@ -1,9 +1,10 @@
|
|||||||
"""Provide Arduino TinyUSB for the ESP32-S2 HybridCompile SDK."""
|
"""Provide Arduino TinyUSB for the ESP32-S2 HybridCompile SDK."""
|
||||||
|
|
||||||
|
from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
|
||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from SCons.Script import Return
|
from SCons.Script import Return
|
||||||
|
|
||||||
@@ -13,31 +14,27 @@ if env.IsCleanTarget():
|
|||||||
Return()
|
Return()
|
||||||
|
|
||||||
|
|
||||||
def checkout(repository, revision, directory):
|
def download_sources(repository, revision, cache, paths):
|
||||||
if not (directory / ".git").is_dir():
|
directory = cache / (repository.rsplit("/", 1)[-1] + "-" + revision)
|
||||||
subprocess.run(["git", "clone", "--filter=blob:none", "--no-checkout",
|
marker = directory / ".ready"
|
||||||
repository, str(directory)], check=True)
|
if marker.is_file() and all((directory / path).exists() for path in paths):
|
||||||
result = subprocess.run(["git", "-C", str(directory), "rev-parse", "--verify", revision + "^{commit}"],
|
return directory
|
||||||
capture_output=True, text=True)
|
marker.unlink(missing_ok=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:
|
request = Request("https://codeload.github.com/" + repository + "/zip/" + revision,
|
||||||
commit = result.stdout.strip()
|
headers={"User-Agent": "OTGateway"})
|
||||||
|
with urlopen(request, timeout=60) as response, ZipFile(BytesIO(response.read())) as archive:
|
||||||
|
if len(archive.comment) != 40 or not archive.comment.decode("ascii").startswith(revision):
|
||||||
|
raise RuntimeError("Source archive does not match SDK revision " + revision)
|
||||||
|
prefix = directory.name + "/"
|
||||||
|
members = [name for name in archive.namelist()
|
||||||
|
if any(name == prefix + path or name.startswith(prefix + path + "/") for path in paths)]
|
||||||
|
archive.extractall(cache, members=members)
|
||||||
|
|
||||||
# A fresh --no-checkout clone can have the correct HEAD and still lack its files.
|
if not all((directory / path).exists() for path in paths):
|
||||||
subprocess.run(["git", "-C", str(directory), "checkout", "--detach", commit], check=True)
|
raise RuntimeError("Source archive is missing required files")
|
||||||
|
marker.touch()
|
||||||
|
return directory
|
||||||
|
|
||||||
|
|
||||||
platform = env.PioPlatform()
|
platform = env.PioPlatform()
|
||||||
@@ -53,12 +50,15 @@ for line in (sdk / "versions.txt").read_text(encoding="utf-8").splitlines():
|
|||||||
|
|
||||||
builder_revision = versions["lib-builder"]
|
builder_revision = versions["lib-builder"]
|
||||||
tinyusb_revision = versions["tinyusb"]
|
tinyusb_revision = versions["tinyusb"]
|
||||||
|
|
||||||
cache = project / ".pio/tinyusb-s2"
|
cache = project / ".pio/tinyusb-s2"
|
||||||
cache.mkdir(parents=True, exist_ok=True)
|
cache.mkdir(parents=True, exist_ok=True)
|
||||||
builder = cache / ("lib-builder-" + builder_revision)
|
sources = cache / "sources"
|
||||||
tinyusb = cache / ("tinyusb-" + tinyusb_revision)
|
sources.mkdir(exist_ok=True)
|
||||||
checkout("https://github.com/espressif/esp32-arduino-lib-builder.git", builder_revision, builder)
|
builder = download_sources("espressif/esp32-arduino-lib-builder", builder_revision, sources,
|
||||||
checkout("https://github.com/hathach/tinyusb.git", tinyusb_revision, tinyusb)
|
("components/arduino_tinyusb/CMakeLists.txt",
|
||||||
|
"components/arduino_tinyusb/Kconfig.projbuild", "components/arduino_tinyusb/include"))
|
||||||
|
tinyusb = download_sources("hathach/tinyusb", tinyusb_revision, sources, ("src", "hw/bsp"))
|
||||||
|
|
||||||
original = builder / "components/arduino_tinyusb"
|
original = builder / "components/arduino_tinyusb"
|
||||||
component = cache / ("component-" + builder_revision + "-" + tinyusb_revision) / "arduino_tinyusb"
|
component = cache / ("component-" + builder_revision + "-" + tinyusb_revision) / "arduino_tinyusb"
|
||||||
|
|||||||
Reference in new issue
Block a user