Skip to content

Commit

Permalink
use getNimRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jan 13, 2020
1 parent 87446c8 commit 8fa348b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 2 additions & 4 deletions compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1049,8 +1049,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)
Expand All @@ -1066,7 +1064,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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/installer.ini
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,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"
16 changes: 16 additions & 0 deletions compiler/nimconf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,22 @@ 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
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

proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) =
setDefaultLibpath(conf)

Expand Down

0 comments on commit 8fa348b

Please sign in to comment.