Skip to content

Commit d40e35b

Browse files
committed
Make inter JVM communication be string based
1 parent 5fbbd03 commit d40e35b

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
@@ -23,8 +23,6 @@ import dotc.interfaces.Diagnostic.ERROR
2323
import dotc.util.DiffUtil
2424
import dotc.{ Driver, Compiler }
2525

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

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

5865
def title: String = self match {
5966
case self: JointCompilationSource =>
@@ -294,15 +301,6 @@ trait ParallelTesting extends RunnerOrchestration { self =>
294301

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

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

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

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

@@ -463,19 +460,16 @@ trait ParallelTesting extends RunnerOrchestration { self =>
463460
}
464461
}
465462

466-
case failure: Failure =>
467-
echo(renderFailure(failure))
463+
case Failure(output) =>
464+
echo(output)
468465
failTestSource(testSource)
469466

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

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

521515
if (errorCount == 0 && hasCheckFile) verifier()
522-
else if (errorCount == 0) runMain(testSource.outDir) match {
523-
case status: Failure =>
524-
echo(renderFailure(status))
516+
else if (errorCount == 0) runMain(testSource.classPath) match {
517+
case Success(_) => // success!
518+
case Failure(output) =>
525519
failTestSource(testSource)
526-
case _: Timeout =>
527-
echo("failed because test " + testSource.title + " timed out")
520+
case Timeout =>
528521
failTestSource(testSource, Some("test timed out"))
529-
case _: Success => // success!
530522
}
531523
else if (errorCount > 0) {
532-
echo(s"\nCompilation failed for: '$testSource'")
533524
val buildInstr = testSource.buildInstructions(errorCount, warningCount)
534525
addFailureInstruction(buildInstr)
535526
failTestSource(testSource)

0 commit comments

Comments
 (0)