Skip to content

Commit 447008e

Browse files
committed
Add -with-compiler flag to Scala runner
1 parent 0b526de commit 447008e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ case class Settings(
3333
targetScript: String = "",
3434
save: Boolean = false,
3535
modeShouldBeRun: Boolean = false,
36+
compiler: Boolean = false,
3637
) {
3738
def withExecuteMode(em: ExecuteMode): Settings = this.executeMode match
3839
case ExecuteMode.Guess =>
@@ -67,6 +68,9 @@ case class Settings(
6768

6869
def withModeShouldBeRun: Settings =
6970
this.copy(modeShouldBeRun = true)
71+
72+
def withCompiler: Settings =
73+
this.copy(compiler = true)
7074
}
7175

7276
object MainGenericRunner {
@@ -99,6 +103,8 @@ object MainGenericRunner {
99103
)
100104
case "-save" :: tail =>
101105
process(tail, settings.withSave)
106+
case "-with-compiler" :: tail =>
107+
process(tail, settings.withCompiler)
102108
case (o @ javaOption(striped)) :: tail =>
103109
process(tail, settings.withJavaArgs(striped).withScalaArgs(o))
104110
case (o @ scalaOption(_*)) :: tail =>
@@ -130,7 +136,15 @@ object MainGenericRunner {
130136
repl.Main.main(properArgs.toArray)
131137
case ExecuteMode.Run =>
132138
val scalaClasspath = ClasspathFromClassloader(Thread.currentThread().getContextClassLoader).split(classpathSeparator)
133-
val newClasspath = (settings.classPath ++ scalaClasspath :+ ".").map(File(_).toURI.toURL)
139+
140+
def removeCompiler(cp: Array[String]) =
141+
if (!settings.compiler) then // Let's remove compiler from the classpath
142+
val compilerLibs = Seq("scala3-compiler", "scala3-interfaces", "tasty-core", "scala-asm", "scala3-staging", "scala3-tasty-inspector")
143+
cp.filterNot(c => compilerLibs.exists(c.contains))
144+
else
145+
cp
146+
val newClasspath = (settings.classPath ++ removeCompiler(scalaClasspath) :+ ".").map(File(_).toURI.toURL)
147+
134148
val res = ObjectRunner.runAndCatch(newClasspath, settings.residualArgs.head, settings.residualArgs.drop(1)).flatMap {
135149
case ex: ClassNotFoundException if ex.getMessage == settings.residualArgs.head =>
136150
val file = settings.residualArgs.head

0 commit comments

Comments
 (0)