Skip to content

sbt-dotty: various fixes, bump to 0.1.0 #2549

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 4 commits into from
May 26, 2017
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: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
57 changes: 51 additions & 6 deletions sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dotty.tools.sbtplugin

import sbt._
import sbt.Keys._
import sbt.inc.{ ClassfileManager, IncOptions }

object DottyPlugin extends AutoPlugin {
object autoImport {
Expand All @@ -27,7 +28,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:
Expand All @@ -46,10 +48,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
}
}
}

Expand All @@ -72,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(
Expand All @@ -93,9 +131,16 @@ 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)
"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
}
Expand Down