2022-04-16 13:37:37 +02:00
|
|
|
{ config
|
2022-04-02 11:33:07 +02:00
|
|
|
, defaultVersion
|
2022-04-16 13:37:37 +02:00
|
|
|
, forceUpdate
|
|
|
|
, gnused
|
|
|
|
, graalVersion
|
|
|
|
, javaVersion
|
|
|
|
, jq
|
2022-03-29 16:59:42 +02:00
|
|
|
, lib
|
2022-04-16 13:37:37 +02:00
|
|
|
, name
|
|
|
|
, sourcesPath
|
2022-04-01 12:59:37 +02:00
|
|
|
, writeShellScript
|
2022-03-28 08:06:08 +02:00
|
|
|
}:
|
|
|
|
|
2022-03-29 16:59:42 +02:00
|
|
|
/*
|
|
|
|
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": {
|
|
|
|
...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2022-03-28 08:06:08 +02:00
|
|
|
let
|
2022-04-01 12:59:37 +02:00
|
|
|
separator = "|";
|
2022-03-29 16:59:42 +02:00
|
|
|
|
|
|
|
# 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;
|
|
|
|
|
2022-03-28 08:06:08 +02:00
|
|
|
# getArchString :: String -> String
|
|
|
|
getArchString = nixArchString:
|
|
|
|
{
|
|
|
|
"aarch64-linux" = "linux-aarch64";
|
2022-04-28 00:07:21 +02:00
|
|
|
"aarch64-darwin" = "darwin-aarch64";
|
2022-03-28 08:06:08 +02:00
|
|
|
"x86_64-linux" = "linux-amd64";
|
|
|
|
"x86_64-darwin" = "darwin-amd64";
|
|
|
|
}.${nixArchString};
|
|
|
|
|
|
|
|
|
|
|
|
# getProductSuffix :: String -> String
|
2022-03-29 16:59:42 +02:00
|
|
|
getProductSuffix = productName:
|
|
|
|
{
|
|
|
|
"graalvm-ce" = ".tar.gz";
|
|
|
|
"native-image-installable-svm" = ".jar";
|
|
|
|
"ruby-installable-svm" = ".jar";
|
|
|
|
"wasm-installable-svm" = ".jar";
|
|
|
|
"python-installable-svm" = ".jar";
|
|
|
|
}.${productName};
|
2022-03-28 08:06:08 +02:00
|
|
|
|
|
|
|
# getProductSuffix :: String -> String
|
2022-03-29 16:59:42 +02:00
|
|
|
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};
|
2022-03-29 12:36:39 +02:00
|
|
|
|
|
|
|
# getDevUrl :: String
|
2022-03-29 16:59:42 +02:00
|
|
|
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}";
|
2022-03-28 08:06:08 +02:00
|
|
|
|
2022-03-29 12:36:39 +02:00
|
|
|
# getReleaseUrl :: AttrSet -> String
|
2022-03-29 16:59:42 +02:00
|
|
|
getReleaseUrl = { arch, graalVersion, product, javaVersion }:
|
|
|
|
let baseUrl = getProductBaseUrl product;
|
|
|
|
in
|
|
|
|
"${baseUrl}/vm-${graalVersion}/${product}-${javaVersion}-${arch}-${graalVersion}${getProductSuffix product}";
|
2022-03-28 08:06:08 +02:00
|
|
|
|
2022-03-29 12:36:39 +02:00
|
|
|
# getUrl :: AttrSet -> String
|
2022-03-29 16:59:42 +02:00
|
|
|
getUrl = args@{ arch, graalVersion, product, javaVersion }:
|
|
|
|
if isDev graalVersion
|
|
|
|
then getDevUrl args
|
|
|
|
else getReleaseUrl args;
|
2022-03-28 08:06:08 +02:00
|
|
|
|
2022-03-29 12:36:39 +02:00
|
|
|
# computeSha256 :: String -> String
|
2022-03-29 16:59:42 +02:00
|
|
|
computeSha256 = url:
|
|
|
|
builtins.hashFile "sha256" (builtins.fetchurl url);
|
2022-03-29 12:36:39 +02:00
|
|
|
|
|
|
|
# downloadSha256 :: String -> String
|
2022-03-29 16:59:42 +02:00
|
|
|
downloadSha256 = url:
|
|
|
|
let sha256Url = url + ".sha256";
|
|
|
|
in
|
|
|
|
builtins.readFile (builtins.fetchurl sha256Url);
|
2022-03-29 12:36:39 +02:00
|
|
|
|
|
|
|
# getSha256 :: String -> String -> String
|
2022-03-29 16:59:42 +02:00
|
|
|
getSha256 = graalVersion: url:
|
|
|
|
if isDev graalVersion
|
|
|
|
then computeSha256 url
|
|
|
|
else downloadSha256 url;
|
2022-03-28 08:06:08 +02:00
|
|
|
|
|
|
|
# cartesianZipListsWith :: (a -> b -> c) -> [a] -> [b] -> [c]
|
2022-03-29 16:59:42 +02:00
|
|
|
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';
|
2022-03-28 08:06:08 +02:00
|
|
|
|
|
|
|
# zipListsToAttrs :: [a] -> [b] -> AttrSet
|
2022-03-29 16:59:42 +02:00
|
|
|
zipListsToAttrs = names: values:
|
|
|
|
lib.listToAttrs (
|
|
|
|
lib.zipListsWith (name: value: { inherit name value; }) names values
|
|
|
|
);
|
2022-03-28 08:06:08 +02:00
|
|
|
|
|
|
|
# genProductJavaVersionGraalVersionAttrSet :: String -> AttrSet
|
2022-03-29 16:59:42 +02:00
|
|
|
genProductJavaVersionGraalVersionAttrSet = product_javaVersion_graalVersion:
|
|
|
|
let
|
|
|
|
attrNames = [ "product" "javaVersion" "graalVersion" ];
|
2022-04-01 12:59:37 +02:00
|
|
|
attrValues = lib.splitString separator product_javaVersion_graalVersion;
|
2022-03-29 16:59:42 +02:00
|
|
|
in
|
|
|
|
zipListsToAttrs attrNames attrValues;
|
2022-03-28 08:06:08 +02:00
|
|
|
|
|
|
|
# genUrlAndSha256 :: String -> String -> AttrSet
|
2022-03-29 16:59:42 +02:00
|
|
|
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;
|
2022-03-28 08:06:08 +02:00
|
|
|
};
|
|
|
|
};
|
2022-03-29 16:59:42 +02:00
|
|
|
};
|
2022-03-28 08:06:08 +02:00
|
|
|
|
2022-04-02 11:33:07 +02:00
|
|
|
# genArchProductVersionPairs :: String -> -> String -> AttrSet -> [AttrSet]
|
|
|
|
genArchProductVersionList = javaVersion: graalVersion: archProducts:
|
2022-03-29 16:59:42 +02:00
|
|
|
let
|
|
|
|
arch = archProducts.arch;
|
|
|
|
products = archProducts.products;
|
2022-04-02 11:33:07 +02:00
|
|
|
javaGraalVersion = javaVersion + separator + (getLatestVersion (archProducts.version or graalVersion));
|
2022-03-29 16:59:42 +02:00
|
|
|
productJavaGraalVersionList =
|
2022-04-01 12:59:37 +02:00
|
|
|
cartesianZipListsWith (a: b: a + separator + b)
|
2022-03-29 16:59:42 +02:00
|
|
|
products [ javaGraalVersion ];
|
|
|
|
in
|
|
|
|
cartesianZipListsWith (genUrlAndSha256) [ arch ] productJavaGraalVersionList;
|
2022-03-28 08:06:08 +02:00
|
|
|
|
|
|
|
|
2022-04-02 11:33:07 +02:00
|
|
|
# genSources :: String -> String -> AttrSet -> Path String
|
|
|
|
genSources = javaVersion: defaultVersion: config:
|
2022-03-29 16:59:42 +02:00
|
|
|
let
|
|
|
|
archProducts = builtins.attrValues config;
|
2022-04-02 11:33:07 +02:00
|
|
|
sourcesList = builtins.concatMap (genArchProductVersionList javaVersion defaultVersion) archProducts;
|
2022-03-29 16:59:42 +02:00
|
|
|
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;
|
2022-04-02 11:33:07 +02:00
|
|
|
sourcesJson = genSources javaVersion defaultVersion config;
|
2022-04-16 13:37:37 +02:00
|
|
|
sourcesJsonPath = lib.strings.escapeShellArg sourcesPath;
|
2022-04-01 12:59:37 +02:00
|
|
|
|
|
|
|
# versionKeyInDefaultNix String -> String
|
|
|
|
versionKeyInDefaultNix = graalVersion:
|
|
|
|
if isDev graalVersion
|
|
|
|
then "${name}-dev-version"
|
|
|
|
else "${name}-release-version";
|
2022-03-29 16:59:42 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
updateScriptText :: String -> String -> String
|
2022-04-01 12:59:37 +02:00
|
|
|
Writes the json file and updates the version in default.nix using sed
|
|
|
|
because update-source-version does not work srcs.
|
2022-03-29 16:59:42 +02:00
|
|
|
*/
|
|
|
|
updateScriptText = newVersion: currentVersion:
|
2022-04-01 12:59:37 +02:00
|
|
|
|
2022-04-15 21:08:43 +02:00
|
|
|
if (forceUpdate || (isNew newVersion currentVersion))
|
2022-03-29 16:59:42 +02:00
|
|
|
then
|
2022-04-01 12:59:37 +02:00
|
|
|
let
|
|
|
|
versionKey = versionKeyInDefaultNix currentVersion;
|
|
|
|
in
|
2022-03-29 16:59:42 +02:00
|
|
|
''
|
|
|
|
echo "New version found. Updating ${currentVersion} -> ${newVersion}".
|
2022-04-01 12:59:37 +02:00
|
|
|
export PATH="${lib.makeBinPath [ jq gnused ]}:$PATH"
|
2022-03-29 16:59:42 +02:00
|
|
|
jq . ${sourcesJson} > ${sourcesJsonPath}
|
2022-04-01 12:59:37 +02:00
|
|
|
sed -i 's|${versionKey} = "${currentVersion}";|${versionKey} = "${newVersion}";|' \
|
2022-04-02 10:54:44 +02:00
|
|
|
${lib.strings.escapeShellArg ./default.nix}
|
2022-03-29 16:59:42 +02:00
|
|
|
''
|
|
|
|
else ''echo "No new version found. Skip updating."'';
|
2022-03-28 08:06:08 +02:00
|
|
|
|
|
|
|
in
|
2022-04-01 12:59:37 +02:00
|
|
|
writeShellScript "update-graal.sh" ''
|
2022-03-29 16:59:42 +02:00
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
${updateScriptText newVersion graalVersion}
|
|
|
|
''
|