Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ant: use upstream launcher script #364094

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 16 additions & 51 deletions pkgs/by-name/an/ant/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
fetchurl,
lib,
stdenv,
coreutils,
jre,
makeWrapper,
gitUpdater,
}:
Expand All @@ -11,6 +11,8 @@ stdenv.mkDerivation (finalAttrs: {
pname = "ant";
version = "1.10.15";

buildInputs = [ jre ];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, will this change make it so that we don't actually need to add both jdk and ant into nativeBuildInputs when using ant?

Also also, jdk vs jre? (I'd say jdk)
--@TomaSajt

From my testing, if we use jdk, that is the case, but setting it to jdk makes it difficult to use a different version of Java without overriding ant.
--Me

Is there a reason that we shouldn't have consumers explicitly specify a JDK?
--Me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn’t jre the same as jdk these days?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the distinction usually is the fact that jre may be overridden to be run on a different java version than it was built on (why tho) or it can be overridden with a minimal java.
Though I doubt many people would care, so I guess we don't have to care either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant re: “From my testing, if we use jdk, that is the case” – since I do think ensuring people explicitly specify a JDK is best.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say "explicitly specify" do you mean that ant should have a hardcoded jdk that can be overridden, or do you mean that it should not have a hardcoded jdk, but should use whatever's in JAVA_HOME.

I'm torn between the two options.


nativeBuildInputs = [ makeWrapper ];

src = fetchurl {
Expand All @@ -24,64 +26,27 @@ stdenv.mkDerivation (finalAttrs: {
};

installPhase = ''
mkdir -p $out/bin $out/share/ant
mkdir -p $out/share/ant
mv * $out/share/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 <exec/> 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/share/ant/bin/antRun $out/bin/
rm -rf $out/share/ant/{manual,bin,WHATSNEW}
mkdir $out/share/ant/bin
mv $out/bin/antRun $out/share/ant/bin/
# separate output.
rm -rf $out/share/ant/{manual,WHATSNEW}

# Link Ant's special $ANT_HOME/bin to the standard /bin location
ln -s $out/share/ant/bin $out

# Install ant-contrib.
unpackFile $contrib
cp -p ant-contrib/ant-contrib-*.jar $out/share/ant/lib/

cat >> $out/bin/ant <<EOF
#! ${stdenv.shell} -e

ANT_HOME=$out/share/ant

# 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

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

chmod +x $out/bin/ant
# Wrap the wrappers.
for wrapper in ant runant.py runant.pl; do
wrapProgram "$out/share/ant/bin/$wrapper" \
--set JAVA_HOME "${jre.home}" \
--set ANT_HOME "$out/share/ant" \
--prefix CLASSPATH : "$out/share/ant/lib"
done
'';

passthru = {
Expand Down
Loading