Skip to content

Commit 22f060b

Browse files
authored
Add a Partest option to use a different compiler (scala#8407)
Add a Partest option to use a different compiler
2 parents 716bd19 + abc2623 commit 22f060b

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

project/PartestUtil.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ object PartestUtil {
3737
"--instrumented", "--presentation", "--failed", "--update-check", "--no-exec",
3838
"--show-diff", "--show-log", "--verbose", "--terse", "--debug", "--version", "--help")
3939
val srcPathOption = "--srcpath"
40+
val compilerPathOption = "--compilerpath"
4041
val grepOption = "--grep"
4142

4243
// HACK: if we parse `--srcpath scaladoc`, we overwrite this var. The parser for test file paths
@@ -93,9 +94,14 @@ object PartestUtil {
9394
opt + " " + path
9495
}
9596

97+
val CompilerPath = ((token(compilerPathOption) <~ Space) ~ token(NotSpace)) map {
98+
case opt ~ path =>
99+
opt + " " + path
100+
}
101+
96102
val ScalacOptsParser = (token("-Dpartest.scalac_opts=") ~ token(NotSpace)) map { case opt ~ v => opt + v }
97103

98-
val P = oneOf(knownUnaryOptions.map(x => token(x))) | SrcPath | TestPathParser | Grep | ScalacOptsParser
104+
val P = oneOf(knownUnaryOptions.map(x => token(x))) | SrcPath | CompilerPath | TestPathParser | Grep | ScalacOptsParser
99105
(Space ~> repsep(P, oneOrMore(Space))).map(_.mkString(" ")).?.map(_.getOrElse(""))
100106
}
101107
}

src/partest/scala/tools/partest/nest/DirectCompiler.scala

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import scala.reflect.io.AbstractFile
2121
import scala.tools.nsc.reporters.{ConsoleReporter, Reporter}
2222
import scala.tools.nsc.{CompilerCommand, Global, Settings}
2323
import scala.util.chaining._
24+
import scala.sys.process._
2425

2526
object ExtConsoleReporter {
2627
def apply(settings: Settings, writer: PrintWriter) = new ConsoleReporter(settings, Console.in, writer, writer).tap(_.shortname = true)
@@ -116,7 +117,7 @@ class DirectCompiler(val runner: Runner) {
116117
if (command.files.nonEmpty) reportError(command.files.mkString("flags file may only contain compiler options, found: ", space, ""))
117118
}
118119

119-
suiteRunner.verbose(s"% scalac ${ sources.map(_.testIdent).mkString(space) }${ if (suiteRunner.debug) " -d " + outDir else ""}")
120+
suiteRunner.verbose(s"% compiling ${ sources.map(_.testIdent).mkString(space) }${ if (suiteRunner.debug) " -d " + outDir else ""}")
120121

121122
def execCompile() =
122123
if (command.shouldStopWithInfo) {
@@ -134,7 +135,21 @@ class DirectCompiler(val runner: Runner) {
134135
result
135136
}
136137

137-
try { execCompile() }
138+
def execOtherCompiler() = {
139+
val stdout = new StringBuilder
140+
val stderr = new StringBuilder
141+
val logger = ProcessLogger(stdout append _, stderr append _)
142+
val resultCode = (suiteRunner.config.optCompilerPath.get + " " + sources.map(_.getPath).mkString(" ")) ! logger
143+
logWriter append stdout
144+
logWriter append stderr
145+
if (resultCode == 0) runner.genPass()
146+
else runner.genFail(s"compilation failed")
147+
}
148+
149+
try {
150+
if (suiteRunner.config.optCompilerPath.isEmpty) execCompile()
151+
else execOtherCompiler()
152+
}
138153
catch { case t: Throwable => reportError(t.getMessage) ; runner.genCrash(t) }
139154
finally { logWriter.close() }
140155
}

src/partest/scala/tools/partest/nest/RunnerSpec.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ trait RunnerSpec extends Spec with Meta.StdOpts with Interpolation {
4242
val optBuildPath = "buildpath" / "set (relative) path to build jars (ex.: --buildpath build/pack)" --|
4343
val optClassPath = "classpath" / "set (absolute) path to build classes" --|
4444
val optSourcePath = "srcpath" / "set (relative) path to test source files (ex.: --srcpath pending)" --|
45+
// Compile with a different compiler, not used internally. Used by AxLang, see PR #8407.
46+
// Note: this will be much slower than creating a new global in the same JVM.
47+
// Note: run tests will still use the internal Scala version for running.
48+
val optCompilerPath = "compilerpath" / "set (absolute) path to a different compiler to test (ex.: --compilerpath /usr/local/bin/scalac)" --|
4549

4650
heading("Test output options:")
4751
val optShowDiff = "show-diff" / "show diffs for failed tests" --?

0 commit comments

Comments
 (0)