Skip to content

Commit

Permalink
SI-7314 Partest locates tools.jar and javac
Browse files Browse the repository at this point in the history
This commit lets partest locate tools.jar the way REPL does, with
the addition that java.home.parent is also tried.

The partest script will use JAVAC_CMD if set, or else JAVA_HOME, and
will try the sibling of JAVACMD if set (on the theory that if you specify
java, you are avoiding the path lookup and javac may also be in
that special place), or else query the path for javac.

The use cases are: no env vars, look around java.home; JDK or JAVA_HOME is
set; JAVACMD is set; and finally tools.jar can live in jre/lib/ext and
the fallback deep search will find it.

These cases have been tried on cygwin with Java installed under
s"Program${space}Files", which is usually the most brittle environment.
That means tested with bash.

The windows partest.bat has not been upgraded or side-graded.
  • Loading branch information
som-snytt committed Apr 18, 2013
1 parent 86651c1 commit 01edd04
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/partest/scala/tools/partest/nest/PathSettings.scala
Expand Up @@ -8,6 +8,7 @@ package nest
import scala.tools.nsc.Properties.{ setProp, propOrEmpty, propOrNone, propOrElse } import scala.tools.nsc.Properties.{ setProp, propOrEmpty, propOrNone, propOrElse }
import scala.tools.nsc.util.ClassPath import scala.tools.nsc.util.ClassPath
import scala.tools.nsc.io import scala.tools.nsc.io
import scala.util.Properties.{ envOrElse, envOrNone, javaHome, jdkHome }
import io.{ Path, File, Directory } import io.{ Path, File, Directory }


object PathSettings { object PathSettings {
Expand Down Expand Up @@ -74,6 +75,35 @@ object PathSettings {


lazy val diffUtils: File = lazy val diffUtils: File =
findJar(buildPackLibDir.files, "diffutils") getOrElse sys.error(s"No diffutils.jar found in '$buildPackLibDir'.") findJar(buildPackLibDir.files, "diffutils") getOrElse sys.error(s"No diffutils.jar found in '$buildPackLibDir'.")

/** The platform-specific support jar.
* Usually this is tools.jar in the jdk/lib directory of the platform distribution.
* The file location is determined by probing the lib directory under JDK_HOME or JAVA_HOME,
* if one of those environment variables is set, then the lib directory under java.home,
* and finally the lib directory under the parent of java.home. Or, as a last resort,
* search deeply under those locations (except for the parent of java.home, on the notion
* that if this is not a canonical installation, then that search would have litte
* chance of succeeding).
*/
lazy val platformTools: Option[File] = {
val jarName = "tools.jar"
def jarPath(path: Path) = (path / "lib" / jarName).toFile
def jarAt(path: Path) = {
val f = jarPath(path)
if (f.isFile) Some(f) else None
}
val jdkDir = {
val d = Directory(jdkHome)
if (d.isDirectory) Some(d) else None
}
def deeply(dir: Directory) = dir.deepFiles find (_.name == jarName)

val home = envOrNone("JDK_HOME") orElse envOrNone("JAVA_HOME") map (p => Path(p))
val install = Some(Path(javaHome))

(home flatMap jarAt) orElse (install flatMap jarAt) orElse (install map (_.parent) flatMap jarAt) orElse
(jdkDir flatMap deeply)
}
} }


class PathSettings() { class PathSettings() {
Expand Down
2 changes: 2 additions & 0 deletions src/partest/scala/tools/partest/nest/RunnerManager.scala
Expand Up @@ -74,8 +74,10 @@ object Output {


class RunnerManager(kind: String, val fileManager: FileManager, params: TestRunParams) { class RunnerManager(kind: String, val fileManager: FileManager, params: TestRunParams) {
import fileManager._ import fileManager._

fileManager.CLASSPATH += File.pathSeparator + PathSettings.scalaCheck fileManager.CLASSPATH += File.pathSeparator + PathSettings.scalaCheck
fileManager.CLASSPATH += File.pathSeparator + PathSettings.diffUtils // needed to put diffutils on test/partest's classpath fileManager.CLASSPATH += File.pathSeparator + PathSettings.diffUtils // needed to put diffutils on test/partest's classpath
PathSettings.platformTools foreach (fileManager.CLASSPATH += File.pathSeparator + _)


def runTest(testFile: File): TestState = { def runTest(testFile: File): TestState = {
val runner = new Runner(testFile, fileManager) { val runner = new Runner(testFile, fileManager) {
Expand Down
25 changes: 22 additions & 3 deletions test/partest
Expand Up @@ -75,6 +75,22 @@ if [ -z "$EXT_CLASSPATH" ] ; then
fi fi
fi fi


# Locate a javac command
# Try: JAVA_HOME, sibling to specific JAVACMD, or PATH
# Don't fail if there is no javac, since not all tests require it.
if [ -z "$JAVAC_CMD" ] ; then
if [ -n "${JAVA_HOME}" ] && [ -f "${JAVA_HOME}/bin/javac" ] ; then
JAVAC_CMD="${JAVA_HOME}/bin/javac"
fi
if [ -z "$JAVAC_CMD" ] && [ -n "$JAVACMD" ] ; then
JDIR=`dirname "${JAVACMD}"`
JAVAC_CMD="${JDIR}/javac"
fi
if [ -z "$JAVAC_CMD" ] ; then
JAVAC_CMD=`type -p javac`
fi
fi

if $cygwin; then if $cygwin; then
if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
format=mixed format=mixed
Expand All @@ -87,6 +103,9 @@ if $cygwin; then
if [ -n "${JAVACMD}" ] ; then if [ -n "${JAVACMD}" ] ; then
JAVACMD=`cygpath --$format "$JAVACMD"` JAVACMD=`cygpath --$format "$JAVACMD"`
fi fi
if [ -n "${JAVAC_CMD}" ] ; then
JAVAC_CMD=`cygpath --$format "$JAVAC_CMD"`
fi
SCALA_HOME=`cygpath --$format "$SCALA_HOME"` SCALA_HOME=`cygpath --$format "$SCALA_HOME"`
EXT_CLASSPATH=`cygpath --path --$format "$EXT_CLASSPATH"` EXT_CLASSPATH=`cygpath --path --$format "$EXT_CLASSPATH"`
fi fi
Expand All @@ -97,8 +116,8 @@ fi
JAVA_OPTS="-Xmx1024M -Xms64M -XX:MaxPermSize=128M $JAVA_OPTS" JAVA_OPTS="-Xmx1024M -Xms64M -XX:MaxPermSize=128M $JAVA_OPTS"


# the ant task doesn't supply any options by default, # the ant task doesn't supply any options by default,
# so don't to that here either -- note that you may want to pass -optimise # so don't do that here either -- note that you may want to pass -optimise
# to mimic what happens during nightlies # to mimic what happens during nightlies.
# [ -n "$SCALAC_OPTS" ] || SCALAC_OPTS="-deprecation" # [ -n "$SCALAC_OPTS" ] || SCALAC_OPTS="-deprecation"


partestDebugStr="" partestDebugStr=""
Expand All @@ -114,5 +133,5 @@ fi
-Dpartest.javacmd="${JAVACMD}" \ -Dpartest.javacmd="${JAVACMD}" \
-Dpartest.java_opts="${JAVA_OPTS}" \ -Dpartest.java_opts="${JAVA_OPTS}" \
-Dpartest.scalac_opts="${SCALAC_OPTS}" \ -Dpartest.scalac_opts="${SCALAC_OPTS}" \
-Dpartest.javac_cmd="${JAVA_HOME}/bin/javac" \ -Dpartest.javac_cmd="${JAVAC_CMD}" \
scala.tools.partest.nest.NestRunner "$@" scala.tools.partest.nest.NestRunner "$@"

0 comments on commit 01edd04

Please sign in to comment.