1
1
package dotty .tools .backend .jvm
2
2
3
- import java .io .{DataOutputStream , IOException , BufferedOutputStream , FileOutputStream }
3
+ import java .io .{DataOutputStream , File , IOException , BufferedOutputStream , FileOutputStream }
4
4
import java .nio .ByteBuffer
5
5
import java .nio .channels .{ClosedByInterruptException , FileChannel }
6
6
import java .nio .charset .StandardCharsets .UTF_8
@@ -12,7 +12,7 @@ import java.util.zip.{CRC32, Deflater, ZipEntry, ZipOutputStream}
12
12
13
13
import dotty .tools .dotc .core .Contexts .*
14
14
import dotty .tools .dotc .core .Decorators .em
15
- import dotty .tools .io .{AbstractFile , PlainFile }
15
+ import dotty .tools .io .{AbstractFile , PlainFile , VirtualFile }
16
16
import dotty .tools .io .PlainFile .toPlainFile
17
17
import BTypes .InternalName
18
18
import scala .util .chaining ._
@@ -22,7 +22,6 @@ import scala.language.unsafeNulls
22
22
23
23
24
24
class ClassfileWriters (frontendAccess : PostProcessorFrontendAccess ) {
25
- type NullableFile = AbstractFile | Null
26
25
import frontendAccess .{compilerSettings , backendReporting }
27
26
28
27
sealed trait TastyWriter {
@@ -42,7 +41,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
42
41
/**
43
42
* Write a classfile
44
43
*/
45
- def writeClass (name : InternalName , bytes : Array [Byte ], sourceFile : AbstractFile ): NullableFile
44
+ def writeClass (name : InternalName , bytes : Array [Byte ], sourceFile : AbstractFile ): AbstractFile
46
45
47
46
48
47
/**
@@ -87,7 +86,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
87
86
}
88
87
89
88
private final class SingleClassWriter (underlying : FileWriter ) extends ClassfileWriter {
90
- override def writeClass (className : InternalName , bytes : Array [Byte ], sourceFile : AbstractFile ): NullableFile = {
89
+ override def writeClass (className : InternalName , bytes : Array [Byte ], sourceFile : AbstractFile ): AbstractFile = {
91
90
underlying.writeFile(classRelativePath(className), bytes)
92
91
}
93
92
override def writeTasty (className : InternalName , bytes : Array [Byte ], sourceFile : AbstractFile ): Unit = {
@@ -99,7 +98,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
99
98
}
100
99
101
100
private final class DebugClassWriter (basic : ClassfileWriter , dump : FileWriter ) extends ClassfileWriter {
102
- override def writeClass (className : InternalName , bytes : Array [Byte ], sourceFile : AbstractFile ): NullableFile = {
101
+ override def writeClass (className : InternalName , bytes : Array [Byte ], sourceFile : AbstractFile ): AbstractFile = {
103
102
val outFile = basic.writeClass(className, bytes, sourceFile)
104
103
dump.writeFile(classRelativePath(className), bytes)
105
104
outFile
@@ -117,7 +116,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
117
116
}
118
117
119
118
sealed trait FileWriter {
120
- def writeFile (relativePath : String , bytes : Array [Byte ]): NullableFile
119
+ def writeFile (relativePath : String , bytes : Array [Byte ]): AbstractFile
121
120
def close (): Unit
122
121
}
123
122
@@ -161,7 +160,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
161
160
162
161
lazy val crc = new CRC32
163
162
164
- override def writeFile (relativePath : String , bytes : Array [Byte ]): NullableFile = this .synchronized {
163
+ override def writeFile (relativePath : String , bytes : Array [Byte ]): AbstractFile = this .synchronized {
165
164
val entry = new ZipEntry (relativePath)
166
165
if (storeOnly) {
167
166
// When using compression method `STORED`, the ZIP spec requires the CRC and compressed/
@@ -178,7 +177,13 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
178
177
jarWriter.putNextEntry(entry)
179
178
try jarWriter.write(bytes, 0 , bytes.length)
180
179
finally jarWriter.flush()
181
- null
180
+ // important detail here, even on Windows, Zinc expects the separator within the jar
181
+ // to be the system default, (even if in the actual jar file the entry always uses '/').
182
+ // see https://github.com/sbt/zinc/blob/dcddc1f9cfe542d738582c43f4840e17c053ce81/internal/compiler-bridge/src/main/scala/xsbt/JarUtils.scala#L47
183
+ val pathInJar =
184
+ if File .separatorChar == '/' then relativePath
185
+ else relativePath.replace('/' , File .separatorChar)
186
+ PlainFile .toPlainFile(Paths .get(s " ${file.absolutePath}! $pathInJar" ))
182
187
}
183
188
184
189
override def close (): Unit = this .synchronized (jarWriter.close())
@@ -226,7 +231,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
226
231
private val fastOpenOptions = util.EnumSet .of(StandardOpenOption .CREATE_NEW , StandardOpenOption .WRITE )
227
232
private val fallbackOpenOptions = util.EnumSet .of(StandardOpenOption .CREATE , StandardOpenOption .WRITE , StandardOpenOption .TRUNCATE_EXISTING )
228
233
229
- override def writeFile (relativePath : String , bytes : Array [Byte ]): NullableFile = {
234
+ override def writeFile (relativePath : String , bytes : Array [Byte ]): AbstractFile = {
230
235
val path = base.resolve(relativePath)
231
236
try {
232
237
ensureDirForPath(base, path)
@@ -275,7 +280,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
275
280
finally out.close()
276
281
}
277
282
278
- override def writeFile (relativePath : String , bytes : Array [Byte ]): NullableFile = {
283
+ override def writeFile (relativePath : String , bytes : Array [Byte ]): AbstractFile = {
279
284
val outFile = getFile(base, relativePath)
280
285
writeBytes(outFile, bytes)
281
286
outFile
0 commit comments