btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / development / compilers / dart / update.sh
blob87f430cd5d2dc999d14541c45819a5aef814acc6
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl jq
4 set -euo pipefail
6 # so if the script fails, debug logs are on stderr
7 log() {
8 >&2 echo "DART_UPDATER: $@"
11 # fetch the latest version number from upstream
12 NEW_VER_DETAILS=$(curl -sL https://storage.googleapis.com/dart-archive/channels/stable/release/latest/VERSION)
13 NEW_VER=$(jq -r '.version' <<< "$NEW_VER_DETAILS")
15 MY_PATH=$(dirname $(realpath "$0"))
16 SRC_FILE=$(mktemp)
18 log "file to write is $SRC_FILE"
20 PRELUDE="let version = \"$NEW_VER\"; in
21 { fetchurl }: {
22 versionUsed = version;"
23 echo "$PRELUDE" > "$SRC_FILE"
24 log "wrote prelude"
26 # Fetches the source, then writes the fetcher and hash into the sources file.
27 # Arguments:
28 # - $1: VARIABLE NAME of (table of nix platform -> dart platform mappings) ("DARWIN_PLATFORMS"|"LIN_PLATFORMS")
29 # - $2: Dart-OS ("macos"|"linux")
30 write_for_platform() {
31 BASE_OF_ALL_URLS='https://storage.googleapis.com/dart-archive/channels/stable/release'
32 BASE_URL_WRITTEN="$BASE_OF_ALL_URLS/\${version}/sdk"
33 BASE_URL_FETCHED="$BASE_OF_ALL_URLS/$NEW_VER/sdk"
35 TABLE_NAME=$1
36 declare -n TABLE=$TABLE_NAME
38 for platform in "${!TABLE[@]}"; do
39 DART_PLATFORM="${TABLE[$platform]}"
40 log "trying for dartplatform $DART_PLATFORM (platform $platform) (OS $2)"
42 URL_POSTFIX="dartsdk-$2-$DART_PLATFORM-release.zip"
43 URL="$BASE_URL_FETCHED/$URL_POSTFIX"
44 log "URL for $DART_PLATFORM: $URL"
46 HASH=$(nix-prefetch-url "$URL" --type sha256)
47 log "hash for platform $platform: $HASH"
49 FETCHER=" \"\${version}-$platform\" = fetchurl {
50 url = \"$BASE_URL_WRITTEN/$URL_POSTFIX\";
51 sha256 = \"$HASH\";
52 };"
54 echo "$FETCHER" >> $SRC_FILE
55 done
56 log "finished for $1"
60 # Map nix platforms -> Dart platforms
61 X8664="x64"
62 AARCH64="arm64"
63 I686="ia32"
64 declare -A DARWIN_PLATFORMS=(["aarch64-darwin"]="$AARCH64"
65 ["x86_64-darwin"]="$X8664")
67 declare -A LIN_PLATFORMS=( ["x86_64-linux"]="$X8664"
68 ["i686-linux"]="$I686"
69 ["aarch64-linux"]="$AARCH64")
71 write_for_platform "DARWIN_PLATFORMS" "macos"
72 write_for_platform "LIN_PLATFORMS" "linux"
74 echo '}' >> $SRC_FILE
76 log "moving tempfile to target directory"
77 mv "$SRC_FILE" "$MY_PATH/sources.nix"