nimpaths.nim 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ##[
  2. Represents absolute paths, but using a symbolic variables (eg $nimr) which can be
  3. resolved at runtime; this avoids hardcoding at compile time absolute paths so
  4. that the project root can be relocated.
  5. xxx factor pending https://github.com/timotheecour/Nim/issues/616, see also
  6. $nim/testament/lib/stdtest/specialpaths.nim
  7. specialpaths is simpler because it doesn't need variables to be relocatable at
  8. runtime (eg for use in testament)
  9. interpolation variables:
  10. $nimr: such that `$nimr/lib/system.nim` exists (avoids confusion with $nim binary)
  11. in compiler, it's obtainable via getPrefixDir(); for other tools (eg koch),
  12. this could be getCurrentDir() or getAppFilename().parentDir.parentDir,
  13. depending on use case
  14. Unstable API
  15. ]##
  16. import os, strutils
  17. const
  18. docCss* = "$nimr/doc/nimdoc.css"
  19. docHackNim* = "$nimr/tools/dochack/dochack.nim"
  20. docHackJs* = docHackNim.changeFileExt("js")
  21. docHackJsFname* = docHackJs.lastPathPart
  22. theindexFname* = "theindex.html"
  23. nimdocOutCss* = "nimdoc.out.css"
  24. # `out` to make it easier to use with gitignore in user's repos
  25. htmldocsDirname* = "htmldocs"
  26. dotdotMangle* = "_._" ## refs #13223
  27. # if this changes, make sure it's consistent with `esc` and `escapeLink`
  28. # lots of other obvious options won't work, see #14454; `_` could work too
  29. proc interp*(path: string, nimr: string): string =
  30. result = path % ["nimr", nimr]
  31. doAssert '$' notin result, $(path, nimr, result) # avoids un-interpolated variables in output
  32. proc getDocHacksJs*(nimr: string, nim = getCurrentCompilerExe(), forceRebuild = false): string =
  33. ## return absolute path to dochack.js, rebuilding if it doesn't exist or if
  34. ## `forceRebuild`.
  35. let docHackJs2 = docHackJs.interp(nimr = nimr)
  36. if forceRebuild or not docHackJs2.fileExists:
  37. let cmd = "$nim js -d:release $file" % ["nim", nim.quoteShell, "file", docHackNim.interp(nimr = nimr).quoteShell]
  38. echo "getDocHacksJs: cmd: " & cmd
  39. doAssert execShellCmd(cmd) == 0, $(cmd)
  40. doAssert docHackJs2.fileExists
  41. result = docHackJs2