Skip to content

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

Merged
merged 1 commit into from
May 4, 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 .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ matrix:
CI_PUBLISH: true
- CI_TEST: legacyTests
CI_PUBLISH: false
- CI_TEST: test
- CI_TEST: ;test;sbt-dotty/scripted
CI_PUBLISH: false
- CI_TEST: ;dotty-sbt-bridge/publishLocal ;dotty-bootstrapped/test
CI_PUBLISH: false
2 changes: 1 addition & 1 deletion .drone.yml.sig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eyJhbGciOiJIUzI1NiJ9.IyBBZnRlciB1cGRhdGluZyB0aGlzIGZpbGUsIHlvdSBuZWVkIHRvIHJlLXNpZ24gaXQ6CiMKIyAtIEluc3RhbGwgW2Ryb25lLWNsaV0oaHR0cDovL3JlYWRtZS5kcm9uZS5pby91c2FnZS9nZXR0aW5nLXN0YXJ0ZWQtY2xpLykKIyAtIENvcHkgeW91ciB0b2tlbiBmcm9tICBodHRwOi8vZG90dHktY2kuZXBmbC5jaC9hY2NvdW50IChDbGljayBTSE9XIFRPS0VOKQojIC0gKGV4cG9ydCBEUk9ORV9UT0tFTj15b3VyLXRva2VuOyBleHBvcnQgRFJPTkVfU0VSVkVSPWh0dHA6Ly9kb3R0eS1jaS5lcGZsLmNoOyBkcm9uZSBzaWduIGxhbXBlcGZsL2RvdHR5KQojCiMgUGxlYXNlIG5vdGUgdGhhdCB0aGUgc2lnbmluZyBjYW4gb25seSBiZSBkb25lIGJ5IGNvbGxhYm9yYXRvcnMuCgpwa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ICAtIHNidCAtSi1YbXg0MDk2bSAtSi1YWDpSZXNlcnZlZENvZGVDYWNoZVNpemU9NTEybSAtSi1YWDpNYXhNZXRhc3BhY2VTaXplPTEwMjRtIC1EZG90dHkuZHJvbmUubWVtPTQwOTZtICIke0NJX1RFU1R9IgogICAgd2hlbjoKICAgICAgYnJhbmNoOgogICAgICAgIGV4Y2x1ZGU6IGdoLXBhZ2VzCgogIGRvY3VtZW50YXRpb246CiAgICBpbWFnZTogbGFtcGVwZmwvZG90dHk6MjQtMDQtMjAxNwogICAgcHVsbDogdHJ1ZQogICAgY29tbWFuZHM6CiAgICAgIC0gLi9wcm9qZWN0L3NjcmlwdHMvZ2VuRG9jcyAiJHtDSV9QVUJMSVNIfSIgJEJPVF9QQVNTCiAgICB3aGVuOgogICAgICBicmFuY2g6IG1hc3RlcgoKICBzbGFjazoKICAgIGltYWdlOiBwbHVnaW5zL3NsYWNrCiAgICBjaGFubmVsOiBkb3R0eQogICAgd2hlbjoKICAgICAgYnJhbmNoOiBtYXN0ZXIKICAgICAgc3RhdHVzOiBjaGFuZ2VkCgptYXRyaXg6CiAgaW5jbHVkZToKICAgIC0gQ0lfVEVTVDogZG90dHktYmluLXRlc3RzL3Rlc3QKICAgICAgQ0lfUFVCTElTSDogdHJ1ZQogICAgLSBDSV9URVNUOiBsZWdhY3lUZXN0cwogICAgICBDSV9QVUJMSVNIOiBmYWxzZQogICAgLSBDSV9URVNUOiA7dGVzdDtzYnQtZG90dHkvc2NyaXB0ZWQKICAgICAgQ0lfUFVCTElTSDogZmFsc2UKICAgIC0gQ0lfVEVTVDogO2RvdHR5LXNidC1icmlkZ2UvcHVibGlzaExvY2FsIDtkb3R0eS1ib290c3RyYXBwZWQvdGVzdAogICAgICBDSV9QVUJMSVNIOiBmYWxzZQo.g6eg6JBtlJFjOb9oCS6kzRJ3E1Df5gV8LVksXBmFDq8
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ val `scala-compiler` = Build.`scala-compiler`
val `scala-reflect` = Build.`scala-reflect`
val scalap = Build.scalap

val `sbt-dotty` = Build.`sbt-dotty`

inThisBuild(Build.thisBuildSettings)
24 changes: 1 addition & 23 deletions docs/_includes/getting-started.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,7 @@
<div class="centered" style="padding-top: 32px">
<h1 id="getting-started">Getting Started</h1>
<p>
Using Dotty to compile your project is now pretty simple. Create the
following structure:
</p>
<pre class="sourceCode bordered">
<code>.
├── build.sbt
├── project
│ ├── build.properties
│ └── plugins.sbt
└── src</code></pre>
<h2 id="build.sbt">build.sbt</h2>
<pre class="sourceCode bordered"><code>name := "application"
version := "0.1"
enablePlugins(DottyPlugin)</code></pre>
<h2 id="build.properties">build.properties</h2>
<pre class="sourceCode bordered"><code>sbt.version=0.13.11</code></pre>
<h2 id="plugins.sbt">plugins.sbt</h2>
<pre class="sourceCode bordered"><code>addSbtPlugin("com.felixmulder" % "sbt-dotty" % "0.1.7")</code></pre>
<p>
This plugin is based on the
<a href="https://github.com/smarter/dotty-example-project">
dotty-example-project
</a>, but let’s you skip building dotty from scratch.
See the <a href="https://github.com/lampepfl/dotty-example-project">example project</a>.
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

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.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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).

</p>
</div>
</div>
Expand Down
8 changes: 1 addition & 7 deletions docs/docs/usage/sbt-projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Copy link
Contributor

Choose a reason for hiding this comment

The 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 _include and as such we don't need to duplicate any info here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let you do that in a follow-up PR ;)

14 changes: 14 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,20 @@ object DottyInjectedPlugin extends AutoPlugin {
libraryDependencies := Seq("org.scala-lang" % "scalap" % scalacVersion)
)


// sbt plugin to use Dotty in your own build, see
// https://github.com/lampepfl/dotty-example-project for usage.
lazy val `sbt-dotty` = project.in(file("sbt-dotty")).
settings(commonSettings).
settings(
sbtPlugin := true,
version := "0.1.0-RC4",
ScriptedPlugin.scriptedSettings,
ScriptedPlugin.sbtTestDirectory := baseDirectory.value / "sbt-test",
ScriptedPlugin.scriptedBufferLog := false,
ScriptedPlugin.scriptedLaunchOpts += "-Dplugin.version=" + version.value
)

lazy val publishSettings = Seq(
publishMavenStyle := true,
isSnapshot := version.value.contains("SNAPSHOT"),
Expand Down
3 changes: 3 additions & 0 deletions sbt-dotty/sbt-test/sbt-dotty/example-project/build.sbt
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!")
}
}
1 change: 1 addition & 0 deletions sbt-dotty/sbt-test/sbt-dotty/example-project/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> run
104 changes: 104 additions & 0 deletions sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala
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
}
)
}
}