fix nim doc subdir/foo which was generating broken css; + other fixes (#13647)

* docgen: minor refactoring via docOutDir
* fix css for `nim doc subdir/foo` without --outdir nor -o
* tcompilesetting.nim: keep `git status` clean
* re-enable pkg nimgame2 that got fixed upstream
This commit is contained in:
Timothee Cour 2020-03-17 05:44:37 -07:00 • committed by GitHub
commit af9c852701
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 14 deletions

View file

@ -54,6 +54,9 @@ proc nativeToUnix(path: string): string =
result = replace(path, '\\', '/') result = replace(path, '\\', '/')
else: result = path else: result = path
proc docOutDir(conf: ConfigRef, subdir: RelativeDir = RelativeDir""): AbsoluteDir =
if not conf.outDir.isEmpty: conf.outDir else: conf.projectPath / subdir
proc presentationPath*(conf: ConfigRef, file: AbsoluteFile, isTitle = false): RelativeFile = proc presentationPath*(conf: ConfigRef, file: AbsoluteFile, isTitle = false): RelativeFile =
## returns a relative file that will be appended to outDir ## returns a relative file that will be appended to outDir
let file2 = $file let file2 = $file
@ -146,12 +149,11 @@ proc parseRst(text, filename: string,
proc getOutFile2(conf: ConfigRef; filename: RelativeFile, proc getOutFile2(conf: ConfigRef; filename: RelativeFile,
ext: string, dir: RelativeDir; guessTarget: bool): AbsoluteFile = ext: string, dir: RelativeDir; guessTarget: bool): AbsoluteFile =
if optWholeProject in conf.globalOptions: if optWholeProject in conf.globalOptions:
let d = if conf.outDir.isEmpty: conf.projectPath / dir else: conf.outDir let d = conf.docOutDir(dir)
createDir(d) createDir(d)
result = d / changeFileExt(filename, ext) result = d / changeFileExt(filename, ext)
elif guessTarget: elif guessTarget:
let d = if not conf.outDir.isEmpty: conf.outDir let d = conf.docOutDir
else: conf.projectPath
createDir(d) createDir(d)
result = d / changeFileExt(filename, ext) result = d / changeFileExt(filename, ext)
elif not conf.outFile.isEmpty: elif not conf.outFile.isEmpty:
@ -1079,8 +1081,11 @@ proc genSection(d: PDoc, kind: TSymKind) =
"sectionid", "sectionTitle", "sectionTitleID", "content"], [ "sectionid", "sectionTitle", "sectionTitleID", "content"], [
ord(kind).rope, title, rope(ord(kind) + 50), d.toc[kind]]) ord(kind).rope, title, rope(ord(kind) + 50), d.toc[kind]])
const nimdocOutCss = "nimdoc.out.css"
# `out` to make it easier to use with gitignore in user's repos
proc cssHref(outDir: AbsoluteDir, destFile: AbsoluteFile): Rope = proc cssHref(outDir: AbsoluteDir, destFile: AbsoluteFile): Rope =
rope($relativeTo(outDir / RelativeFile"nimdoc.out.css", destFile.splitFile().dir, '/')) rope($relativeTo(outDir / nimdocOutCss.RelativeFile, destFile.splitFile().dir, '/'))
proc genOutFile(d: PDoc): Rope = proc genOutFile(d: PDoc): Rope =
var var
@ -1127,15 +1132,14 @@ proc genOutFile(d: PDoc): Rope =
proc generateIndex*(d: PDoc) = proc generateIndex*(d: PDoc) =
if optGenIndex in d.conf.globalOptions: if optGenIndex in d.conf.globalOptions:
let dir = if not d.conf.outDir.isEmpty: d.conf.outDir let dir = d.conf.docOutDir(htmldocsDir)
else: d.conf.projectPath / htmldocsDir
createDir(dir) createDir(dir)
let dest = dir / changeFileExt(presentationPath(d.conf, AbsoluteFile d.filename), IndexExt) let dest = dir / changeFileExt(presentationPath(d.conf, AbsoluteFile d.filename), IndexExt)
writeIndexFile(d[], dest.string) writeIndexFile(d[], dest.string)
proc updateOutfile(d: PDoc, outfile: AbsoluteFile) = proc updateOutfile(d: PDoc, outfile: AbsoluteFile) =
if d.module == nil or sfMainModule in d.module.flags: # nil for eg for commandRst2Html if d.module == nil or sfMainModule in d.module.flags: # nil for eg for commandRst2Html
if d.conf.outDir.isEmpty: d.conf.outDir = d.conf.projectPath if d.conf.outDir.isEmpty: d.conf.outDir = d.conf.docOutDir
if d.conf.outFile.isEmpty: d.conf.outFile = outfile.relativeTo(d.conf.outDir) if d.conf.outFile.isEmpty: d.conf.outFile = outfile.relativeTo(d.conf.outDir)
proc writeOutput*(d: PDoc, useWarning = false) = proc writeOutput*(d: PDoc, useWarning = false) =
@ -1146,15 +1150,15 @@ proc writeOutput*(d: PDoc, useWarning = false) =
else: else:
template outfile: untyped = d.destFile template outfile: untyped = d.destFile
#let outfile = getOutFile2(d.conf, shortenDir(d.conf, filename), outExt, htmldocsDir) #let outfile = getOutFile2(d.conf, shortenDir(d.conf, filename), outExt, htmldocsDir)
createDir(outfile.splitFile.dir) let dir = outfile.splitFile.dir
createDir(dir)
updateOutfile(d, outfile) updateOutfile(d, outfile)
if not writeRope(content, outfile): if not writeRope(content, outfile):
rawMessage(d.conf, if useWarning: warnCannotOpenFile else: errCannotOpenFile, rawMessage(d.conf, if useWarning: warnCannotOpenFile else: errCannotOpenFile,
outfile.string) outfile.string)
elif not d.wroteCss: elif not d.wroteCss:
let cssSource = $d.conf.getPrefixDir() / "doc" / "nimdoc.css" let cssSource = $d.conf.getPrefixDir() / "doc" / "nimdoc.css"
let cssDest = $d.conf.outDir / "nimdoc.out.css" let cssDest = $dir / nimdocOutCss
# renamed to make it easier to use with gitignore in user's repos
copyFile(cssSource, cssDest) copyFile(cssSource, cssDest)
d.wroteCss = true d.wroteCss = true

View file

@ -12,9 +12,9 @@
import import
ast, modules, idents, passes, condsyms, ast, modules, idents, passes, condsyms,
options, sem, llstream, vm, vmdef, commands, msgs, options, sem, llstream, vm, vmdef, commands,
os, times, osproc, wordrecg, strtabs, modulegraphs, os, times, osproc, wordrecg, strtabs, modulegraphs,
lineinfos, pathutils pathutils
# we support 'cmpIgnoreStyle' natively for efficiency: # we support 'cmpIgnoreStyle' natively for efficiency:
from strutils import cmpIgnoreStyle, contains from strutils import cmpIgnoreStyle, contains

View file

@ -52,7 +52,7 @@ pkg "nimcrypto", false, "nim c -r tests/testall.nim"
pkg "NimData", true, "nim c -o:nimdataa src/nimdata.nim" pkg "NimData", true, "nim c -o:nimdataa src/nimdata.nim"
pkg "nimes", true, "nim c src/nimes.nim" pkg "nimes", true, "nim c src/nimes.nim"
pkg "nimfp", true, "nim c -o:nfp -r src/fp.nim" pkg "nimfp", true, "nim c -o:nfp -r src/fp.nim"
#pkg "nimgame2", true, "nim c nimgame2/nimgame.nim" pkg "nimgame2", true, "nim c nimgame2/nimgame.nim"
pkg "nimgen", true, "nim c -o:nimgenn -r src/nimgen/runcfg.nim" pkg "nimgen", true, "nim c -o:nimgenn -r src/nimgen/runcfg.nim"
# pkg "nimlsp", true # pkg "nimlsp", true
pkg "nimly", true pkg "nimly", true

View file

@ -1,5 +1,5 @@
discard """ discard """
cmd: "nim c --nimcache:myNimCache --nimblePath:myNimblePath $file" cmd: "nim c --nimcache:build/myNimCache --nimblePath:myNimblePath $file"
joinable: false joinable: false
""" """