From ada420dac575b511924428faf960c1660041a4a2 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sat, 11 Jan 2020 16:36:21 -0800 Subject: [PATCH 1/5] fix #12998 nim doc regression --- .gitignore | 2 ++ compiler/docgen.nim | 13 ++++++++++++- config/nimdoc.cfg | 2 +- koch.nim | 4 +++- nimdoc/test_out_index_dot_html/expected/index.html | 2 +- .../test_out_index_dot_html/expected/theindex.html | 2 +- .../testproject/expected/subdir/subdir_b/utils.html | 2 +- nimdoc/testproject/expected/testproject.html | 2 +- nimdoc/testproject/expected/theindex.html | 2 +- tools/kochdocs.nim | 9 +++------ 10 files changed, 26 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index a9b65bb0245b4..895e3637c6178 100644 --- a/.gitignore +++ b/.gitignore @@ -89,3 +89,5 @@ megatest.nim # ignore debug dirs generated by dsymutil on OSX *.dSYM + +nimdoc.out.css diff --git a/compiler/docgen.nim b/compiler/docgen.nim index a09f54c165178..583a5267e0b20 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -43,6 +43,7 @@ type destFile*: AbsoluteFile thisDir*: AbsoluteDir examples: string + wroteCss*: bool PDoc* = ref TDocumentor ## Alias to type less. @@ -1060,6 +1061,8 @@ proc generateIndex*(d: PDoc) = d.conf.projectPath), IndexExt) writeIndexFile(d[], dest.string) +const nimRepoDir = currentSourcePath / ".." / ".." # this should be exposed somewhere + proc writeOutput*(d: PDoc, useWarning = false) = runAllExamples(d) var content = genOutFile(d) @@ -1068,10 +1071,18 @@ proc writeOutput*(d: PDoc, useWarning = false) = else: template outfile: untyped = d.destFile #let outfile = getOutFile2(d.conf, shortenDir(d.conf, filename), outExt, "htmldocs") - createDir(outfile.splitFile.dir) + let dir = outfile.`$`.parentDir + createDir(dir) if not writeRope(content, outfile): rawMessage(d.conf, if useWarning: warnCannotOpenFile else: errCannotOpenFile, outfile.string) + else: + if not d.wroteCss: + let cssSource = nimRepoDir / "doc" / "nimdoc.css" + let cssDest = $d.conf.outDir / "nimdoc.out.css" + # renamed to make it easier to use with gitignore in user's repos + copyFile(cssSource, cssDest) + d.wroteCss = true d.conf.outFile = outfile.extractFilename.RelativeFile proc writeOutputJson*(d: PDoc, useWarning = false) = diff --git a/config/nimdoc.cfg b/config/nimdoc.cfg index e3282ee7f94dd..0ecb75c36d779 100644 --- a/config/nimdoc.cfg +++ b/config/nimdoc.cfg @@ -237,7 +237,7 @@ doc.file = """ $title - + diff --git a/koch.nim b/koch.nim index a0a7dd903d659..7d7e252bf36f5 100644 --- a/koch.nim +++ b/koch.nim @@ -24,7 +24,7 @@ when defined(i386) and defined(windows) and defined(vcc): {.link: "icons/koch-i386-windows-vcc.res".} import - os, strutils, parseopt, osproc, streams + os, strutils, parseopt, osproc import tools / kochdocs @@ -45,6 +45,7 @@ Options: --help, -h shows this help and quits --latest bundle the installers with a bleeding edge Nimble --stable bundle the installers with a stable Nimble (default) + --nim:path use specified path for nim binary Possible Commands: boot [options] bootstraps with given command line options distrohelper [bindir] helper for distro packagers @@ -605,6 +606,7 @@ when isMainModule: case normalize(op.key) of "latest": latest = true of "stable": latest = false + of "nim": nimExe = op.val.absolutePath # absolute so still works with changeDir else: showHelp() of cmdArgument: case normalize(op.key) diff --git a/nimdoc/test_out_index_dot_html/expected/index.html b/nimdoc/test_out_index_dot_html/expected/index.html index caf38a86d19af..d9ad0d625394c 100644 --- a/nimdoc/test_out_index_dot_html/expected/index.html +++ b/nimdoc/test_out_index_dot_html/expected/index.html @@ -18,7 +18,7 @@ foo - + diff --git a/nimdoc/test_out_index_dot_html/expected/theindex.html b/nimdoc/test_out_index_dot_html/expected/theindex.html index e0b0c067d377b..49e37bddf0486 100644 --- a/nimdoc/test_out_index_dot_html/expected/theindex.html +++ b/nimdoc/test_out_index_dot_html/expected/theindex.html @@ -18,7 +18,7 @@ Index - + diff --git a/nimdoc/testproject/expected/subdir/subdir_b/utils.html b/nimdoc/testproject/expected/subdir/subdir_b/utils.html index 8d646e6a142f9..30a172226aaad 100644 --- a/nimdoc/testproject/expected/subdir/subdir_b/utils.html +++ b/nimdoc/testproject/expected/subdir/subdir_b/utils.html @@ -18,7 +18,7 @@ utils - + diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html index 123ddce595ecc..b641bad6e9499 100644 --- a/nimdoc/testproject/expected/testproject.html +++ b/nimdoc/testproject/expected/testproject.html @@ -18,7 +18,7 @@ testproject - + diff --git a/nimdoc/testproject/expected/theindex.html b/nimdoc/testproject/expected/theindex.html index e0282e3552dbb..912ba98c24475 100644 --- a/nimdoc/testproject/expected/theindex.html +++ b/nimdoc/testproject/expected/theindex.html @@ -18,7 +18,7 @@ Index - + diff --git a/tools/kochdocs.nim b/tools/kochdocs.nim index 4adfef71e092f..f99567cd0b657 100644 --- a/tools/kochdocs.nim +++ b/tools/kochdocs.nim @@ -11,12 +11,15 @@ const webUploadOutput = "web/upload" docHackDir = "tools/dochack" +var nimExe*: string + proc exe*(f: string): string = result = addFileExt(f, ExeExt) when defined(windows): result = result.replace('/','\\') proc findNim*(): string = + if nimExe.len > 0: return nimExe var nim = "nim".exe result = "bin" / nim if existsFile(result): return @@ -366,14 +369,11 @@ proc buildJS() = proc buildDocs*(args: string) = const docHackJs = "dochack.js" - css = "nimdoc.css" let a = nimArgs & " " & args docHackJsSource = docHackDir / docHackJs docHackJsDest = docHtmlOutput / docHackJs - cssSource = "doc" / css - cssDest = docHtmlOutput / css buildJS() # This call generates docHackJsSource let docup = webUploadOutput / NimVersion createDir(docup) @@ -387,6 +387,3 @@ proc buildDocs*(args: string) = buildDoc(nimArgs, docHtmlOutput) copyFile(docHackJsSource, docHackJsDest) copyFile(docHackJsSource, docup / docHackJs) - - copyFile(cssSource, cssDest) - copyFile(cssSource, docup / css) From 663a97fbd143b57311af652d4a0c5957e4625632 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sun, 12 Jan 2020 15:30:36 -0800 Subject: [PATCH 2/5] use getNimRoot --- compiler/docgen.nim | 6 ++---- compiler/installer.ini | 2 +- compiler/main.nim | 3 +++ compiler/nimconf.nim | 20 ++++++++++++++++++++ compiler/options.nim | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 583a5267e0b20..b5c34a077df25 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -17,7 +17,7 @@ import packages/docutils/rst, packages/docutils/rstgen, json, xmltree, cgi, trees, types, typesrenderer, astalgo, lineinfos, intsets, - pathutils, trees + pathutils, trees, nimconf const exportSection = skField @@ -1061,8 +1061,6 @@ proc generateIndex*(d: PDoc) = d.conf.projectPath), IndexExt) writeIndexFile(d[], dest.string) -const nimRepoDir = currentSourcePath / ".." / ".." # this should be exposed somewhere - proc writeOutput*(d: PDoc, useWarning = false) = runAllExamples(d) var content = genOutFile(d) @@ -1078,7 +1076,7 @@ proc writeOutput*(d: PDoc, useWarning = false) = outfile.string) else: if not d.wroteCss: - let cssSource = nimRepoDir / "doc" / "nimdoc.css" + let cssSource = getNimRoot(d.conf).string / "doc" / "nimdoc.css" let cssDest = $d.conf.outDir / "nimdoc.out.css" # renamed to make it easier to use with gitignore in user's repos copyFile(cssSource, cssDest) diff --git a/compiler/installer.ini b/compiler/installer.ini index fed077fdb4d34..f8676ab08f324 100644 --- a/compiler/installer.ini +++ b/compiler/installer.ini @@ -139,4 +139,4 @@ licenses: "bin/nim,MIT;lib/*,MIT;" [nimble] pkgName: "compiler" -pkgFiles: "compiler/*;doc/basicopt.txt;doc/advopt.txt" +pkgFiles: "compiler/*;doc/basicopt.txt;doc/advopt.txt;doc/nimdoc.css" diff --git a/compiler/main.nim b/compiler/main.nim index 3cafe1f2c018a..1e380f6ec9cd8 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -303,8 +303,11 @@ proc mainCommand*(graph: ModuleGraph) = let key = lineinfos.WarningsToStr[ord(a) - ord(warnMin)] warnings[key] = %(a in conf.notes) + let nimroot = getNimRoot(conf) + var dumpdata = %[ (key: "version", val: %VersionAsString), + (key: "nimroot", val: %nimroot.string), (key: "project_path", val: %conf.projectFull.string), (key: "defined_symbols", val: definedSymbols), (key: "lib_paths", val: %libpaths), diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index 93cc215734f3d..e9dd16a409b23 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -238,6 +238,26 @@ proc getSystemConfigPath*(conf: ConfigRef; filename: RelativeFile): AbsoluteFile if not fileExists(result): result = p / RelativeDir"etc/nim" / filename if not fileExists(result): result = AbsoluteDir"/etc/nim" / filename +const nimRepoDirCT = currentSourcePath / ".." / ".." # this should be exposed somewhere + +proc getNimRoot*(conf: ConfigRef): AbsoluteDir = + ## returns root nim dir; works both with installed nim and local nim git repo. + ## This can be easily overridden if needed with NIM_ROOT_DIR environment variable + ## The result should satisfy: $result/doc/basicopt.txt exists + if conf.nimRootDir.isEmpty: + result = getEnv("NIM_ROOT_DIR").AbsoluteDir + if result.isEmpty: + if dirExists(nimRepoDirCT / ".git"): + result = nimRepoDirCT.AbsoluteDir + else: + result = AbsoluteDir getSystemConfigPath(conf, "".RelativeFile).`$` + # sanity check to make sure we have the right directory + let file = $result / "doc" / "basicopt.txt" + doAssert fileExists(file), $file + conf.nimRootDir = result + else: + result = conf.nimRootDir + proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) = setDefaultLibpath(conf) diff --git a/compiler/options.nim b/compiler/options.nim index 9c17ea1e6d835..68fa9a1abd523 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -246,6 +246,7 @@ type outFile*: RelativeFile outDir*: AbsoluteDir prefixDir*, libpath*, nimcacheDir*: AbsoluteDir + nimRootDir*: AbsoluteDir ## works both for install dir and local git nim repo dllOverrides, moduleOverrides*, cfileSpecificOptions*: StringTableRef projectName*: string # holds a name like 'nim' projectPath*: AbsoluteDir # holds a path like /home/alice/projects/nim/compiler/ From 834a34af5093a4e6184509800b8e311f39ce06bd Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 13 Jan 2020 13:55:41 -0800 Subject: [PATCH 3/5] remove NIM_ROOT_DIR --- compiler/nimconf.nim | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index e9dd16a409b23..f54e49e30fbfe 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -242,15 +242,12 @@ const nimRepoDirCT = currentSourcePath / ".." / ".." # this should be exposed so proc getNimRoot*(conf: ConfigRef): AbsoluteDir = ## returns root nim dir; works both with installed nim and local nim git repo. - ## This can be easily overridden if needed with NIM_ROOT_DIR environment variable - ## The result should satisfy: $result/doc/basicopt.txt exists + ## The result should satisfy: $result/doc/basicopt.txt exists as sanity check if conf.nimRootDir.isEmpty: - result = getEnv("NIM_ROOT_DIR").AbsoluteDir - if result.isEmpty: - if dirExists(nimRepoDirCT / ".git"): - result = nimRepoDirCT.AbsoluteDir - else: - result = AbsoluteDir getSystemConfigPath(conf, "".RelativeFile).`$` + if dirExists(nimRepoDirCT / ".git"): + result = nimRepoDirCT.AbsoluteDir + else: + result = AbsoluteDir getSystemConfigPath(conf, "".RelativeFile).`$` # sanity check to make sure we have the right directory let file = $result / "doc" / "basicopt.txt" doAssert fileExists(file), $file From dd6c025700762885c2c3c0cb1d16df75a6b01d15 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 14 Jan 2020 12:01:48 -0800 Subject: [PATCH 4/5] use getPrefixDir instead --- compiler/docgen.nim | 2 +- compiler/main.nim | 4 ++-- compiler/nimconf.nim | 17 ----------------- compiler/options.nim | 4 +++- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index b5c34a077df25..6f461faf44013 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -1076,7 +1076,7 @@ proc writeOutput*(d: PDoc, useWarning = false) = outfile.string) else: if not d.wroteCss: - let cssSource = getNimRoot(d.conf).string / "doc" / "nimdoc.css" + 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 copyFile(cssSource, cssDest) diff --git a/compiler/main.nim b/compiler/main.nim index 1e380f6ec9cd8..b12b7c194bc10 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -303,11 +303,11 @@ proc mainCommand*(graph: ModuleGraph) = let key = lineinfos.WarningsToStr[ord(a) - ord(warnMin)] warnings[key] = %(a in conf.notes) - let nimroot = getNimRoot(conf) + let prefixDir = conf.getPrefixDir() var dumpdata = %[ (key: "version", val: %VersionAsString), - (key: "nimroot", val: %nimroot.string), + (key: "prefixdir", val: %prefixDir.string), (key: "project_path", val: %conf.projectFull.string), (key: "defined_symbols", val: definedSymbols), (key: "lib_paths", val: %libpaths), diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index f54e49e30fbfe..93cc215734f3d 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -238,23 +238,6 @@ proc getSystemConfigPath*(conf: ConfigRef; filename: RelativeFile): AbsoluteFile if not fileExists(result): result = p / RelativeDir"etc/nim" / filename if not fileExists(result): result = AbsoluteDir"/etc/nim" / filename -const nimRepoDirCT = currentSourcePath / ".." / ".." # this should be exposed somewhere - -proc getNimRoot*(conf: ConfigRef): AbsoluteDir = - ## returns root nim dir; works both with installed nim and local nim git repo. - ## The result should satisfy: $result/doc/basicopt.txt exists as sanity check - if conf.nimRootDir.isEmpty: - if dirExists(nimRepoDirCT / ".git"): - result = nimRepoDirCT.AbsoluteDir - else: - result = AbsoluteDir getSystemConfigPath(conf, "".RelativeFile).`$` - # sanity check to make sure we have the right directory - let file = $result / "doc" / "basicopt.txt" - doAssert fileExists(file), $file - conf.nimRootDir = result - else: - result = conf.nimRootDir - proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) = setDefaultLibpath(conf) diff --git a/compiler/options.nim b/compiler/options.nim index 68fa9a1abd523..3866f4b7f3e03 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -246,7 +246,6 @@ type outFile*: RelativeFile outDir*: AbsoluteDir prefixDir*, libpath*, nimcacheDir*: AbsoluteDir - nimRootDir*: AbsoluteDir ## works both for install dir and local git nim repo dllOverrides, moduleOverrides*, cfileSpecificOptions*: StringTableRef projectName*: string # holds a name like 'nim' projectPath*: AbsoluteDir # holds a path like /home/alice/projects/nim/compiler/ @@ -510,6 +509,9 @@ proc getPrefixDir*(conf: ConfigRef): AbsoluteDir = ## ## This is overridden by some tools (namely nimsuggest) via the ``conf.prefixDir`` ## field. + ## This should resolve to root of nim sources, whether running nim from a local + ## clone or using installed nim, so that these exist: `result/doc/advopt.txt` + ## and `result/lib/system.nim` if not conf.prefixDir.isEmpty: result = conf.prefixDir else: result = AbsoluteDir splitPath(getAppDir()).head From ffaa4ac48674c2ad64e93e399673894154721447 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 15 Jan 2020 11:08:23 -0800 Subject: [PATCH 5/5] address comments --- compiler/docgen.nim | 18 ++++++++---------- compiler/main.nim | 4 +--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 6f461faf44013..505488e2717ce 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -1069,19 +1069,17 @@ proc writeOutput*(d: PDoc, useWarning = false) = else: template outfile: untyped = d.destFile #let outfile = getOutFile2(d.conf, shortenDir(d.conf, filename), outExt, "htmldocs") - let dir = outfile.`$`.parentDir - createDir(dir) + createDir(outfile.splitFile.dir) + d.conf.outFile = outfile.extractFilename.RelativeFile if not writeRope(content, outfile): rawMessage(d.conf, if useWarning: warnCannotOpenFile else: errCannotOpenFile, outfile.string) - else: - if 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 - copyFile(cssSource, cssDest) - d.wroteCss = true - d.conf.outFile = outfile.extractFilename.RelativeFile + 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 + copyFile(cssSource, cssDest) + d.wroteCss = true proc writeOutputJson*(d: PDoc, useWarning = false) = runAllExamples(d) diff --git a/compiler/main.nim b/compiler/main.nim index b12b7c194bc10..4e444bff7b80e 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -303,11 +303,9 @@ proc mainCommand*(graph: ModuleGraph) = let key = lineinfos.WarningsToStr[ord(a) - ord(warnMin)] warnings[key] = %(a in conf.notes) - let prefixDir = conf.getPrefixDir() - var dumpdata = %[ (key: "version", val: %VersionAsString), - (key: "prefixdir", val: %prefixDir.string), + (key: "prefixdir", val: %conf.getPrefixDir().string), (key: "project_path", val: %conf.projectFull.string), (key: "defined_symbols", val: definedSymbols), (key: "lib_paths", val: %libpaths),