uboot: (firmwareOdroidC2/C4) don't invoke patch tool, use patches = [] instead

https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L948
this can do it nicely.

Signed-off-by: Anton Arapov <anton@deadbeef.mx>
This commit is contained in:
Anton Arapov 2021-04-03 12:58:10 +02:00 committed by Alan Daniels
commit 56de2bcd43
30691 changed files with 3076956 additions and 0 deletions

View file

@ -0,0 +1,75 @@
{ 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) {
inherit Foundation;
};
/*
Looks a bit ugly but makes version update in the update script using sed
much easier
Don't change these values! They will be updated by the update script, see ./update.nix.
*/
graalvm11-ce-release-version = "22.1.0";
graalvm17-ce-release-version = "22.1.0";
products = [
"graalvm-ce"
"native-image-installable-svm"
];
in
{
inherit mkGraal;
graalvm11-ce = mkGraal rec {
config = {
x86_64-darwin = {
inherit products;
arch = "darwin-amd64";
};
x86_64-linux = {
inherit products;
arch = "linux-amd64";
};
aarch64-darwin = {
inherit products;
arch = "darwin-aarch64";
};
aarch64-linux = {
inherit products;
arch = "linux-aarch64";
};
};
defaultVersion = graalvm11-ce-release-version;
javaVersion = "11";
};
graalvm17-ce = mkGraal rec {
config = {
x86_64-darwin = {
inherit products;
arch = "darwin-amd64";
};
x86_64-linux = {
inherit products;
arch = "linux-amd64";
};
aarch64-darwin = {
inherit products;
arch = "darwin-aarch64";
};
aarch64-linux = {
inherit products;
arch = "linux-aarch64";
};
};
defaultVersion = graalvm17-ce-release-version;
javaVersion = "17";
};
}

View file

@ -0,0 +1,42 @@
{
"darwin-aarch64": {
"graalvm-ce|java11|22.1.0": {
"sha256": "06bc19a0b1e93aa3df5e15c08e97f8cef624cb6070eeae40a69a51ec7fd41152",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/graalvm-ce-java11-darwin-aarch64-22.1.0.tar.gz"
},
"native-image-installable-svm|java11|22.1.0": {
"sha256": "21f84ccf7b979dccc9091032fe76b5737b38e0092f282107cef75143dadb3bdb",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/native-image-installable-svm-java11-darwin-aarch64-22.1.0.jar"
}
},
"darwin-amd64": {
"graalvm-ce|java11|22.1.0": {
"sha256": "c4c9df94ca47b83b582758b87d39042732ba0193fc63f1ab93f6818005a1fe6b",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/graalvm-ce-java11-darwin-amd64-22.1.0.tar.gz"
},
"native-image-installable-svm|java11|22.1.0": {
"sha256": "e0758687f4bd46f15fcee9b0a5bdd65d702ec81c41d465ee7229d3f4465bcf13",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/native-image-installable-svm-java11-darwin-amd64-22.1.0.jar"
}
},
"linux-aarch64": {
"graalvm-ce|java11|22.1.0": {
"sha256": "050a4d471247d91935f7f485e92d678f0163e1d6209e26e8fe75d7c924f73e71",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/graalvm-ce-java11-linux-aarch64-22.1.0.tar.gz"
},
"native-image-installable-svm|java11|22.1.0": {
"sha256": "12715793b223ce1db7ec7d0a339f0b578a0c9fb6dcc6607044e5af4fd33b25a7",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/native-image-installable-svm-java11-linux-aarch64-22.1.0.jar"
}
},
"linux-amd64": {
"graalvm-ce|java11|22.1.0": {
"sha256": "78c628707007bb97b09562932ee16f50beb1c3fa4a36e4311a0465a4a718e683",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/graalvm-ce-java11-linux-amd64-22.1.0.tar.gz"
},
"native-image-installable-svm|java11|22.1.0": {
"sha256": "36e4a2a9a73a19b03883f9e783bc8bde7c214bb0fa4b617379cb81798de425bf",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/native-image-installable-svm-java11-linux-amd64-22.1.0.jar"
}
}
}

View file

@ -0,0 +1,42 @@
{
"darwin-aarch64": {
"graalvm-ce|java17|22.1.0": {
"sha256": "06075cd390bd261721392cd6fd967b1d28c0500d1b5625272ea906038e5cd533",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/graalvm-ce-java17-darwin-aarch64-22.1.0.tar.gz"
},
"native-image-installable-svm|java17|22.1.0": {
"sha256": "beabecdd5b87e7536772d4dfe70abf4c5dd9847e87615464cf309138d21c39af",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/native-image-installable-svm-java17-darwin-aarch64-22.1.0.jar"
}
},
"darwin-amd64": {
"graalvm-ce|java17|22.1.0": {
"sha256": "b9327fa73531a822d9a27d25980396353869eefbd73fdcef89b4fceb9f529c75",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/graalvm-ce-java17-darwin-amd64-22.1.0.tar.gz"
},
"native-image-installable-svm|java17|22.1.0": {
"sha256": "e6bfe208bb28cd1d98da55e00fa705890a7f69286b919947b07d18cc9bb9c270",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/native-image-installable-svm-java17-darwin-amd64-22.1.0.jar"
}
},
"linux-aarch64": {
"graalvm-ce|java17|22.1.0": {
"sha256": "05128e361ed44beebc89495faaa504b0b975bf93aa5e512e217b3cf5e42dfada",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/graalvm-ce-java17-linux-aarch64-22.1.0.tar.gz"
},
"native-image-installable-svm|java17|22.1.0": {
"sha256": "6e10f6953ec8b9509c7a7d0194d57f265cf2a05dcb8f3272a6a8e847bda49cda",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/native-image-installable-svm-java17-linux-aarch64-22.1.0.jar"
}
},
"linux-amd64": {
"graalvm-ce|java17|22.1.0": {
"sha256": "f11d46098efbf78465a875c502028767e3de410a31e45d92a9c5cf5046f42aa2",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/graalvm-ce-java17-linux-amd64-22.1.0.tar.gz"
},
"native-image-installable-svm|java17|22.1.0": {
"sha256": "d81eecea15ebbf4f24850860c14104eaf6f8ae74574330e22afac533b8f96738",
"url": "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/native-image-installable-svm-java17-linux-amd64-22.1.0.jar"
}
}
}

View file

@ -0,0 +1,334 @@
{
# An attrset describing each platform configuration. All values are extract
# from the GraalVM releases available on
# https://github.com/graalvm/graalvm-ce-builds/releases
# Example:
# config = {
# x86_64-linux = {
# # List of products that will be included in the GraalVM derivation
# # See `with{NativeImage,Ruby,Python,WASM,*}Svm` variables for the
# # available values
# products = [ "graalvm-ce" "native-image-installable-svm" ];
# # GraalVM arch, not to be confused with the nix platform
# arch = "linux-amd64";
# # GraalVM version
# version = "22.0.0.2";
# };
# }
config
# GraalVM version that will be used unless overriden by `config.<platform>.version`
, defaultVersion
# Java version used by GraalVM
, javaVersion
# Platforms were GraalVM will be allowed to build (i.e. `meta.platforms`)
, platforms ? builtins.attrNames config
# If set to true, update script will (re-)generate the sources file even if
# there are no updates available
, forceUpdate ? false
# Path for the sources file that will be used
# See `update.nix` file for a description on how this file works
, sourcesPath ? ./. + "/graalvm${javaVersion}-ce-sources.json"
# Use musl instead of glibc to allow true static builds in GraalVM's
# Native Image (i.e.: `--static --libc=musl`). This will cause glibc static
# builds to fail, so it should be used with care
, useMusl ? false
}:
{ stdenv
, lib
, autoPatchelfHook
, fetchurl
, makeWrapper
, setJavaClassPath
, writeShellScriptBin
# minimum dependencies
, alsa-lib
, fontconfig
, Foundation
, freetype
, glibc
, openssl
, perl
, unzip
, xorg
, zlib
# runtime dependencies
, binutils
, cups
, gcc
, musl
# runtime dependencies for GTK+ Look and Feel
, gtkSupport ? stdenv.isLinux
, cairo
, glib
# updateScript deps
, gnused
, gtk3
, jq
, writeShellScript
}:
assert useMusl -> stdenv.isLinux;
let
platform = config.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
version = platform.version or defaultVersion;
name = "graalvm${javaVersion}-ce";
sources = builtins.fromJSON (builtins.readFile sourcesPath);
runtimeLibraryPath = lib.makeLibraryPath
([ cups ] ++ lib.optionals gtkSupport [ cairo glib gtk3 ]);
runtimeDependencies = lib.makeBinPath ([
binutils
stdenv.cc
] ++ lib.optionals useMusl [
(lib.getDev musl)
# GraalVM 21.3.0+ expects musl-gcc as <system>-musl-gcc
(writeShellScriptBin "${stdenv.hostPlatform.system}-musl-gcc" ''${lib.getDev musl}/bin/musl-gcc "$@"'')
]);
withNativeImageSvm = builtins.elem "native-image-installable-svm" platform.products;
withRubySvm = builtins.elem "ruby-installable-svm" platform.products;
withPythonSvm = builtins.elem "python-installable-svm" platform.products;
withWasmSvm = builtins.elem "wasm-installable-svm" platform.products;
graalvmXXX-ce = stdenv.mkDerivation rec {
inherit version;
pname = name;
srcs = map fetchurl (builtins.attrValues sources.${platform.arch});
buildInputs = lib.optionals stdenv.isLinux [
alsa-lib # libasound.so wanted by lib/libjsound.so
fontconfig
freetype
stdenv.cc.cc.lib # libstdc++.so.6
xorg.libX11
xorg.libXext
xorg.libXi
xorg.libXrender
xorg.libXtst
zlib
] ++ lib.optionals withRubySvm [
openssl # libssl.so wanted by languages/ruby/lib/mri/openssl.so
];
nativeBuildInputs = [ unzip perl makeWrapper ]
++ lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook;
unpackPhase = ''
unpack_jar() {
jar=$1
unzip -q -o $jar -d $out
perl -ne 'use File::Path qw(make_path);
use File::Basename qw(dirname);
if (/^(.+) = (.+)$/) {
make_path dirname("$ENV{out}/$1");
system "ln -s $2 $ENV{out}/$1";
}' $out/META-INF/symlinks
perl -ne 'if (/^(.+) = ([r-])([w-])([x-])([r-])([w-])([x-])([r-])([w-])([x-])$/) {
my $mode = ($2 eq 'r' ? 0400 : 0) + ($3 eq 'w' ? 0200 : 0) + ($4 eq 'x' ? 0100 : 0) +
($5 eq 'r' ? 0040 : 0) + ($6 eq 'w' ? 0020 : 0) + ($7 eq 'x' ? 0010 : 0) +
($8 eq 'r' ? 0004 : 0) + ($9 eq 'w' ? 0002 : 0) + ($10 eq 'x' ? 0001 : 0);
chmod $mode, "$ENV{out}/$1";
}' $out/META-INF/permissions
rm -rf $out/META-INF
}
mkdir -p $out
arr=($srcs)
# The tarball on Linux has the following directory structure:
#
# graalvm-ce-java11-20.3.0/*
#
# while on Darwin it looks like this:
#
# graalvm-ce-java11-20.3.0/Contents/Home/*
#
# We therefor use --strip-components=1 vs 3 depending on the platform.
tar xf ''${arr[0]} -C $out --strip-components=${
if stdenv.isLinux then "1" else "3"
}
# Sanity check
if [ ! -d $out/bin ]; then
echo "The `bin` is directory missing after extracting the graalvm"
echo "tarball, please compare the directory structure of the"
echo "tarball with what happens in the unpackPhase (in particular"
echo "with regards to the `--strip-components` flag)."
exit 1
fi
for jar in "''${arr[@]:1}"; do
unpack_jar "$jar"
done
'';
outputs = [ "out" "lib" ];
installPhase = ''
# 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) ''
# provide libraries needed for static compilation
${
if useMusl then
''for f in "${musl.stdenv.cc.cc}/lib/"* "${musl}/lib/"* "${zlib.static}/lib/"*; do''
else
''for f in "${glibc}/lib/"* "${glibc.static}/lib/"* "${zlib.static}/lib/"*; do''
}
ln -s "$f" "$out/lib/svm/clibraries/${platform.arch}/$(basename $f)"
done
# add those libraries to $lib output too, so we can use them with
# `native-image -H:CLibraryPath=''${lib.getLib graalvmXX-ce}/lib ...` and reduce
# closure size by not depending on GraalVM $out (that is much bigger)
# we always use glibc here, since musl is only supported for static compilation
for f in "${glibc}/lib/"*; do
ln -s "$f" "$lib/lib/$(basename $f)"
done
''
}
'';
dontStrip = true;
# Workaround for libssl.so.10 wanted by TruffleRuby
# Resulting TruffleRuby cannot use `openssl` library.
autoPatchelfIgnoreMissingDeps = withRubySvm && stdenv.isDarwin;
preFixup = lib.optionalString (stdenv.isLinux) ''
# Find all executables in any directory that contains '/bin/'
for bin in $(find "$out" -executable -type f -wholename '*/bin/*'); do
wrapProgram "$bin" \
--prefix LD_LIBRARY_PATH : "${runtimeLibraryPath}" \
--prefix PATH : "${runtimeDependencies}"
done
find "$out" -name libfontmanager.so -exec \
patchelf --add-needed libfontconfig.so {} \;
${
lib.optionalString withRubySvm ''
# Workaround for libssl.so.10/libcrypto.so.10 wanted by TruffleRuby
patchelf $out/languages/ruby/lib/mri/openssl.so \
--replace-needed libssl.so.10 libssl.so \
--replace-needed libcrypto.so.10 libcrypto.so
''
}
'';
# $out/bin/native-image needs zlib to build native executables.
propagatedBuildInputs = [ setJavaClassPath zlib ] ++
# On Darwin native-image calls clang and it
# tries to include <Foundation/Foundation.h>,
# and Interactive Ruby (irb) requires OpenSSL
# headers.
lib.optionals stdenv.hostPlatform.isDarwin [ Foundation openssl ];
doInstallCheck = true;
installCheckPhase = ''
echo ${
lib.escapeShellArg ''
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
''
} > HelloWorld.java
$out/bin/javac HelloWorld.java
# run on JVM with Graal Compiler
$out/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler HelloWorld | fgrep 'Hello World'
${# --static flag doesn't work for darwin
lib.optionalString (withNativeImageSvm && stdenv.isLinux && !useMusl) ''
echo "Ahead-Of-Time compilation"
$out/bin/native-image -H:-CheckToolchain -H:+ReportExceptionStackTraces --no-server HelloWorld
./helloworld | fgrep 'Hello World'
echo "Ahead-Of-Time compilation with --static"
$out/bin/native-image --no-server --static HelloWorld
./helloworld | fgrep 'Hello World'
''
}
${# --static flag doesn't work for darwin
lib.optionalString (withNativeImageSvm && stdenv.isLinux && useMusl) ''
echo "Ahead-Of-Time compilation with --static and --libc=musl"
$out/bin/native-image --no-server --libc=musl --static HelloWorld
./helloworld | fgrep 'Hello World'
''
}
${
lib.optionalString withWasmSvm ''
echo "Testing Jshell"
echo '1 + 1' | $out/bin/jshell
''
}
${
lib.optionalString withPythonSvm ''
echo "Testing GraalPython"
$out/bin/graalpython -c 'print(1 + 1)'
echo '1 + 1' | $out/bin/graalpython
''
}
${
lib.optionalString withRubySvm ''
echo "Testing TruffleRuby"
# Hide warnings about wrong locale
export LANG=C
export LC_ALL=C
$out/bin/ruby -e 'puts(1 + 1)'
''
# FIXME: irb is broken in all platforms
+ lib.optionalString false ''
echo '1 + 1' | $out/bin/irb
''
}
'';
passthru = {
inherit (platform) products;
home = graalvmXXX-ce;
updateScript = import ./update.nix {
inherit config defaultVersion forceUpdate gnused jq lib name sourcesPath writeShellScript;
graalVersion = version;
javaVersion = "java${javaVersion}";
};
};
meta = with lib; {
inherit platforms;
homepage = "https://www.graalvm.org/";
description = "High-Performance Polyglot VM";
license = with licenses; [ upl gpl2Classpath bsd3 ];
maintainers = with maintainers; [
bandresen
volth
hlolli
glittershark
babariviere
ericdallo
thiagokokada
];
};
};
in
graalvmXXX-ce

View file

@ -0,0 +1,225 @@
{ 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";
}.${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};
# 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}
''