Skip to content

Commit d11e137

Browse files
authored
Merge pull request #9666 from dotty-staging/fix-4588
Enable Windows CI
2 parents 8c94870 + ffe8bf7 commit d11e137

34 files changed

+153
-114
lines changed

.appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ build_script:
1515
- cmd: sbt dotty-bootstrapped/compile
1616
test_script:
1717
- cmd: sbt "dotty-bootstrapped/dotc tests\pos\HelloWorld.scala"
18+
# - cmd: sbt test
19+
# - cmd: sbt dotty-bootstrapped/test
1820
- cmd: sbt sjsJUnitTests/test

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ import Denotations.Denotation
1212
import typer.Typer
1313
import typer.ImportInfo._
1414
import Decorators._
15-
import io.{AbstractFile, PlainFile}
15+
import io.{AbstractFile, PlainFile, VirtualFile}
1616
import Phases.unfusedPhases
1717

18-
import scala.io.Codec
1918
import util._
2019
import reporting.Reporter
2120
import rewrites.Rewrites
22-
import java.io.{BufferedWriter, OutputStreamWriter}
2321

2422
import profile.Profiler
2523
import printing.XprintMode
2624
import parsing.Parsers.Parser
2725
import parsing.JavaParsers.JavaParser
2826
import typer.ImplicitRunInfo
29-
import collection.mutable
3027

31-
import dotty.tools.io.VirtualFile
28+
import java.io.{BufferedWriter, OutputStreamWriter}
29+
import java.nio.charset.StandardCharsets
3230

31+
import scala.collection.mutable
3332
import scala.util.control.NonFatal
33+
import scala.io.Codec
3434

3535
/** A compiler run. Exports various methods to compile source files */
3636
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
@@ -274,7 +274,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
274274
val uuid = java.util.UUID.randomUUID().toString
275275
val ext = if (isJava) ".java" else ".scala"
276276
val virtualFile = new VirtualFile(s"compileFromString-$uuid.$ext")
277-
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc
277+
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, StandardCharsets.UTF_8.name)) // buffering is still advised by javadoc
278278
writer.write(source)
279279
writer.close()
280280
new SourceFile(virtualFile, Codec.UTF8)

compiler/src/dotty/tools/dotc/config/Properties.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import scala.annotation.internal.sharable
66

77
import java.io.IOException
88
import java.util.jar.Attributes.{ Name => AttributeName }
9+
import java.nio.charset.StandardCharsets
910

1011
/** Loads `library.properties` from the jar. */
1112
object Properties extends PropertiesTrait {
@@ -88,13 +89,13 @@ trait PropertiesTrait {
8889
/** This is the encoding to use reading in source files, overridden with -encoding
8990
* Note that it uses "prop" i.e. looks in the scala jar, not the system properties.
9091
*/
91-
def sourceEncoding: String = scalaPropOrElse("file.encoding", "UTF-8")
92+
def sourceEncoding: String = scalaPropOrElse("file.encoding", StandardCharsets.UTF_8.name)
9293
def sourceReader: String = scalaPropOrElse("source.reader", "scala.tools.nsc.io.SourceReader")
9394

9495
/** This is the default text encoding, overridden (unreliably) with
9596
* `JAVA_OPTS="-Dfile.encoding=Foo"`
9697
*/
97-
def encodingString: String = propOrElse("file.encoding", "UTF-8")
98+
def encodingString: String = propOrElse("file.encoding", StandardCharsets.UTF_8.name)
9899

99100
/** The default end of line character.
100101
*/

compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dotty.tools.dotc.core.Contexts._
77
import dotty.tools.tasty.TastyBuffer
88
import TastyBuffer.{Addr, NoAddr}
99

10-
import java.nio.charset.Charset
10+
import java.nio.charset.StandardCharsets
1111

1212
class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Addr, docString: untpd.MemberDef => Option[Comment]):
1313
private val buf = new TastyBuffer(5000)
@@ -17,7 +17,7 @@ class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Addr, docStr
1717

1818
private def pickleComment(addr: Addr, comment: Comment): Unit =
1919
if addr != NoAddr then
20-
val bytes = comment.raw.getBytes(Charset.forName("UTF-8"))
20+
val bytes = comment.raw.getBytes(StandardCharsets.UTF_8)
2121
val length = bytes.length
2222
buf.writeAddr(addr)
2323
buf.writeNat(length)

compiler/src/dotty/tools/dotc/core/tasty/CommentUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import util.HashMap
88
import dotty.tools.tasty.{TastyReader, TastyBuffer}
99
import TastyBuffer.Addr
1010

11-
import java.nio.charset.Charset
11+
import java.nio.charset.StandardCharsets
1212

1313
class CommentUnpickler(reader: TastyReader) {
1414
import reader._
@@ -21,7 +21,7 @@ class CommentUnpickler(reader: TastyReader) {
2121
if (length > 0) {
2222
val bytes = readBytes(length)
2323
val position = new Span(readLongInt())
24-
val rawComment = new String(bytes, Charset.forName("UTF-8"))
24+
val rawComment = new String(bytes, StandardCharsets.UTF_8)
2525
comments(addr) = Comment(position, rawComment)
2626
}
2727
}

compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotty.tools.dotc
22
package decompiler
33

44
import java.io.{OutputStream, PrintStream}
5+
import java.nio.charset.StandardCharsets
56

67
import scala.io.Codec
78

@@ -27,7 +28,7 @@ class DecompilationPrinter extends Phase {
2728
var ps: PrintStream = null
2829
try {
2930
os = File(outputDir.fileNamed("decompiled.scala").path)(Codec.UTF8).outputStream(append = true)
30-
ps = new PrintStream(os, /* autoFlush = */ false, "UTF-8")
31+
ps = new PrintStream(os, /* autoFlush = */ false, StandardCharsets.UTF_8.name)
3132
printToOutput(ps)
3233
}
3334
finally {

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import java.net.URI
66
import java.io._
77
import java.nio.file._
88
import java.nio.file.attribute.BasicFileAttributes
9+
import java.nio.charset.StandardCharsets
910
import java.util.zip._
1011

1112
import scala.collection._
@@ -298,7 +299,7 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
298299
private def toSource(uri: URI, sourceCode: String): SourceFile = {
299300
val path = Paths.get(uri)
300301
val virtualFile = new VirtualFile(path.getFileName.toString, path.toString)
301-
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8"))
302+
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, StandardCharsets.UTF_8.name))
302303
writer.write(sourceCode)
303304
writer.close()
304305
new SourceFile(virtualFile, Codec.UTF8)

compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbInputStream.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package dotty.tools.dotc.semanticdb.internal
33
import java.io.IOException
44
import java.io.InputStream
55
import java.util.Arrays
6+
import java.nio.charset.StandardCharsets
7+
68
import SemanticdbInputStream._
79

810
import scala.collection.mutable
@@ -434,15 +436,15 @@ class SemanticdbInputStream private (buffer: Array[Byte], input: InputStream) {
434436
def readString(): String = {
435437
val size: Int = readRawVarint32()
436438
if (size <= (bufferSize - bufferPos) && size > 0) {
437-
val result: String = new String(buffer, bufferPos, size, Internal.UTF_8)
439+
val result: String = new String(buffer, bufferPos, size, StandardCharsets.UTF_8)
438440
bufferPos += size
439441
return result
440442
}
441443
else if (size == 0) {
442444
return ""
443445
}
444446
else {
445-
return new String(readRawBytesSlowPath(size), Internal.UTF_8)
447+
return new String(readRawBytesSlowPath(size), StandardCharsets.UTF_8)
446448
}
447449
}
448450

compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbOutputStream.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package dotty.tools.dotc.semanticdb.internal
33
import java.io.IOException
44
import java.io.OutputStream
55
import java.nio.ByteBuffer
6+
import java.nio.charset.StandardCharsets
7+
68
import SemanticdbOutputStream._
79

810
object SemanticdbOutputStream {
@@ -144,7 +146,7 @@ object SemanticdbOutputStream {
144146
def computeBoolSizeNoTag(value: Boolean): Int = 1
145147

146148
def computeStringSizeNoTag(value: String): Int = {
147-
val bytes = value.getBytes(Internal.UTF_8)
149+
val bytes = value.getBytes(StandardCharsets.UTF_8)
148150
computeRawVarint32Size(bytes.length) + bytes.length
149151
}
150152

@@ -391,7 +393,7 @@ class SemanticdbOutputStream(output: OutputStream, buffer: Array[Byte]) {
391393
}
392394

393395
def writeStringNoTag(value: String): Unit = {
394-
val bytes = value.getBytes(Internal.UTF_8)
396+
val bytes = value.getBytes(StandardCharsets.UTF_8)
395397
writeRawVarint32(bytes.length)
396398
writeRawBytes(bytes)
397399
}
@@ -602,6 +604,5 @@ class SemanticdbOutputStream(output: OutputStream, buffer: Array[Byte]) {
602604
}
603605

604606
object Internal {
605-
val UTF_8 = java.nio.charset.Charset.forName("UTF-8")
606607
val EMPTY_BYTE_ARRAY: Array[Byte] = Array()
607608
}

compiler/src/dotty/tools/dotc/util/ShowPickled.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package dotty.tools.dotc
22
package util
33

44
import java.io.PrintStream
5+
import java.nio.charset.StandardCharsets
56
import java.lang.Long.toHexString
67
import java.lang.Float.intBitsToFloat
78
import java.lang.Double.longBitsToDouble
9+
810
import core.unpickleScala2.PickleBuffer
911
import core.Names._
1012

@@ -18,7 +20,7 @@ object ShowPickled {
1820
case _ => false
1921
}
2022
def readName: String =
21-
if (isName) new String(bytes, "UTF-8")
23+
if (isName) new String(bytes, StandardCharsets.UTF_8)
2224
else sys.error("%s is no name" format tagName)
2325
def nameIndex: Int =
2426
if (hasName) readNat(bytes, 0)

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ package dotty.tools
22
package dotc
33
package util
44

5-
import scala.collection.mutable.ArrayBuffer
65
import dotty.tools.io._
7-
import java.util.regex.Pattern
8-
import java.io.IOException
9-
import scala.internal.Chars._
106
import Spans._
11-
import scala.io.Codec
127
import core.Contexts._
8+
9+
import scala.io.Codec
10+
import scala.internal.Chars._
1311
import scala.annotation.internal.sharable
14-
import java.util.concurrent.atomic.AtomicInteger
1512
import scala.collection.mutable
13+
import scala.collection.mutable.ArrayBuffer
1614

15+
import java.io.IOException
16+
import java.nio.charset.StandardCharsets
1717
import java.util.Optional
18+
import java.util.concurrent.atomic.AtomicInteger
19+
import java.util.regex.Pattern
1820

1921
object ScriptSourceFile {
2022
@sharable private val headerPattern = Pattern.compile("""^(::)?!#.*(\r|\n|\r\n)""", Pattern.MULTILINE)
@@ -212,7 +214,7 @@ object SourceFile {
212214
def fromId(id: Int): SourceFile = sourceOfChunk(id >> ChunkSizeLog)
213215

214216
def virtual(name: String, content: String, maybeIncomplete: Boolean = false) =
215-
val src = new SourceFile(new VirtualFile(name, content.getBytes), scala.io.Codec.UTF8)
217+
val src = new SourceFile(new VirtualFile(name, content.getBytes(StandardCharsets.UTF_8)), scala.io.Codec.UTF8)
216218
src._maybeInComplete = maybeIncomplete
217219
src
218220

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools.repl
22

33
import java.io.{File => JFile, PrintStream}
4+
import java.nio.charset.StandardCharsets
45

56
import dotty.tools.dotc.ast.Trees._
67
import dotty.tools.dotc.ast.{tpd, untpd}
@@ -367,7 +368,7 @@ class ReplDriver(settings: Array[String],
367368
case Load(path) =>
368369
val file = new JFile(path)
369370
if (file.exists) {
370-
val contents = Using(scala.io.Source.fromFile(file, "UTF-8"))(_.mkString).get
371+
val contents = Using(scala.io.Source.fromFile(file, StandardCharsets.UTF_8.name))(_.mkString).get
371372
run(contents)
372373
}
373374
else {

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
129129
)
130130
}.checkRuns()
131131

132-
@Test def runWithCompiler: Unit = {
132+
@Test def runWithCompiler: Unit = if (!scala.util.Properties.isWin) {
133133
implicit val testGroup: TestGroup = TestGroup("runWithCompiler")
134134
aggregateTests(
135135
compileFilesInDir("tests/run-with-compiler", withCompilerOptions),

compiler/test/dotty/tools/dotc/printing/PrintingTest.scala

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import reporting.TestReporter
1010
import java.io._
1111
import java.nio.file.{Path => JPath}
1212
import java.lang.System.{lineSeparator => EOL}
13+
import java.nio.charset.StandardCharsets
1314

1415
import interfaces.Diagnostic.INFO
1516
import dotty.tools.io.Directory
@@ -35,21 +36,8 @@ class PrintingTest {
3536
e.printStackTrace()
3637
}
3738

38-
val actualLines = byteStream.toString("UTF-8").split("\\r?\\n")
39-
// 'options' includes option '-Xprint:typer' so the first output line
40-
// looks similar to "result of tests/printing/i620.scala after typer:";
41-
// check files use slashes as file separators (Unix) but running tests
42-
// on Windows produces backslashes.
43-
// NB. option '-Xprint:<..>' can specify several phases.
44-
val filteredLines =
45-
if (config.Properties.isWin)
46-
actualLines.map(line =>
47-
if (line.startsWith("result of")) line.replaceAll("\\\\", "/") else line
48-
)
49-
else
50-
actualLines
51-
52-
FileDiff.checkAndDump(path.toString, filteredLines.toIndexedSeq, checkFilePath)
39+
val actualLines = byteStream.toString(StandardCharsets.UTF_8.name).linesIterator
40+
FileDiff.checkAndDump(path.toString, actualLines.toIndexedSeq, checkFilePath)
5341
}
5442

5543
@Test

compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SemanticdbTests:
3636
val metacExpectFile = rootSrc.resolve("metac.expect")
3737

3838
@Category(Array(classOf[dotty.SlowTests]))
39-
@Test def expectTests: Unit = runExpectTest(updateExpectFiles = false)
39+
@Test def expectTests: Unit = if (!scala.util.Properties.isWin) runExpectTest(updateExpectFiles = false)
4040

4141
def runExpectTest(updateExpectFiles: Boolean): Unit =
4242
val target = generateSemanticdb()

compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,39 @@ class PatmatExhaustivityTest {
2020
// stop-after: patmatexhaust-huge.scala crash compiler
2121
val options = List("-color:never", "-Ystop-after:crossCast", "-Ycheck-all-patmat", "-classpath", TestConfiguration.basicClasspath)
2222

23-
private def compileFile(path: JPath): Boolean = {
23+
private def compile(files: Seq[String]): Seq[String] = {
2424
val stringBuffer = new StringWriter()
2525
val reporter = TestReporter.simplifiedReporter(new PrintWriter(stringBuffer))
2626

2727
try {
28-
Main.process((path.toString::options).toArray, reporter, null)
28+
Main.process((options ++ files).toArray, reporter, null)
2929
} catch {
3030
case e: Throwable =>
31-
println(s"Compile $path exception:")
31+
println(s"Compile $files exception:")
3232
e.printStackTrace()
3333
}
3434

35-
val actualLines: Seq[String] = stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match {
35+
stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match {
3636
case "" => Nil
37-
case s => s.split("\\r?\\n").toIndexedSeq
37+
case s => s.linesIterator.toSeq
3838
}
39-
val baseFilePath = path.toString.stripSuffix(".scala")
39+
}
40+
41+
private def compileFile(path: JPath): Boolean = {
42+
val actualLines = compile(path.toString :: Nil)
43+
val baseFilePath = path.toString.stripSuffix(".scala")
4044
val checkFilePath = baseFilePath + ".check"
4145

4246
FileDiff.checkAndDump(path.toString, actualLines, checkFilePath)
4347
}
4448

4549
/** A single test with multiple files grouped in a folder */
4650
private def compileDir(path: JPath): Boolean = {
47-
val stringBuffer = new StringWriter()
48-
val reporter = TestReporter.simplifiedReporter(new PrintWriter(stringBuffer))
49-
5051
val files = Directory(path).list.toList
5152
.filter(f => f.extension == "scala" || f.extension == "java" )
5253
.map(_.jpath.toString)
5354

54-
try {
55-
Main.process((options ++ files).toArray, reporter, null)
56-
} catch {
57-
case e: Throwable =>
58-
println(s"Compile $path exception:")
59-
e.printStackTrace()
60-
}
61-
62-
val actualLines: Seq[String] = stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match {
63-
case "" => Nil
64-
case s => s.split("\\r?\\n").toIndexedSeq
65-
}
66-
55+
val actualLines = compile(files)
6756
val checkFilePath = s"${path}${File.separator}expected.check"
6857

6958
FileDiff.checkAndDump(path.toString, actualLines, checkFilePath)

0 commit comments

Comments
 (0)