electron: adapt updater to the new gn package

Co-authored-by: emilylange <git@emilylange.de>
Signed-off-by: Marcin Serwin <marcin@serwin.dev>
This commit is contained in:
Marcin Serwin
2025-08-09 08:53:43 +02:00
co-authored by emilylange
parent ab74600708
commit e5a76165ea
+26 -15
View File
@@ -1,5 +1,5 @@
#! /usr/bin/env nix-shell
#! nix-shell -i python -p python3.pkgs.joblib python3.pkgs.click python3.pkgs.click-log nix nix-prefetch-git prefetch-yarn-deps prefetch-npm-deps gclient2nix
#! nix-shell -i python -p python3.pkgs.joblib python3.pkgs.click python3.pkgs.click-log nix nurl prefetch-yarn-deps prefetch-npm-deps gclient2nix
"""
electron updater
@@ -32,7 +32,7 @@ import urllib.request
import click
import click_log
from datetime import datetime
from datetime import datetime, UTC
from typing import Iterable, Tuple
from urllib.request import urlopen
from joblib import Parallel, delayed, Memory
@@ -44,6 +44,9 @@ SOURCE_INFO_JSON = "info.json"
os.chdir(os.path.dirname(__file__))
# Absolute path of nixpkgs top-level directory
NIXPKGS_PATH = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip()
memory: Memory = Memory("cache", verbose=0)
logger = logging.getLogger(__name__)
@@ -78,26 +81,34 @@ def get_electron_file(electron_tag: str, filepath: str) -> str:
)
@memory.cache
def get_gn_hash(gn_version, gn_commit):
print("gn.override", file=sys.stderr)
expr = f'(import {NIXPKGS_PATH} {{}}).gn.override {{ version = "{gn_version}"; rev = "{gn_commit}"; hash = ""; }}'
out = subprocess.check_output(["nurl", "--hash", "--expr", expr])
return out.decode("utf-8").strip()
@memory.cache
def get_chromium_gn_source(chromium_tag: str) -> dict:
gn_pattern = r"'gn_version': 'git_revision:([0-9a-f]{40})'"
gn_commit = re.search(gn_pattern, get_chromium_file(chromium_tag, "DEPS")).group(1)
gn_prefetch: bytes = subprocess.check_output(
[
"nix-prefetch-git",
"--quiet",
"https://gn.googlesource.com/gn",
"--rev",
gn_commit,
]
gn_commit_info = json.loads(
urlopen(f"https://gn.googlesource.com/gn/+/{gn_commit}?format=json")
.read()
.decode("utf-8")
.split(")]}'\n")[1]
)
gn: dict = json.loads(gn_prefetch)
gn_commit_date = datetime.strptime(gn_commit_info["commiter"]["time"], "%a %b %d %H:%M:%S %Y %z")
gn_date = gn_commit_date.astimezone(UTC).date().isoformat()
gn_version = f"0-unstable-{gn_date}"
return {
"gn": {
"version": datetime.fromisoformat(gn["date"]).date().isoformat(),
"url": gn["url"],
"rev": gn["rev"],
"hash": gn["hash"],
"version": gn_version,
"rev": gn_commit,
"hash": get_gn_hash(gn_version, gn_commit),
}
}