@@ -26,14 +26,15 @@ import Denotations._
2626import Phases ._
2727import java .lang .AssertionError
2828import java .io .{DataOutputStream , File => JFile }
29+ import dotty .tools .io .{Jar , File , Directory }
2930
3031import scala .tools .asm
3132import scala .tools .asm .tree ._
3233import dotty .tools .dotc .util .{DotClass , Positions }
3334import tpd ._
3435import StdNames ._
3536
36- import dotty .tools .io .{ AbstractFile , Directory , PlainDirectory }
37+ import dotty .tools .io ._
3738
3839class GenBCode extends Phase {
3940 def phaseName : String = " genBCode"
@@ -46,14 +47,37 @@ class GenBCode extends Phase {
4647 superCallsMap.put(sym, old + calls)
4748 }
4849
49- def outputDir (implicit ctx : Context ): AbstractFile =
50- new PlainDirectory (ctx.settings.outputDir.value)
50+ def outputDir (implicit ctx : Context ): AbstractFile = {
51+ val path = ctx.settings.outputDir.value
52+ if (path.isDirectory) new PlainDirectory (Directory (path))
53+ else new PlainFile (path)
54+ }
55+
56+ private [this ] var classOutput : AbstractFile = _
5157
5258 def run (implicit ctx : Context ): Unit = {
5359 new GenBCodePipeline (entryPoints.toList,
54- new DottyBackendInterface (outputDir , superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
60+ new DottyBackendInterface (classOutput , superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
5561 entryPoints.clear()
5662 }
63+
64+ override def runOn (units : List [CompilationUnit ])(implicit ctx : Context ) = {
65+ val output = outputDir
66+ if (output.isDirectory) {
67+ classOutput = output
68+ val res = super .runOn(units)
69+ classOutput = null
70+ res
71+ } else {
72+ assert(output.hasExtension(" jar" ))
73+ classOutput = new PlainDirectory (Path (Path (output.file).parent + " /tmp-jar-" + System .currentTimeMillis().toHexString).createDirectory())
74+ val res = super .runOn(units)
75+ Jar .create(new File (ctx.settings.outputDir.value.jfile), new Directory (classOutput.file), mainClass = " " )
76+ classOutput.delete()
77+ classOutput = null
78+ res
79+ }
80+ }
5781}
5882
5983class GenBCodePipeline (val entryPoints : List [Symbol ], val int : DottyBackendInterface )(implicit val ctx : Context ) extends BCodeSyncAndTry {
0 commit comments