Skip to content

Commit 13443fa

Browse files
authored
Merge pull request #2361 from dotty-staging/add/sbt-dotty
Merge the sbt dotty plugin in this repo
2 parents df22149 + 11235ef commit 13443fa

File tree

12 files changed

+137
-32
lines changed

12 files changed

+137
-32
lines changed

.drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ matrix:
4040
CI_PUBLISH: true
4141
- CI_TEST: legacyTests
4242
CI_PUBLISH: false
43-
- CI_TEST: test
43+
- CI_TEST: ;test;sbt-dotty/scripted
4444
CI_PUBLISH: false
4545
- CI_TEST: ;dotty-sbt-bridge/publishLocal ;dotty-bootstrapped/test
4646
CI_PUBLISH: false

.drone.yml.sig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
eyJhbGciOiJIUzI1NiJ9.IyBBZnRlciB1cGRhdGluZyB0aGlzIGZpbGUsIHlvdSBuZWVkIHRvIHJlLXNpZ24gaXQ6CiMKIyAtIEluc3RhbGwgW2Ryb25lLWNsaV0oaHR0cDovL3JlYWRtZS5kcm9uZS5pby91c2FnZS9nZXR0aW5nLXN0YXJ0ZWQtY2xpLykKIyAtIENvcHkgeW91ciB0b2tlbiBmcm9tICBodHRwOi8vZG90dHktY2kuZXBmbC5jaC9hY2NvdW50IChDbGljayBTSE9XIFRPS0VOKQojIC0gKGV4cG9ydCBEUk9ORV9UT0tFTj15b3VyLXRva2VuOyBleHBvcnQgRFJPTkVfU0VSVkVSPWh0dHA6Ly9kb3R0eS1jaS5lcGZsLmNoOyBkcm9uZSBzaWduIGxhbXBlcGZsL2RvdHR5KQojCiMgUGxlYXNlIG5vdGUgdGhhdCB0aGUgc2lnbmluZyBjYW4gb25seSBiZSBkb25lIGJ5IGNvbGxhYm9yYXRvcnMuCgpwaXBlbGluZToKICB0ZXN0OgogICAgaW1hZ2U6IGxhbXBlcGZsL2RvdHR5OjI0LTA0LTIwMTcKICAgIHB1bGw6IHRydWUKICAgIGNvb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aXplPTEwMjRtIC1EZG90dHkuZHJvbmUubWVtPTQwOTZtICIke0NJX1RFU1R9IgogICAgd2hlbjoKICAgICAgYnJhbmNoOgogICAgICAgIGV4Y2x1ZGU6IGdoLXBhZ2VzCgogIGRvY3VtZW50YXRpb246CiAgICBpbWFnZTogbGFtcGVwZmwvZG90dHk6MjQtMDQtMjAxNwogICAgcHVsbDogdHJ1ZQogICAgY29tbWFuZHM6CiAgICAgIC0gLi9wcm9qZWN0L3NjcmlwdHMvZ2VuRG9jcyAiJHtDSV9QVUJMSVNIfSIgJEJPVF9QQVNTCiAgICB3aGVuOgogICAgICBicmFuY2g6IG1hc3RlcgoKICBzbGFjazoKICAgIGltYWdlOiBwbHVnaW5zL3NsYWNrCiAgICBjaGFubmVsOiBkb3R0eQogICAgd2hlbjoKICAgICAgYnJhbmNoOiBtYXN0ZXIKICAgICAgc3RhdHVzOiBjaGFuZ2VkCgptYXRyaXg6CiAgaW5jbHVkZToKICAgIC0gQ0lfVEVTVDogZG90dHktYmluLXRlc3RzL3Rlc3QKICAgICAgQ0lfUFVCTElTSDogdHJ1ZQogICAgLSBDSV9URVNUOiBsZWdhY3lUZXN0cwogICAgICBDSV9QVUJMSVNIOiBmYWxzZQogICAgLSBDSV9URVNUOiA7dGVzdDtzYnQtZG90dHkvc2NyaXB0ZWQKICAgICAgQ0lfUFVCTElTSDogZmFsc2UKICAgIC0gQ0lfVEVTVDogO2RvdHR5LXNidC1icmlkZ2UvcHVibGlzaExvY2FsIDtkb3R0eS1ib290c3RyYXBwZWQvdGVzdAogICAgICBDSV9QVUJMSVNIOiBmYWxzZQo.g6eg6JBtlJFjOb9oCS6kzRJ3E1Df5gV8LVksXBmFDq8

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ val `scala-compiler` = Build.`scala-compiler`
1919
val `scala-reflect` = Build.`scala-reflect`
2020
val scalap = Build.scalap
2121

22+
val `sbt-dotty` = Build.`sbt-dotty`
23+
2224
inThisBuild(Build.thisBuildSettings)

docs/_includes/getting-started.html

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,7 @@
22
<div class="centered" style="padding-top: 32px">
33
<h1 id="getting-started">Getting Started</h1>
44
<p>
5-
Using Dotty to compile your project is now pretty simple. Create the
6-
following structure:
7-
</p>
8-
<pre class="sourceCode bordered">
9-
<code>.
10-
├── build.sbt
11-
├── project
12-
│ ├── build.properties
13-
│ └── plugins.sbt
14-
└── src</code></pre>
15-
<h2 id="build.sbt">build.sbt</h2>
16-
<pre class="sourceCode bordered"><code>name := "application"
17-
version := "0.1"
18-
enablePlugins(DottyPlugin)</code></pre>
19-
<h2 id="build.properties">build.properties</h2>
20-
<pre class="sourceCode bordered"><code>sbt.version=0.13.11</code></pre>
21-
<h2 id="plugins.sbt">plugins.sbt</h2>
22-
<pre class="sourceCode bordered"><code>addSbtPlugin("com.felixmulder" % "sbt-dotty" % "0.1.7")</code></pre>
23-
<p>
24-
This plugin is based on the
25-
<a href="https://github.com/smarter/dotty-example-project">
26-
dotty-example-project
27-
</a>, but let’s you skip building dotty from scratch.
5+
See the <a href="https://github.com/lampepfl/dotty-example-project">example project</a>.
286
</p>
297
</div>
308
</div>

docs/docs/usage/sbt-projects.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,4 @@ layout: doc-page
33
title: "Using Dotty with sbt"
44
---
55

6-
It is now possible to use Dotty with sbt thanks to the dotty-bridge project.
7-
There are two alternatives in how to create an sbt project that uses dotty:
8-
9-
* [dotty-example-project](https://github.com/smarter/dotty-example-project)
10-
for a simple sbt project that compiles code with Dotty
11-
* [sbt-dotty](https://github.com/felixmulder/sbt-dotty) an sbt plugin that
12-
takes care of all dependencies and settings needed to get a Dotty sbt project
6+
See the [example project](https://github.com/lampepfl/dotty-example-project).

project/Build.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,20 @@ object DottyInjectedPlugin extends AutoPlugin {
844844
libraryDependencies := Seq("org.scala-lang" % "scalap" % scalacVersion)
845845
)
846846

847+
848+
// sbt plugin to use Dotty in your own build, see
849+
// https://github.com/lampepfl/dotty-example-project for usage.
850+
lazy val `sbt-dotty` = project.in(file("sbt-dotty")).
851+
settings(commonSettings).
852+
settings(
853+
sbtPlugin := true,
854+
version := "0.1.0-RC4",
855+
ScriptedPlugin.scriptedSettings,
856+
ScriptedPlugin.sbtTestDirectory := baseDirectory.value / "sbt-test",
857+
ScriptedPlugin.scriptedBufferLog := false,
858+
ScriptedPlugin.scriptedLaunchOpts += "-Dplugin.version=" + version.value
859+
)
860+
847861
lazy val publishSettings = Seq(
848862
publishMavenStyle := true,
849863
isSnapshot := version.value.contains("SNAPSHOT"),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
scalaVersion := dottyLatestNightlyBuild.get
2+
3+
libraryDependencies += ("org.scala-lang.modules" %% "scala-xml" % "1.0.1").withDottyCompat()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=0.13.15
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package hello
2+
object Hello {
3+
def main(args: Array[String]): Unit = {
4+
val dotty: Int | String = "dotty"
5+
println(s"Hello $dotty!")
6+
}
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> run
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package dotty.tools.sbtplugin
2+
3+
import sbt._
4+
import sbt.Keys._
5+
6+
object DottyPlugin extends AutoPlugin {
7+
object autoImport {
8+
val isDotty = settingKey[Boolean]("Is this project compiled with Dotty?")
9+
10+
// NOTE:
11+
// - this is a def to support `scalaVersion := dottyLatestNightlyBuild`
12+
// - if this was a taskKey, then you couldn't do `scalaVersion := dottyLatestNightlyBuild`
13+
// - if this was a settingKey, then this would evaluate even if you don't use it.
14+
def dottyLatestNightlyBuild: Option[String] = {
15+
println("Fetching latest Dotty nightly version (requires an internet connection)...")
16+
val Version = """ <version>(0.1\..*-bin.*)</version>""".r
17+
val latest = scala.io.Source
18+
.fromURL(
19+
"http://repo1.maven.org/maven2/ch/epfl/lamp/dotty_0.1/maven-metadata.xml")
20+
.getLines()
21+
.collect { case Version(version) => version }
22+
.toSeq
23+
.lastOption
24+
println(s"Latest Dotty nightly build version: $latest")
25+
latest
26+
}
27+
28+
implicit class DottyCompatModuleID(moduleID: ModuleID) {
29+
/** If this ModuleID cross-version is a Dotty version, replace it
30+
* by the Scala 2.x version that the Dotty version is retro-compatible with.
31+
*
32+
* This setting is useful when your build contains dependencies that have only
33+
* been published with Scala 2.x, if you have:
34+
* {{{
35+
* libraryDependencies += "a" %% "b" % "c"
36+
* }}}
37+
* you can replace it by:
38+
* {{{
39+
* libraryDependencies += ("a" %% "b" % "c").withDottyCompat()
40+
* }}}
41+
* This will have no effect when compiling with Scala 2.x, but when compiling
42+
* with Dotty this will change the cross-version to a Scala 2.x one. This
43+
* works because Dotty is currently retro-compatible with Scala 2.x.
44+
*
45+
* NOTE: Dotty's retro-compatibility with Scala 2.x will be dropped before
46+
* Dotty is released, you should not rely on it.
47+
*/
48+
def withDottyCompat(): ModuleID =
49+
moduleID.cross(CrossVersion.binaryMapped {
50+
case version if version.startsWith("0.") => "2.11"
51+
case version => version
52+
})
53+
}
54+
}
55+
56+
import autoImport._
57+
58+
override def requires: Plugins = plugins.JvmPlugin
59+
override def trigger = allRequirements
60+
61+
// Adapted from CrossVersionUtil#sbtApiVersion
62+
private def sbtFullVersion(v: String): Option[(Int, Int, Int)] =
63+
{
64+
val ReleaseV = """(\d+)\.(\d+)\.(\d+)(-\d+)?""".r
65+
val CandidateV = """(\d+)\.(\d+)\.(\d+)(-RC\d+)""".r
66+
val NonReleaseV = """(\d+)\.(\d+)\.(\d+)([-\w+]*)""".r
67+
v match {
68+
case ReleaseV(x, y, z, ht) => Some((x.toInt, y.toInt, z.toInt))
69+
case CandidateV(x, y, z, ht) => Some((x.toInt, y.toInt, z.toInt))
70+
case NonReleaseV(x, y, z, ht) if z.toInt > 0 => Some((x.toInt, y.toInt, z.toInt))
71+
case _ => None
72+
}
73+
}
74+
75+
76+
override def projectSettings: Seq[Setting[_]] = {
77+
Seq(
78+
isDotty := {
79+
val log = sLog.value
80+
81+
sbtFullVersion(sbtVersion.value) match {
82+
case Some((sbtMajor, sbtMinor, sbtPatch)) if sbtMajor == 0 && sbtMinor == 13 && sbtPatch < 15 =>
83+
log.error(s"The sbt-dotty plugin cannot work with this version of sbt (${sbtVersion.value}), sbt >= 0.13.15 is required.")
84+
false
85+
case _ =>
86+
scalaVersion.value.startsWith("0.")
87+
}
88+
},
89+
scalaOrganization := {
90+
if (isDotty.value)
91+
"ch.epfl.lamp"
92+
else
93+
scalaOrganization.value
94+
},
95+
96+
scalaBinaryVersion := {
97+
if (isDotty.value)
98+
"0.1" // TODO: Fix sbt so that this isn't needed
99+
else
100+
scalaBinaryVersion.value
101+
}
102+
)
103+
}
104+
}

0 commit comments

Comments
 (0)