Skip to content

Commit f5e36f5

Browse files
Add documentation snapshotting capability
1 parent 654f303 commit f5e36f5

File tree

6 files changed

+70
-18
lines changed

6 files changed

+70
-18
lines changed

.drone.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,27 @@ steps:
124124
target:
125125
- nightly
126126

127+
- name: nightly_documentation
128+
pull: default
129+
image: lampepfl/dotty:2020-01-22-2
130+
depends_on:
131+
- test
132+
- test_bootstrapped
133+
- community_build
134+
- test_java11
135+
- publish_nightly
136+
commands:
137+
- ./project/scripts/genDocs -doc-snapshot
138+
environment:
139+
BOT_TOKEN:
140+
from_secret: bot_token
141+
NIGHTLYBUILD: yes
142+
when:
143+
event:
144+
- promote
145+
target:
146+
- nightly
147+
127148
- name: publish_release
128149
pull: default
129150
image: lampepfl/dotty:2020-01-22-2
@@ -150,6 +171,26 @@ steps:
150171
event:
151172
- tag
152173

174+
- name: release_documentation
175+
pull: default
176+
image: lampepfl/dotty:2020-01-22-2
177+
depends_on:
178+
- test
179+
- test_bootstrapped
180+
- community_build
181+
- test_java11
182+
- publish_release
183+
- github_release
184+
commands:
185+
- ./project/scripts/genDocs -doc-snapshot
186+
environment:
187+
BOT_TOKEN:
188+
from_secret: bot_token
189+
RELEASEBUILD: yes
190+
when:
191+
event:
192+
- tag
193+
153194
- name: github_release
154195
pull: default
155196
image: plugins/github-release

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,7 @@ class ScalaSettings extends Settings.SettingGroup {
215215
""
216216
)
217217

218+
val docSnapshot: Setting[Boolean] = BooleanSetting("-doc-snapshot", "Generate a documentation snapshot for the current Dotty version")
219+
218220
val wikiSyntax: Setting[Boolean] = BooleanSetting("-Xwiki-syntax", "Retains the Scala2 behavior of using Wiki Syntax in Scaladoc.")
219221
}

doc-tool/src/dotty/tools/dottydoc/DocDriver.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dotty.tools
22
package dottydoc
33

4+
import java.io.File
5+
46
import dotty.tools.dottydoc.util.syntax._
57
import core.ContextDottydoc
68
import dotc.core.Contexts._
@@ -38,22 +40,26 @@ class DocDriver extends Driver {
3840
implicit val ctx: Context = ictx
3941
val reporter = doCompile(newCompiler, filesToDocument)
4042

41-
val siteRoot = new java.io.File(ctx.settings.siteRoot.value)
43+
val siteRoot = File(ctx.settings.siteRoot.value)
4244
val projectName = ctx.settings.projectName.value
4345
val projectVersion = ctx.settings.projectVersion.value
4446
val projectUrl = Option(ctx.settings.projectUrl.value).filter(_.nonEmpty)
4547
val projectLogo = Option(ctx.settings.projectLogo.value).filter(_.nonEmpty)
48+
val docSnapshot = ctx.settings.docSnapshot.value
49+
50+
var outDir = File(siteRoot, "_site")
51+
if docSnapshot then outDir = File(outDir, projectVersion)
4652

4753
if (projectName.isEmpty)
4854
ctx.error(s"Site project name not set. Use `-project <title>` to set the project name")
4955
else if (!siteRoot.exists || !siteRoot.isDirectory)
5056
ctx.error(s"Site root does not exist: $siteRoot")
5157
else {
5258
Site(siteRoot, projectName, projectVersion, projectUrl, projectLogo, ctx.docbase.packages)
53-
.generateApiDocs()
54-
.copyStaticFiles()
55-
.generateHtmlFiles()
56-
.generateBlog()
59+
.generateApiDocs(outDir)
60+
.copyStaticFiles(outDir)
61+
.generateHtmlFiles(outDir)
62+
.generateBlog(outDir)
5763

5864
ctx.docbase.printSummary()
5965
}

doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ case class Site(
128128
new SourceFile(virtualFile, Codec.UTF8)
129129
}
130130

131-
/** Copy static files to `outDir` */
132-
private[this] val defaultOutDir = new JFile(root.getAbsolutePath + JFile.separator + "_site")
133-
134-
def copyStaticFiles(outDir: JFile = defaultOutDir)(implicit ctx: Context): this.type =
131+
def copyStaticFiles(outDir: JFile)(implicit ctx: Context): this.type =
135132
createOutput (outDir) {
136133
// Copy user-defined static assets
137134
staticAssets.foreach { asset =>
@@ -197,7 +194,7 @@ case class Site(
197194
}
198195

199196
/** Generate HTML for the API documentation */
200-
def generateApiDocs(outDir: JFile = defaultOutDir)(implicit ctx: Context): this.type =
197+
def generateApiDocs(outDir: JFile)(implicit ctx: Context): this.type =
201198
createOutput(outDir) {
202199
def genDoc(e: model.Entity): Unit = {
203200
ctx.docbase.echo(s"Generating doc page for: ${e.path.mkString(".")}")
@@ -243,7 +240,7 @@ case class Site(
243240
}
244241

245242
/** Generate HTML files from markdown and .html sources */
246-
def generateHtmlFiles(outDir: JFile = defaultOutDir)(implicit ctx: Context): this.type =
243+
def generateHtmlFiles(outDir: JFile)(implicit ctx: Context): this.type =
247244
createOutput(outDir) {
248245
compilableFiles.foreach { asset =>
249246
val pathFromRoot = stripRoot(asset)
@@ -263,7 +260,7 @@ case class Site(
263260
}
264261

265262
/** Generate blog from files in `blog/_posts` and output in `outDir` */
266-
def generateBlog(outDir: JFile = defaultOutDir)(implicit ctx: Context): this.type =
263+
def generateBlog(outDir: JFile)(implicit ctx: Context): this.type =
267264
createOutput(outDir) {
268265
blogposts.foreach { file =>
269266
val BlogPost.extract(year, month, day, name, ext) = file.getName

project/Build.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ object Build {
130130
val dotr = inputKey[Unit]("run compiled binary using the correct classpath, or the user supplied classpath")
131131

132132
// Compiles the documentation and static site
133-
val genDocs = taskKey[Unit]("run dottydoc to generate static documentation site")
133+
val genDocs = inputKey[Unit]("run dottydoc to generate static documentation site")
134134

135135
// Shorthand for compiling a docs site
136136
val dottydoc = inputKey[Unit]("run dottydoc")
@@ -409,7 +409,9 @@ object Build {
409409

410410
javaOptions ++= (javaOptions in `dotty-compiler`).value,
411411

412-
genDocs := Def.taskDyn {
412+
genDocs := Def.inputTaskDyn {
413+
val dottydocExtraArgs = spaceDelimited("<arg>").parsed
414+
413415
// Make majorVersion available at dotty.epfl.ch/versions/latest-nightly-base
414416
// Used by sbt-dotty to resolve the latest nightly
415417
val majorVersion = baseVersion.take(baseVersion.lastIndexOf('.'))
@@ -427,11 +429,11 @@ object Build {
427429
"-project-logo", "dotty-logo.svg",
428430
"-classpath", dottydocClasspath.value,
429431
"-Yerased-terms"
430-
)
432+
) ++ dottydocExtraArgs
431433
(runMain in Compile).toTask(
432434
s""" dotty.tools.dottydoc.Main ${args.mkString(" ")} ${sources.mkString(" ")}"""
433435
)
434-
}.value,
436+
}.evaluated,
435437

436438
dottydoc := Def.inputTaskDyn {
437439
val args = spaceDelimited("<arg>").parsed

project/scripts/genDocs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env bash
22

33
# Usage:
4-
# BOT_TOKEN=<dotty-bot password> ./genDocs
4+
# BOT_TOKEN=<dotty-bot password> ./genDocs [-doc-snapshot]
55

66
set -e
7+
GENDOC_EXTRA_ARGS=$@
78

89
# set extended glob, needed for rm everything but x
910
shopt -s extglob
@@ -18,7 +19,7 @@ echo "Working directory: $PWD"
1819

1920
# this command will generate docs in $PWD/docs/_site
2021
SBT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/sbt"
21-
"$SBT" "genDocs"
22+
"$SBT" "genDocs $GENDOC_EXTRA_ARGS"
2223

2324
# make sure that the previous command actually succeeded
2425
if [ ! -d "$PWD/docs/_site" ]; then
@@ -39,6 +40,9 @@ git config user.email "[email protected]"
3940
git fetch doc-remote gh-pages
4041
git checkout gh-pages
4142

43+
# save the old snapshots to the newly generated site
44+
mv 0.*/ $PWD/docs/_site
45+
4246
# move newly generated _site dir to $PWD
4347
mv $PWD/docs/_site .
4448

0 commit comments

Comments
 (0)