Skip to content

Commit 3f7a047

Browse files
Merge pull request #665 from alexarchambault/prepare-scala-2.13-cli
Prepare to build CLI with Scala 2.13
2 parents de98520 + 1fcf9a9 commit 3f7a047

File tree

26 files changed

+385
-313
lines changed

26 files changed

+385
-313
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package scala.build.internal;
2+
3+
import java.util.ArrayList;
4+
5+
import coursier.cache.shaded.dirs.GetWinDirs;
6+
import coursier.jniutils.WindowsKnownFolders;
7+
8+
public class JniGetWinDirs implements GetWinDirs {
9+
@Override
10+
public String[] getWinDirs(String... guids) {
11+
ArrayList<String> list = new ArrayList<>();
12+
for (int i = 0; i < guids.length; i++) {
13+
list.add(WindowsKnownFolders.knownFolderPath("{" + guids[i] + "}"));
14+
}
15+
return list.toArray(new String[list.size()]);
16+
}
17+
}

modules/build/src/main/scala/scala/build/Directories.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package scala.build
22

33
import coursier.cache.shaded.dirs.{GetWinDirs, ProjectDirectories}
44

5+
import scala.build.internal.JniGetWinDirs
56
import scala.util.Properties
67

78
trait Directories {
@@ -59,14 +60,7 @@ object Directories {
5960
def default(): Directories = {
6061
val getWinDirs: GetWinDirs =
6162
if (coursier.paths.Util.useJni())
62-
new GetWinDirs {
63-
def getWinDirs(guids: String*) =
64-
guids
65-
.map { guid =>
66-
coursier.jniutils.WindowsKnownFolders.knownFolderPath("{" + guid + "}")
67-
}
68-
.toArray
69-
}
63+
new JniGetWinDirs
7064
else
7165
GetWinDirs.powerShellBased
7266

modules/build/src/main/scala/scala/build/Inputs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final case class Inputs(
3333
}
3434

3535
def sourceFiles(): Seq[Inputs.SourceFile] =
36-
singleFiles.collect {
36+
singleFiles().collect {
3737
case f: Inputs.SourceFile => f
3838
}
3939

modules/build/src/main/scala/scala/build/internal/Name.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,6 @@ object Name {
112112
!s.contains(blockCommentStart) &&
113113
!s.contains(lineCommentStart)
114114

115-
if (valid) s else '`' + s + '`'
115+
if (valid) s else "`" + s + '`'
116116
}
117117
}

modules/build/src/main/scala/scala/build/internal/Runner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ object Runner {
189189
AsmTestRunner.taskDefs(
190190
classPath,
191191
keepJars = false,
192-
framework.fingerprints(),
192+
framework.fingerprints().toIndexedSeq,
193193
parentInspector
194194
).toArray
195195

196196
val runner = framework.runner(args.toArray, Array(), null)
197197
val initialTasks = runner.tasks(taskDefs)
198-
val events = TestRunner.runTasks(initialTasks, System.out)
198+
val events = TestRunner.runTasks(initialTasks.toIndexedSeq, System.out)
199199

200200
val doneMsg = runner.done()
201201
if (doneMsg.nonEmpty)

modules/build/src/main/scala/scala/build/internal/ScalaParse.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object ScalaParse {
2525
s"$fileName:$lineColIndex expected $expected$newLine$locationString"
2626
}
2727

28-
def Header[_: P]: P[Seq[(Int, Int)]] = {
28+
def Header[X: P]: P[Seq[(Int, Int)]] = {
2929
def PkgAsEmptyList = P(TopPkgSeq).map(_ => List.empty[(Int, Int)])
3030
def ImportStartEnd = P(Index ~ Import ~ Index).map(List(_))
3131
def TopStat = P(PkgAsEmptyList | ImportStartEnd)
@@ -34,9 +34,9 @@ object ScalaParse {
3434
}
3535

3636
// For some reason Scala doesn't import this by default
37-
private def `_`[_: P] = scalaparse.Scala.`_`
37+
private def `_`[X: P] = scalaparse.Scala.`_`
3838

39-
def ImportSplitter[_: P]: P[Seq[ImportTree]] = {
39+
def ImportSplitter[X: P]: P[Seq[ImportTree]] = {
4040
def IdParser = P((Id | `_`).!).map(s => if (s(0) == '`') s.drop(1).dropRight(1) else s)
4141
def Selector = P(IdParser ~ (`=>` ~/ IdParser).?)
4242
def Selectors = P("{" ~/ Selector.rep(sep = ","./) ~ "}")

modules/build/src/main/scala/scala/build/options/ScalaNativeOptions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final case class ScalaNativeOptions(
4848
.map(Paths.get(_))
4949
.getOrElse(sn.Discover.clang())
5050
private def clangCliOption(): List[String] =
51-
List("--clang", clangPath.toString())
51+
List("--clang", clangPath().toString())
5252

5353
private def clangppPath() = clangpp
5454
.filter(_.nonEmpty)
@@ -63,10 +63,10 @@ final case class ScalaNativeOptions(
6363
compileOptions ++ (if (compileDefaults.getOrElse(true)) sn.Discover.compileOptions() else Nil)
6464

6565
private def linkingCliOptions(): List[String] =
66-
finalLinkingOptions.flatMap(option => List("--linking-option", option))
66+
finalLinkingOptions().flatMap(option => List("--linking-option", option))
6767

6868
private def compileCliOptions(): List[String] =
69-
finalCompileOptions.flatMap(option => List("--compile-option", option))
69+
finalCompileOptions().flatMap(option => List("--compile-option", option))
7070

7171
def platformSuffix: String =
7272
"native" + ScalaVersion.nativeBinary(finalVersion).getOrElse(finalVersion)

modules/build/src/main/scala/scala/build/preprocessing/ScalaPreprocessor.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ case object ScalaPreprocessor extends Preprocessor {
213213
// TODO Report error if indicesOrErrorMsg.isLeft?
214214

215215
val importTrees = indicesOrErrorMsg
216-
.right
217216
.toSeq
218217
.iterator
219218
.flatMap(_.iterator)
@@ -380,7 +379,7 @@ case object ScalaPreprocessor extends Preprocessor {
380379
def getDirectives(directives: UsingDirectives) =
381380
directives.getAst() match {
382381
case ud: UsingDefs =>
383-
ud.getUsingDefs().asScala
382+
ud.getUsingDefs().asScala.toSeq
384383
case _ =>
385384
Nil
386385
}
@@ -429,7 +428,10 @@ case object ScalaPreprocessor extends Preprocessor {
429428

430429
val flattened = usedDirectives.getFlattenedMap.asScala.toSeq
431430
val strictDirectives =
432-
flattened.map { case (k, l) => StrictDirective(k.getPath.asScala.mkString("."), l.asScala) }
431+
flattened.map {
432+
case (k, l) =>
433+
StrictDirective(k.getPath.asScala.mkString("."), l.asScala.toSeq)
434+
}
433435

434436
val offset =
435437
if (usedDirectives.getKind() != UsingDirectiveKind.Code) 0
@@ -438,7 +440,7 @@ case object ScalaPreprocessor extends Preprocessor {
438440
}
439441
else {
440442
val errors0 = errors.map(diag => new MalformedDirectiveError(diag.message, diag.positions))
441-
Left(CompositeBuildException(errors0))
443+
Left(CompositeBuildException(errors0.toSeq))
442444
}
443445
}
444446

modules/build/src/test/scala/scala/build/tests/BuildTests.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ class BuildTests extends munit.FunSuite {
806806
)
807807
testInputs.withBuild(buildOptions, buildThreads, bloopConfig) { (_, _, maybeBuild) =>
808808
assert(maybeBuild.isLeft)
809-
assert(maybeBuild.left.get.isInstanceOf[ScalaNativeCompatibilityError])
809+
assert(maybeBuild.swap.toOption.get.isInstanceOf[ScalaNativeCompatibilityError])
810810
}
811811
}
812812

@@ -837,7 +837,7 @@ class BuildTests extends munit.FunSuite {
837837

838838
inputs.withBuild(buildOptions, buildThreads, bloopConfig) { (_, _, maybeBuild) =>
839839
assert(maybeBuild.isRight)
840-
val build = maybeBuild.right.get
840+
val build = maybeBuild.toOption.get
841841
val artifacts = build.options.classPathOptions.extraDependencies.toSeq
842842
assert(artifacts.exists(_.value.toString() == cliDependency))
843843
}
@@ -870,7 +870,7 @@ class BuildTests extends munit.FunSuite {
870870

871871
inputs.withBuild(buildOptions, buildThreads, bloopConfig) { (_, _, maybeBuild) =>
872872
assert(maybeBuild.isRight)
873-
val build = maybeBuild.right.get
873+
val build = maybeBuild.toOption.get
874874
val scalacOptions = build.options.scalaOptions.scalacOptions.toSeq.map(_.value.value)
875875
expect(scalacOptions == expectedOptions)
876876
}

modules/build/src/test/scala/scala/build/tests/PreprocessingTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PreprocessingTests extends munit.FunSuite {
1717

1818
assert(res.nonEmpty)
1919
assert(res.get.isLeft)
20-
expect(res.get.left.get.message == expectedMessage)
20+
expect(res.get.swap.toOption.get.message == expectedMessage)
2121
}
2222

2323
test("Report error if scala script not exists") {
@@ -29,6 +29,6 @@ class PreprocessingTests extends munit.FunSuite {
2929

3030
assert(res.nonEmpty)
3131
assert(res.get.isLeft)
32-
expect(res.get.left.get.message == expectedMessage)
32+
expect(res.get.swap.toOption.get.message == expectedMessage)
3333
}
3434
}

0 commit comments

Comments
 (0)