Fix Java detection on some Linux distributions

On some Linux distributions (spotted here on OpenMandriva Lx, but I'm
pretty sure some others do the same thing), "which javac" returns
/usr/bin/javac, which is a symlink to "../../etc/alternatives/javac",
which in turn points at whatever the JDK the user picked as his default.

Given "../../etc/alternatives/javac" is a relative symlink, the next
iteration of LSLINE=$(ls -l "$JAVAC") fails (no ../../etc/alternatives/java
relative to the build directory), causing tools.jar not to be found.

Using realpath and readlink where possible should work in all cases.

Change-Id: Ic60ac84a5b263dc1c1f2960092a7549d1024ed2e
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
This commit is contained in:
Bernhard Rosenkraenzer 2014-10-01 03:30:11 +02:00
parent 35dd358cc4
commit 311384fec3
1 changed files with 7 additions and 1 deletions

View File

@ -2,7 +2,13 @@
if [ "x$ANDROID_JAVA_HOME" != x ] && [ -e "$ANDROID_JAVA_HOME/lib/tools.jar" ] ; then
echo $ANDROID_JAVA_HOME/lib/tools.jar
else
JAVAC=$(realpath $(which javac) 2>/dev/null)
if [ -z "$JAVAC" ]; then
JAVAC=$(readlink -f $(which javac) 2>/dev/null)
fi
if [ -z "$JAVAC" ]; then
JAVAC=$(which javac)
fi
if [ -z "$JAVAC" ] ; then
exit 1
fi