Skip to content

Commit ccf4f88

Browse files
Dotty SBT plugin updated to work with Scala 3
Read latest nightly metadata from the scala3-compiler artefact Co-authored-by: Guillaume Martres <smarter@ubuntu.com> Properly set binary version for Scala 3 Fetch Dotty nightlies correctly
1 parent a77d70a commit ccf4f88

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ object DottyPlugin extends AutoPlugin {
3535

3636
// get latest nightly version from maven
3737
def fetchSource(version: String): (scala.io.BufferedSource, String) =
38-
try Source.fromURL(s"https://repo1.maven.org/maven2/ch/epfl/lamp/dotty_$version/maven-metadata.xml") -> version
38+
try {
39+
val url =
40+
if (version.startsWith("0"))
41+
s"https://repo1.maven.org/maven2/ch/epfl/lamp/dotty-compiler_$version/maven-metadata.xml"
42+
else
43+
s"https://repo1.maven.org/maven2/org/scala-lang/scala3-compiler_$version/maven-metadata.xml"
44+
Source.fromURL(url) -> version
45+
}
3946
catch { case t: java.io.FileNotFoundException =>
4047
val major :: minor :: Nil = version.split('.').toList
4148
if (minor.toInt <= 0) throw t
@@ -92,7 +99,7 @@ object DottyPlugin extends AutoPlugin {
9299
*/
93100
def withDottyCompat(scalaVersion: String): ModuleID = {
94101
val name = moduleID.name
95-
if (name != "dotty" && name != "dotty-library" && name != "dotty-compiler")
102+
if (name != "scala3" && name != "scala3-library" && name != "scala3-compiler")
96103
moduleID.crossVersion match {
97104
case binary: librarymanagement.Binary =>
98105
val compatVersion =
@@ -167,6 +174,14 @@ object DottyPlugin extends AutoPlugin {
167174

168175
// https://github.com/sbt/sbt/issues/3110
169176
val Def = sbt.Def
177+
178+
private def scala3Artefact(version: String, name: String) =
179+
if (version.startsWith("0.")) s"dotty-$name"
180+
else if (version.startsWith("3.")) s"scala3-$name"
181+
else throw new RuntimeException(
182+
s"Cannot construct a Scala 3 artefact name $name for a non-Scala3 " +
183+
s"scala version ${version}")
184+
170185
override def projectSettings: Seq[Setting[_]] = {
171186
Seq(
172187
isDotty := scalaVersion.value.startsWith("0.") || scalaVersion.value.startsWith("3."),
@@ -195,8 +210,10 @@ object DottyPlugin extends AutoPlugin {
195210
},
196211

197212
scalaOrganization := {
198-
if (isDotty.value)
213+
if (scalaVersion.value.startsWith("0."))
199214
"ch.epfl.lamp"
215+
else if (scalaVersion.value.startsWith("3."))
216+
"org.scala-lang"
200217
else
201218
scalaOrganization.value
202219
},
@@ -212,14 +229,14 @@ object DottyPlugin extends AutoPlugin {
212229
scalaCompilerBridgeBinaryJar := Def.settingDyn {
213230
if (isDotty.value) Def.task {
214231
val updateReport = fetchArtifactsOf(
215-
scalaOrganization.value % "dotty-sbt-bridge" % scalaVersion.value,
232+
scalaOrganization.value % scala3Artefact(scalaVersion.value, "sbt-bridge") % scalaVersion.value,
216233
dependencyResolution.value,
217234
scalaModuleInfo.value,
218235
updateConfiguration.value,
219236
(unresolvedWarningConfiguration in update).value,
220237
streams.value.log,
221238
)
222-
Option(getJar(updateReport, scalaOrganization.value, "dotty-sbt-bridge", scalaVersion.value))
239+
Option(getJar(updateReport, scalaOrganization.value, scala3Artefact(scalaVersion.value, "sbt-bridge"), scalaVersion.value))
223240
}
224241
else Def.task {
225242
None: Option[File]
@@ -228,10 +245,15 @@ object DottyPlugin extends AutoPlugin {
228245

229246
// Needed for RCs publishing
230247
scalaBinaryVersion := {
231-
if (isDotty.value)
232-
scalaVersion.value.split("\\.").take(2).mkString(".")
233-
else
234-
scalaBinaryVersion.value
248+
scalaVersion.value.split("[\\.-]").toList match {
249+
case "0" :: minor :: _ => s"0.$minor"
250+
case "3" :: minor :: patch :: suffix =>
251+
s"3.$minor.$patch" + (suffix match {
252+
case milestone :: _ => s"-$milestone"
253+
case Nil => ""
254+
})
255+
case _ => scalaBinaryVersion.value
256+
}
235257
},
236258

237259
// We want:
@@ -326,15 +348,15 @@ object DottyPlugin extends AutoPlugin {
326348
// ... instead, we'll fetch the compiler and its dependencies ourselves.
327349
scalaInstance := Def.taskDyn {
328350
if (isDotty.value)
329-
dottyScalaInstanceTask("dotty-compiler")
351+
dottyScalaInstanceTask(scala3Artefact(scalaVersion.value, "compiler"))
330352
else
331353
Def.valueStrict { scalaInstance.taskValue }
332354
}.value,
333355

334356
// We need more stuff on the classpath to run the `doc` task.
335357
scalaInstance in doc := Def.taskDyn {
336358
if (isDotty.value)
337-
dottyScalaInstanceTask("dotty-doc")
359+
dottyScalaInstanceTask(scala3Artefact(scalaVersion.value, "doc"))
338360
else
339361
Def.valueStrict { (scalaInstance in doc).taskValue }
340362
}.value,
@@ -343,8 +365,8 @@ object DottyPlugin extends AutoPlugin {
343365
libraryDependencies ++= {
344366
if (isDotty.value && autoScalaLibrary.value) {
345367
val name =
346-
if (isDottyJS.value) "dotty-library_sjs1"
347-
else "dotty-library"
368+
if (isDottyJS.value) scala3Artefact(scalaVersion.value, "library_sjs1")
369+
else scala3Artefact(scalaVersion.value, "library")
348370
Seq(scalaOrganization.value %% name % scalaVersion.value)
349371
} else
350372
Seq()
@@ -479,9 +501,9 @@ object DottyPlugin extends AutoPlugin {
479501
val scalaLibraryJar = getJar(updateReport,
480502
"org.scala-lang", "scala-library", revision = AllPassFilter)
481503
val dottyLibraryJar = getJar(updateReport,
482-
scalaOrganization.value, s"dotty-library_${scalaBinaryVersion.value}", scalaVersion.value)
504+
scalaOrganization.value, scala3Artefact(scalaVersion.value, s"library_${scalaBinaryVersion.value}"), scalaVersion.value)
483505
val compilerJar = getJar(updateReport,
484-
scalaOrganization.value, s"dotty-compiler_${scalaBinaryVersion.value}", scalaVersion.value)
506+
scalaOrganization.value, scala3Artefact(scalaVersion.value, s"compiler_${scalaBinaryVersion.value}"), scalaVersion.value)
485507
val allJars =
486508
getJars(updateReport, AllPassFilter, AllPassFilter, AllPassFilter)
487509

0 commit comments

Comments
 (0)