Skip to content

Commit 2c28a97

Browse files
committed
Make inter JVM communication be string based
1 parent dc92248 commit 2c28a97

File tree

7 files changed

+133
-168
lines changed

7 files changed

+133
-168
lines changed

compiler/test/dotty/Jars.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,17 @@ object Jars {
1919

2020
val dottyTestDeps: List[String] =
2121
dottyLib :: dottyCompiler :: dottyInterfaces :: dottyExtras
22+
23+
24+
def scalaLibraryFromRuntime: String = findJarFromRuntime("scala-library-2.")
25+
26+
private def findJarFromRuntime(partialName: String) = {
27+
val urls = ClassLoader.getSystemClassLoader.asInstanceOf[java.net.URLClassLoader].getURLs.map(_.getFile.toString)
28+
urls.find(_.contains(partialName)).getOrElse {
29+
throw new java.io.FileNotFoundException(
30+
s"""Unable to locate $partialName on classpath:\n${urls.toList.mkString("\n")}"""
31+
)
32+
}
33+
}
34+
2235
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dotty.tools.vulpix;
2+
3+
import java.io.File;
4+
import java.io.InputStreamReader;
5+
import java.io.BufferedReader;
6+
import java.net.URL;
7+
import java.net.URLClassLoader;
8+
import java.util.ArrayList;
9+
import java.lang.reflect.Method;
10+
11+
public class ChildJVMMain {
12+
static final String MessageEnd = "##THIS IS THE END FOR ME, GOODBYE##";
13+
14+
private static void runMain(String dir) throws Exception {
15+
ArrayList<URL> cp = new ArrayList<>();
16+
for (String path : dir.split(":"))
17+
cp.add(new File(path).toURI().toURL());
18+
19+
URLClassLoader ucl = new URLClassLoader(cp.toArray(new URL[cp.size()]));
20+
Class<?> cls = ucl.loadClass("Test");
21+
Method meth = cls.getMethod("main", String[].class);
22+
Object[] args = new Object[]{ new String[]{ "jvm" } };
23+
meth.invoke(null, args);
24+
}
25+
26+
public static void main(String[] args) throws Exception {
27+
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
28+
29+
while (true) {
30+
runMain(stdin.readLine());
31+
System.out.println(MessageEnd);
32+
}
33+
}
34+
}

compiler/test/dotty/tools/vulpix/ChildMain.scala

Lines changed: 0 additions & 82 deletions
This file was deleted.

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import dotc.interfaces.Diagnostic.ERROR
2222
import dotc.util.DiffUtil
2323
import dotc.{ Driver, Compiler }
2424

25-
import vulpix.Statuses._
26-
2725
/** A parallel testing suite whose goal is to integrate nicely with JUnit
2826
*
2927
* This trait can be mixed in to offer parallel testing to compile runs. When
@@ -53,6 +51,15 @@ trait ParallelTesting extends RunnerOrchestration { self =>
5351
def outDir: JFile
5452
def flags: Array[String]
5553

54+
def classPath: String = {
55+
val (beforeCp, cpAndAfter) = flags.toList.span(_ != "-classpath")
56+
if (cpAndAfter.nonEmpty) {
57+
val (_ :: cpArg :: _) = cpAndAfter
58+
s"${outDir.getAbsolutePath}:" + cpArg
59+
}
60+
else outDir.getAbsolutePath
61+
}
62+
5663

5764
def title: String = self match {
5865
case self: JointCompilationSource =>
@@ -293,15 +300,6 @@ trait ParallelTesting extends RunnerOrchestration { self =>
293300

294301
val files: Array[JFile] = files0.flatMap(flattenFiles)
295302

296-
def findJarFromRuntime(partialName: String) = {
297-
val urls = ClassLoader.getSystemClassLoader.asInstanceOf[java.net.URLClassLoader].getURLs.map(_.getFile.toString)
298-
urls.find(_.contains(partialName)).getOrElse {
299-
throw new java.io.FileNotFoundException(
300-
s"""Unable to locate $partialName on classpath:\n${urls.toList.mkString("\n")}"""
301-
)
302-
}
303-
}
304-
305303
def addOutDir(xs: Array[String]): Array[String] = {
306304
val (beforeCp, cpAndAfter) = xs.toList.span(_ != "-classpath")
307305
if (cpAndAfter.nonEmpty) {
@@ -312,11 +310,10 @@ trait ParallelTesting extends RunnerOrchestration { self =>
312310
}
313311

314312
def compileWithJavac(fs: Array[String]) = if (fs.nonEmpty) {
315-
val scalaLib = findJarFromRuntime("scala-library-2.")
316313
val fullArgs = Array(
317314
"javac",
318315
"-classpath",
319-
s".:$scalaLib:${targetDir.getAbsolutePath}"
316+
s".:${Jars.scalaLibraryFromRuntime}:${targetDir.getAbsolutePath}"
320317
) ++ flags.takeRight(2) ++ fs
321318

322319
Runtime.getRuntime.exec(fullArgs).waitFor() == 0
@@ -429,9 +426,9 @@ trait ParallelTesting extends RunnerOrchestration { self =>
429426
private final class RunTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)
430427
extends Test(testSources, times, threadLimit, suppressAllOutput) {
431428
private def verifyOutput(checkFile: JFile, dir: JFile, testSource: TestSource, warnings: Int) = {
432-
runMain(dir) match {
433-
case success: Success => {
434-
val outputLines = success.output.lines.toArray
429+
runMain(testSource.classPath) match {
430+
case Success(output) => {
431+
val outputLines = output.lines.toArray
435432
val checkLines: Array[String] = Source.fromFile(checkFile).getLines.toArray
436433
val sourceTitle = testSource.title
437434

@@ -462,19 +459,16 @@ trait ParallelTesting extends RunnerOrchestration { self =>
462459
}
463460
}
464461

465-
case failure: Failure =>
466-
echo(renderFailure(failure))
462+
case Failure(output) =>
463+
echo(output)
467464
failTestSource(testSource)
468465

469-
case _: Timeout =>
466+
case Timeout =>
470467
echo("failed because test " + testSource.title + " timed out")
471468
failTestSource(testSource, Some("test timed out"))
472469
}
473470
}
474471

475-
private def renderFailure(failure: Failure): String =
476-
failure.message + "\n" + failure.stacktrace
477-
478472
protected def compilationRunnable(testSource: TestSource): Runnable = new Runnable {
479473
def run(): Unit = tryCompile(testSource) {
480474
val (errorCount, warningCount, hasCheckFile, verifier: Function0[Unit]) = testSource match {
@@ -518,17 +512,14 @@ trait ParallelTesting extends RunnerOrchestration { self =>
518512
}
519513

520514
if (errorCount == 0 && hasCheckFile) verifier()
521-
else if (errorCount == 0) runMain(testSource.outDir) match {
522-
case status: Failure =>
523-
echo(renderFailure(status))
515+
else if (errorCount == 0) runMain(testSource.classPath) match {
516+
case Success(_) => // success!
517+
case Failure(output) =>
524518
failTestSource(testSource)
525-
case _: Timeout =>
526-
echo("failed because test " + testSource.title + " timed out")
519+
case Timeout =>
527520
failTestSource(testSource, Some("test timed out"))
528-
case _: Success => // success!
529521
}
530522
else if (errorCount > 0) {
531-
echo(s"\nCompilation failed for: '$testSource'")
532523
val buildInstr = testSource.buildInstructions(errorCount, warningCount)
533524
addFailureInstruction(buildInstr)
534525
failTestSource(testSource)

0 commit comments

Comments
 (0)