From 4035706d5846a9815b147cc9a12aef453632f224 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 26 May 2017 22:43:26 +0200 Subject: [PATCH 1/4] sbt-dotty: Future-proof scalaBinaryVersion Needs to work for dotty 0.2 and onwards too. --- sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala b/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala index 31ca1cfd9f7c..b560a853b63e 100644 --- a/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala +++ b/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala @@ -95,7 +95,7 @@ object DottyPlugin extends AutoPlugin { scalaBinaryVersion := { if (isDotty.value) - "0.1" // TODO: Fix sbt so that this isn't needed + scalaVersion.value.split("\\.").take(2).mkString(".") // Not needed with sbt >= 0.13.16 else scalaBinaryVersion.value } From b8e56b7f107ad1fa70bd3e7de58e71804d49ada8 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 26 May 2017 22:54:17 +0200 Subject: [PATCH 2/4] Make withDottyCompat() the identity on non-crossversioned ModuleIDs This way you can do for example: libraryDependencies ~= (_.map(_.withDottyCompat())) --- .../src/dotty/tools/sbtplugin/DottyPlugin.scala | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala b/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala index b560a853b63e..4d8044e3ca6f 100644 --- a/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala +++ b/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala @@ -27,7 +27,8 @@ object DottyPlugin extends AutoPlugin { implicit class DottyCompatModuleID(moduleID: ModuleID) { /** If this ModuleID cross-version is a Dotty version, replace it - * by the Scala 2.x version that the Dotty version is retro-compatible with. + * by the Scala 2.x version that the Dotty version is retro-compatible with, + * otherwise do nothing. * * This setting is useful when your build contains dependencies that have only * been published with Scala 2.x, if you have: @@ -46,10 +47,15 @@ object DottyPlugin extends AutoPlugin { * Dotty is released, you should not rely on it. */ def withDottyCompat(): ModuleID = - moduleID.cross(CrossVersion.binaryMapped { - case version if version.startsWith("0.") => "2.11" - case version => version - }) + moduleID.crossVersion match { + case _: CrossVersion.Binary => + moduleID.cross(CrossVersion.binaryMapped { + case version if version.startsWith("0.") => "2.11" + case version => version + }) + case _ => + moduleID + } } } From 452bc5e9645021df496e99b824c7817af92a28ff Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 26 May 2017 23:16:29 +0200 Subject: [PATCH 3/4] sbt-dotty: Delete .tasty files Since 1293e2f49b320873c58552ab86f49ef7999b91f8 we emit empty .tasty files by default (and already before that, non-empty ones if -YemitTasty is used). But these files were never deleted by sbt when the corresponding classfiles got deleted. This commit fixes that by stealing some code from Scala.js --- .../dotty/tools/sbtplugin/DottyPlugin.scala | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala b/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala index 4d8044e3ca6f..b3ef759c7d9b 100644 --- a/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala +++ b/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala @@ -2,6 +2,7 @@ package dotty.tools.sbtplugin import sbt._ import sbt.Keys._ +import sbt.inc.{ ClassfileManager, IncOptions } object DottyPlugin extends AutoPlugin { object autoImport { @@ -78,6 +79,37 @@ object DottyPlugin extends AutoPlugin { } } + /** Patches the IncOptions so that .tasty files are pruned as needed. + * + * This code is adapted from `scalaJSPatchIncOptions` in Scala.js, which needs + * to do the exact same thing but for classfiles. + * + * This complicated logic patches the ClassfileManager factory of the given + * IncOptions with one that is aware of .tasty files emitted by the Dotty + * compiler. This makes sure that, when a .class file must be deleted, the + * corresponding .tasty file is also deleted. + */ + def dottyPatchIncOptions(incOptions: IncOptions): IncOptions = { + val inheritedNewClassfileManager = incOptions.newClassfileManager + val newClassfileManager = () => new ClassfileManager { + private[this] val inherited = inheritedNewClassfileManager() + + def delete(classes: Iterable[File]): Unit = { + inherited.delete(classes flatMap { classFile => + val dottyFiles = if (classFile.getPath endsWith ".class") { + val f = new File(classFile.getAbsolutePath.stripSuffix(".class") + ".tasty") + if (f.exists) List(f) + else Nil + } else Nil + classFile :: dottyFiles + }) + } + + def generated(classes: Iterable[File]): Unit = inherited.generated(classes) + def complete(success: Boolean): Unit = inherited.complete(success) + } + incOptions.withNewClassfileManager(newClassfileManager) + } override def projectSettings: Seq[Setting[_]] = { Seq( @@ -99,6 +131,13 @@ object DottyPlugin extends AutoPlugin { scalaOrganization.value }, + incOptions in Compile := { + if (isDotty.value) + dottyPatchIncOptions((incOptions in Compile).value) + else + (incOptions in Compile).value + }, + scalaBinaryVersion := { if (isDotty.value) scalaVersion.value.split("\\.").take(2).mkString(".") // Not needed with sbt >= 0.13.16 From 1310d71498f132e4e2a5899185bf3da3e2cc551e Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 26 May 2017 23:18:33 +0200 Subject: [PATCH 4/4] sbt-dotty: Bump version to 0.1.0 --- project/Build.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Build.scala b/project/Build.scala index 7f0c059b9b84..9893aabd93bf 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -923,7 +923,7 @@ object DottyInjectedPlugin extends AutoPlugin { sbtPlugin := true, - version := "0.1.0-RC5", + version := "0.1.0", ScriptedPlugin.scriptedSettings, ScriptedPlugin.sbtTestDirectory := baseDirectory.value / "sbt-test", ScriptedPlugin.scriptedBufferLog := false,