Skip to content

Commit e07104f

Browse files
committed
initial limited checkin of idea
1 parent d049102 commit e07104f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

compiler/src/dotty/tools/scripting/Main.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ object Main:
1515

1616
def main(args: Array[String]): Unit =
1717
val (compilerArgs, scriptFile, scriptArgs) = distinguishArgs(args)
18-
try ScriptingDriver(compilerArgs, scriptFile, scriptArgs).compileAndRun()
18+
try ScriptingDriver(compilerArgs, scriptFile, scriptArgs).compileAndRun { (tmpDir:java.nio.file.Path,cp:String) =>
19+
// compile to jar, with classpath
20+
}
1921
catch
2022
case ScriptingException(msg) =>
2123
println(s"Error: $msg")

compiler/src/dotty/tools/scripting/ScriptingDriver.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import dotty.tools.dotc.config.Settings.Setting._
1717
import sys.process._
1818

1919
class ScriptingDriver(compilerArgs: Array[String], scriptFile: File, scriptArgs: Array[String]) extends Driver:
20-
def compileAndRun(): Unit =
20+
def compileAndRun(pack:(Path,String) => Unit = null): Unit =
2121
val outDir = Files.createTempDirectory("scala3-scripting")
2222
val (toCompile, rootCtx) = setup(compilerArgs :+ scriptFile.getAbsolutePath, initCtx.fresh)
2323
given Context = rootCtx.fresh.setSetting(rootCtx.settings.outputDir,
@@ -26,6 +26,12 @@ class ScriptingDriver(compilerArgs: Array[String], scriptFile: File, scriptArgs:
2626
if doCompile(newCompiler, toCompile).hasErrors then
2727
throw ScriptingException("Errors encountered during compilation")
2828

29+
Option(pack) match {
30+
case None =>
31+
case Some(func) =>
32+
func(outDir,ctx.settings.classpath.value)
33+
}
34+
2935
try detectMainMethod(outDir, ctx.settings.classpath.value).invoke(null, scriptArgs)
3036
catch
3137
case e: java.lang.reflect.InvocationTargetException =>

compiler/test/dotty/tools/scripting/ScriptingTests.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ class ScriptingTests:
3636
"-classpath", TestConfiguration.basicClasspath),
3737
scriptFile = scriptFile,
3838
scriptArgs = scriptArgs
39-
).compileAndRun()
39+
).compileAndRun { (path:java.nio.file.Path,classpath:String) =>
40+
path.toFile.listFiles.foreach { (f:File) => printf(" [%s]\n",f.getName) }
41+
printf("%s\n%s\n",path,classpath)
42+
}
43+

0 commit comments

Comments
 (0)