build: script now downloads git+https deps

This commit is contained in:
Jeffrey C. Ollie
2025-02-14 11:06:15 -06:00
parent 8eb1f3347d
commit 3e2491476d
4 changed files with 74 additions and 18 deletions

6
build.zig.zon.nix generated
View File

@ -232,7 +232,7 @@ in
path = fetchZigArtifact { path = fetchZigArtifact {
name = "wayland"; name = "wayland";
url = "https://deps.files.ghostty.org/wayland-9cb3d7aa9dc995ffafdbdef7ab86a949d0fb0e7d.tar.gz"; url = "https://deps.files.ghostty.org/wayland-9cb3d7aa9dc995ffafdbdef7ab86a949d0fb0e7d.tar.gz";
hash = "sha256-m9G72jdG30KH2yQhNBcBJ46OnekzuX0i2uIOyczkpLk="; hash = "sha256-6kGR1o5DdnflHzqs3ieCmBAUTpMdOXoyfcYDXiw5xQ0=";
}; };
} }
{ {
@ -367,8 +367,8 @@ in
name = "12207ff340169c7d40c570b4b6a97db614fe47e0d83b5801a932dcd44917424c8806"; name = "12207ff340169c7d40c570b4b6a97db614fe47e0d83b5801a932dcd44917424c8806";
path = fetchZigArtifact { path = fetchZigArtifact {
name = "pixels"; name = "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 = "sha256-ABnfxLMtY8E5KqJkrtIlPB4ML7CSFvjizCabv7i7SbU="; hash = "sha256-Veg7FtCRCCUCvxSb9FfzH0IJLFmCZQ4/+657SIcb8Ro=";
}; };
} }
{ {

View File

@ -92,7 +92,7 @@
"12202cdac858abc52413a6c6711d5026d2d3c8e13f95ca2c327eade0736298bb021f": { "12202cdac858abc52413a6c6711d5026d2d3c8e13f95ca2c327eade0736298bb021f": {
"name": "wayland", "name": "wayland",
"url": "https://deps.files.ghostty.org/wayland-9cb3d7aa9dc995ffafdbdef7ab86a949d0fb0e7d.tar.gz", "url": "https://deps.files.ghostty.org/wayland-9cb3d7aa9dc995ffafdbdef7ab86a949d0fb0e7d.tar.gz",
"hash": "sha256-m9G72jdG30KH2yQhNBcBJ46OnekzuX0i2uIOyczkpLk=" "hash": "sha256-6kGR1o5DdnflHzqs3ieCmBAUTpMdOXoyfcYDXiw5xQ0="
}, },
"12201a57c6ce0001aa034fa80fba3e1cd2253c560a45748f4f4dd21ff23b491cddef": { "12201a57c6ce0001aa034fa80fba3e1cd2253c560a45748f4f4dd21ff23b491cddef": {
"name": "wayland_protocols", "name": "wayland_protocols",
@ -176,8 +176,8 @@
}, },
"12207ff340169c7d40c570b4b6a97db614fe47e0d83b5801a932dcd44917424c8806": { "12207ff340169c7d40c570b4b6a97db614fe47e0d83b5801a932dcd44917424c8806": {
"name": "pixels", "name": "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": "sha256-ABnfxLMtY8E5KqJkrtIlPB4ML7CSFvjizCabv7i7SbU=" "hash": "sha256-Veg7FtCRCCUCvxSb9FfzH0IJLFmCZQ4/+657SIcb8Ro="
}, },
"12201278a1a05c0ce0b6eb6026c65cd3e9247aa041b1c260324bf29cee559dd23ba1": { "12201278a1a05c0ce0b6eb6026c65cd3e9247aa041b1c260324bf29cee559dd23ba1": {
"name": "glslang", "name": "glslang",

View File

@ -8,7 +8,7 @@
}, },
.pixels = .{ .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", .hash = "12207ff340169c7d40c570b4b6a97db614fe47e0d83b5801a932dcd44917424c8806",
}, },

View File

@ -1,9 +1,61 @@
import json import json
import pathlib import pathlib
import subprocess
import tempfile
import urllib.parse import urllib.parse
import urllib.request 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: def main() -> None:
deps = pathlib.Path("deps") deps = pathlib.Path("deps")
deps.mkdir(exist_ok=True) deps.mkdir(exist_ok=True)
@ -13,18 +65,22 @@ def main() -> None:
continue continue
url = urllib.parse.urlparse(data["url"]) url = urllib.parse.urlparse(data["url"])
if url.scheme.startswith("git+"): if url.scheme.startswith("git+"):
continue file = clone(deps, data["name"], url)
print(f"{data["url"]} -> {file}")
else:
path = pathlib.Path(url.path) path = pathlib.Path(url.path)
basename = path.parts[-1] basename = path.parts[-1]
if not basename.startswith(f"{data["name"]}-"): if not basename.startswith(f"{data["name"]}-"):
file = deps / f"{data["name"]}-{basename}" file = deps / f"{data["name"]}-{basename}"
else: else:
file = deps / basename file = deps / basename
req = urllib.request.Request(data["url"], headers={"User-Agent": "ghostty/1.0"}) req = urllib.request.Request(
data["url"], headers={"User-Agent": "ghostty-downloader/1.0"}
)
with urllib.request.urlopen(req) as response: with urllib.request.urlopen(req) as response:
body = response.read() body = response.read()
file.write_bytes(body) file.write_bytes(body)
print(f"{data["url"]} -> https://deps.files.ghostty.org/{file.parts[-1]}") print(f"{data["url"]} -> {file}")
if __name__ == "__main__": if __name__ == "__main__":