platform_build/core/find-jdk-tools-jar.sh
Colin Cross 112753ca55 Error out early on nonstandard JDK directory layouts
On Darwin, javac may be located in a nonstandard directory layout such as:
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac
The sed command to replace bin/javac with lib/tools.jar would fail to
match, resulting in the HOST_JDK_TOOLS_JAR being set to the javac path.
Since javac exists, the checks for missing tools.jar would all pass, and
javac would be added to the classpath instead of tools.jar, and causing
hard to debug errors about missing com.sun.javadoc when building doclava.

Change the sed command to replace /javac$, which should always be found,
with /../lib/tools.jar.

Change-Id: I5072f04636a5c14b3aeaa3a5cc3b366feae89c37
2015-10-23 19:00:43 -07:00

20 lines
598 B
Bash
Executable file

#!/bin/sh
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
while [ -L "$JAVAC" ] ; do
LSLINE=$(ls -l "$JAVAC")
JAVAC=$(echo -n "$LSLINE" | sed -e "s/.* -> //")
done
echo $JAVAC | sed -e 's:\(.*\)/javac$:\1/../lib/tools.jar:'
fi