@@ -7,6 +7,7 @@ import dotty.tools.dotc.core.Phases.Phase
7
7
import dotty .tools .dotc .core .Names .TypeName
8
8
9
9
import scala .collection .mutable
10
+ import scala .collection .JavaConverters ._
10
11
import scala .tools .asm .{ClassVisitor , CustomAttr , FieldVisitor , MethodVisitor }
11
12
import scala .tools .nsc .backend .jvm ._
12
13
import dotty .tools .dotc
@@ -26,14 +27,15 @@ import Denotations._
26
27
import Phases ._
27
28
import java .lang .AssertionError
28
29
import 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 }
30
33
31
34
import scala .tools .asm
32
35
import scala .tools .asm .tree ._
33
36
import dotty .tools .dotc .util .{DotClass , Positions }
34
37
import tpd ._
35
38
import StdNames ._
36
-
37
39
import dotty .tools .io ._
38
40
39
41
class GenBCode extends Phase {
@@ -47,40 +49,36 @@ class GenBCode extends Phase {
47
49
superCallsMap.put(sym, old + calls)
48
50
}
49
51
52
+ private [this ] var jarFS : JarFS = _
53
+
50
54
def outputDir (implicit ctx : Context ): AbstractFile = {
51
55
val path = ctx.settings.outputDir.value
52
56
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
+ }
54
64
}
55
65
56
- private [this ] var classOutput : AbstractFile = _
57
-
58
66
def run (implicit ctx : Context ): Unit = {
59
67
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)
61
69
entryPoints.clear()
62
70
}
63
71
64
72
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
79
77
}
80
78
}
81
79
}
82
80
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 {
84
82
85
83
var tree : Tree = _
86
84
0 commit comments