Skip to content

Enable Windows CI #9666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ build_script:
- cmd: sbt dotty-bootstrapped/compile
test_script:
- cmd: sbt "dotty-bootstrapped/dotc tests\pos\HelloWorld.scala"
# - cmd: sbt test
# - cmd: sbt dotty-bootstrapped/test
- cmd: sbt sjsJUnitTests/test
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ import Denotations.Denotation
import typer.Typer
import typer.ImportInfo._
import Decorators._
import io.{AbstractFile, PlainFile}
import io.{AbstractFile, PlainFile, VirtualFile}
import Phases.unfusedPhases

import scala.io.Codec
import util._
import reporting.Reporter
import rewrites.Rewrites
import java.io.{BufferedWriter, OutputStreamWriter}

import profile.Profiler
import printing.XprintMode
import parsing.Parsers.Parser
import parsing.JavaParsers.JavaParser
import typer.ImplicitRunInfo
import collection.mutable

import dotty.tools.io.VirtualFile
import java.io.{BufferedWriter, OutputStreamWriter}
import java.nio.charset.StandardCharsets

import scala.collection.mutable
import scala.util.control.NonFatal
import scala.io.Codec

/** A compiler run. Exports various methods to compile source files */
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
Expand Down Expand Up @@ -274,7 +274,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
val uuid = java.util.UUID.randomUUID().toString
val ext = if (isJava) ".java" else ".scala"
val virtualFile = new VirtualFile(s"compileFromString-$uuid.$ext")
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, StandardCharsets.UTF_8.name)) // buffering is still advised by javadoc
writer.write(source)
writer.close()
new SourceFile(virtualFile, Codec.UTF8)
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/config/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import scala.annotation.internal.sharable

import java.io.IOException
import java.util.jar.Attributes.{ Name => AttributeName }
import java.nio.charset.StandardCharsets

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

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

/** The default end of line character.
*/
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dotty.tools.dotc.core.Contexts._
import dotty.tools.tasty.TastyBuffer
import TastyBuffer.{Addr, NoAddr}

import java.nio.charset.Charset
import java.nio.charset.StandardCharsets

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

private def pickleComment(addr: Addr, comment: Comment): Unit =
if addr != NoAddr then
val bytes = comment.raw.getBytes(Charset.forName("UTF-8"))
val bytes = comment.raw.getBytes(StandardCharsets.UTF_8)
val length = bytes.length
buf.writeAddr(addr)
buf.writeNat(length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import util.HashMap
import dotty.tools.tasty.{TastyReader, TastyBuffer}
import TastyBuffer.Addr

import java.nio.charset.Charset
import java.nio.charset.StandardCharsets

class CommentUnpickler(reader: TastyReader) {
import reader._
Expand All @@ -21,7 +21,7 @@ class CommentUnpickler(reader: TastyReader) {
if (length > 0) {
val bytes = readBytes(length)
val position = new Span(readLongInt())
val rawComment = new String(bytes, Charset.forName("UTF-8"))
val rawComment = new String(bytes, StandardCharsets.UTF_8)
comments(addr) = Comment(position, rawComment)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dotty.tools.dotc
package decompiler

import java.io.{OutputStream, PrintStream}
import java.nio.charset.StandardCharsets

import scala.io.Codec

Expand All @@ -27,7 +28,7 @@ class DecompilationPrinter extends Phase {
var ps: PrintStream = null
try {
os = File(outputDir.fileNamed("decompiled.scala").path)(Codec.UTF8).outputStream(append = true)
ps = new PrintStream(os, /* autoFlush = */ false, "UTF-8")
ps = new PrintStream(os, /* autoFlush = */ false, StandardCharsets.UTF_8.name)
printToOutput(ps)
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.net.URI
import java.io._
import java.nio.file._
import java.nio.file.attribute.BasicFileAttributes
import java.nio.charset.StandardCharsets
import java.util.zip._

import scala.collection._
Expand Down Expand Up @@ -298,7 +299,7 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
private def toSource(uri: URI, sourceCode: String): SourceFile = {
val path = Paths.get(uri)
val virtualFile = new VirtualFile(path.getFileName.toString, path.toString)
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8"))
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, StandardCharsets.UTF_8.name))
writer.write(sourceCode)
writer.close()
new SourceFile(virtualFile, Codec.UTF8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package dotty.tools.dotc.semanticdb.internal
import java.io.IOException
import java.io.InputStream
import java.util.Arrays
import java.nio.charset.StandardCharsets

import SemanticdbInputStream._

import scala.collection.mutable
Expand Down Expand Up @@ -434,15 +436,15 @@ class SemanticdbInputStream private (buffer: Array[Byte], input: InputStream) {
def readString(): String = {
val size: Int = readRawVarint32()
if (size <= (bufferSize - bufferPos) && size > 0) {
val result: String = new String(buffer, bufferPos, size, Internal.UTF_8)
val result: String = new String(buffer, bufferPos, size, StandardCharsets.UTF_8)
bufferPos += size
return result
}
else if (size == 0) {
return ""
}
else {
return new String(readRawBytesSlowPath(size), Internal.UTF_8)
return new String(readRawBytesSlowPath(size), StandardCharsets.UTF_8)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package dotty.tools.dotc.semanticdb.internal
import java.io.IOException
import java.io.OutputStream
import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets

import SemanticdbOutputStream._

object SemanticdbOutputStream {
Expand Down Expand Up @@ -144,7 +146,7 @@ object SemanticdbOutputStream {
def computeBoolSizeNoTag(value: Boolean): Int = 1

def computeStringSizeNoTag(value: String): Int = {
val bytes = value.getBytes(Internal.UTF_8)
val bytes = value.getBytes(StandardCharsets.UTF_8)
computeRawVarint32Size(bytes.length) + bytes.length
}

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

def writeStringNoTag(value: String): Unit = {
val bytes = value.getBytes(Internal.UTF_8)
val bytes = value.getBytes(StandardCharsets.UTF_8)
writeRawVarint32(bytes.length)
writeRawBytes(bytes)
}
Expand Down Expand Up @@ -602,6 +604,5 @@ class SemanticdbOutputStream(output: OutputStream, buffer: Array[Byte]) {
}

object Internal {
val UTF_8 = java.nio.charset.Charset.forName("UTF-8")
val EMPTY_BYTE_ARRAY: Array[Byte] = Array()
}
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/util/ShowPickled.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package dotty.tools.dotc
package util

import java.io.PrintStream
import java.nio.charset.StandardCharsets
import java.lang.Long.toHexString
import java.lang.Float.intBitsToFloat
import java.lang.Double.longBitsToDouble

import core.unpickleScala2.PickleBuffer
import core.Names._

Expand All @@ -18,7 +20,7 @@ object ShowPickled {
case _ => false
}
def readName: String =
if (isName) new String(bytes, "UTF-8")
if (isName) new String(bytes, StandardCharsets.UTF_8)
else sys.error("%s is no name" format tagName)
def nameIndex: Int =
if (hasName) readNat(bytes, 0)
Expand Down
16 changes: 9 additions & 7 deletions compiler/src/dotty/tools/dotc/util/SourceFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ package dotty.tools
package dotc
package util

import scala.collection.mutable.ArrayBuffer
import dotty.tools.io._
import java.util.regex.Pattern
import java.io.IOException
import scala.internal.Chars._
import Spans._
import scala.io.Codec
import core.Contexts._

import scala.io.Codec
import scala.internal.Chars._
import scala.annotation.internal.sharable
import java.util.concurrent.atomic.AtomicInteger
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

import java.io.IOException
import java.nio.charset.StandardCharsets
import java.util.Optional
import java.util.concurrent.atomic.AtomicInteger
import java.util.regex.Pattern

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

def virtual(name: String, content: String, maybeIncomplete: Boolean = false) =
val src = new SourceFile(new VirtualFile(name, content.getBytes), scala.io.Codec.UTF8)
val src = new SourceFile(new VirtualFile(name, content.getBytes(StandardCharsets.UTF_8)), scala.io.Codec.UTF8)
src._maybeInComplete = maybeIncomplete
src

Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dotty.tools.repl

import java.io.{File => JFile, PrintStream}
import java.nio.charset.StandardCharsets

import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.ast.{tpd, untpd}
Expand Down Expand Up @@ -367,7 +368,7 @@ class ReplDriver(settings: Array[String],
case Load(path) =>
val file = new JFile(path)
if (file.exists) {
val contents = Using(scala.io.Source.fromFile(file, "UTF-8"))(_.mkString).get
val contents = Using(scala.io.Source.fromFile(file, StandardCharsets.UTF_8.name))(_.mkString).get
run(contents)
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
)
}.checkRuns()

@Test def runWithCompiler: Unit = {
@Test def runWithCompiler: Unit = if (!scala.util.Properties.isWin) {
implicit val testGroup: TestGroup = TestGroup("runWithCompiler")
aggregateTests(
compileFilesInDir("tests/run-with-compiler", withCompilerOptions),
Expand Down
18 changes: 3 additions & 15 deletions compiler/test/dotty/tools/dotc/printing/PrintingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import reporting.TestReporter
import java.io._
import java.nio.file.{Path => JPath}
import java.lang.System.{lineSeparator => EOL}
import java.nio.charset.StandardCharsets

import interfaces.Diagnostic.INFO
import dotty.tools.io.Directory
Expand All @@ -35,21 +36,8 @@ class PrintingTest {
e.printStackTrace()
}

val actualLines = byteStream.toString("UTF-8").split("\\r?\\n")
// 'options' includes option '-Xprint:typer' so the first output line
// looks similar to "result of tests/printing/i620.scala after typer:";
// check files use slashes as file separators (Unix) but running tests
// on Windows produces backslashes.
// NB. option '-Xprint:<..>' can specify several phases.
val filteredLines =
if (config.Properties.isWin)
actualLines.map(line =>
if (line.startsWith("result of")) line.replaceAll("\\\\", "/") else line
)
else
actualLines

FileDiff.checkAndDump(path.toString, filteredLines.toIndexedSeq, checkFilePath)
val actualLines = byteStream.toString(StandardCharsets.UTF_8.name).linesIterator
FileDiff.checkAndDump(path.toString, actualLines.toIndexedSeq, checkFilePath)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SemanticdbTests:
val metacExpectFile = rootSrc.resolve("metac.expect")

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

def runExpectTest(updateExpectFiles: Boolean): Unit =
val target = generateSemanticdb()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,39 @@ class PatmatExhaustivityTest {
// stop-after: patmatexhaust-huge.scala crash compiler
val options = List("-color:never", "-Ystop-after:crossCast", "-Ycheck-all-patmat", "-classpath", TestConfiguration.basicClasspath)

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

try {
Main.process((path.toString::options).toArray, reporter, null)
Main.process((options ++ files).toArray, reporter, null)
} catch {
case e: Throwable =>
println(s"Compile $path exception:")
println(s"Compile $files exception:")
e.printStackTrace()
}

val actualLines: Seq[String] = stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match {
stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match {
case "" => Nil
case s => s.split("\\r?\\n").toIndexedSeq
case s => s.linesIterator.toSeq
}
val baseFilePath = path.toString.stripSuffix(".scala")
}

private def compileFile(path: JPath): Boolean = {
val actualLines = compile(path.toString :: Nil)
val baseFilePath = path.toString.stripSuffix(".scala")
val checkFilePath = baseFilePath + ".check"

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

/** A single test with multiple files grouped in a folder */
private def compileDir(path: JPath): Boolean = {
val stringBuffer = new StringWriter()
val reporter = TestReporter.simplifiedReporter(new PrintWriter(stringBuffer))

val files = Directory(path).list.toList
.filter(f => f.extension == "scala" || f.extension == "java" )
.map(_.jpath.toString)

try {
Main.process((options ++ files).toArray, reporter, null)
} catch {
case e: Throwable =>
println(s"Compile $path exception:")
e.printStackTrace()
}

val actualLines: Seq[String] = stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match {
case "" => Nil
case s => s.split("\\r?\\n").toIndexedSeq
}

val actualLines = compile(files)
val checkFilePath = s"${path}${File.separator}expected.check"

FileDiff.checkAndDump(path.toString, actualLines, checkFilePath)
Expand Down
Loading