nimpaths.nim 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 std/[os, strutils]
  17. when defined(nimPreviewSlimSystem):
  18. import std/assertions
  19. const
  20. docCss* = "$nimr/doc/nimdoc.css"
  21. docCls* = "$nimr/doc/nimdoc.cls"
  22. docHackNim* = "$nimr/tools/dochack/dochack.nim"
  23. docHackJs* = docHackNim.changeFileExt("js")
  24. docHackJsFname* = docHackJs.lastPathPart
  25. theindexFname* = "theindex.html"
  26. nimdocOutCss* = "nimdoc.out.css"
  27. nimdocOutCls* = "nimdoc.cls"
  28. # `out` to make it easier to use with gitignore in user's repos
  29. htmldocsDirname* = "htmldocs"
  30. dotdotMangle* = "_._" ## refs #13223
  31. # if this changes, make sure it's consistent with `esc` and `escapeLink`
  32. # lots of other obvious options won't work, see #14454; `_` could work too
  33. proc interp*(path: string, nimr: string): string =
  34. result = path % ["nimr", nimr]
  35. doAssert '$' notin result, $(path, nimr, result) # avoids un-interpolated variables in output
  36. proc getDocHacksJs*(nimr: string, nim = getCurrentCompilerExe(), forceRebuild = false): string =
  37. ## return absolute path to dochack.js, rebuilding if it doesn't exist or if
  38. ## `forceRebuild`.
  39. let docHackJs2 = docHackJs.interp(nimr = nimr)
  40. if forceRebuild or not docHackJs2.fileExists:
  41. let cmd = "$nim js -d:release $file" % ["nim", nim.quoteShell, "file", docHackNim.interp(nimr = nimr).quoteShell]
  42. echo "getDocHacksJs: cmd: " & cmd
  43. doAssert execShellCmd(cmd) == 0, $(cmd)
  44. doAssert docHackJs2.fileExists
  45. result = docHackJs2