Unverified Commit 680303bb authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

dart: add fetchGitHashesScript (#461421)

parents a5c765f7 505f22a4
Loading
Loading
Loading
Loading
+25 −8
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
  yq-go,
  _experimental-update-script-combinators,
  gitUpdater,
  dart,
}:

let
@@ -26,7 +27,7 @@ flutter335.buildFlutterApplication {

  sourceRoot = "${src.name}/app";

  gitHashes = lib.importJSON ./gitHashes.json;
  gitHashes = lib.importJSON ./git-hashes.json;

  postInstall = ''
    cp -r linux/debian/usr/share $out/share
@@ -43,14 +44,30 @@ flutter335.buildFlutterApplication {
          yq eval --output-format=json --prettyPrint $src/app/pubspec.lock > "$out"
        '';
    updateScript = _experimental-update-script-combinators.sequence [
      (
        (gitUpdater {
          ignoredVersions = ".*(rc|beta).*";
          rev-prefix = "v";
        })
        // {
          supportedFeatures = [ ];
        }
      )
      (
        (_experimental-update-script-combinators.copyAttrOutputToFile "butterfly.pubspecSource" ./pubspec.lock.json)
        // {
          supportedFeatures = [ ];
        }
      )
      {
        command = [ ./update-gitHashes.py ];
        supportedFeatures = [ "silent" ];
        command = [
          dart.fetchGitHashesScript
          "--input"
          ./pubspec.lock.json
          "--output"
          ./git-hashes.json
        ];
        supportedFeatures = [ ];
      }
    ];
  };
+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ flutter332.buildFlutterApplication {

  pubspecLock = lib.importJSON ./pubspec.lock.json;

  gitHashes = lib.importJSON ./gitHashes.json;
  gitHashes = lib.importJSON ./git-hashes.json;

  nativeBuildInputs = [ autoPatchelfHook ];

+0 −51
Original line number Diff line number Diff line
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 nix-prefetch-git

import json
import subprocess
import sys
from pathlib import Path

THIS_FOLDER = Path(__file__).parent.resolve()
PUBSPEC_LOCK = THIS_FOLDER / "pubspec.lock.json"
GIT_HASHES = THIS_FOLDER / "gitHashes.json"


def fetch_git_hash(url: str, rev: str) -> str:
    result = subprocess.run(
        ["nix-prefetch-git", "--url", url, "--rev", rev],
        capture_output=True,
        text=True,
        check=True,
    )
    return json.loads(result.stdout)["hash"]


def main() -> None:
    if not PUBSPEC_LOCK.exists():
        sys.exit(1)
    try:
        data = json.loads(PUBSPEC_LOCK.read_text())
    except json.JSONDecodeError:
        sys.exit(1)
    output: dict[str, str] = {}
    for name, info in data.get("packages", {}).items():
        if info.get("source") != "git":
            continue
        desc = info.get("description")
        if not isinstance(desc, dict):
            continue
        url = desc.get("url")
        rev = desc.get("resolved-ref")
        if not (isinstance(url, str) and isinstance(rev, str)):
            continue
        try:
            package_hash = fetch_git_hash(url, rev)
        except subprocess.CalledProcessError:
            continue
        output[name] = package_hash
    GIT_HASHES.write_text(json.dumps(output, indent=2) + "\n")


if __name__ == "__main__":
    main()
Loading