graalvm*-ce: 22.3.0 -> 22.3.1, migrate upgrade script to sh

This commit is contained in:
Thiago Kenji Okada 2023-02-11 13:06:18 +00:00
parent 0c7f039bad
commit 79c2eceda8
5 changed files with 178 additions and 238 deletions

View File

@ -132,6 +132,7 @@ let
passthru = {
inherit products;
home = graalvmXXX-ce;
updateScript = ./update.sh;
};
meta = with lib; ({

View File

@ -8,36 +8,45 @@
let
buildGraalvm = callPackage ./buildGraalvm.nix { inherit Foundation; };
buildGraalvmProduct = callPackage ./buildGraalvmProduct.nix { };
sources = javaVersion: builtins.fromJSON (builtins.readFile (./. + "/graalvm${javaVersion}-ce-sources.json"));
javaPlatform = {
"aarch64-linux" = "linux-aarch64";
"x86_64-linux" = "linux-amd64";
"aarch64-darwin" = "darwin-aarch64";
"x86_64-darwin" = "darwin-amd64";
};
javaPlatformVersion = javaVersion:
"${javaVersion}-${javaPlatform.${stdenv.system} or (throw "Unsupported platform: ${stdenv.system}")}";
source = product: javaVersion: (import ./hashes.nix).${product}.${javaPlatformVersion javaVersion};
in
rec {
inherit buildGraalvm buildGraalvmProduct;
graalvm11-ce = buildGraalvm rec {
version = "22.3.0";
version = "22.3.1";
javaVersion = "11";
src = fetchurl (sources javaVersion).${stdenv.system}.${"graalvm-ce|java${javaVersion}|${version}"};
meta.platforms = builtins.attrNames (sources javaVersion);
src = fetchurl (source "graalvm-ce" javaVersion);
meta.platforms = builtins.attrNames javaPlatform;
products = [ native-image-installable-svm-java11 ];
};
native-image-installable-svm-java11 = callPackage ./native-image-installable-svm.nix rec {
javaVersion = "11";
version = "22.3.0";
src = fetchurl (sources javaVersion).${stdenv.system}.${"native-image-installable-svm|java${javaVersion}|${version}"};
version = "22.3.1";
src = fetchurl (source "native-image-installable-svm" javaVersion);
};
graalvm17-ce = buildGraalvm rec {
version = "22.3.0";
version = "22.3.1";
javaVersion = "17";
src = fetchurl (sources javaVersion).${stdenv.system}.${"graalvm-ce|java${javaVersion}|${version}"};
meta.platforms = builtins.attrNames (sources javaVersion);
src = fetchurl (source "graalvm-ce" javaVersion);
meta.platforms = builtins.attrNames javaPlatform;
products = [ native-image-installable-svm-java17 ];
};
native-image-installable-svm-java17 = callPackage ./native-image-installable-svm.nix rec {
javaVersion = "17";
version = "22.3.0";
src = fetchurl (sources javaVersion).${stdenv.system}.${"native-image-installable-svm|java${javaVersion}|${version}"};
version = "22.3.1";
src = fetchurl (source "native-image-installable-svm" javaVersion);
};
}

View File

@ -0,0 +1,71 @@
# Generated by pkgs/development/compilers/graalvm/community-edition/update.sh script
{
"native-image-installable-svm" = {
"11-linux-aarch64" = {
sha256 = "0z9rbmci6yz7f7mqd3xzsxc5ih4hq72lyzqfchan7fr6mh38d6gw";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/native-image-installable-svm-java11-linux-aarch64-22.3.1.jar";
};
"17-linux-aarch64" = {
sha256 = "03v20fc9famlnbrznpasnd5gdl5k9nl4dlj3pp6bad4y6l7rqnx5";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/native-image-installable-svm-java17-linux-aarch64-22.3.1.jar";
};
"11-linux-amd64" = {
sha256 = "1yb7kpbs7hrzlysvrqjzgfz678p1hbg6237jzb35zmwdaczav51n";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/native-image-installable-svm-java11-linux-amd64-22.3.1.jar";
};
"17-linux-amd64" = {
sha256 = "00fbyqsj4xj9ay8bki1190lf59bgrzvla8lzzq51p53a1bdrhhmv";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/native-image-installable-svm-java17-linux-amd64-22.3.1.jar";
};
"11-darwin-aarch64" = {
sha256 = "1kaqvkbhj3iifq6asyrpy225a89y7klzbh7an1ycnvc2hvqkv4nz";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/native-image-installable-svm-java11-darwin-aarch64-22.3.1.jar";
};
"17-darwin-aarch64" = {
sha256 = "09l7x4x8yanq55v6y6wpfx94mvsq1bpbnihknjc6dnq3vcrci77n";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/native-image-installable-svm-java17-darwin-aarch64-22.3.1.jar";
};
"11-darwin-amd64" = {
sha256 = "036w9dmdcs46kmjqr3086mg389fgr3h1zysavfq8cbh199x0ibia";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/native-image-installable-svm-java11-darwin-amd64-22.3.1.jar";
};
"17-darwin-amd64" = {
sha256 = "1hvjfvcn878bzvi944v3x23sby72hbfvg5s3zzspyc37l5cdpqi3";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/native-image-installable-svm-java17-darwin-amd64-22.3.1.jar";
};
};
"graalvm-ce" = {
"11-linux-aarch64" = {
sha256 = "1g4a3z9993pq52j3jf25pbcq9rvl8jz1yar8c859jw5chaf3ysml";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/graalvm-ce-java11-linux-aarch64-22.3.1.tar.gz";
};
"17-linux-aarch64" = {
sha256 = "06288dwbql943nii74i9mngzb38h2nzrxzzgs346mgk2965gwm59";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/graalvm-ce-java17-linux-aarch64-22.3.1.tar.gz";
};
"11-linux-amd64" = {
sha256 = "1f6xkdnxn6xsm24sqw24rsca72wm7v6q96m23l5fng5ym0jpfm2m";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/graalvm-ce-java11-linux-amd64-22.3.1.tar.gz";
};
"17-linux-amd64" = {
sha256 = "0aci9i28rq5nk2qya9dcg5hxr3sgsbv7f5x8679hrjrqmrclmkrs";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/graalvm-ce-java17-linux-amd64-22.3.1.tar.gz";
};
"11-darwin-aarch64" = {
sha256 = "0cbcm9d211m4b6g1bkpfksma917lzqkl4kx38vm1nrwjkll357y5";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/graalvm-ce-java11-darwin-aarch64-22.3.1.tar.gz";
};
"17-darwin-aarch64" = {
sha256 = "1qbw3hlmqcrmd70xk56463scdxr50n66z2n3c24h68qlwwlpqc73";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/graalvm-ce-java17-darwin-aarch64-22.3.1.tar.gz";
};
"11-darwin-amd64" = {
sha256 = "0a12rzf99x5l29f6bwm6myk18dgnrx2c9rwmii2pm864y7azlnij";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/graalvm-ce-java11-darwin-amd64-22.3.1.tar.gz";
};
"17-darwin-amd64" = {
sha256 = "02lclv2j3v850izh84wdvksi3d3xmgpfl7x85vzifhgsvagm6sz4";
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/graalvm-ce-java17-darwin-amd64-22.3.1.tar.gz";
};
};
}

View File

@ -1,227 +0,0 @@
{ config
, defaultVersion
, forceUpdate
, gnused
, graalVersion
, javaVersion
, jq
, lib
, name
, sourcesPath
, writeShellScript
}:
/*
How to use:
run `nix-shell maintainers/scripts/update.nix --argstr package graalvmXX-ce`
to update the graalvmXX-ce-sources.json file.
E.g: nix-shell maintainers/scripts/update.nix --argstr package graalvm17-ce
Basic idea:
If we know the platform, product, javaVersion and graalVersion
we can create the url. This leads to the following json structure:
{
"platform/arch1": {
"product1|javaVersion|graalVersion": { "sha256": "...", "url": "..."},
"product2|javaVersion|graalVersion": { "sha256": "...", "url": "..."},
...
},
"platform/arch2": {
...
}
}
*/
let
separator = "|";
# isDev :: String -> Boolean
isDev = version:
lib.hasInfix "dev" version;
# getLatestVersion :: String -> String
getLatestVersion = currentVersion:
let
dev = if isDev currentVersion then "dev-" else "";
url = "https://api.github.com/repos/graalvm/graalvm-ce-${dev}builds/releases/latest";
file = builtins.fetchurl url;
json = builtins.fromJSON (builtins.readFile file);
in
lib.removePrefix "vm-" json.tag_name;
# getArchString :: String -> String
getArchString = nixArchString:
{
"aarch64-linux" = "linux-aarch64";
"aarch64-darwin" = "darwin-aarch64";
"x86_64-linux" = "linux-amd64";
"x86_64-darwin" = "darwin-amd64";
}.${nixArchString};
# getProductSuffix :: String -> String
getProductSuffix = productName:
{
"graalvm-ce" = ".tar.gz";
"native-image-installable-svm" = ".jar";
"ruby-installable-svm" = ".jar";
"wasm-installable-svm" = ".jar";
"python-installable-svm" = ".jar";
"js-installable-svm" = ".jar";
}.${productName};
# getProductSuffix :: String -> String
getProductBaseUrl = productName:
{
"graalvm-ce" = "https://github.com/graalvm/graalvm-ce-builds/releases/download";
"native-image-installable-svm" = "https://github.com/graalvm/graalvm-ce-builds/releases/download";
"ruby-installable-svm" = "https://github.com/oracle/truffleruby/releases/download";
"wasm-installable-svm" = "https://github.com/graalvm/graalvm-ce-builds/releases/download";
"python-installable-svm" = "https://github.com/graalvm/graalpython/releases/download";
"js-installable-svm" = "https://github.com/oracle/graaljs/releases/download";
}.${productName};
# getDevUrl :: String
getDevUrl = { arch, graalVersion, product, javaVersion }:
let
baseUrl = https://github.com/graalvm/graalvm-ce-dev-builds/releases/download;
in
"${baseUrl}/${graalVersion}/${product}-${javaVersion}-${arch}-dev${getProductSuffix product}";
# getReleaseUrl :: AttrSet -> String
getReleaseUrl = { arch, graalVersion, product, javaVersion }:
let baseUrl = getProductBaseUrl product;
in
"${baseUrl}/vm-${graalVersion}/${product}-${javaVersion}-${arch}-${graalVersion}${getProductSuffix product}";
# getUrl :: AttrSet -> String
getUrl = args@{ arch, graalVersion, product, javaVersion }:
if isDev graalVersion
then getDevUrl args
else getReleaseUrl args;
# computeSha256 :: String -> String
computeSha256 = url:
builtins.hashFile "sha256" (builtins.fetchurl url);
# downloadSha256 :: String -> String
downloadSha256 = url:
let sha256Url = url + ".sha256";
in
builtins.readFile (builtins.fetchurl sha256Url);
# getSha256 :: String -> String -> String
getSha256 = graalVersion: url:
if isDev graalVersion
then computeSha256 url
else downloadSha256 url;
# cartesianZipListsWith :: (a -> b -> c) -> [a] -> [b] -> [c]
cartesianZipListsWith = f: fst: snd:
let
cartesianProduct = lib.cartesianProductOfSets { a = fst; b = snd; };
fst' = builtins.catAttrs "a" cartesianProduct;
snd' = builtins.catAttrs "b" cartesianProduct;
in
lib.zipListsWith f fst' snd';
# zipListsToAttrs :: [a] -> [b] -> AttrSet
zipListsToAttrs = names: values:
lib.listToAttrs (
lib.zipListsWith (name: value: { inherit name value; }) names values
);
# genProductJavaVersionGraalVersionAttrSet :: String -> AttrSet
genProductJavaVersionGraalVersionAttrSet = product_javaVersion_graalVersion:
let
attrNames = [ "product" "javaVersion" "graalVersion" ];
attrValues = lib.splitString separator product_javaVersion_graalVersion;
in
zipListsToAttrs attrNames attrValues;
# genUrlAndSha256 :: String -> String -> AttrSet
genUrlAndSha256 = arch: product_javaVersion_graalVersion:
let
productJavaVersionGraalVersion =
(genProductJavaVersionGraalVersionAttrSet product_javaVersion_graalVersion)
// { inherit arch; };
url = getUrl productJavaVersionGraalVersion;
sha256 = getSha256 productJavaVersionGraalVersion.graalVersion url;
in
{
${arch} = {
${product_javaVersion_graalVersion} = {
inherit sha256 url;
};
};
};
# genArchProductVersionPairs :: String -> -> String -> AttrSet -> [AttrSet]
genArchProductVersionList = javaVersion: graalVersion: archProducts:
let
arch = archProducts.arch;
products = archProducts.products;
javaGraalVersion = javaVersion + separator + (getLatestVersion (archProducts.version or graalVersion));
productJavaGraalVersionList =
cartesianZipListsWith (a: b: a + separator + b)
products [ javaGraalVersion ];
in
cartesianZipListsWith (genUrlAndSha256) [ arch ] productJavaGraalVersionList;
# genSources :: String -> String -> AttrSet -> Path String
genSources = javaVersion: defaultVersion: config:
let
archProducts = builtins.attrValues config;
sourcesList = builtins.concatMap (genArchProductVersionList javaVersion defaultVersion) archProducts;
sourcesAttr = builtins.foldl' (lib.recursiveUpdate) { } sourcesList;
in
builtins.toFile "sources.json" (builtins.toJSON sourcesAttr);
# isNew :: String -> String -> Boolean
isNew = newVersion: currentVersion:
{
"-1" = false;
"0" = false;
"1" = true;
}.${builtins.toString (builtins.compareVersions newVersion currentVersion)};
newVersion = getLatestVersion graalVersion;
sourcesJson = genSources javaVersion defaultVersion config;
sourcesJsonPath = lib.strings.escapeShellArg sourcesPath;
# versionKeyInDefaultNix String -> String
versionKeyInDefaultNix = graalVersion:
if isDev graalVersion
then "${name}-dev-version"
else "${name}-release-version";
/*
updateScriptText :: String -> String -> String
Writes the json file and updates the version in default.nix using sed
because update-source-version does not work srcs.
*/
updateScriptText = newVersion: currentVersion:
if (forceUpdate || (isNew newVersion currentVersion))
then
let
versionKey = versionKeyInDefaultNix currentVersion;
in
''
echo "New version found. Updating ${currentVersion} -> ${newVersion}".
export PATH="${lib.makeBinPath [ jq gnused ]}:$PATH"
jq . ${sourcesJson} > ${sourcesJsonPath}
sed -i 's|${versionKey} = "${currentVersion}";|${versionKey} = "${newVersion}";|' \
${lib.strings.escapeShellArg ./default.nix}
''
else ''echo "No new version found. Skip updating."'';
in
writeShellScript "update-graal.sh" ''
set -o errexit
set -o nounset
set -o pipefail
${updateScriptText newVersion graalVersion}
''

View File

@ -0,0 +1,86 @@
#!/usr/bin/env nix-shell
#!nix-shell -p coreutils curl.out nix jq gnused -i bash
set -eou pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
tmpfile="$(mktemp --suffix=.nix)"
info() { echo "[INFO] $*"; }
echo_file() { echo "$@" >> "$tmpfile"; }
verlte() {
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
}
readonly nixpkgs=../../../../..
readonly current_version="$(nix-instantiate "$nixpkgs" --eval --strict -A graalvm11-ce.version | tr -d \")"
if [[ -z "${1:-}" ]]; then
readonly gh_version="$(curl \
${GITHUB_TOKEN:+"-u \":$GITHUB_TOKEN\""} \
-s https://api.github.com/repos/graalvm/graalvm-ce-builds/releases/latest | \
jq --raw-output .tag_name)"
readonly new_version="${gh_version//vm-/}"
else
readonly new_version="$1"
fi
info "Current version: $current_version"
info "New version: $new_version"
if verlte "$new_version" "$current_version"; then
info "graalvm-ce $current_version is up-to-date."
[[ -z "${FORCE:-}" ]] && exit 0
else
info "graalvm-ce $current_version is out-of-date. Updating..."
fi
declare -r -A products_urls=(
[graalvm-ce]="https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/graalvm-ce-java@platform@-${new_version}.tar.gz"
[native-image-installable-svm]="https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/native-image-installable-svm-java@platform@-${new_version}.jar"
# [ruby-installable-svm]="https://github.com/oracle/truffleruby/releases/download/vm-${new_version}/ruby-installable-svm-java@platform@-${new_version}.jar"
# [wasm-installable-svm]="https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/wasm-installable-svm-java@platform@-${new_version}.jar"
# [python-installable-svm]="https://github.com/graalvm/graalpython/releases/download/vm-${new_version}/python-installable-svm-java@platform@-${new_version}.jar"
)
readonly platforms=(
"11-linux-aarch64"
"17-linux-aarch64"
"11-linux-amd64"
"17-linux-amd64"
"11-darwin-aarch64"
"17-darwin-aarch64"
"11-darwin-amd64"
"17-darwin-amd64"
)
info "Generating hashes.nix file for 'graalvm-ce' $new_version. This will take a while..."
# Indentation of `echo_file` function is on purpose to make it easier to visualize the output
echo_file "# Generated by $0 script"
echo_file "{"
for product in "${!products_urls[@]}"; do
url="${products_urls["${product}"]}"
echo_file " \"$product\" = {"
for platform in "${platforms[@]}"; do
if hash="$(nix-prefetch-url "${url//@platform@/$platform}")"; then
echo_file " \"$platform\" = {"
echo_file " sha256 = \"$hash\";"
echo_file " url = \"${url//@platform@/${platform}}\";"
echo_file " };"
fi
done
echo_file " };"
done
echo_file "}"
info "Updating graalvm-ce version..."
# update-source-version does not work here since it expects src attribute
sed "s|$current_version|$new_version|" -i default.nix
info "Moving the temporary file to hashes.nix"
mv "$tmpfile" hashes.nix
info "Done!"