Skip to content

Commit 6068aee

Browse files
authored
Cut dependency from website.fastPages on slow build tasks (#6045)
It now no longer depends on: - `example.thirdparty[android-compose-samples].downloadedRepo` - `build.website.apidocs.unidocLocal` This should speed up local iteration on the docsite. Anyone who wants the fuller website can use `website.localPages` or `website.githubPages`
1 parent 63109ed commit 6068aee

File tree

2 files changed

+58
-56
lines changed

2 files changed

+58
-56
lines changed

example/package.mill

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ object `package` extends Module {
151151
val upstreamOpt = upstreamCross(this.moduleSegments.parts.dropRight(1).last)
152152
.flatMap(_.valuesToModules.get(List(crossValue)))
153153

154-
def testRepoRoot = Task {
155-
os.copy(super.testRepoRoot().path, Task.dest, mergeFolders = true)
154+
def testRepoSourceRoot = Task {
155+
os.copy(super.testRepoSourceRoot().path, Task.dest, mergeFolders = true)
156156
for (suffix <- Seq("build.mill")) {
157157
for (lines <- buildScLines() if os.exists(Task.dest / suffix)) {
158158
os.write.over(Task.dest / suffix, lines.mkString("\n"))
@@ -177,10 +177,10 @@ object `package` extends Module {
177177
case None => Task { None }
178178
case Some(upstream) => Task {
179179
Some {
180-
val upstreamRoot = upstream.testRepoRoot().path
180+
val upstreamRoot = upstream.testRepoSourceRoot().path
181181
val suffix = Seq("build.mill").find(s => os.exists(upstreamRoot / s)).head
182-
val upstreamLines = os.read.lines(upstream.testRepoRoot().path / suffix)
183-
val lines = os.read.lines(super.testRepoRoot().path / suffix)
182+
val upstreamLines = os.read.lines(upstream.testRepoSourceRoot().path / suffix)
183+
val lines = os.read.lines(super.testRepoSourceRoot().path / suffix)
184184

185185
import collection.mutable
186186
val groupedLines = mutable.Map.empty[String, mutable.Buffer[String]]
@@ -242,7 +242,7 @@ object `package` extends Module {
242242
* Parses a `build.mill` for specific comments and return the split-by-type content
243243
*/
244244
def parsed: T[Seq[(String, String)]] = Task {
245-
mill.testkit.ExampleParser(testRepoRoot().path)
245+
mill.testkit.ExampleParser(testRepoSourceRoot().path)
246246
}
247247

248248
def rendered = Task {

website/package.mill

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ object `package` extends mill.Module {
1616
* API documentation generated with ScalaDoc.
1717
*/
1818
object apidocs extends UnidocModule {
19+
def dummy = Task { PathRef(Task.dest) }
1920
def unidocDocumentTitle = Task { "Mill" }
2021

2122
def unidocCompileClasspath =
@@ -389,73 +390,74 @@ object `package` extends mill.Module {
389390
}
390391
}
391392
def githubPages: T[PathRef] = Task {
392-
generatePages(authorMode = false).apply().apply(oldDocSources().map(_.path))
393+
generatePages(false, apidocs.unidocSite).apply().apply(oldDocSources().map(_.path))
393394
}
394395

395396
def localPages: T[PathRef] = Task {
396-
val pages = generatePages(authorMode = true).apply().apply(oldDocSources().map(_.path))
397+
val pages = generatePages(true, apidocs.unidocLocal).apply().apply(Nil)
397398
Task.log.streams.out.println(
398399
s"You can browse the pages at: ${(pages.path / "index.html").toNIO.toUri()}"
399400
)
400401
pages
401402
}
402403
def fastPages: T[PathRef] = Task {
403-
val pages = generatePages(authorMode = true).apply().apply(Nil)
404+
val pages = generatePages(true, apidocs.dummy).apply().apply(Nil)
404405
Task.log.streams.out.println(
405406
s"You can browse the pages at: ${(pages.path / "index.html").toNIO.toUri()}"
406407
)
407408
pages
408409
}
409410

410-
def generatePages(authorMode: Boolean) = Task.Anon { (extraSources: Seq[os.Path]) =>
411-
Task.log.streams.err.println("Creating Antora playbook ...")
412-
// dependency to sources
413-
source()
414-
val docSite = Task.dest
415-
val playbook = docSite / "antora-playbook.yml"
416-
val siteDir = docSite / "site"
417-
os.write(
418-
target = playbook,
419-
data = githubPagesPlaybookText(authorMode).apply().apply(extraSources),
420-
createFolders = true
421-
)
422-
Task.log.streams.err.println("Running Antora ...")
423-
runAntora(
424-
npmDir = npmBase(),
425-
workDir = docSite,
426-
args = Seq(
427-
playbook.last,
428-
"--to-dir",
429-
siteDir.toString(),
430-
"--attribute",
431-
"page-pagination"
432-
) ++
433-
Option.when(!authorMode)("--fetch").toSeq
434-
)
435-
os.write(siteDir / ".nojekyll", "")
436-
437-
// sanitize devAntora source URLs
438-
Task.log.streams.err.println("Sanitizing links ...")
439-
sanitizeDevUrls(
440-
siteDir,
441-
devAntoraSources().path,
442-
BuildCtx.workspaceRoot / "docs",
443-
mill.api.BuildCtx.workspaceRoot
444-
)
411+
def generatePages(authorMode: Boolean, apiDocTask: Task[PathRef]) =
412+
Task.Anon { (extraSources: Seq[os.Path]) =>
413+
Task.log.streams.err.println("Creating Antora playbook ...")
414+
// dependency to sources
415+
source()
416+
val docSite = Task.dest
417+
val playbook = docSite / "antora-playbook.yml"
418+
val siteDir = docSite / "site"
419+
os.write(
420+
target = playbook,
421+
data = githubPagesPlaybookText(authorMode).apply().apply(extraSources),
422+
createFolders = true
423+
)
424+
Task.log.streams.err.println("Running Antora ...")
425+
runAntora(
426+
npmDir = npmBase(),
427+
workDir = docSite,
428+
args = Seq(
429+
playbook.last,
430+
"--to-dir",
431+
siteDir.toString(),
432+
"--attribute",
433+
"page-pagination"
434+
) ++
435+
Option.when(!authorMode)("--fetch").toSeq
436+
)
437+
os.write(siteDir / ".nojekyll", "")
438+
439+
// sanitize devAntora source URLs
440+
Task.log.streams.err.println("Sanitizing links ...")
441+
sanitizeDevUrls(
442+
siteDir,
443+
devAntoraSources().path,
444+
BuildCtx.workspaceRoot / "docs",
445+
mill.api.BuildCtx.workspaceRoot
446+
)
445447

446-
for (p <- os.walk(siteDir) if p.ext == "html") {
447-
// Manually un-substitute ellipses in normal text to reverse the antora unicode
448-
// substitution, because the font for the unicode ellipses looks very bad
449-
os.write.over(p, os.read(p).replace("…", "..."))
450-
}
448+
for (p <- os.walk(siteDir) if p.ext == "html") {
449+
// Manually un-substitute ellipses in normal text to reverse the antora unicode
450+
// substitution, because the font for the unicode ellipses looks very bad
451+
os.write.over(p, os.read(p).replace("…", "..."))
452+
}
451453

452-
// only copy the "api" sub-dir; api docs contains a top-level index.html with we don't want
453-
val unidocSrc = if (authorMode) apidocs.unidocLocal().path else apidocs.unidocSite().path
454-
Task.log.streams.err.println(s"Copying API docs from ${unidocSrc} ...")
455-
os.copy(unidocSrc, siteDir / "api/latest", createFolders = true)
454+
// only copy the "api" sub-dir; api docs contains a top-level index.html with we don't want
455+
val unidocSrc = apiDocTask().path
456+
Task.log.streams.err.println(s"Copying API docs from ${unidocSrc} ...")
457+
os.copy(unidocSrc, siteDir / "api/latest", createFolders = true)
456458

457-
PathRef(siteDir)
458-
}
459+
PathRef(siteDir)
460+
}
459461

460462
def sanitizeDevUrls(
461463
dir: os.Path,
@@ -500,7 +502,7 @@ object `package` extends mill.Module {
500502

501503
def allLinksAndAnchors
502504
: T[IndexedSeq[(os.Path, Seq[(String, String)], Seq[(String, String)], Set[String])]] = Task {
503-
val base = fastPages().path
505+
val base = localPages().path
504506
val validExtensions = Set("html", "scala")
505507
for (path <- os.walk(base) if validExtensions(path.ext))
506508
yield {

0 commit comments

Comments
 (0)