-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Migrate Scala3doc repo to Dotty #10092
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
c3bbbe2
c3596ae
cfcfb95
8960935
ddf6067
f70e439
ffaaca1
fe7ae5c
7b24b9e
3215fd8
d28da30
31956e2
be16cc0
2a26e75
27a1038
71dfa0a
207429a
2ad01dc
8a3da50
d00f187
1dd067b
ab89f60
78c7b95
a251a9e
62aa5fa
b580713
abc5318
aa53cdd
d63fac3
0a5f5de
0cda682
c1146d6
8e20de0
c1ba2a4
e12c359
44ff308
be4f36b
083d1cb
f359a7a
eda1a43
2e0e4ba
9b932da
bed26f8
1aafa3d
b32c70b
1db554c
a642f84
afde24e
434e44b
6f95531
57806f2
f9973de
b6a8437
2a30cef
3a25cd6
7c38c25
97d0e1d
850852d
7eae771
47b370c
02d4134
94fdc59
4da54da
fd077ae
757e893
aa45416
0411d35
d64138f
5593428
a9a5750
5c89624
a222530
404ee7b
28077d4
6eb75ee
bfd7667
3676f0f
d3eb068
6d2e7e4
b56a0d7
86aecfe
4d71b52
c5ddef4
39373e6
0926be3
e154e13
7a0a4ae
f0e1f15
de8fd27
9a76722
6e05c68
5128929
c343dac
3bf9551
e380394
1d48b49
f1657dc
8d3b92e
089e974
0bd5240
15cf282
0043d6e
b9db874
d682623
35d3990
1ec9cb0
bf7002c
802cfb7
bd1c319
dd38fbc
9d97241
da883ff
363acdd
6687e0c
e75c91f
5f65ab2
b0ae733
e10020c
1e8e031
a3aef18
e904857
d736bc6
afeeff1
54a77e3
94a3510
25425b3
0d0f950
800bc66
fbcce6f
7ad4500
e7bbdb5
a4b9c58
884a1ba
dea4fe6
3a63e62
04d8ce2
428c17f
59c5f8d
e31d0af
a9650e5
81f39f6
82b6dc8
5c15b25
f06988e
d58478a
ba9f4a7
76f496a
2047533
91bc522
d41bec5
f9fd37c
b1b9941
200b5a1
3415d1e
c416882
63c30b6
55daf7a
b76f414
3839f6e
7ecdb68
38a33c0
707eef9
c46d7d7
a6c5094
87f34f3
75f94da
41fba61
85fd4a9
76b3ea0
dcf0ded
b0a80a8
1f63365
ddbab8b
1ce3198
58d193f
69bced4
ac9dfca
ec466c1
8d66d31
3851fb4
c81ede9
9f167ac
b17439a
901965a
62f9120
6dc0f21
7b8288c
9646d0b
bb031e5
7ef69dd
f0f0d52
84b0022
8b12402
56c698b
0eeedc6
b727366
5724289
c832f1d
16364a4
263b82c
25639a3
47b367f
8fc6dc6
d5c9543
3cc19f8
48f81c8
d371373
03ae7a1
cdb3856
a2c6775
1a15594
453ad30
dee0efd
950de42
b047e11
45e4fbc
aa977b1
af893e9
e9b5f95
7a05a7c
49067e6
37b47b6
f0efc46
3a458e1
762f644
c883fe3
47b91b1
24e89e2
50fd2bc
c23ef2d
2bc7355
84bef51
c7b70e1
d605a4f
b5361fa
f510be1
fa0d794
608b6e3
f0a8719
4aa49bd
11d190b
b195184
e84ad19
08016f6
db014b2
4571518
f94494e
0b4cbeb
2974e92
a1d4814
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: CI for Scala3doc | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
container: lampepfl/dotty:2020-04-24 | ||
|
||
steps: | ||
- name: Git Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache Coursier | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.cache/coursier | ||
key: sbt-coursier-cache | ||
- name: Cache SBT | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.sbt | ||
key: sbt-${{ hashFiles('**/build.sbt') }} | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
|
||
- name: Compile and test | ||
run: ./project/scripts/sbt scala3doc/test | ||
|
||
- name: Locally publish self | ||
run: ./project/scripts/sbt scala3doc/publishLocal | ||
|
||
- name: Generate test documentation | ||
run: ./project/scripts/sbt scala3doc/generateSelfDocumentation | ||
|
||
- name: Generate Scala 3 documentation | ||
run: ./project/scripts/sbt scala3doc/generateScala3Documentation | ||
|
||
- name: Generate documentation for example project using dotty-sbt | ||
run: ./project/scripts/sbt "sbt-dotty/scripted sbt-dotty/scala3doc" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,6 +213,12 @@ object Build { | |
} | ||
) | ||
|
||
lazy val disableDocSetting = | ||
// Disable scaladoc generation, it's way too slow and we'll replace it | ||
// by dottydoc anyway. We still publish an empty -javadoc.jar to make | ||
// sonatype happy. | ||
sources in (Compile, doc) := Seq() | ||
|
||
lazy val commonSettings = publishSettings ++ Seq( | ||
scalaSource in Compile := baseDirectory.value / "src", | ||
scalaSource in Test := baseDirectory.value / "test", | ||
|
@@ -221,11 +227,6 @@ object Build { | |
resourceDirectory in Compile := baseDirectory.value / "resources", | ||
resourceDirectory in Test := baseDirectory.value / "test-resources", | ||
|
||
// Disable scaladoc generation, it's way too slow and we'll replace it | ||
// by dottydoc anyway. We still publish an empty -javadoc.jar to make | ||
// sonatype happy. | ||
sources in (Compile, doc) := Seq(), | ||
|
||
// Prevent sbt from rewriting our dependencies | ||
scalaModuleInfo ~= (_.map(_.withOverrideScalaVersion(false))), | ||
|
||
|
@@ -244,7 +245,8 @@ object Build { | |
crossPaths := false, | ||
// Do not depend on the Scala library | ||
autoScalaLibrary := false, | ||
excludeFromIDE := true | ||
excludeFromIDE := true, | ||
disableDocSetting | ||
) | ||
|
||
// Settings used when compiling dotty (both non-bootstrapped and bootstrapped) | ||
|
@@ -258,6 +260,8 @@ object Build { | |
moduleName ~= { _.stripSuffix("-scala2") }, | ||
version := dottyVersion, | ||
target := baseDirectory.value / ".." / "out" / "scala-2" / name.value, | ||
|
||
disableDocSetting | ||
) | ||
|
||
// Settings used when compiling dotty with the reference compiler | ||
|
@@ -267,6 +271,8 @@ object Build { | |
version := dottyNonBootstrappedVersion, | ||
scalaVersion := referenceVersion, | ||
excludeFromIDE := true, | ||
|
||
disableDocSetting | ||
) | ||
|
||
// Settings used when compiling dotty with a non-bootstrapped dotty | ||
|
@@ -328,6 +334,8 @@ object Build { | |
}, | ||
// sbt-dotty defines `scalaInstance in doc` so we need to override it manually | ||
scalaInstance in doc := scalaInstance.value, | ||
|
||
disableDocSetting, | ||
) | ||
|
||
lazy val commonBenchmarkSettings = Seq( | ||
|
@@ -1153,6 +1161,14 @@ object Build { | |
lazy val `scala3-bench-bootstrapped` = project.in(file("bench")).asDottyBench(Bootstrapped) | ||
lazy val `scala3-bench-run` = project.in(file("bench-run")).asDottyBench(Bootstrapped) | ||
|
||
val testcasesOutputDir = taskKey[String]("Root directory where tests classses are generated") | ||
val testcasesSourceRoot = taskKey[String]("Root directory where tests sources are generated") | ||
val generateSelfDocumentation = taskKey[Unit]("Generate example documentation") | ||
val generateScala3Documentation = taskKey[Unit]("Generate documentation for dotty lib") | ||
val generateTestcasesDocumentation = taskKey[Unit]("Generate documentation for testcases, usefull for debugging tests") | ||
lazy val `scala3doc` = project.in(file("scala3doc")).asScala3doc | ||
lazy val `scala3doc-testcases` = project.in(file("scala3doc-testcases")).asScala3docTestcases | ||
|
||
// sbt plugin to use Dotty in your own build, see | ||
// https://github.com/lampepfl/scala3-example-project for usage. | ||
lazy val `sbt-dotty` = project.in(file("sbt-dotty")). | ||
|
@@ -1192,6 +1208,7 @@ object Build { | |
publishLocal in `scala3-staging`, | ||
publishLocal in `scala3-tasty-inspector`, | ||
publishLocal in `scala3-doc-bootstrapped`, | ||
publishLocal in `scala3doc`, | ||
publishLocal in `scala3-bootstrapped` // Needed because sbt currently hardcodes the dotty artifact | ||
).evaluated | ||
) | ||
|
@@ -1393,7 +1410,7 @@ object Build { | |
def asDottyRoot(implicit mode: Mode): Project = project.withCommonSettings. | ||
aggregate(`scala3-interfaces`, dottyLibrary, dottyCompiler, tastyCore, dottyDoc, `scala3-sbt-bridge`). | ||
bootstrappedAggregate(`scala3-language-server`, `scala3-staging`, `scala3-tasty-inspector`, | ||
`scala3-library-bootstrappedJS`). | ||
`scala3-library-bootstrappedJS`, scala3doc). | ||
dependsOn(tastyCore). | ||
dependsOn(dottyCompiler). | ||
dependsOn(dottyLibrary). | ||
|
@@ -1440,6 +1457,70 @@ object Build { | |
settings(commonBenchmarkSettings). | ||
enablePlugins(JmhPlugin) | ||
|
||
def asScala3doc: Project = { | ||
def generateDocumentation(targets: String, name: String, outDir: String, params: String = "") = Def.taskDyn { | ||
val sourceMapping = "=https://github.com/lampepfl/dotty/tree/master#L" | ||
run.in(Compile).toTask(s""" -d output/$outDir -t $targets -n "$name" -s $sourceMapping $params""") | ||
} | ||
|
||
project.settings(commonBootstrappedSettings). | ||
dependsOn(`scala3-compiler-bootstrapped`). | ||
dependsOn(`scala3-tasty-inspector`). | ||
settings( | ||
// Needed to download dokka and its dependencies | ||
resolvers += Resolver.jcenterRepo, | ||
// Needed to download dokka-site | ||
resolvers += Resolver.bintrayRepo("virtuslab", "dokka"), | ||
libraryDependencies ++= Seq( | ||
"com.virtuslab.dokka" % "dokka-site" % "0.1.9", | ||
"com.vladsch.flexmark" % "flexmark-all" % "0.42.12", | ||
"nl.big-o" % "liqp" % "0.6.7", | ||
"args4j" % "args4j" % "2.33", | ||
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. Is this really needed? We already have a way to process arguments (https://github.com/lampepfl/dotty/blob/d09600de025e6760dc8614a4ce62d568e90d16d5/compiler/src/dotty/tools/dotc/config/CompilerCommand.scala#L36-L37), we shouldn't use multiple different argument parsers, and we shouldn't depend on external projects unless absolutely necessary. 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. Correct me if I'm wrong, but doesn't this mean that any change to our CLI would require changing the compiler's CLI? Because I think that's the case, and because of that I think that we should have a separate arg parser for the doctool. |
||
|
||
"org.jetbrains.dokka" % "dokka-test-api" % "1.4.10.2" % "test", | ||
"com.novocode" % "junit-interface" % "0.11" % "test", | ||
), | ||
Test / test := (Test / test).dependsOn(compile.in(Compile).in(`scala3doc-testcases`)).value, | ||
testcasesOutputDir.in(Test) := classDirectory.in(Compile).in(`scala3doc-testcases`).value.getAbsolutePath.toString, | ||
testcasesSourceRoot.in(Test) := (baseDirectory.in(`scala3doc-testcases`).value / "src").getAbsolutePath.toString, | ||
Compile / mainClass := Some("dotty.dokka.Main"), | ||
// There is a bug in dokka that prevents parallel tests withing the same jvm | ||
fork.in(test) := true, | ||
generateSelfDocumentation := Def.taskDyn { | ||
generateDocumentation(classDirectory.in(Compile).value.getAbsolutePath, "scala3doc", "self", "-p documentation") | ||
}.value, | ||
generateScala3Documentation := Def.taskDyn { | ||
val dottyJars = Seq( | ||
// All projects below will be used to generated documentation for Scala 3 | ||
classDirectory.in(`scala3-interfaces`).in(Compile).value, | ||
classDirectory.in(`tasty-core`).in(Compile).value, | ||
classDirectory.in(`scala3-library`).in(Compile).value, | ||
// TODO this one fails to load using TASTY | ||
// classDirectory.in(`stdlib-bootstrapped`).in(Compile).value, | ||
) | ||
val roots = dottyJars.map(_.toString).mkString(java.io.File.pathSeparator) | ||
|
||
if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") } | ||
else generateDocumentation(roots, "Scala 3", "stdLib", "-p dotty-docs/docs") | ||
}.value, | ||
generateTestcasesDocumentation := Def.taskDyn { | ||
generateDocumentation(Build.testcasesOutputDir.in(Test).value, "Scala3doc testcases", "testcases") | ||
}.value, | ||
buildInfoKeys in Test := Seq[BuildInfoKey]( | ||
Build.testcasesOutputDir.in(Test), | ||
Build.testcasesSourceRoot.in(Test), | ||
), | ||
buildInfoPackage in Test := "dotty.dokka", | ||
BuildInfoPlugin.buildInfoScopedSettings(Test), | ||
BuildInfoPlugin.buildInfoDefaultSettings, | ||
// Uncomment to debug dokka processing (require to run debug in listen mode on 5005 port) | ||
// javaOptions.in(run) += "-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5005,suspend=y" | ||
) | ||
} | ||
|
||
def asScala3docTestcases: Project = | ||
project.dependsOn(`scala3-compiler-bootstrapped`).settings(commonBootstrappedSettings) | ||
|
||
def asDist(implicit mode: Mode): Project = project. | ||
enablePlugins(PackPlugin). | ||
withCommonSettings. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
scalaVersion := sys.props("plugin.scalaVersion") | ||
|
||
useScala3doc := true |
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,25 @@ | ||
package example | ||
|
||
/** | ||
* Automatic Tupling of Function Params: https://dotty.epfl.ch/docs/reference/other-new-features/auto-parameter-tupling.html | ||
*/ | ||
object AutoParamTupling { | ||
|
||
def test: Unit = { | ||
|
||
/** | ||
* In order to get thread safety, you need to put @volatile before lazy vals. | ||
* https://dotty.epfl.ch/docs/reference/changed-features/lazy-vals.html | ||
*/ | ||
@volatile lazy val xs: List[String] = List("d", "o", "t", "t", "y") | ||
|
||
/** | ||
* Current behaviour in Scala 2.12.2 : | ||
* error: missing parameter type | ||
* Note: The expected type requires a one-argument function accepting a 2-Tuple. | ||
* Consider a pattern matching anonymous function, `{ case (s, i) => ... }` | ||
*/ | ||
xs.zipWithIndex.map((s, i) => println(s"$i: $s")) | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package example | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
import scala.util.Try | ||
|
||
/** | ||
* Context Queries: | ||
* - http://dotty.epfl.ch/docs/reference/contextual/query-types.html, | ||
* - https://www.scala-lang.org/blog/2016/12/07/implicit-function-types.html | ||
*/ | ||
object ContextQueries /* Formerly known as Implicit Function Types */ { | ||
|
||
object context { | ||
// type alias Contextual | ||
type Contextual[T] = ExecutionContext ?=> T | ||
|
||
// sum is expanded to sum(x, y)(ctx) | ||
def asyncSum(x: Int, y: Int): Contextual[Future[Int]] = Future(x + y) | ||
|
||
def asyncMult(x: Int, y: Int)(using ctx: ExecutionContext) = Future(x * y) | ||
} | ||
|
||
object parse { | ||
|
||
type Parseable[T] = ImpliedInstances.StringParser[T] ?=> Try[T] | ||
|
||
def sumStrings(x: String, y: String): Parseable[Int] = { | ||
val parser = implicitly[ImpliedInstances.StringParser[Int]] | ||
val tryA = parser.parse(x) | ||
val tryB = parser.parse(y) | ||
|
||
for { | ||
a <- tryA | ||
b <- tryB | ||
} yield a + b | ||
} | ||
} | ||
|
||
def test: Unit = { | ||
import ExecutionContext.Implicits.global | ||
context.asyncSum(3, 4).foreach(println) | ||
context.asyncMult(3, 4).foreach(println) | ||
|
||
println(parse.sumStrings("3", "4")) | ||
println(parse.sumStrings("3", "a")) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package example | ||
|
||
import scala.language.implicitConversions | ||
|
||
/** | ||
* Conversions: http://dotty.epfl.ch/docs/reference/contextual/conversions.html | ||
*/ | ||
object Conversion { | ||
|
||
case class IntWrapper(a: Int) extends AnyVal | ||
case class DoubleWrapper(b: Double) extends AnyVal | ||
|
||
def convert[T, U](x: T)(using converter: Conversion[T, U]): U = converter(x) | ||
|
||
given IntWrapperToDoubleWrapper as Conversion[IntWrapper, DoubleWrapper] = new Conversion[IntWrapper, DoubleWrapper] { | ||
override def apply(i: IntWrapper): DoubleWrapper = new DoubleWrapper(i.a.toDouble) | ||
} | ||
|
||
def useConversion(using f: Conversion[IntWrapper, DoubleWrapper]) = { | ||
val y: IntWrapper = new IntWrapper(4) | ||
val x: DoubleWrapper = y | ||
x | ||
} | ||
|
||
/* Not working anymore. | ||
def useConversion(implicit f: A => B) = { | ||
val y: A = ... | ||
val x: B = a // error under Dotty | ||
} | ||
*/ | ||
|
||
def test: Unit = { | ||
println(useConversion) | ||
println(convert(new IntWrapper(42))) | ||
} | ||
|
||
|
||
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.