summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-03-17 05:44:37 -0700
committerGitHub <noreply@github.com>2020-03-17 13:44:37 +0100
commitaf9c85270198455c7ba218fae919e79060a8960a (patch)
treea032ae34059a9622b7070936b76fd4bc20812c65
parent6a23452bf4f386a57bcbb4e99c8d27149fe1d10b (diff)
downloadNim-af9c85270198455c7ba218fae919e79060a8960a.tar.gz
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
-rw-r--r--compiler/docgen.nim24
-rw-r--r--compiler/scriptconfig.nim4
-rw-r--r--testament/important_packages.nim2
-rw-r--r--tests/vm/tcompilesetting.nim2
4 files changed, 18 insertions, 14 deletions
diff --git a/compiler/docgen.nim b/compiler/docgen.nim
index 064bdc93e..fbdfbc884 100644
--- a/compiler/docgen.nim
+++ b/compiler/docgen.nim
@@ -54,6 +54,9 @@ proc nativeToUnix(path: string): string =
     result = replace(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 =
   ## returns a relative file that will be appended to outDir
   let file2 = $file
@@ -146,12 +149,11 @@ proc parseRst(text, filename: string,
 proc getOutFile2(conf: ConfigRef; filename: RelativeFile,
                  ext: string, dir: RelativeDir; guessTarget: bool): AbsoluteFile =
   if optWholeProject in conf.globalOptions:
-    let d = if conf.outDir.isEmpty: conf.projectPath / dir else: conf.outDir
+    let d = conf.docOutDir(dir)
     createDir(d)
     result = d / changeFileExt(filename, ext)
   elif guessTarget:
-    let d = if not conf.outDir.isEmpty: conf.outDir
-            else: conf.projectPath
+    let d = conf.docOutDir
     createDir(d)
     result = d / changeFileExt(filename, ext)
   elif not conf.outFile.isEmpty:
@@ -1079,8 +1081,11 @@ proc genSection(d: PDoc, kind: TSymKind) =
       "sectionid", "sectionTitle", "sectionTitleID", "content"], [
       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 =
-  rope($relativeTo(outDir / RelativeFile"nimdoc.out.css", destFile.splitFile().dir, '/'))
+  rope($relativeTo(outDir / nimdocOutCss.RelativeFile, destFile.splitFile().dir, '/'))
 
 proc genOutFile(d: PDoc): Rope =
   var
@@ -1127,15 +1132,14 @@ proc genOutFile(d: PDoc): Rope =
 
 proc generateIndex*(d: PDoc) =
   if optGenIndex in d.conf.globalOptions:
-    let dir = if not d.conf.outDir.isEmpty: d.conf.outDir
-              else: d.conf.projectPath / htmldocsDir
+    let dir = d.conf.docOutDir(htmldocsDir)
     createDir(dir)
     let dest = dir / changeFileExt(presentationPath(d.conf, AbsoluteFile d.filename), IndexExt)
     writeIndexFile(d[], dest.string)
 
 proc updateOutfile(d: PDoc, outfile: AbsoluteFile) =
   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)
 
 proc writeOutput*(d: PDoc, useWarning = false) =
@@ -1146,15 +1150,15 @@ proc writeOutput*(d: PDoc, useWarning = false) =
   else:
     template outfile: untyped = d.destFile
     #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)
     if not writeRope(content, outfile):
       rawMessage(d.conf, if useWarning: warnCannotOpenFile else: errCannotOpenFile,
         outfile.string)
     elif not d.wroteCss:
       let cssSource = $d.conf.getPrefixDir() / "doc" / "nimdoc.css"
-      let cssDest = $d.conf.outDir / "nimdoc.out.css"
-        # renamed to make it easier to use with gitignore in user's repos
+      let cssDest = $dir / nimdocOutCss
       copyFile(cssSource, cssDest)
       d.wroteCss = true
 
diff --git a/compiler/scriptconfig.nim b/compiler/scriptconfig.nim
index 220486aed..d53664912 100644
--- a/compiler/scriptconfig.nim
+++ b/compiler/scriptconfig.nim
@@ -12,9 +12,9 @@
 
 import
   ast, modules, idents, passes, condsyms,
-  options, sem, llstream, vm, vmdef, commands, msgs,
+  options, sem, llstream, vm, vmdef, commands,
   os, times, osproc, wordrecg, strtabs, modulegraphs,
-  lineinfos, pathutils
+  pathutils
 
 # we support 'cmpIgnoreStyle' natively for efficiency:
 from strutils import cmpIgnoreStyle, contains
diff --git a/testament/important_packages.nim b/testament/important_packages.nim
index d9c49cb7b..363171082 100644
--- a/testament/important_packages.nim
+++ b/testament/important_packages.nim
@@ -52,7 +52,7 @@ pkg "nimcrypto", false, "nim c -r tests/testall.nim"
 pkg "NimData", true, "nim c -o:nimdataa src/nimdata.nim"
 pkg "nimes", true, "nim c src/nimes.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 "nimlsp", true
 pkg "nimly", true
diff --git a/tests/vm/tcompilesetting.nim b/tests/vm/tcompilesetting.nim
index 0e936d377..79527d584 100644
--- a/tests/vm/tcompilesetting.nim
+++ b/tests/vm/tcompilesetting.nim
@@ -1,5 +1,5 @@
 discard """
-cmd: "nim c --nimcache:myNimCache --nimblePath:myNimblePath $file"
+cmd: "nim c --nimcache:build/myNimCache --nimblePath:myNimblePath $file"
 joinable: false
 """