diff --git a/pkgs/by-name/an/ant/package.nix b/pkgs/by-name/an/ant/package.nix index 785a518edd3b..ad79b1388b6f 100644 --- a/pkgs/by-name/an/ant/package.nix +++ b/pkgs/by-name/an/ant/package.nix @@ -1,4 +1,11 @@ -{ fetchurl, lib, stdenv, coreutils, makeWrapper, gitUpdater }: +{ + fetchurl, + lib, + stdenv, + coreutils, + makeWrapper, + gitUpdater, +}: stdenv.mkDerivation rec { pname = "ant"; @@ -16,67 +23,66 @@ stdenv.mkDerivation rec { sha256 = "1l8say86bz9gxp4yy777z7nm4j6m905pg342li1aphc14p5grvwn"; }; - installPhase = - '' - mkdir -p $out/bin $out/lib/ant - mv * $out/lib/ant/ + installPhase = '' + mkdir -p $out/bin $out/lib/ant + mv * $out/lib/ant/ - # Get rid of the manual (35 MiB). Maybe we should put this in a - # separate output. Keep the antRun script since it's vanilla sh - # and needed for the task (but since we set ANT_HOME to - # a weird value, we have to move antRun to a weird location). - # Get rid of the other Ant scripts since we provide our own. - mv $out/lib/ant/bin/antRun $out/bin/ - rm -rf $out/lib/ant/{manual,bin,WHATSNEW} - mkdir $out/lib/ant/bin - mv $out/bin/antRun $out/lib/ant/bin/ + # Get rid of the manual (35 MiB). Maybe we should put this in a + # separate output. Keep the antRun script since it's vanilla sh + # and needed for the task (but since we set ANT_HOME to + # a weird value, we have to move antRun to a weird location). + # Get rid of the other Ant scripts since we provide our own. + mv $out/lib/ant/bin/antRun $out/bin/ + rm -rf $out/lib/ant/{manual,bin,WHATSNEW} + mkdir $out/lib/ant/bin + mv $out/bin/antRun $out/lib/ant/bin/ - # Install ant-contrib. - unpackFile $contrib - cp -p ant-contrib/ant-contrib-*.jar $out/lib/ant/lib/ + # Install ant-contrib. + unpackFile $contrib + cp -p ant-contrib/ant-contrib-*.jar $out/lib/ant/lib/ - cat >> $out/bin/ant <> $out/bin/ant <&2 - exit 1 - fi - fi + # Find the JDK by looking for javac. As a fall-back, find the + # JRE by looking for java. The latter allows just the JRE to be + # used with (say) ECJ as the compiler. Finally, allow the GNU + # JVM. + if [ -z "\''${JAVA_HOME-}" ]; then + for i in javac java gij; do + if p="\$(type -p \$i)"; then + export JAVA_HOME="\$(${coreutils}/bin/dirname \$(${coreutils}/bin/dirname \$(${coreutils}/bin/readlink -f \$p)))" + break + fi + done + if [ -z "\''${JAVA_HOME-}" ]; then + echo "\$0: cannot find the JDK or JRE" >&2 + exit 1 + fi + fi - if [ -z \$NIX_JVM ]; then - if [ -e \$JAVA_HOME/bin/java ]; then - NIX_JVM=\$JAVA_HOME/bin/java - elif [ -e \$JAVA_HOME/bin/gij ]; then - NIX_JVM=\$JAVA_HOME/bin/gij - else - NIX_JVM=java - fi - fi + if [ -z \$NIX_JVM ]; then + if [ -e \$JAVA_HOME/bin/java ]; then + NIX_JVM=\$JAVA_HOME/bin/java + elif [ -e \$JAVA_HOME/bin/gij ]; then + NIX_JVM=\$JAVA_HOME/bin/gij + else + NIX_JVM=java + fi + fi - LOCALCLASSPATH="\$ANT_HOME/lib/ant-launcher.jar\''${LOCALCLASSPATH:+:}\$LOCALCLASSPATH" + LOCALCLASSPATH="\$ANT_HOME/lib/ant-launcher.jar\''${LOCALCLASSPATH:+:}\$LOCALCLASSPATH" - exec \$NIX_JVM \$NIX_ANT_OPTS \$ANT_OPTS -classpath "\$LOCALCLASSPATH" \ - -Dant.home=\$ANT_HOME -Dant.library.dir="\$ANT_LIB" \ - org.apache.tools.ant.launch.Launcher \$NIX_ANT_ARGS \$ANT_ARGS \ - -cp "\$CLASSPATH" "\$@" - EOF + exec \$NIX_JVM \$NIX_ANT_OPTS \$ANT_OPTS -classpath "\$LOCALCLASSPATH" \ + -Dant.home=\$ANT_HOME -Dant.library.dir="\$ANT_LIB" \ + org.apache.tools.ant.launch.Launcher \$NIX_ANT_ARGS \$ANT_ARGS \ + -cp "\$CLASSPATH" "\$@" + EOF - chmod +x $out/bin/ant - ''; # */ + chmod +x $out/bin/ant + ''; passthru = { updateScript = gitUpdater {