gradle: auto-detect nativeVersion

Instead of having to know the version of native-platform at the Nix
level, we use the file `lib/native-platform-<version>.jar` to figure
out the version of the library JAR to patch.

+54 -29
+24 -15
pkgs/development/tools/build-managers/gradle/default.nix
··· 3 rec { 4 gen = 5 6 - { version, nativeVersion, hash, 7 8 # The default JDK/JRE that will be used for derived Gradle packages. 9 # A current LTS version of a JDK is a good choice. ··· 36 , testers 37 , runCommand 38 , writeText 39 40 # The JDK/JRE used for running Gradle. 41 , java ? defaultJava ··· 57 58 dontBuild = true; 59 60 - nativeBuildInputs = [ makeWrapper unzip ]; 61 - buildInputs = [ java ]; 62 63 installPhase = with builtins; 64 let ··· 87 88 fixupPhase = let arch = if stdenv.is64bit then "amd64" else "i386"; 89 in '' 90 for variant in "" "-ncurses5" "-ncurses6"; do 91 - mkdir "patching$variant" 92 - pushd "patching$variant" 93 - jar xf $out/lib/gradle/lib/native-platform-linux-${arch}$variant-${nativeVersion}.jar 94 - patchelf \ 95 - --set-rpath "${stdenv.cc.cc.lib}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ncurses5 ncurses6 ]}" \ 96 - net/rubygrapefruit/platform/linux-${arch}$variant/libnative-platform*.so 97 - jar cf native-platform-linux-${arch}$variant-${nativeVersion}.jar . 98 - mv native-platform-linux-${arch}$variant-${nativeVersion}.jar $out/lib/gradle/lib/ 99 - popd 100 done 101 102 # The scanner doesn't pick up the runtime dependency in the jar. ··· 162 163 gradle_8 = gen { 164 version = "8.10"; 165 - nativeVersion = "0.22-milestone-26"; 166 hash = "sha256-W5xes/n8LJSrrqV9kL14dHyhF927+WyFnTdBGBoSvyo="; 167 defaultJava = jdk21; 168 }; 169 170 gradle_7 = gen { 171 version = "7.6.4"; 172 - nativeVersion = "0.22-milestone-25"; 173 hash = "sha256-vtHaM8yg9VerE2kcd/OLtnOIEZ5HlNET4FEDm4Cvm7E="; 174 defaultJava = jdk17; 175 }; 176 177 gradle_6 = gen { 178 version = "6.9.4"; 179 - nativeVersion = "0.22-milestone-20"; 180 hash = "sha256-PiQCKFON6fGHcqV06ZoLqVnoPW7zUQFDgazZYxeBOJo="; 181 defaultJava = jdk11; 182 };
··· 3 rec { 4 gen = 5 6 + { version, hash, 7 8 # The default JDK/JRE that will be used for derived Gradle packages. 9 # A current LTS version of a JDK is a good choice. ··· 36 , testers 37 , runCommand 38 , writeText 39 + , autoPatchelfHook 40 41 # The JDK/JRE used for running Gradle. 42 , java ? defaultJava ··· 58 59 dontBuild = true; 60 61 + nativeBuildInputs = [ 62 + makeWrapper 63 + unzip 64 + ] ++ lib.optionals stdenv.isLinux [ 65 + autoPatchelfHook 66 + ]; 67 + 68 + buildInputs = [ 69 + java 70 + stdenv.cc.cc 71 + ncurses5 72 + ncurses6 73 + ]; 74 + 75 + # We only need to patchelf some libs embedded in JARs. 76 + dontAutoPatchelf = true; 77 78 installPhase = with builtins; 79 let ··· 102 103 fixupPhase = let arch = if stdenv.is64bit then "amd64" else "i386"; 104 in '' 105 + . ${./patching.sh} 106 + 107 + nativeVersion="$(extractVersion native-platform $out/lib/gradle/lib/native-platform-*.jar)" 108 for variant in "" "-ncurses5" "-ncurses6"; do 109 + autoPatchelfInJar \ 110 + $out/lib/gradle/lib/native-platform-linux-${arch}$variant-''${nativeVersion}.jar \ 111 + "${stdenv.cc.cc.lib}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ncurses5 ncurses6 ]}" 112 done 113 114 # The scanner doesn't pick up the runtime dependency in the jar. ··· 174 175 gradle_8 = gen { 176 version = "8.10"; 177 hash = "sha256-W5xes/n8LJSrrqV9kL14dHyhF927+WyFnTdBGBoSvyo="; 178 defaultJava = jdk21; 179 }; 180 181 gradle_7 = gen { 182 version = "7.6.4"; 183 hash = "sha256-vtHaM8yg9VerE2kcd/OLtnOIEZ5HlNET4FEDm4Cvm7E="; 184 defaultJava = jdk17; 185 }; 186 187 gradle_6 = gen { 188 version = "6.9.4"; 189 hash = "sha256-PiQCKFON6fGHcqV06ZoLqVnoPW7zUQFDgazZYxeBOJo="; 190 defaultJava = jdk11; 191 };
+29
pkgs/development/tools/build-managers/gradle/patching.sh
···
··· 1 + extractVersion() { 2 + local jar version 3 + local prefix="$1" 4 + shift 5 + local candidates="$@" 6 + 7 + jar="$(basename -a $candidates | sort | head -n1)" 8 + 9 + version="${jar#$prefix-}" 10 + 11 + echo "${version%.jar}" 12 + } 13 + 14 + autoPatchelfInJar() { 15 + local file="$1" rpath="$2" 16 + local work 17 + 18 + work="$(mktemp -dt patching.XXXXXXXXXX)" 19 + pushd "$work" 20 + 21 + jar xf "$file" 22 + rm "$file" 23 + 24 + autoPatchelf -- . 25 + 26 + jar cf "$file" . 27 + 28 + popd 29 + }
+1 -14
pkgs/development/tools/build-managers/gradle/update.sh
··· 49 read -d "\n" gradle_hash gradle_path < <(nix-prefetch-url --print-path $url) 50 gradle_hash=$(nix-hash --to-sri --type sha256 "$gradle_hash") 51 52 - # Prefix and suffix for "native-platform" dependency. 53 - gradle_native_prefix="gradle-$v/lib/native-platform-" 54 - gradle_native_suffix=".jar" 55 - tmp=$(mktemp) 56 - zipinfo -1 "$gradle_path" "$gradle_native_prefix*$gradle_native_suffix" > $tmp 57 - gradle_native=$(cat $tmp | head -n1) 58 - gradle_native=${gradle_native#"$gradle_native_prefix"} 59 - gradle_native=${gradle_native%"$gradle_native_suffix"} 60 - 61 - # Supported architectures 62 - #grep -Pho "(linux|osx)-\w+" $tmp | sort | uniq 63 - rm -f $tmp 64 - 65 - echo -e "{\\n version = \"$v\";\\n nativeVersion = \"$gradle_native\";\\n sha256 = \"$gradle_hash\";\\n}" > $f 66 67 echo "$v DONE" 68 done
··· 49 read -d "\n" gradle_hash gradle_path < <(nix-prefetch-url --print-path $url) 50 gradle_hash=$(nix-hash --to-sri --type sha256 "$gradle_hash") 51 52 + echo -e "{\\n version = \"$v\";\\n sha256 = \"$gradle_hash\";\\n}" > $f 53 54 echo "$v DONE" 55 done