@@ -7,6 +7,7 @@ import dotty.tools.dotc.core.Phases.Phase
77import dotty .tools .dotc .core .Names .TypeName
88
99import scala .collection .mutable
10+ import scala .collection .JavaConverters ._
1011import scala .tools .asm .{ClassVisitor , CustomAttr , FieldVisitor , MethodVisitor }
1112import scala .tools .nsc .backend .jvm ._
1213import dotty .tools .dotc
@@ -26,14 +27,15 @@ import Denotations._
2627import Phases ._
2728import java .lang .AssertionError
2829import java .io .{DataOutputStream , File => JFile }
29- import dotty .tools .io .{Jar , File , Directory }
30+ import java .nio .file .{Files , FileSystem , FileSystems , Path => JPath }
31+
32+ import dotty .tools .io .{Directory , File , Jar }
3033
3134import scala .tools .asm
3235import scala .tools .asm .tree ._
3336import dotty .tools .dotc .util .{DotClass , Positions }
3437import tpd ._
3538import StdNames ._
36-
3739import dotty .tools .io ._
3840
3941class GenBCode extends Phase {
@@ -47,40 +49,36 @@ class GenBCode extends Phase {
4749 superCallsMap.put(sym, old + calls)
4850 }
4951
52+ private [this ] var jarFS : JarFS = _
53+
5054 def outputDir (implicit ctx : Context ): AbstractFile = {
5155 val path = ctx.settings.outputDir.value
5256 if (path.isDirectory) new PlainDirectory (Directory (path))
53- else new PlainFile (path)
57+ else {
58+ if (jarFS == null ) {
59+ path.delete()
60+ jarFS = JarFS .create(path)
61+ }
62+ jarFS.getRoot()
63+ }
5464 }
5565
56- private [this ] var classOutput : AbstractFile = _
57-
5866 def run (implicit ctx : Context ): Unit = {
5967 new GenBCodePipeline (entryPoints.toList,
60- new DottyBackendInterface (classOutput , superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
68+ new DottyBackendInterface (outputDir , superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
6169 entryPoints.clear()
6270 }
6371
6472 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
73+ try super .runOn(units)
74+ finally if (jarFS ne null ) {
75+ try { jarFS.close() } catch { case _ : Throwable => }
76+ jarFS = null
7977 }
8078 }
8179}
8280
83- class GenBCodePipeline (val entryPoints : List [Symbol ], val int : DottyBackendInterface )(implicit val ctx : Context ) extends BCodeSyncAndTry {
81+ class GenBCodePipeline (val entryPoints : List [Symbol ], val int : DottyBackendInterface )(implicit val ctx : Context ) extends BCodeSyncAndTry {
8482
8583 var tree : Tree = _
8684
0 commit comments