From 3e2491476d29346206c9fa8a5a908fa9ce6921df Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Fri, 14 Feb 2025 11:06:15 -0600 Subject: [PATCH] build: script now downloads git+https deps --- build.zig.zon.nix | 6 ++-- build.zig.zon2json-lock | 6 ++-- pkg/wuffs/build.zig.zon | 2 +- src/build/deps.py | 78 +++++++++++++++++++++++++++++++++++------ 4 files changed, 74 insertions(+), 18 deletions(-) diff --git a/build.zig.zon.nix b/build.zig.zon.nix index 06e0c8a75..4ffc264be 100644 --- a/build.zig.zon.nix +++ b/build.zig.zon.nix @@ -232,7 +232,7 @@ in path = fetchZigArtifact { name = "wayland"; url = "https://deps.files.ghostty.org/wayland-9cb3d7aa9dc995ffafdbdef7ab86a949d0fb0e7d.tar.gz"; - hash = "sha256-m9G72jdG30KH2yQhNBcBJ46OnekzuX0i2uIOyczkpLk="; + hash = "sha256-6kGR1o5DdnflHzqs3ieCmBAUTpMdOXoyfcYDXiw5xQ0="; }; } { @@ -367,8 +367,8 @@ in name = "12207ff340169c7d40c570b4b6a97db614fe47e0d83b5801a932dcd44917424c8806"; path = fetchZigArtifact { name = "pixels"; - url = "https://github.com/make-github-pseudonymous-again/pixels/d843c2714d32e15b48b8d7eeb480295af537f877.tar.gz"; - hash = "sha256-ABnfxLMtY8E5KqJkrtIlPB4ML7CSFvjizCabv7i7SbU="; + url = "https://github.com/make-github-pseudonymous-again/pixels/archive/d843c2714d32e15b48b8d7eeb480295af537f877.tar.gz"; + hash = "sha256-Veg7FtCRCCUCvxSb9FfzH0IJLFmCZQ4/+657SIcb8Ro="; }; } { diff --git a/build.zig.zon2json-lock b/build.zig.zon2json-lock index 0619a450a..c4ad47795 100644 --- a/build.zig.zon2json-lock +++ b/build.zig.zon2json-lock @@ -92,7 +92,7 @@ "12202cdac858abc52413a6c6711d5026d2d3c8e13f95ca2c327eade0736298bb021f": { "name": "wayland", "url": "https://deps.files.ghostty.org/wayland-9cb3d7aa9dc995ffafdbdef7ab86a949d0fb0e7d.tar.gz", - "hash": "sha256-m9G72jdG30KH2yQhNBcBJ46OnekzuX0i2uIOyczkpLk=" + "hash": "sha256-6kGR1o5DdnflHzqs3ieCmBAUTpMdOXoyfcYDXiw5xQ0=" }, "12201a57c6ce0001aa034fa80fba3e1cd2253c560a45748f4f4dd21ff23b491cddef": { "name": "wayland_protocols", @@ -176,8 +176,8 @@ }, "12207ff340169c7d40c570b4b6a97db614fe47e0d83b5801a932dcd44917424c8806": { "name": "pixels", - "url": "https://github.com/make-github-pseudonymous-again/pixels/d843c2714d32e15b48b8d7eeb480295af537f877.tar.gz", - "hash": "sha256-ABnfxLMtY8E5KqJkrtIlPB4ML7CSFvjizCabv7i7SbU=" + "url": "https://github.com/make-github-pseudonymous-again/pixels/archive/d843c2714d32e15b48b8d7eeb480295af537f877.tar.gz", + "hash": "sha256-Veg7FtCRCCUCvxSb9FfzH0IJLFmCZQ4/+657SIcb8Ro=" }, "12201278a1a05c0ce0b6eb6026c65cd3e9247aa041b1c260324bf29cee559dd23ba1": { "name": "glslang", diff --git a/pkg/wuffs/build.zig.zon b/pkg/wuffs/build.zig.zon index 673b4e815..dc35b22cd 100644 --- a/pkg/wuffs/build.zig.zon +++ b/pkg/wuffs/build.zig.zon @@ -8,7 +8,7 @@ }, .pixels = .{ - .url = "https://github.com/make-github-pseudonymous-again/pixels/d843c2714d32e15b48b8d7eeb480295af537f877.tar.gz", + .url = "https://github.com/make-github-pseudonymous-again/pixels/archive/d843c2714d32e15b48b8d7eeb480295af537f877.tar.gz", .hash = "12207ff340169c7d40c570b4b6a97db614fe47e0d83b5801a932dcd44917424c8806", }, diff --git a/src/build/deps.py b/src/build/deps.py index 7fb59eb10..e2fb84280 100644 --- a/src/build/deps.py +++ b/src/build/deps.py @@ -1,9 +1,61 @@ import json import pathlib +import subprocess +import tempfile import urllib.parse import urllib.request +def clone(deps: pathlib.Path, name: str, url: urllib.parse.ParseResult) -> pathlib.Path: + repo = urllib.parse.ParseResult( + scheme=url.scheme.removeprefix("git+"), + netloc=url.netloc, + path=url.path, + params="", + query="", + fragment="", + ) + file = deps / f"{name}-{url.fragment}.tar.gz" + with tempfile.TemporaryDirectory() as tmp: + tmpdir = pathlib.Path(tmp) + archivedir = tmpdir / f"{name}-{url.fragment}" + archivedir.mkdir() + subprocess.run( + ["git", "init"], + cwd=str(archivedir), + check=True, + ) + subprocess.run( + ["git", "remote", "add", "origin", repo.geturl()], + cwd=str(archivedir), + check=True, + ) + subprocess.run( + ["git", "fetch", "origin", "--depth=1", url.fragment], + cwd=str(archivedir), + check=True, + ) + subprocess.run( + ["git", "checkout", "FETCH_HEAD"], + cwd=str(archivedir), + check=True, + ) + subprocess.run( + [ + "tar", + "--create", + "--file", + str(file.resolve()), + "--exclude", + ".git", + f"{name}-{url.fragment}", + ], + cwd=str(tmpdir), + check=True, + ) + return file + + def main() -> None: deps = pathlib.Path("deps") deps.mkdir(exist_ok=True) @@ -13,18 +65,22 @@ def main() -> None: continue url = urllib.parse.urlparse(data["url"]) if url.scheme.startswith("git+"): - continue - path = pathlib.Path(url.path) - basename = path.parts[-1] - if not basename.startswith(f"{data["name"]}-"): - file = deps / f"{data["name"]}-{basename}" + file = clone(deps, data["name"], url) + print(f"{data["url"]} -> {file}") else: - file = deps / basename - req = urllib.request.Request(data["url"], headers={"User-Agent": "ghostty/1.0"}) - with urllib.request.urlopen(req) as response: - body = response.read() - file.write_bytes(body) - print(f"{data["url"]} -> https://deps.files.ghostty.org/{file.parts[-1]}") + path = pathlib.Path(url.path) + basename = path.parts[-1] + if not basename.startswith(f"{data["name"]}-"): + file = deps / f"{data["name"]}-{basename}" + else: + file = deps / basename + req = urllib.request.Request( + data["url"], headers={"User-Agent": "ghostty-downloader/1.0"} + ) + with urllib.request.urlopen(req) as response: + body = response.read() + file.write_bytes(body) + print(f"{data["url"]} -> {file}") if __name__ == "__main__":