koch: add --localdocs to allow building only local docs (#14783)

* koch: add --localdocs to allow building only local docs

This flag also make koch doc use the passed arguments when building
the offline docs.

This is useful when generating nightlies as we would want to use
--doccmd:skip and also skipping a pass of docgen speed things up
drastically (for non-native targets).

This flag superseded the undocumented --docslocal.

* kochdocs: filter google analytics code from the arg list instead

This commit introduce a small PEG expression to filter out the google
analytics code before building local docs when --localdocs is not
specified. This lets us keep any arguments unrelated to google analytics
when building local docs, useful for use with --doccmd:skip
This commit is contained in:
alaviss 2020-06-25 08:28:57 +00:00 • committed by GitHub
commit 1a0725f022
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 14 deletions

View file

@ -1,6 +1,6 @@
## Part of 'koch' responsible for the documentation generation.
import os, strutils, osproc, sets, pathnorm
import os, strutils, osproc, sets, pathnorm, pegs
from std/private/globs import nativeToUnixPath, walkDirRecFilter, PathEntry
import "../compiler/nimpaths"
@ -182,7 +182,7 @@ lib/system/iterators.nim
lib/system/dollars.nim
lib/system/widestrs.nim
""".splitWhitespace()
proc follow(a: PathEntry): bool =
a.path.lastPathPart notin ["nimcache", "htmldocs", "includes", "deprecated", "genode"]
for entry in walkDirRecFilter("lib", follow = follow):
@ -318,6 +318,19 @@ proc buildDocsDir*(args: string, dir: string) =
buildDocPackages(args, dir)
copyFile(docHackJsSource, dir / docHackJsSource.lastPathPart)
proc buildDocs*(args: string) =
buildDocsDir(args, webUploadOutput / NimVersion)
buildDocsDir("", docHtmlOutput) # no `args` to avoid offline docs containing the 'gaCode'!
proc buildDocs*(args: string, localOnly = false, localOutDir = "") =
let localOutDir =
if localOutDir.len == 0:
docHtmlOutput
else:
localOutDir
var args = args
if not localOnly:
buildDocsDir(args, webUploadOutput / NimVersion)
let gaFilter = peg"@( y'--doc.googleAnalytics:' @(\s / $) )"
args = args.replace(gaFilter)
buildDocsDir(args, localOutDir)