Merge pull request #221694 from gilice/add-dart-update-script
dart: add update script
This commit is contained in:
commit
d5a71a4f97
@ -4,43 +4,11 @@
|
||||
, unzip
|
||||
, runCommand
|
||||
, darwin
|
||||
# we need a way to build other dart versions
|
||||
# than the latest, because flutter might want
|
||||
# another version
|
||||
, version ? "2.19.3"
|
||||
, sources ? let
|
||||
base = "https://storage.googleapis.com/dart-archive/channels";
|
||||
x86_64 = "x64";
|
||||
i686 = "ia32";
|
||||
aarch64 = "arm64";
|
||||
in
|
||||
{
|
||||
"${version}-aarch64-darwin" = fetchurl {
|
||||
url = "${base}/stable/release/${version}/sdk/dartsdk-macos-${aarch64}-release.zip";
|
||||
sha256 = "sha256-wfUh6rXy8jAC0TVQJzXh4SrV2DQs9SvY8PGtNgZx+cA=";
|
||||
};
|
||||
"${version}-x86_64-darwin" = fetchurl {
|
||||
url = "${base}/stable/release/${version}/sdk/dartsdk-macos-${x86_64}-release.zip";
|
||||
sha256 = "sha256-zyu6r8akId/AHpBKH95wJXXu1LD9CKShWYKfppnSRx4=";
|
||||
};
|
||||
"${version}-x86_64-linux" = fetchurl {
|
||||
url = "${base}/stable/release/${version}/sdk/dartsdk-linux-${x86_64}-release.zip";
|
||||
sha256 = "sha256-45HE7Y9iO5dI+JfLWF1ikFfBFB+er46bK+EYkyuhFjI=";
|
||||
};
|
||||
"${version}-i686-linux" = fetchurl {
|
||||
url = "${base}/stable/release/${version}/sdk/dartsdk-linux-${i686}-release.zip";
|
||||
sha256 = "sha256-IkSJWfAocT1l8F2igAkR+Y5PNYD5PZ0j21D8aJk9JCY=";
|
||||
};
|
||||
"${version}-aarch64-linux" = fetchurl {
|
||||
url = "${base}/stable/release/${version}/sdk/dartsdk-linux-${aarch64}-release.zip";
|
||||
sha256 = "sha256-Bt18brbJA/XfiyP5o197HDXMuGm+a1AZx92Thoriv78=";
|
||||
};
|
||||
}
|
||||
, sources ? import ./sources.nix {inherit fetchurl;}
|
||||
, version ? sources.versionUsed
|
||||
}:
|
||||
|
||||
assert version != null && version != "";
|
||||
assert sources != null && (builtins.isAttrs sources);
|
||||
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
pname = "dart";
|
||||
inherit version;
|
||||
@ -59,29 +27,33 @@ stdenv.mkDerivation (finalAttrs: {
|
||||
|
||||
libPath = lib.makeLibraryPath [ stdenv.cc.cc ];
|
||||
dontStrip = true;
|
||||
passthru.tests = {
|
||||
testCreate = runCommand "dart-test-create" { nativeBuildInputs = [ finalAttrs.finalPackage ]; } ''
|
||||
PROJECTNAME="dart_test_project"
|
||||
dart create --no-pub $PROJECTNAME
|
||||
passthru = {
|
||||
updateScript = ./update.sh;
|
||||
tests = {
|
||||
testCreate = runCommand "dart-test-create" { nativeBuildInputs = [ finalAttrs.finalPackage ]; } ''
|
||||
PROJECTNAME="dart_test_project"
|
||||
dart create --no-pub $PROJECTNAME
|
||||
|
||||
[[ -d $PROJECTNAME ]]
|
||||
[[ -f $PROJECTNAME/bin/$PROJECTNAME.dart ]]
|
||||
touch $out
|
||||
'';
|
||||
[[ -d $PROJECTNAME ]]
|
||||
[[ -f $PROJECTNAME/bin/$PROJECTNAME.dart ]]
|
||||
touch $out
|
||||
'';
|
||||
|
||||
testCompile = runCommand "dart-test-compile" {
|
||||
nativeBuildInputs = [ finalAttrs.finalPackage ]
|
||||
++ lib.optionals stdenv.isDarwin [ darwin.cctools darwin.sigtool ];
|
||||
} ''
|
||||
HELLO_MESSAGE="Hello, world!"
|
||||
echo "void main() => print('$HELLO_MESSAGE');" > hello.dart
|
||||
dart compile exe hello.dart
|
||||
PROGRAM_OUT=$(./hello.exe)
|
||||
testCompile = runCommand "dart-test-compile" {
|
||||
nativeBuildInputs = [ finalAttrs.finalPackage ]
|
||||
++ lib.optionals stdenv.isDarwin [ darwin.cctools darwin.sigtool ];
|
||||
} ''
|
||||
HELLO_MESSAGE="Hello, world!"
|
||||
echo "void main() => print('$HELLO_MESSAGE');" > hello.dart
|
||||
dart compile exe hello.dart
|
||||
PROGRAM_OUT=$(./hello.exe)
|
||||
|
||||
[[ "$PROGRAM_OUT" == "$HELLO_MESSAGE" ]]
|
||||
touch $out
|
||||
'';
|
||||
[[ "$PROGRAM_OUT" == "$HELLO_MESSAGE" ]]
|
||||
touch $out
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
meta = with lib; {
|
||||
homepage = "https://www.dartlang.org/";
|
||||
maintainers = with maintainers; [ grburst ];
|
||||
|
27
pkgs/development/compilers/dart/sources.nix
Normal file
27
pkgs/development/compilers/dart/sources.nix
Normal file
@ -0,0 +1,27 @@
|
||||
# This file was generated by ./update.sh.
|
||||
# If you do not find a line of three #-s at the end, it is broken and should not be used.
|
||||
let version = "2.19.3"; in
|
||||
{ fetchurl }: {
|
||||
versionUsed = version;
|
||||
"${version}-x86_64-darwin" = fetchurl {
|
||||
url = "https://storage.googleapis.com/dart-archive/channels/stable/release/${version}/sdk/dartsdk-macos-x64-release.zip";
|
||||
sha256 = "193hf56j7bws8bzqxxzz2sgbn2d80g5s8vp8ihi22cm3mmppfi4v";
|
||||
};
|
||||
"${version}-aarch64-darwin" = fetchurl {
|
||||
url = "https://storage.googleapis.com/dart-archive/channels/stable/release/${version}/sdk/dartsdk-macos-arm64-release.zip";
|
||||
sha256 = "0b30l8kfcsl1j6w2vbq08p0v4h4gca013l5fpznjqq0midxhybnw";
|
||||
};
|
||||
"${version}-aarch64-linux" = fetchurl {
|
||||
url = "https://storage.googleapis.com/dart-archive/channels/stable/release/${version}/sdk/dartsdk-linux-arm64-release.zip";
|
||||
sha256 = "0qyi7ppsf4rmzx1qgx3qbn4k7bgbncxjql6a9f2b1aj6l6lllvmg";
|
||||
};
|
||||
"${version}-x86_64-linux" = fetchurl {
|
||||
url = "https://storage.googleapis.com/dart-archive/channels/stable/release/${version}/sdk/dartsdk-linux-x64-release.zip";
|
||||
sha256 = "0iq7mdwpsnykk3j2bsgmazg30m4qg7i2lpv1ygbhy2lbhrkdpdck";
|
||||
};
|
||||
"${version}-i686-linux" = fetchurl {
|
||||
url = "https://storage.googleapis.com/dart-archive/channels/stable/release/${version}/sdk/dartsdk-linux-ia32-release.zip";
|
||||
sha256 = "0xksis14ff6bzjvycgxgldg96n88rh42adjyrrhcay2s183vh480";
|
||||
};
|
||||
}
|
||||
###
|
80
pkgs/development/compilers/dart/update.sh
Executable file
80
pkgs/development/compilers/dart/update.sh
Executable file
@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p curl jq
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# so if the script fails, debug logs are on stdenv
|
||||
log() {
|
||||
>&2 echo "DART_UPDATER: $@"
|
||||
}
|
||||
|
||||
# fetch the latest version number from upstream
|
||||
NEW_VER_DETAILS=$(curl -sL https://storage.googleapis.com/dart-archive/channels/stable/release/latest/VERSION)
|
||||
NEW_VER=$(jq -r '.version' <<< "$NEW_VER_DETAILS")
|
||||
|
||||
MY_PATH=$(dirname $(realpath "$0"))
|
||||
SRC_FILE="$MY_PATH/sources.nix"
|
||||
log "file to write is $SRC_FILE"
|
||||
|
||||
PRELUDE="# This file was generated by ./update.sh.
|
||||
# If you do not find a line of three #-s at the end, it is broken and should not be used.
|
||||
let version = \"$NEW_VER\"; in
|
||||
{ fetchurl }: {
|
||||
versionUsed = version;"
|
||||
echo "$PRELUDE" > "$SRC_FILE"
|
||||
log "wrote prelude"
|
||||
|
||||
# Fetches the source, then writes the fetcher and hash into the sources file.
|
||||
# Arguments:
|
||||
# - $1: VARIABLE NAME of (table of nix platform -> dart platform mappings) ("DARWIN_PLATFORMS"|"LIN_PLATFORMS")
|
||||
# - $2: Dart-OS ("macos"|"linux")
|
||||
write_for_platform() {
|
||||
BASE_OF_ALL_URLS='https://storage.googleapis.com/dart-archive/channels/stable/release'
|
||||
BASE_URL_WRITTEN="$BASE_OF_ALL_URLS/\${version}/sdk"
|
||||
BASE_URL_FETCHED="$BASE_OF_ALL_URLS/$NEW_VER/sdk"
|
||||
|
||||
TABLE_NAME=$1
|
||||
declare -n TABLE=$TABLE_NAME
|
||||
|
||||
for platform in "${!TABLE[@]}"; do
|
||||
DART_PLATFORM="${TABLE[$platform]}"
|
||||
log "trying for dartplatform $DART_PLATFORM (platform $platform) (OS $2)"
|
||||
|
||||
URL_POSTFIX="dartsdk-$2-$DART_PLATFORM-release.zip"
|
||||
URL="$BASE_URL_FETCHED/$URL_POSTFIX"
|
||||
log "URL for $DART_PLATFORM: $URL"
|
||||
|
||||
HASH=$(nix-prefetch-url "$URL" --type sha256)
|
||||
log "hash for platform $platform: $HASH"
|
||||
|
||||
FETCHER=" \"\${version}-$platform\" = fetchurl {
|
||||
url = \"$BASE_URL_WRITTEN/$URL_POSTFIX\";
|
||||
sha256 = \"$HASH\";
|
||||
};"
|
||||
|
||||
echo "$FETCHER" >> $SRC_FILE
|
||||
done
|
||||
log "finished for $1
|
||||
---"
|
||||
|
||||
}
|
||||
|
||||
# Map nix platforms -> Dart platforms
|
||||
X8664="x64"
|
||||
AARCH64="arm64"
|
||||
I686="ia32"
|
||||
declare -A DARWIN_PLATFORMS=(["aarch64-darwin"]="$AARCH64"
|
||||
["x86_64-darwin"]="$X8664")
|
||||
|
||||
declare -A LIN_PLATFORMS=( ["x86_64-linux"]="$X8664"
|
||||
["i686-linux"]="$I686"
|
||||
["aarch64-linux"]="$AARCH64")
|
||||
|
||||
write_for_platform "DARWIN_PLATFORMS" "macos"
|
||||
write_for_platform "LIN_PLATFORMS" "linux"
|
||||
|
||||
echo '}
|
||||
###' >> $SRC_FILE
|
||||
|
||||
log "Replacing version in dart/default.nix"
|
||||
sed -i "s/$UPDATE_NIX_OLD_VERSION/$NEW_VER/g" "$MY_PATH/default.nix"
|
Loading…
Reference in New Issue
Block a user