From 50f6c0dfa78b0ef081059953df6aad0769c7a0e1 Mon Sep 17 00:00:00 2001 From: Thibault Gagnaux Date: Tue, 29 Mar 2022 16:59:42 +0200 Subject: [PATCH] graalvmXX-ce: refactor and clean up of update.nix The update script fetches the latest versions and only computes/downloads the sha256 if there is a new version to improve runtime. --- .../graalvm/community-edition/default.nix | 6 +- .../graalvm17-ce-dev-sources.json | 12 +- .../graalvm/community-edition/hashes.nix | 57 ---- .../graalvm/community-edition/mkGraal.nix | 55 ++-- .../graalvm/community-edition/update.nix | 272 +++++++++++------- .../graalvm/community-edition/update.sh | 81 ------ 6 files changed, 204 insertions(+), 279 deletions(-) delete mode 100644 pkgs/development/compilers/graalvm/community-edition/hashes.nix delete mode 100755 pkgs/development/compilers/graalvm/community-edition/update.sh diff --git a/pkgs/development/compilers/graalvm/community-edition/default.nix b/pkgs/development/compilers/graalvm/community-edition/default.nix index 5a3a9e4d6ca6..d45b600d8401 100644 --- a/pkgs/development/compilers/graalvm/community-edition/default.nix +++ b/pkgs/development/compilers/graalvm/community-edition/default.nix @@ -1,4 +1,8 @@ { lib, callPackage, Foundation }: +/* +Add new graal versions and products here and then see update.nix on how to +generate the sources. +*/ let mkGraal = opts: callPackage (import ./mkGraal.nix opts) { @@ -67,7 +71,7 @@ in ]; }; }; - version = "22.2.0-dev-20220326_0133"; + version = "22.2.0-dev-20220330_2302"; javaVersion = "17"; platforms = builtins.attrNames config; }; diff --git a/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-dev-sources.json b/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-dev-sources.json index f3f15fdbc2c9..fba77c58b74a 100644 --- a/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-dev-sources.json +++ b/pkgs/development/compilers/graalvm/community-edition/graalvm17-ce-dev-sources.json @@ -1,12 +1,12 @@ { "darwin-aarch64": { - "graalvm-ce|java17|22.2.0-dev-20220326_0133": { - "sha256": "72bab733783684dba422d9e04eb4fbd9103adb21db6937cf204c0c46e6ce5b7d", - "url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220326_0133/graalvm-ce-java17-darwin-aarch64-dev.tar.gz" + "graalvm-ce|java17|22.2.0-dev-20220330_2302": { + "sha256": "e072cdcdf1dcc7884cfe53806e997649ae829a30e1efe19b0b77a91800da79c3", + "url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220330_2302/graalvm-ce-java17-darwin-aarch64-dev.tar.gz" }, - "native-image-installable-svm|java17|22.2.0-dev-20220326_0133": { - "sha256": "397fd17fef67456f66820cbdae9493d16785499b91002d20fdef6e5aaf067ba7", - "url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220326_0133/native-image-installable-svm-java17-darwin-aarch64-dev.jar" + "native-image-installable-svm|java17|22.2.0-dev-20220330_2302": { + "sha256": "fb554d9de8252630e8bde122ca98a75d39e200390384ddb410b3c3af3898ba6a", + "url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220330_2302/native-image-installable-svm-java17-darwin-aarch64-dev.jar" } } } diff --git a/pkgs/development/compilers/graalvm/community-edition/hashes.nix b/pkgs/development/compilers/graalvm/community-edition/hashes.nix deleted file mode 100644 index f21fdb252708..000000000000 --- a/pkgs/development/compilers/graalvm/community-edition/hashes.nix +++ /dev/null @@ -1,57 +0,0 @@ -# Generated by ./update.sh script -{ javaVersionPlatform, ... }: -[ - { - sha256 = { - "11-linux-aarch64" = "0n1cgd9rn5aw7rzbd45nlzpnqif095zwl3999vddlhpnjlyjdh0w"; - "17-linux-aarch64" = "1iw27igiyzzl43yfgid1h6h7hd0xnv0rfdkp4r7r8i51sa3q7my7"; - "11-linux-amd64" = "00vipkrhc7d5xxznm07pjrdjahhfg5s5vxg49xz8qxz2nwxhi1mw"; - "17-linux-amd64" = "1m4v2s1b2878r6dqpcxvbqpc3s2l8l0xcbna37bbfx6rsc73wx2g"; - "11-darwin-amd64" = "08v37avg439hywx2yqx0bnfpazwaja2xhyc0kj1imib6iadib042"; - "17-darwin-amd64" = "16lg3qfx7j8w8cxc3abl7c19nj6jhkni99wmff153lyhyk8zjjnm"; - }.${javaVersionPlatform} or null; - url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/graalvm-ce-java${javaVersionPlatform}-22.0.0.2.tar.gz"; - } - { - sha256 = { - "11-linux-aarch64" = "17h0yfw0lxsiblqv1nzpc6i71vh6hbwf1x6lp7kziass1a4ixm2i"; - "17-linux-aarch64" = "1nvm04smzbis1jy9znac2a4yf9ajqvvmadcf5ffr521rm784g2br"; - "11-linux-amd64" = "07g7fab0zj1h77a30kiswqm0hvr1m5s6crszcbyvha2v3x2a6145"; - "17-linux-amd64" = "0c8qi7b63zkjrz3sz01bbmfni7pcz9nq1jv1f34lj9lcsm8gc9cc"; - "11-darwin-amd64" = "0xn1frj1f4pzrd5gm6xwq31blgvz8l9249c97q3yh7p6rkk7vhh3"; - "17-darwin-amd64" = "1dr80314fxcklmhi19jn3pqrsz3iivbvcxnphdzl978krm1afzq0"; - }.${javaVersionPlatform} or null; - url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/native-image-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar"; - } - { - sha256 = { - "11-linux-aarch64" = "103d91sz2dmlc5hcbi9v3d3irgb83755hz16vkknfhbbkhm5iyz0"; - "17-linux-aarch64" = "0vas98knpvpajmv8bkgcf0fh7n5fy361nd47002cpppg6hrp7k9q"; - "11-linux-amd64" = "0h4s1dgx2wn63pabdckl85s70s1kw97vp0c8z7izihdn2fy7w3z9"; - "17-linux-amd64" = "1g98ashyvscwyn1k8mamih6qhcbxsk62x6ynd7x81ndy1karlv6q"; - "11-darwin-amd64" = "1y8d6c2ri7hrvsv3aqbcp49pmxh9yppcsfnx0jcwm88wlach0p52"; - "17-darwin-amd64" = "13a6rchnaczpmxga6g405z55913ayq5gwihzlvyy6shk6gwbcppw"; - }.${javaVersionPlatform} or null; - url = "https://github.com/oracle/truffleruby/releases/download/vm-22.0.0.2/ruby-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar"; - } - { - sha256 = { - "11-linux-aarch64" = "135zkpqm8z5nzcyn5h6vdx3c09f9wb6jgzmp0llcnx8w76p71154"; - "17-linux-aarch64" = "0pij3kh70lxrzmbzx8zw97f9nb0rr492l7x3n13wcr859cr8akas"; - "11-linux-amd64" = "0ppvsgs216jmm5p8m34lqg2kv0awadh1dlkxb7qzcw2b6x0grzf0"; - "17-linux-amd64" = "1gf0jfmqy8lp6w7bimjp0j5abzmi0ndsn4hcjvfv7123lbj52zkz"; - "11-darwin-amd64" = "1mq6013crjmrpf3yvxwv9p4yn0rcdzg5z9hq9l6fpf47i8522k6p"; - "17-darwin-amd64" = "15l7p48vsca4cvqxbpb9lcmafysmdsxpv6avrpxajz705j3nsvmp"; - }.${javaVersionPlatform} or null; - url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/wasm-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar"; - } - { - sha256 = { - "11-linux-amd64" = "0m8cqqqdks34b2zv7i6qw9kzqxi1rfqsmknqa9wm0b7dqaxx209g"; - "17-linux-amd64" = "12nszxp2yv35y8zkm94bnd0mnanah48y41r61ypymd19plaqmdxk"; - "11-darwin-amd64" = "00g6akpv0gkw8gcxfbgcyipn6gj25yr32k1lb7iqj08bq4f2zvk7"; - "17-darwin-amd64" = "1hd71qg0nmklyakl4cc29vl10fxalbyd2b5yn7x9iv6m0h1pp25g"; - }.${javaVersionPlatform} or null; - url = "https://github.com/graalvm/graalpython/releases/download/vm-22.0.0.2/python-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar"; - } -] diff --git a/pkgs/development/compilers/graalvm/community-edition/mkGraal.nix b/pkgs/development/compilers/graalvm/community-edition/mkGraal.nix index cc8027dd128d..ea4fd89bbcbe 100644 --- a/pkgs/development/compilers/graalvm/community-edition/mkGraal.nix +++ b/pkgs/development/compilers/graalvm/community-edition/mkGraal.nix @@ -36,14 +36,15 @@ , writeScript , jq , runtimeShell -, callPackage +, gawk }: assert useMusl -> stdenv.isLinux; let platform = config.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); - name = if lib.hasInfix "dev" version + name = + if lib.hasInfix "dev" version then "graalvm${javaVersion}-ce-dev" else "graalvm${javaVersion}-ce"; sourcesFilename = "${name}-sources.json"; @@ -61,20 +62,10 @@ let (writeShellScriptBin "${stdenv.system}-musl-gcc" ''${lib.getDev musl}/bin/musl-gcc "$@"'') ]); - javaVersionPlatform = "${javaVersion}-${platform.arch}"; - graalvmXXX-ce = stdenv.mkDerivation rec { inherit version name; + srcs = map fetchurl (builtins.attrValues sources.${platform.arch}); - /*let - # Some platforms doesn't have all GraalVM features - # e.g.: GraalPython on aarch64-linux - # When the platform doesn't have a feature, sha256 is null on hashes.nix - # To update hashes.nix file, run `./update.sh ` - maybeFetchUrl = url: if url.sha256 != null then (fetchurl url) else null; - in - (lib.remove null - (map maybeFetchUrl (hashes { inherit javaVersionPlatform; })));*/ buildInputs = lib.optionals stdenv.isLinux [ alsa-lib # libasound.so wanted by lib/libjsound.so @@ -166,25 +157,25 @@ let done ''; in - '' - # ensure that $lib/lib exists to avoid breaking builds - mkdir -p $lib/lib - # jni.h expects jni_md.h to be in the header search path. - ln -s $out/include/linux/*_md.h $out/include/ + '' + # ensure that $lib/lib exists to avoid breaking builds + mkdir -p $lib/lib + # jni.h expects jni_md.h to be in the header search path. + ln -s $out/include/linux/*_md.h $out/include/ - # copy-paste openjdk's preFixup - # Set JAVA_HOME automatically. - mkdir -p $out/nix-support - cat > $out/nix-support/setup-hook << EOF - if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi - EOF - ${ - lib.optionalString (stdenv.isLinux) '' - ${copyClibrariesToOut "$out/lib/svm/clibraries"} - ${copyClibrariesToLib} - '' - } - ''; + # copy-paste openjdk's preFixup + # Set JAVA_HOME automatically. + mkdir -p $out/nix-support + cat > $out/nix-support/setup-hook << EOF + if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi + EOF + ${ + lib.optionalString (stdenv.isLinux) '' + ${copyClibrariesToOut "$out/lib/svm/clibraries"} + ${copyClibrariesToLib} + '' + } + ''; dontStrip = true; @@ -303,7 +294,7 @@ let passthru = { home = graalvmXXX-ce; updateScript = import ./update.nix { - inherit lib writeScript jq runtimeShell sourcesFilename config; + inherit lib writeScript jq runtimeShell sourcesFilename name config gawk; graalVersion = version; javaVersion = "java${javaVersion}"; }; diff --git a/pkgs/development/compilers/graalvm/community-edition/update.nix b/pkgs/development/compilers/graalvm/community-edition/update.nix index efb46fe838dc..e9d32cf7bdeb 100644 --- a/pkgs/development/compilers/graalvm/community-edition/update.nix +++ b/pkgs/development/compilers/graalvm/community-edition/update.nix @@ -1,16 +1,53 @@ -{ - javaVersion, - graalVersion, - config, - sourcesFilename, - lib, - writeScript, - jq, - runtimeShell +{ javaVersion +, graalVersion +, config +, sourcesFilename +, name +, lib +, writeScript +, jq +, runtimeShell +, gawk }: +/* + 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 productJavaVersionGraalVersionSep = "|"; + + # 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: { @@ -21,129 +58,160 @@ let # 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"; - }.${productName}; + getProductSuffix = productName: + { + "graalvm-ce" = ".tar.gz"; + "native-image-installable-svm" = ".jar"; + "ruby-installable-svm" = ".jar"; + "wasm-installable-svm" = ".jar"; + "python-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"; - }.${productName}; + 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"; + }.${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}"; + 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}"; + 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 lib.hasInfix "dev" graalVersion - then getDevUrl args - else getReleaseUrl args; + 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); + computeSha256 = url: + builtins.hashFile "sha256" (builtins.fetchurl url); # downloadSha256 :: String -> String - downloadSha256 = url: - let sha256Url = url + ".sha256"; - in - builtins.readFile (builtins.fetchurl sha256Url); + downloadSha256 = url: + let sha256Url = url + ".sha256"; + in + builtins.readFile (builtins.fetchurl sha256Url); # getSha256 :: String -> String -> String - getSha256 = graalVersion: url: - if lib.hasInfix "dev" graalVersion - then computeSha256 url - else downloadSha256 url; + 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'; + 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 - ); + 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 productJavaVersionGraalVersionSep product_javaVersion_graalVersion; - in zipListsToAttrs attrNames attrValues; + genProductJavaVersionGraalVersionAttrSet = product_javaVersion_graalVersion: + let + attrNames = [ "product" "javaVersion" "graalVersion" ]; + attrValues = lib.splitString productJavaVersionGraalVersionSep 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; - }; + 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 -> AttrSet -> [AttrSet] - genArchProductVersionList = javaGraalVersion: archProducts: - let - arch = archProducts.arch; - products = archProducts.products; - productJavaGraalVersionList = - cartesianZipListsWith (a: b: a + productJavaVersionGraalVersionSep + b) - products [ javaGraalVersion ]; - in - cartesianZipListsWith (genUrlAndSha256) [ arch ] productJavaGraalVersionList; + genArchProductVersionList = javaGraalVersion: archProducts: + let + arch = archProducts.arch; + products = archProducts.products; + productJavaGraalVersionList = + cartesianZipListsWith (a: b: a + productJavaVersionGraalVersionSep + b) + products [ javaGraalVersion ]; + in + cartesianZipListsWith (genUrlAndSha256) [ arch ] productJavaGraalVersionList; # genSources :: String -> String -> AttrSet -> Path String - genSources = graalVersion: javaVersion: config: - let - javaGraalVersion = javaVersion + productJavaVersionGraalVersionSep + graalVersion; - archProducts = builtins.attrValues config; - sourcesList = builtins.concatMap (genArchProductVersionList javaGraalVersion) archProducts; - sourcesAttr = builtins.foldl' (lib.recursiveUpdate) {} sourcesList; - in - builtins.toFile "sources.json" (builtins.toJSON sourcesAttr); + genSources = graalVersion: javaVersion: config: + let + javaGraalVersion = javaVersion + productJavaVersionGraalVersionSep + graalVersion; + archProducts = builtins.attrValues config; + sourcesList = builtins.concatMap (genArchProductVersionList javaGraalVersion) archProducts; + sourcesAttr = builtins.foldl' (lib.recursiveUpdate) { } sourcesList; + in + builtins.toFile "sources.json" (builtins.toJSON sourcesAttr); - sourcesJson = genSources graalVersion javaVersion config; + # isNew :: String -> String -> Boolean + isNew = newVersion: currentVersion: + { + "-1" = false; + "0" = false; + "1" = true; + }.${builtins.toString (builtins.compareVersions newVersion currentVersion)}; + + newVersion = getLatestVersion graalVersion; + sourcesJson = genSources newVersion javaVersion config; + sourcesJsonPath = lib.strings.escapeShellArg ././${sourcesFilename}; + defaultNixPath = lib.strings.escapeShellArg ././default.nix; + + /* + updateScriptText :: String -> String -> String + Writes the json file, finds the line number of the current derivation + name, which wants to update with awk and replace the first version match + after that line. + */ + updateScriptText = newVersion: currentVersion: + if isNew newVersion currentVersion + then + '' + echo "New version found. Updating ${currentVersion} -> ${newVersion}". + export PATH="${lib.makeBinPath [ jq gawk ]}:$PATH" + jq . ${sourcesJson} > ${sourcesJsonPath} + drvName=$(awk '/${name}/{ print NR; exit }' ${defaultNixPath}) + awk -v drvName="$drvName" -i inplace \ + 'NR>drvName {sub(/${graalVersion}/, "${newVersion}")} 1' ${defaultNixPath} + '' + else ''echo "No new version found. Skip updating."''; in - writeScript "update-graal.sh" '' - #!${runtimeShell} - set -o errexit - set -o nounset - set -o pipefail +writeScript "update-graal.sh" '' + #!${runtimeShell} + set -o errexit + set -o nounset + set -o pipefail - export PATH="${lib.makeBinPath [ jq ]}:$PATH" - - jq . ${sourcesJson} > ${lib.strings.escapeShellArg ./.}/${sourcesFilename} - '' + ${updateScriptText newVersion graalVersion} +'' diff --git a/pkgs/development/compilers/graalvm/community-edition/update.sh b/pkgs/development/compilers/graalvm/community-edition/update.sh deleted file mode 100755 index c821c83a59c8..000000000000 --- a/pkgs/development/compilers/graalvm/community-edition/update.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -p coreutils curl nix jq gnused -i bash - -set -eou pipefail - -cd "$(dirname "${BASH_SOURCE[0]}")" - -info() { echo "[INFO] $*"; } - -echo_file() { echo "$@" >> hashes.nix; } - -verlte() { - [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ] -} - -readonly nixpkgs=../../../../.. - -readonly old_version="$(nix-instantiate "$nixpkgs" --eval --strict -A graalvm11-ce.version)" - -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 - -if verlte "$old_version" "$new_version"; then - info "graalvm-ce $old_version is up-to-date." - [[ -z "${FORCE:-}" ]] && exit 0 -else - info "graalvm-ce $old_version is out-of-date. Updating..." -fi - -readonly urls=( - "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/graalvm-ce-java@platform@-${new_version}.tar.gz" - "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/native-image-installable-svm-java@platform@-${new_version}.jar" - "https://github.com/oracle/truffleruby/releases/download/vm-${new_version}/ruby-installable-svm-java@platform@-${new_version}.jar" - "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/wasm-installable-svm-java@platform@-${new_version}.jar" - "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-amd64" - "17-darwin-amd64" -) - -info "Deleting old hashes.nix file..." -rm -f hashes.nix -info "Generating hashes.nix file for 'graalvm-ce' $new_version. This will take a while..." - -echo_file "# Generated by $0 script" -echo_file "{ javaVersionPlatform, ... }:" -echo_file "[" - -for url in "${urls[@]}"; do - echo_file " {" - echo_file " sha256 = {" - for platform in "${platforms[@]}"; do - if hash="$(nix-prefetch-url "${url//@platform@/$platform}")"; then - echo_file " \"$platform\" = \"$hash\";" - fi - done - echo_file ' }.${javaVersionPlatform} or null;' - echo_file " url = \"${url//@platform@/\$\{javaVersionPlatform\}}\";" - echo_file " }" -done - -echo_file "]" - -info "Updating graalvm-ce version..." -# update-source-version does not work here since it expects src attribute -sed "s|$old_version|\"$new_version\"|" -i default.nix - -info "Done!"