nimpaths.nim 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 consider some refactoring with $nim/testament/lib/stdtest/specialpaths.nim;
  6. specialpaths is simpler because it doesn't need variables to be relocatable at
  7. runtime (eg for use in testament)
  8. interpolation variables:
  9. $nimr: such that `$nimr/lib/system.nim` exists (avoids confusion with $nim binary)
  10. in compiler, it's obtainable via getPrefixDir(); for other tools (eg koch),
  11. this could be getCurrentDir() or getAppFilename().parentDir.parentDir,
  12. depending on use case
  13. Unstable API
  14. ]##
  15. import std/[os,strutils]
  16. const
  17. docCss* = "$nimr/doc/nimdoc.css"
  18. docHackNim* = "$nimr/tools/dochack/dochack.nim"
  19. docHackJs* = docHackNim.changeFileExt("js")
  20. docHackJsFname* = docHackJs.lastPathPart
  21. theindexFname* = "theindex.html"
  22. nimdocOutCss* = "nimdoc.out.css"
  23. # `out` to make it easier to use with gitignore in user's repos
  24. htmldocsDirname* = "htmldocs"
  25. dotdotMangle* = "_._" ## refs #13223
  26. # if this changes, make sure it's consistent with `esc` and `escapeLink`
  27. # lots of other obvious options won't work, see #14454; `_` could work too
  28. proc interp*(path: string, nimr: string): string =
  29. result = path % ["nimr", nimr]
  30. doAssert '$' notin result, $(path, nimr, result) # avoids un-interpolated variables in output
  31. proc getDocHacksJs*(nimr: string, nim = getCurrentCompilerExe(), forceRebuild = false): string =
  32. ## return absolute path to dochhack.js, rebuilding if it doesn't exist or if
  33. ## `forceRebuild`.
  34. let docHackJs2 = docHackJs.interp(nimr = nimr)
  35. if forceRebuild or not docHackJs2.fileExists:
  36. let cmd = "$nim js $file" % ["nim", nim.quoteShell, "file", docHackNim.interp(nimr = nimr).quoteShell]
  37. echo "getDocHacksJs: cmd: " & cmd
  38. doAssert execShellCmd(cmd) == 0, $(cmd)
  39. doAssert docHackJs2.fileExists
  40. result = docHackJs2