Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit 8be7e3b

Browse files
committed
Merge pull request #62 from som-snytt/issue/7786-pick-javac
SI-7786 Partest finds javac
2 parents 6ce0bd1 + cf768b5 commit 8be7e3b

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/main/scala/scala/tools/partest/PartestDefaults.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package partest
33

44
import scala.concurrent.duration.Duration
55
import scala.tools.nsc.Properties.{ propOrNone => prop }
6+
import scala.util.Properties.jdkHome
67
import java.lang.Runtime.{ getRuntime => runtime }
78

89
object PartestDefaults {
910
def sourcePath = prop("partest.srcdir") getOrElse "files"
10-
def javaCmd = prop("partest.javacmd") getOrElse "java"
11-
def javacCmd = prop("partest.javac_cmd") getOrElse "javac"
11+
def javaCmd = prop("partest.javacmd") orElse jdkexec("java") getOrElse "java"
12+
def javacCmd = prop("partest.javac_cmd") orElse jdkexec("javac") getOrElse "javac"
1213
def javaOpts = prop("partest.java_opts") getOrElse "" // opts when running java during tests
1314
def scalacOpts = prop("partest.scalac_opts") getOrElse ""
1415

@@ -18,4 +19,13 @@ object PartestDefaults {
1819
def waitTime = Duration(prop("partest.timeout") getOrElse "4 hours")
1920

2021
//def timeout = "1200000" // per-test timeout
22+
23+
// probe for the named executable
24+
private def jdkexec(name: String): Option[String] = {
25+
import scala.reflect.io.Path, Path._
26+
Some(Path(jdkHome) / "bin") filter (_.isDirectory) flatMap { p =>
27+
val candidates = (p walkFilter { e => (e.name == name || e.name.startsWith(s"$name.")) && e.jfile.canExecute }).toList
28+
(candidates find (_.name == name) orElse candidates.headOption) map (_.path)
29+
}
30+
}
2131
}

src/main/scala/scala/tools/partest/nest/Runner.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
111111
joinPaths(outDir :: testClassPath),
112112
"-J-Duser.language=en",
113113
"-J-Duser.country=US"
114-
) ++ files.map(_.getAbsolutePath)
114+
) ++ (toolArgsFor(files)("javac")
115+
) ++ (files.map(_.getAbsolutePath)
116+
)
115117

116118
pushTranscript(args mkString " ")
117119
val captured = StreamCapture(runCommand(args, logFile))
@@ -439,7 +441,12 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
439441
perTest ++ perGroup
440442
}
441443

442-
def toolArgs(tool: String, split: Boolean = true): List[String] = {
444+
// inspect sources for tool args
445+
def toolArgs(tool: String, split: Boolean = true): List[String] =
446+
toolArgsFor(sources(testFile))(tool, split)
447+
448+
// inspect given files for tool args
449+
def toolArgsFor(files: List[File])(tool: String, split: Boolean = true): List[String] = {
443450
def argsplitter(s: String) = if (split) words(s) filter (_.nonEmpty) else List(s)
444451
def argsFor(f: File): List[String] = {
445452
import scala.util.matching.Regex
@@ -453,7 +460,7 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
453460
} finally src.close()
454461
args.flatten map argsplitter getOrElse Nil
455462
}
456-
sources(testFile) flatMap argsFor
463+
files flatMap argsFor
457464
}
458465

459466
abstract class CompileRound {

0 commit comments

Comments
 (0)