buildDartApplication: add workspace-package-config.py (#454169)
This commit is contained in:
@@ -9,6 +9,9 @@ dartConfigHook() {
|
|||||||
echo "Installing dependencies"
|
echo "Installing dependencies"
|
||||||
mkdir -p .dart_tool
|
mkdir -p .dart_tool
|
||||||
cp "$packageConfig" .dart_tool/package_config.json
|
cp "$packageConfig" .dart_tool/package_config.json
|
||||||
|
chmod u+w .dart_tool/package_config.json
|
||||||
|
@python3@ @workspacePackageConfigScript@
|
||||||
|
chmod u-w .dart_tool/package_config.json
|
||||||
@python3@ @packageGraphScript@ > .dart_tool/package_graph.json
|
@python3@ @packageGraphScript@ > .dart_tool/package_graph.json
|
||||||
|
|
||||||
packagePath() {
|
packagePath() {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
substitutions.jq = "${jq}/bin/jq";
|
substitutions.jq = "${jq}/bin/jq";
|
||||||
substitutions.python3 = lib.getExe (python3.withPackages (ps: with ps; [ pyyaml ]));
|
substitutions.python3 = lib.getExe (python3.withPackages (ps: with ps; [ pyyaml ]));
|
||||||
substitutions.packageGraphScript = ../../pub2nix/package-graph.py;
|
substitutions.packageGraphScript = ../../pub2nix/package-graph.py;
|
||||||
|
substitutions.workspacePackageConfigScript = ../workspace-package-config.py;
|
||||||
} ./dart-config-hook.sh;
|
} ./dart-config-hook.sh;
|
||||||
dartBuildHook = makeSetupHook {
|
dartBuildHook = makeSetupHook {
|
||||||
name = "dart-build-hook";
|
name = "dart-build-hook";
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import json
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
with Path("pubspec.yaml").open("r", encoding="utf-8") as f:
|
||||||
|
pubspec = yaml.load(f, Loader=yaml.CSafeLoader)
|
||||||
|
if not pubspec.get("workspace"):
|
||||||
|
return
|
||||||
|
with Path(".dart_tool/package_config.json").open("r", encoding="utf-8") as f:
|
||||||
|
package_config = json.load(f)
|
||||||
|
for package_path in pubspec.get("workspace", []):
|
||||||
|
with (Path(package_path) / "pubspec.yaml").open("r", encoding="utf-8") as f:
|
||||||
|
package_pubspec = yaml.load(f, Loader=yaml.CSafeLoader)
|
||||||
|
m = re.match(
|
||||||
|
r"^[ \t]*(\^|>=|>)?[ \t]*([0-9]+\.[0-9]+)\.[0-9]+.*$",
|
||||||
|
package_pubspec.get("environment", {}).get("sdk", ""),
|
||||||
|
)
|
||||||
|
if m:
|
||||||
|
languageVersion = m.group(2)
|
||||||
|
elif package_pubspec.get("environment", {}).get("sdk") == "any":
|
||||||
|
languageVersion = "null"
|
||||||
|
else:
|
||||||
|
languageVersion = "2.7"
|
||||||
|
if not any(
|
||||||
|
pkg["name"] == package_pubspec["name"] for pkg in package_config["packages"]
|
||||||
|
):
|
||||||
|
package_config["packages"].append({
|
||||||
|
"name": package_pubspec["name"],
|
||||||
|
"rootUri": Path(package_path).resolve().as_uri(),
|
||||||
|
"packageUri": "lib/",
|
||||||
|
"languageVersion": languageVersion,
|
||||||
|
})
|
||||||
|
with Path(".dart_tool/package_config.json").open("w", encoding="utf-8") as f:
|
||||||
|
json.dump(package_config, f, sort_keys=True, indent=4)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
diff --git a/bin/melos.dart b/bin/melos.dart
|
diff --git a/bin/melos.dart b/bin/melos.dart
|
||||||
index 0db7013..218276f 100644
|
index 0db7013..218276f 100644
|
||||||
--- a/bin/melos.dart
|
--- a/packages/melos/bin/melos.dart
|
||||||
+++ b/bin/melos.dart
|
+++ b/packages/melos/bin/melos.dart
|
||||||
@@ -1,11 +1,37 @@
|
@@ -1,11 +1,37 @@
|
||||||
+import 'dart:io';
|
+import 'dart:io';
|
||||||
import 'package:cli_launcher/cli_launcher.dart';
|
import 'package:cli_launcher/cli_launcher.dart';
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ buildDartApplication {
|
|||||||
pname = "melos";
|
pname = "melos";
|
||||||
inherit version src;
|
inherit version src;
|
||||||
|
|
||||||
sourceRoot = "${src.name}/packages/melos";
|
|
||||||
|
|
||||||
patches = [
|
patches = [
|
||||||
# This patch (created a melos 6.1.0) modify the method melos use to find path to the root of the projects.
|
# This patch (created a melos 6.1.0) modify the method melos use to find path to the root of the projects.
|
||||||
# It is needed because when melos is in the nixstore, it break it and fail to find the projects root with melos.yaml
|
# It is needed because when melos is in the nixstore, it break it and fail to find the projects root with melos.yaml
|
||||||
@@ -28,12 +26,12 @@ buildDartApplication {
|
|||||||
|
|
||||||
# hard code the path to the melos templates
|
# hard code the path to the melos templates
|
||||||
preBuild = ''
|
preBuild = ''
|
||||||
substituteInPlace lib/src/common/utils.dart \
|
substituteInPlace packages/melos/lib/src/common/utils.dart \
|
||||||
--replace-fail "final melosPackageFileUri = await Isolate.resolvePackageUri(melosPackageUri);" "return \"$out\";"
|
--replace-fail "final melosPackageFileUri = await Isolate.resolvePackageUri(melosPackageUri);" "return \"$out\";"
|
||||||
substituteInPlace lib/src/common/utils.dart \
|
substituteInPlace packages/melos/lib/src/common/utils.dart \
|
||||||
--replace-fail "return p.normalize('\''${melosPackageFileUri!.toFilePath()}/../..');" " "
|
--replace-fail "return p.normalize('\''${melosPackageFileUri!.toFilePath()}/../..');" " "
|
||||||
mkdir --parents $out
|
mkdir --parents $out
|
||||||
cp --recursive templates $out/
|
cp --recursive packages/melos/templates $out/
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
|
|||||||
@@ -709,15 +709,6 @@
|
|||||||
},
|
},
|
||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "2.2.2"
|
"version": "2.2.2"
|
||||||
},
|
|
||||||
"conventional_commit": {
|
|
||||||
"dependency": "direct main",
|
|
||||||
"description": {
|
|
||||||
"path": "../conventional_commit",
|
|
||||||
"relative": true
|
|
||||||
},
|
|
||||||
"source": "path",
|
|
||||||
"version": "0.6.1"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sdks": {
|
"sdks": {
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
lib,
|
lib,
|
||||||
buildDartApplication,
|
buildDartApplication,
|
||||||
fetchFromGitHub,
|
fetchFromGitHub,
|
||||||
|
_experimental-update-script-combinators,
|
||||||
|
gitUpdater,
|
||||||
|
writeShellScript,
|
||||||
|
dart,
|
||||||
|
yq-go,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
buildDartApplication rec {
|
buildDartApplication rec {
|
||||||
@@ -15,11 +20,30 @@ buildDartApplication rec {
|
|||||||
hash = "sha256-8pSCYlbZLqHnpetM4luyfGo1qnWgKx93JPjRVWCOX0w=";
|
hash = "sha256-8pSCYlbZLqHnpetM4luyfGo1qnWgKx93JPjRVWCOX0w=";
|
||||||
};
|
};
|
||||||
|
|
||||||
sourceRoot = "${src.name}/protoc_plugin";
|
|
||||||
|
|
||||||
pubspecLock = lib.importJSON ./pubspec.lock.json;
|
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 = {
|
meta = {
|
||||||
description = "Protobuf plugin for generating Dart code";
|
description = "Protobuf plugin for generating Dart code";
|
||||||
|
|||||||
@@ -4,21 +4,21 @@
|
|||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "_fe_analyzer_shared",
|
"name": "_fe_analyzer_shared",
|
||||||
"sha256": "da0d9209ca76bde579f2da330aeb9df62b6319c834fa7baae052021b0462401f",
|
"sha256": "c209688d9f5a5f26b2fb47a188131a6fb9e876ae9e47af3737c0b4f58a93470d",
|
||||||
"url": "https://pub.dev"
|
"url": "https://pub.dev"
|
||||||
},
|
},
|
||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "85.0.0"
|
"version": "91.0.0"
|
||||||
},
|
},
|
||||||
"analyzer": {
|
"analyzer": {
|
||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "analyzer",
|
"name": "analyzer",
|
||||||
"sha256": "b1ade5707ab7a90dfd519eaac78a7184341d19adb6096c68d499b59c7c6cf880",
|
"sha256": "a40a0cee526a7e1f387c6847bd8a5ccbf510a75952ef8a28338e989558072cb0",
|
||||||
"url": "https://pub.dev"
|
"url": "https://pub.dev"
|
||||||
},
|
},
|
||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "7.7.0"
|
"version": "8.4.0"
|
||||||
},
|
},
|
||||||
"args": {
|
"args": {
|
||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
@@ -40,6 +40,16 @@
|
|||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "2.13.0"
|
"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": {
|
"boolean_selector": {
|
||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
@@ -61,7 +71,7 @@
|
|||||||
"version": "0.2.0"
|
"version": "0.2.0"
|
||||||
},
|
},
|
||||||
"collection": {
|
"collection": {
|
||||||
"dependency": "direct main",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "collection",
|
"name": "collection",
|
||||||
"sha256": "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76",
|
"sha256": "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76",
|
||||||
@@ -101,14 +111,14 @@
|
|||||||
"version": "3.0.6"
|
"version": "3.0.6"
|
||||||
},
|
},
|
||||||
"dart_style": {
|
"dart_style": {
|
||||||
"dependency": "direct main",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "dart_style",
|
"name": "dart_style",
|
||||||
"sha256": "5b236382b47ee411741447c1f1e111459c941ea1b3f2b540dde54c210a3662af",
|
"sha256": "c87dfe3d56f183ffe9106a18aebc6db431fc7c98c31a54b952a77f3d54a85697",
|
||||||
"url": "https://pub.dev"
|
"url": "https://pub.dev"
|
||||||
},
|
},
|
||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "3.1.0"
|
"version": "3.1.2"
|
||||||
},
|
},
|
||||||
"file": {
|
"file": {
|
||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
@@ -121,7 +131,7 @@
|
|||||||
"version": "7.0.1"
|
"version": "7.0.1"
|
||||||
},
|
},
|
||||||
"fixnum": {
|
"fixnum": {
|
||||||
"dependency": "direct main",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "fixnum",
|
"name": "fixnum",
|
||||||
"sha256": "b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be",
|
"sha256": "b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be",
|
||||||
@@ -184,14 +194,14 @@
|
|||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "js",
|
"name": "js",
|
||||||
"sha256": "53385261521cc4a0c4658fd0ad07a7d14591cf8fc33abbceae306ddb974888dc",
|
"sha256": "f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3",
|
||||||
"url": "https://pub.dev"
|
"url": "https://pub.dev"
|
||||||
},
|
},
|
||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "0.7.2"
|
"version": "0.6.7"
|
||||||
},
|
},
|
||||||
"lints": {
|
"lints": {
|
||||||
"dependency": "direct dev",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "lints",
|
"name": "lints",
|
||||||
"sha256": "a5e2b223cb7c9c8efdc663ef484fdd95bb243bff242ef5b13e26883547fce9a0",
|
"sha256": "a5e2b223cb7c9c8efdc663ef484fdd95bb243bff242ef5b13e26883547fce9a0",
|
||||||
@@ -261,7 +271,7 @@
|
|||||||
"version": "2.2.0"
|
"version": "2.2.0"
|
||||||
},
|
},
|
||||||
"path": {
|
"path": {
|
||||||
"dependency": "direct main",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "path",
|
"name": "path",
|
||||||
"sha256": "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5",
|
"sha256": "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5",
|
||||||
@@ -274,24 +284,14 @@
|
|||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "pool",
|
"name": "pool",
|
||||||
"sha256": "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a",
|
"sha256": "978783255c543aa3586a1b3c21f6e9d720eb315376a915872c61ef8b5c20177d",
|
||||||
"url": "https://pub.dev"
|
"url": "https://pub.dev"
|
||||||
},
|
},
|
||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "1.5.1"
|
"version": "1.5.2"
|
||||||
},
|
|
||||||
"protobuf": {
|
|
||||||
"dependency": "direct main",
|
|
||||||
"description": {
|
|
||||||
"name": "protobuf",
|
|
||||||
"sha256": "6153efcc92a06910918f3db8231fd2cf828ac81e50ebd87adc8f8a8cb3caff0e",
|
|
||||||
"url": "https://pub.dev"
|
|
||||||
},
|
|
||||||
"source": "hosted",
|
|
||||||
"version": "4.1.1"
|
|
||||||
},
|
},
|
||||||
"pub_semver": {
|
"pub_semver": {
|
||||||
"dependency": "direct main",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "pub_semver",
|
"name": "pub_semver",
|
||||||
"sha256": "5bfcf68ca79ef689f8990d1160781b4bad40a3bd5e5218ad4076ddb7f4081585",
|
"sha256": "5bfcf68ca79ef689f8990d1160781b4bad40a3bd5e5218ad4076ddb7f4081585",
|
||||||
@@ -411,34 +411,34 @@
|
|||||||
"version": "1.2.2"
|
"version": "1.2.2"
|
||||||
},
|
},
|
||||||
"test": {
|
"test": {
|
||||||
"dependency": "direct dev",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "test",
|
"name": "test",
|
||||||
"sha256": "65e29d831719be0591f7b3b1a32a3cda258ec98c58c7b25f7b84241bc31215bb",
|
"sha256": "75906bf273541b676716d1ca7627a17e4c4070a3a16272b7a3dc7da3b9f3f6b7",
|
||||||
"url": "https://pub.dev"
|
"url": "https://pub.dev"
|
||||||
},
|
},
|
||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "1.26.2"
|
"version": "1.26.3"
|
||||||
},
|
},
|
||||||
"test_api": {
|
"test_api": {
|
||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "test_api",
|
"name": "test_api",
|
||||||
"sha256": "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00",
|
"sha256": "ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55",
|
||||||
"url": "https://pub.dev"
|
"url": "https://pub.dev"
|
||||||
},
|
},
|
||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "0.7.6"
|
"version": "0.7.7"
|
||||||
},
|
},
|
||||||
"test_core": {
|
"test_core": {
|
||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "test_core",
|
"name": "test_core",
|
||||||
"sha256": "80bf5a02b60af04b09e14f6fe68b921aad119493e26e490deaca5993fef1b05a",
|
"sha256": "0cc24b5ff94b38d2ae73e1eb43cc302b77964fbf67abad1e296025b78deb53d0",
|
||||||
"url": "https://pub.dev"
|
"url": "https://pub.dev"
|
||||||
},
|
},
|
||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "0.6.11"
|
"version": "0.6.12"
|
||||||
},
|
},
|
||||||
"typed_data": {
|
"typed_data": {
|
||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
@@ -464,11 +464,11 @@
|
|||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
"description": {
|
"description": {
|
||||||
"name": "watcher",
|
"name": "watcher",
|
||||||
"sha256": "0b7fd4a0bbc4b92641dbf20adfd7e3fd1398fe17102d94b674234563e110088a",
|
"sha256": "592ab6e2892f67760543fb712ff0177f4ec76c031f02f5b4ff8d3fc5eb9fb61a",
|
||||||
"url": "https://pub.dev"
|
"url": "https://pub.dev"
|
||||||
},
|
},
|
||||||
"source": "hosted",
|
"source": "hosted",
|
||||||
"version": "1.1.2"
|
"version": "1.1.4"
|
||||||
},
|
},
|
||||||
"web": {
|
"web": {
|
||||||
"dependency": "transitive",
|
"dependency": "transitive",
|
||||||
@@ -522,6 +522,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sdks": {
|
"sdks": {
|
||||||
"dart": ">=3.8.0-0 <4.0.0"
|
"dart": ">=3.9.0 <4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
#!/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"
|
|
||||||
Reference in New Issue
Block a user