Commit b483a6f0 authored by qzylinra's avatar qzylinra
Browse files

protoc-gen-dart: use workspace

parent a6eaeab5
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -2,6 +2,11 @@
  lib,
  buildDartApplication,
  fetchFromGitHub,
  _experimental-update-script-combinators,
  gitUpdater,
  writeShellScript,
  dart,
  yq-go,
}:

buildDartApplication rec {
@@ -15,11 +20,30 @@ buildDartApplication rec {
    hash = "sha256-8pSCYlbZLqHnpetM4luyfGo1qnWgKx93JPjRVWCOX0w=";
  };

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

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

  passthru.updateScript = ./update.sh;
  preBuild = ''
    pushd protoc_plugin
  '';

  postInstall = ''
    popd
  '';

  passthru.updateScript = _experimental-update-script-combinators.sequence [
    (gitUpdater { rev-prefix = "protoc_plugin-v"; } // { supportedFeatures = [ ]; })
    (writeShellScript "update-protoc-gen-dart" ''
      src=$(nix build --print-out-paths --no-link .#protoc-gen-dart.src)
      export HOME=$(mktemp -d)
      WORKDIR=$(mktemp -d)
      cp --recursive --no-preserve=mode $src/* $WORKDIR
      PACKAGE_DIR=$(dirname $(EDITOR=echo nix edit --file . protoc-gen-dart))
      pushd $WORKDIR
      ${lib.getExe dart} pub update
      ${lib.getExe yq-go} eval --output-format=json --prettyPrint pubspec.lock > $PACKAGE_DIR/pubspec.lock.json
      popd
    '')
  ];

  meta = {
    description = "Protobuf plugin for generating Dart code";
+36 −36
Original line number Diff line number Diff line
@@ -4,21 +4,21 @@
      "dependency": "transitive",
      "description": {
        "name": "_fe_analyzer_shared",
        "sha256": "da0d9209ca76bde579f2da330aeb9df62b6319c834fa7baae052021b0462401f",
        "sha256": "c209688d9f5a5f26b2fb47a188131a6fb9e876ae9e47af3737c0b4f58a93470d",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "85.0.0"
      "version": "91.0.0"
    },
    "analyzer": {
      "dependency": "transitive",
      "description": {
        "name": "analyzer",
        "sha256": "b1ade5707ab7a90dfd519eaac78a7184341d19adb6096c68d499b59c7c6cf880",
        "sha256": "a40a0cee526a7e1f387c6847bd8a5ccbf510a75952ef8a28338e989558072cb0",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "7.7.0"
      "version": "8.4.0"
    },
    "args": {
      "dependency": "transitive",
@@ -40,6 +40,16 @@
      "source": "hosted",
      "version": "2.13.0"
    },
    "benchmark_harness": {
      "dependency": "transitive",
      "description": {
        "name": "benchmark_harness",
        "sha256": "83f65107165883ba8623eb822daacb23dcf9f795c66841de758c9dd7c5a0cf28",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "2.3.1"
    },
    "boolean_selector": {
      "dependency": "transitive",
      "description": {
@@ -61,7 +71,7 @@
      "version": "0.2.0"
    },
    "collection": {
      "dependency": "direct main",
      "dependency": "transitive",
      "description": {
        "name": "collection",
        "sha256": "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76",
@@ -101,14 +111,14 @@
      "version": "3.0.6"
    },
    "dart_style": {
      "dependency": "direct main",
      "dependency": "transitive",
      "description": {
        "name": "dart_style",
        "sha256": "5b236382b47ee411741447c1f1e111459c941ea1b3f2b540dde54c210a3662af",
        "sha256": "c87dfe3d56f183ffe9106a18aebc6db431fc7c98c31a54b952a77f3d54a85697",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "3.1.0"
      "version": "3.1.2"
    },
    "file": {
      "dependency": "transitive",
@@ -121,7 +131,7 @@
      "version": "7.0.1"
    },
    "fixnum": {
      "dependency": "direct main",
      "dependency": "transitive",
      "description": {
        "name": "fixnum",
        "sha256": "b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be",
@@ -184,14 +194,14 @@
      "dependency": "transitive",
      "description": {
        "name": "js",
        "sha256": "53385261521cc4a0c4658fd0ad07a7d14591cf8fc33abbceae306ddb974888dc",
        "sha256": "f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "0.7.2"
      "version": "0.6.7"
    },
    "lints": {
      "dependency": "direct dev",
      "dependency": "transitive",
      "description": {
        "name": "lints",
        "sha256": "a5e2b223cb7c9c8efdc663ef484fdd95bb243bff242ef5b13e26883547fce9a0",
@@ -261,7 +271,7 @@
      "version": "2.2.0"
    },
    "path": {
      "dependency": "direct main",
      "dependency": "transitive",
      "description": {
        "name": "path",
        "sha256": "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5",
@@ -274,24 +284,14 @@
      "dependency": "transitive",
      "description": {
        "name": "pool",
        "sha256": "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a",
        "sha256": "978783255c543aa3586a1b3c21f6e9d720eb315376a915872c61ef8b5c20177d",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "1.5.1"
    },
    "protobuf": {
      "dependency": "direct main",
      "description": {
        "name": "protobuf",
        "sha256": "6153efcc92a06910918f3db8231fd2cf828ac81e50ebd87adc8f8a8cb3caff0e",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "4.1.1"
      "version": "1.5.2"
    },
    "pub_semver": {
      "dependency": "direct main",
      "dependency": "transitive",
      "description": {
        "name": "pub_semver",
        "sha256": "5bfcf68ca79ef689f8990d1160781b4bad40a3bd5e5218ad4076ddb7f4081585",
@@ -411,34 +411,34 @@
      "version": "1.2.2"
    },
    "test": {
      "dependency": "direct dev",
      "dependency": "transitive",
      "description": {
        "name": "test",
        "sha256": "65e29d831719be0591f7b3b1a32a3cda258ec98c58c7b25f7b84241bc31215bb",
        "sha256": "75906bf273541b676716d1ca7627a17e4c4070a3a16272b7a3dc7da3b9f3f6b7",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "1.26.2"
      "version": "1.26.3"
    },
    "test_api": {
      "dependency": "transitive",
      "description": {
        "name": "test_api",
        "sha256": "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00",
        "sha256": "ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "0.7.6"
      "version": "0.7.7"
    },
    "test_core": {
      "dependency": "transitive",
      "description": {
        "name": "test_core",
        "sha256": "80bf5a02b60af04b09e14f6fe68b921aad119493e26e490deaca5993fef1b05a",
        "sha256": "0cc24b5ff94b38d2ae73e1eb43cc302b77964fbf67abad1e296025b78deb53d0",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "0.6.11"
      "version": "0.6.12"
    },
    "typed_data": {
      "dependency": "transitive",
@@ -464,11 +464,11 @@
      "dependency": "transitive",
      "description": {
        "name": "watcher",
        "sha256": "0b7fd4a0bbc4b92641dbf20adfd7e3fd1398fe17102d94b674234563e110088a",
        "sha256": "592ab6e2892f67760543fb712ff0177f4ec76c031f02f5b4ff8d3fc5eb9fb61a",
        "url": "https://pub.dev"
      },
      "source": "hosted",
      "version": "1.1.2"
      "version": "1.1.4"
    },
    "web": {
      "dependency": "transitive",
@@ -522,6 +522,6 @@
    }
  },
  "sdks": {
    "dart": ">=3.8.0-0 <4.0.0"
    "dart": ">=3.9.0 <4.0.0"
  }
}
+0 −34
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p yq ripgrep common-updater-scripts dart

set -xeu -o pipefail

PACKAGE_DIR="$(realpath "$(dirname "$0")")"
cd "$PACKAGE_DIR/.."
while ! test -f flake.nix; do cd ..; done
NIXPKGS_DIR="$PWD"

version="$(
  list-git-tags --url=https://github.com/google/protobuf.dart |
    rg '^protoc_plugin-v(.*)' -r '$1' |
    sort --version-sort |
    tail -n1
)"

cd "$NIXPKGS_DIR"
update-source-version protoc-gen-dart "$version"

TMPDIR="$(mktemp -d)"
cd "$TMPDIR"

src="$(nix-build --no-link "$NIXPKGS_DIR" -A protoc-gen-dart.src)/protoc_plugin"
cp $src/pubspec.* .

if ! test -f pubspec.lock; then
  sed -i '/resolution: workspace/d' pubspec.yaml
  dart pub update
fi

yq . pubspec.lock >"$PACKAGE_DIR/pubspec.lock.json"

rm -rf "$TMPDIR"