@@ -26,14 +26,15 @@ import Denotations._
26
26
import Phases ._
27
27
import java .lang .AssertionError
28
28
import java .io .{DataOutputStream , File => JFile }
29
+ import dotty .tools .io .{Jar , File , Directory }
29
30
30
31
import scala .tools .asm
31
32
import scala .tools .asm .tree ._
32
33
import dotty .tools .dotc .util .{DotClass , Positions }
33
34
import tpd ._
34
35
import StdNames ._
35
36
36
- import dotty .tools .io .{ AbstractFile , Directory , PlainDirectory }
37
+ import dotty .tools .io ._
37
38
38
39
class GenBCode extends Phase {
39
40
def phaseName : String = " genBCode"
@@ -46,14 +47,37 @@ class GenBCode extends Phase {
46
47
superCallsMap.put(sym, old + calls)
47
48
}
48
49
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 = _
51
57
52
58
def run (implicit ctx : Context ): Unit = {
53
59
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)
55
61
entryPoints.clear()
56
62
}
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
+ }
57
81
}
58
82
59
83
class GenBCodePipeline (val entryPoints : List [Symbol ], val int : DottyBackendInterface )(implicit val ctx : Context ) extends BCodeSyncAndTry {
0 commit comments