-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Merge the sbt dotty plugin in this repo #2361
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
eyJhbGciOiJIUzI1NiJ9.IyBBZnRlciB1cGRhdGluZyB0aGlzIGZpbGUsIHlvdSBuZWVkIHRvIHJlLXNpZ24gaXQ6CiMKIyAtIEluc3RhbGwgW2Ryb25lLWNsaV0oaHR0cDovL3JlYWRtZS5kcm9uZS5pby91c2FnZS9nZXR0aW5nLXN0YXJ0ZWQtY2xpLykKIyAtIENvcHkgeW91ciB0b2tlbiBmcm9tICBodHRwOi8vZG90dHktY2kuZXBmbC5jaC9hY2NvdW50IChDbGljayBTSE9XIFRPS0VOKQojIC0gKGV4cG9ydCBEUk9ORV9UT0tFTj15b3VyLXRva2VuOyBleHBvcnQgRFJPTkVfU0VSVkVSPWh0dHA6Ly9kb3R0eS1jaS5lcGZsLmNoOyBkcm9uZSBzaWduIGxhbXBlcGZsL2RvdHR5KQojCiMgUGxlYXNlIG5vdGUgdGhhdCB0aGUgc2lnbmluZyBjYW4gb25seSBiZSBkb25lIGJ5IGNvbGxhYm9yYXRvcnMuCgpwaXBlbGluZToKICB0ZXN0OgogICAgaW1hZ2U6IGxhbXBlcGZsL2RvdHR5OjI0LTA0LTIwMTcKICAgIHB1bGw6IHRydWUKICAgIGNvbW1hbmRzOgogICAgICAtIGxuIC1zIC92YXIvY2FjaGUvZHJvbmUvc2NhbGEtc2NhbGEgc2NhbGEtc2NhbGEKICAgICAgLSBsbiAtcyAvdmFyL2NhY2hlL2Ryb25lL2l2eTIgIiRIT01FLy5pdnkyIgogICAgICAtIC4vcHJvamVjdC9zY3JpcH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k6MjQtMDQtMjAxNwogICAgcHVsbDogdHJ1ZQogICAgY29tbWFuZHM6CiAgICAgIC0gLi9wcm9qZWN0L3NjcmlwdHMvZ2VuRG9jcyAiJHtDSV9QVUJMSVNIfSIgJEJPVF9QQVNTCiAgICB3aGVuOgogICAgICBicmFuY2g6IG1hc3RlcgoKICBzbGFjazoKICAgIGltYWdlOiBwbHVnaW5zL3NsYWNrCiAgICBjaGFubmVsOiBkb3R0eQogICAgd2hlbjoKICAgICAgYnJhbmNoOiBtYXN0ZXIKICAgICAgc3RhdHVzOiBjaGFuZ2VkCgptYXRyaXg6CiAgaW5jbHVkZToKICAgIC0gQ0lfVEVTVDogZG90dHktYmluLXRlc3RzL3Rlc3QKICAgICAgQ0lfUFVCTElTSDogdHJ1ZQogICAgLSBDSV9URVNUOiBsZWdhY3lUZXN0cwogICAgICBDSV9QVUJMSVNIOiBmYWxzZQogICAgLSBDSV9URVNUOiA7dGVzdDtzYnQtZG90dHkvc2NyaXB0ZWQKICAgICAgQ0lfUFVCTElTSDogZmFsc2UKICAgIC0gQ0lfVEVTVDogO2RvdHR5LXNidC1icmlkZ2UvcHVibGlzaExvY2FsIDtkb3R0eS1ib290c3RyYXBwZWQvdGVzdAogICAgICBDSV9QVUJMSVNIOiBmYWxzZQo.g6eg6JBtlJFjOb9oCS6kzRJ3E1Df5gV8LVksXBmFDq8 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,4 @@ layout: doc-page | |
title: "Using Dotty with sbt" | ||
--- | ||
|
||
It is now possible to use Dotty with sbt thanks to the dotty-bridge project. | ||
There are two alternatives in how to create an sbt project that uses dotty: | ||
|
||
* [dotty-example-project](https://github.com/smarter/dotty-example-project) | ||
for a simple sbt project that compiles code with Dotty | ||
* [sbt-dotty](https://github.com/felixmulder/sbt-dotty) an sbt plugin that | ||
takes care of all dependencies and settings needed to get a Dotty sbt project | ||
See the [example project](https://github.com/lampepfl/dotty-example-project). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could just put the config info from the front-page into an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll let you do that in a follow-up PR ;) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
scalaVersion := dottyLatestNightlyBuild.get | ||
|
||
libraryDependencies += ("org.scala-lang.modules" %% "scala-xml" % "1.0.1").withDottyCompat() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=0.13.15 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version")) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package hello | ||
object Hello { | ||
def main(args: Array[String]): Unit = { | ||
val dotty: Int | String = "dotty" | ||
println(s"Hello $dotty!") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
> run |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package dotty.tools.sbtplugin | ||
|
||
import sbt._ | ||
import sbt.Keys._ | ||
|
||
object DottyPlugin extends AutoPlugin { | ||
object autoImport { | ||
val isDotty = settingKey[Boolean]("Is this project compiled with Dotty?") | ||
|
||
// NOTE: | ||
// - this is a def to support `scalaVersion := dottyLatestNightlyBuild` | ||
// - if this was a taskKey, then you couldn't do `scalaVersion := dottyLatestNightlyBuild` | ||
// - if this was a settingKey, then this would evaluate even if you don't use it. | ||
def dottyLatestNightlyBuild: Option[String] = { | ||
println("Fetching latest Dotty nightly version (requires an internet connection)...") | ||
val Version = """ <version>(0.1\..*-bin.*)</version>""".r | ||
val latest = scala.io.Source | ||
.fromURL( | ||
"http://repo1.maven.org/maven2/ch/epfl/lamp/dotty_0.1/maven-metadata.xml") | ||
.getLines() | ||
.collect { case Version(version) => version } | ||
.toSeq | ||
.lastOption | ||
println(s"Latest Dotty nightly build version: $latest") | ||
latest | ||
} | ||
|
||
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. | ||
* | ||
* This setting is useful when your build contains dependencies that have only | ||
* been published with Scala 2.x, if you have: | ||
* {{{ | ||
* libraryDependencies += "a" %% "b" % "c" | ||
* }}} | ||
* you can replace it by: | ||
* {{{ | ||
* libraryDependencies += ("a" %% "b" % "c").withDottyCompat() | ||
* }}} | ||
* This will have no effect when compiling with Scala 2.x, but when compiling | ||
* with Dotty this will change the cross-version to a Scala 2.x one. This | ||
* works because Dotty is currently retro-compatible with Scala 2.x. | ||
* | ||
* NOTE: Dotty's retro-compatibility with Scala 2.x will be dropped before | ||
* 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 | ||
}) | ||
} | ||
} | ||
|
||
import autoImport._ | ||
|
||
override def requires: Plugins = plugins.JvmPlugin | ||
override def trigger = allRequirements | ||
|
||
// Adapted from CrossVersionUtil#sbtApiVersion | ||
private def sbtFullVersion(v: String): Option[(Int, Int, Int)] = | ||
{ | ||
val ReleaseV = """(\d+)\.(\d+)\.(\d+)(-\d+)?""".r | ||
val CandidateV = """(\d+)\.(\d+)\.(\d+)(-RC\d+)""".r | ||
val NonReleaseV = """(\d+)\.(\d+)\.(\d+)([-\w+]*)""".r | ||
v match { | ||
case ReleaseV(x, y, z, ht) => Some((x.toInt, y.toInt, z.toInt)) | ||
case CandidateV(x, y, z, ht) => Some((x.toInt, y.toInt, z.toInt)) | ||
case NonReleaseV(x, y, z, ht) if z.toInt > 0 => Some((x.toInt, y.toInt, z.toInt)) | ||
case _ => None | ||
} | ||
} | ||
|
||
|
||
override def projectSettings: Seq[Setting[_]] = { | ||
Seq( | ||
isDotty := { | ||
val log = sLog.value | ||
|
||
sbtFullVersion(sbtVersion.value) match { | ||
case Some((sbtMajor, sbtMinor, sbtPatch)) if sbtMajor == 0 && sbtMinor == 13 && sbtPatch < 15 => | ||
log.error(s"The sbt-dotty plugin cannot work with this version of sbt (${sbtVersion.value}), sbt >= 0.13.15 is required.") | ||
false | ||
case _ => | ||
scalaVersion.value.startsWith("0.") | ||
} | ||
}, | ||
scalaOrganization := { | ||
if (isDotty.value) | ||
"ch.epfl.lamp" | ||
else | ||
scalaOrganization.value | ||
}, | ||
|
||
scalaBinaryVersion := { | ||
if (isDotty.value) | ||
"0.1" // TODO: Fix sbt so that this isn't needed | ||
else | ||
scalaBinaryVersion.value | ||
} | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like removing this, but I'm sure your reason is that we'd need to keep it in sync with the example project. I feel that it will take everyone who's interested in trying Dotty through multiple hoops. I'd like it to just be "google dotty, find webpage, minimal sbt config, run dotty". Instead of "google dotty, find webpage, find link to example project, read most of README to know which options to use, set up sbt config, run dotty".
Maybe we should restructure the intro page and put this information at the top after the logo and show a condensed version of the dotty example project README which we also refer to for more information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make an
sbt new
template and add the command to create it on the homepage: http://www.scala-sbt.org/0.13/docs/sbt-new-and-Templates.htmlThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't want to duplicate information, we're already doing a bad job at keeping one copy of our documentation up to date, and we completely fail for information in multiple places (the homepage talked about a very old version of the sbt-dotty plugin).