From 82b74001f0648004151428d89e9c63fc46f75a28 Mon Sep 17 00:00:00 2001 From: Tomodachi94 Date: Thu, 27 Jun 2024 23:00:58 -0700 Subject: [PATCH] batik: refactor * All JARs end up in $out/share/java, and a few wrappers for the applications are made in $out/bin (closes #50932). * stdenv -> stdenvNoCC, since no compilers are needed in any stages. * Remove the vendored Rhino JavaScript engine and replace it with our Nixpkgs one. * Add the stripJavaArchivesHook. This is hopefully a large improvement over the previous derivation (which simply copied the binary tarball into $out). --- pkgs/by-name/ba/batik/package.nix | 47 ++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/pkgs/by-name/ba/batik/package.nix b/pkgs/by-name/ba/batik/package.nix index 8a71a24773ff..18bdb7c37e19 100644 --- a/pkgs/by-name/ba/batik/package.nix +++ b/pkgs/by-name/ba/batik/package.nix @@ -1,18 +1,50 @@ { lib, - stdenv, + stdenvNoCC, fetchurl, + jre, + rhino, + stripJavaArchivesHook, + makeWrapper, }: -stdenv.mkDerivation rec { +stdenvNoCC.mkDerivation (finalAttrs: { pname = "batik"; version = "1.17"; src = fetchurl { - url = "mirror://apache/xmlgraphics/batik/binaries/batik-bin-${version}.tar.gz"; - sha256 = "sha256-sEJphF3grlwZCEt3gHHm4JF8RpvKKBLLvKXf2lu/dhA="; + url = "mirror://apache/xmlgraphics/batik/binaries/batik-bin-${finalAttrs.version}.tar.gz"; + hash = "sha256-sEJphF3grlwZCEt3gHHm4JF8RpvKKBLLvKXf2lu/dhA="; }; + nativeBuildInputs = [ + stripJavaArchivesHook + makeWrapper + ]; + + buildInputs = [ + jre + rhino + ]; + + patchPhase = '' + # Vendored dependencies + rm lib/rhino-*.jar + ''; + + installPhase = '' + mkdir -p $out/bin $out/share/java + cp *.jar lib/*.jar $out/share/java + chmod +x $out/share/java/*.jar + classpath="$(find $out/share/java -name '*.jar' -printf '${rhino}/share/java/js.jar:%h/%f')" + for appName in rasterizer slideshow squiggle svgpp ttf2svg; do + makeWrapper ${lib.getExe jre} $out/bin/batik-$appName \ + --add-flags "-jar $out/share/java/batik-all-${finalAttrs.version}.jar" \ + --add-flags "-classpath $classpath" \ + --add-flags "org.apache.batik.apps.$appName.Main" + done + ''; + meta = with lib; { description = "Java based toolkit for handling SVG"; homepage = "https://xmlgraphics.apache.org/batik"; @@ -20,9 +52,4 @@ stdenv.mkDerivation rec { platforms = platforms.unix; sourceProvenance = with sourceTypes; [ binaryBytecode ]; }; - - installPhase = '' - mkdir $out - cp -r * $out/ - ''; -} +})