Skip to content

Commit

Permalink
Merge pull request #2338 from som-snytt/issue/7314-test-tools-jar
Browse files Browse the repository at this point in the history
SI-7314 Partest locates tools.jar and javac
  • Loading branch information
paulp committed Apr 19, 2013
2 parents 86651c1 + 01edd04 commit 857dfa6
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.util.ClassPath
import scala.tools.nsc.io
import scala.util.Properties.{ envOrElse, envOrNone, javaHome, jdkHome }
import io.{ Path, File, Directory }

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

lazy val diffUtils: File =
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() {
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) {
import fileManager._

fileManager.CLASSPATH += File.pathSeparator + PathSettings.scalaCheck
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 = {
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

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

# 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
# to mimic what happens during nightlies
# so don't do that here either -- note that you may want to pass -optimise
# to mimic what happens during nightlies.
# [ -n "$SCALAC_OPTS" ] || SCALAC_OPTS="-deprecation"

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

0 comments on commit 857dfa6

Please sign in to comment.