koch.nim 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. #
  2. #
  3. # Maintenance program for Nim
  4. # (c) Copyright 2017 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. # See doc/koch.txt for documentation.
  10. #
  11. const
  12. NimbleStableCommit = "da82e3111e662fc1b12f96b3cddd66c749c0f686" # master
  13. when defined(gcc) and defined(windows):
  14. when defined(x86):
  15. {.link: "icons/koch.res".}
  16. else:
  17. {.link: "icons/koch_icon.o".}
  18. when defined(amd64) and defined(windows) and defined(vcc):
  19. {.link: "icons/koch-amd64-windows-vcc.res".}
  20. when defined(i386) and defined(windows) and defined(vcc):
  21. {.link: "icons/koch-i386-windows-vcc.res".}
  22. import
  23. os, strutils, parseopt, osproc, streams
  24. import tools / kochdocs
  25. const VersionAsString = system.NimVersion
  26. const
  27. HelpText = """
  28. +-----------------------------------------------------------------+
  29. | Maintenance program for Nim |
  30. | Version $1|
  31. | (c) 2017 Andreas Rumpf |
  32. +-----------------------------------------------------------------+
  33. Build time: $2, $3
  34. Usage:
  35. koch [options] command [options for command]
  36. Options:
  37. --help, -h shows this help and quits
  38. --latest bundle the installers with a bleeding edge Nimble
  39. --stable bundle the installers with a stable Nimble (default)
  40. Possible Commands:
  41. boot [options] bootstraps with given command line options
  42. distrohelper [bindir] helper for distro packagers
  43. tools builds Nim related tools
  44. toolsNoNimble builds Nim related tools (except nimble)
  45. doesn't require network connectivity
  46. nimble builds the Nimble tool
  47. Boot options:
  48. -d:release produce a release version of the compiler
  49. -d:useLinenoise use the linenoise library for interactive mode
  50. (not needed on Windows)
  51. -d:leanCompiler produce a compiler without JS codegen or
  52. documentation generator in order to use less RAM
  53. for bootstrapping
  54. Commands for core developers:
  55. runCI runs continuous integration (CI), eg from travis
  56. docs [options] generates the full documentation
  57. csource -d:release builds the C sources for installation
  58. pdf builds the PDF documentation
  59. zip builds the installation zip package
  60. xz builds the installation tar.xz package
  61. testinstall test tar.xz package; Unix only!
  62. tests [options] run the testsuite (run a subset of tests by
  63. specifying a category, e.g. `tests cat async`)
  64. temp options creates a temporary compiler for testing
  65. pushcsource push generated C sources to its repo
  66. Web options:
  67. --googleAnalytics:UA-... add the given google analytics code to the docs. To
  68. build the official docs, use UA-48159761-1
  69. """
  70. let kochExe* = when isMainModule: os.getAppFilename() # always correct when koch is main program, even if `koch` exe renamed eg: `nim c -o:koch_debug koch.nim`
  71. else: getAppDir() / "koch".exe # works for winrelease
  72. proc kochExec*(cmd: string) =
  73. exec kochExe.quoteShell & " " & cmd
  74. proc kochExecFold*(desc, cmd: string) =
  75. execFold(desc, kochExe.quoteShell & " " & cmd)
  76. template withDir(dir, body) =
  77. let old = getCurrentDir()
  78. try:
  79. setCurrentDir(dir)
  80. body
  81. finally:
  82. setCurrentDir(old)
  83. let origDir = getCurrentDir()
  84. setCurrentDir(getAppDir())
  85. proc tryExec(cmd: string): bool =
  86. echo(cmd)
  87. result = execShellCmd(cmd) == 0
  88. proc safeRemove(filename: string) =
  89. if existsFile(filename): removeFile(filename)
  90. proc overwriteFile(source, dest: string) =
  91. safeRemove(dest)
  92. moveFile(source, dest)
  93. proc copyExe(source, dest: string) =
  94. safeRemove(dest)
  95. copyFile(dest=dest, source=source)
  96. inclFilePermissions(dest, {fpUserExec, fpGroupExec, fpOthersExec})
  97. const
  98. compileNimInst = "tools/niminst/niminst"
  99. proc csource(args: string) =
  100. nimexec(("cc $1 -r $3 --var:version=$2 --var:mingw=none csource " &
  101. "--main:compiler/nim.nim compiler/installer.ini $1") %
  102. [args, VersionAsString, compileNimInst])
  103. proc bundleC2nim(args: string) =
  104. if not dirExists("dist/c2nim/.git"):
  105. exec("git clone https://github.com/nim-lang/c2nim.git dist/c2nim")
  106. nimCompile("dist/c2nim/c2nim",
  107. options = "--noNimblePath --path:. " & args)
  108. proc bundleNimbleExe(latest: bool, args: string) =
  109. if not dirExists("dist/nimble/.git"):
  110. exec("git clone https://github.com/nim-lang/nimble.git dist/nimble")
  111. if not latest:
  112. withDir("dist/nimble"):
  113. exec("git fetch")
  114. exec("git checkout " & NimbleStableCommit)
  115. # installer.ini expects it under $nim/bin
  116. nimCompile("dist/nimble/src/nimble.nim",
  117. options = "-d:release --nilseqs:on " & args)
  118. proc buildNimble(latest: bool, args: string) =
  119. # if koch is used for a tar.xz, build the dist/nimble we shipped
  120. # with the tarball:
  121. var installDir = "dist/nimble"
  122. if not latest and dirExists(installDir) and not dirExists("dist/nimble/.git"):
  123. discard "don't do the git dance"
  124. else:
  125. if not dirExists("dist/nimble/.git"):
  126. if dirExists(installDir):
  127. var id = 0
  128. while dirExists("dist/nimble" & $id):
  129. inc id
  130. installDir = "dist/nimble" & $id
  131. exec("git clone https://github.com/nim-lang/nimble.git " & installDir)
  132. withDir(installDir):
  133. if latest:
  134. exec("git checkout -f master")
  135. exec("git pull")
  136. else:
  137. exec("git fetch")
  138. exec("git checkout " & NimbleStableCommit)
  139. nimCompile(installDir / "src/nimble.nim",
  140. options = "--noNimblePath --nilseqs:on -d:release " & args)
  141. proc bundleNimsuggest(args: string) =
  142. nimCompileFold("Compile nimsuggest", "nimsuggest/nimsuggest.nim",
  143. options = "-d:release -d:danger " & args)
  144. proc buildVccTool(args: string) =
  145. nimCompileFold("Compile Vcc", "tools/vccexe/vccexe.nim ", options = args)
  146. proc bundleWinTools(args: string) =
  147. nimCompile("tools/finish.nim", outputDir = "", options = args)
  148. buildVccTool(args)
  149. nimCompile("tools/nimgrab.nim", options = "-d:ssl " & args)
  150. nimCompile("tools/nimgrep.nim", options = args)
  151. bundleC2nim(args)
  152. when false:
  153. # not yet a tool worth including
  154. nimCompile(r"tools\downloader.nim",
  155. options = r"--cc:vcc --app:gui -d:ssl --noNimblePath --path:..\ui " & args)
  156. proc zip(latest: bool; args: string) =
  157. bundleNimbleExe(latest, args)
  158. bundleNimsuggest(args)
  159. bundleWinTools(args)
  160. nimexec("cc -r $2 --var:version=$1 --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" %
  161. [VersionAsString, compileNimInst])
  162. exec("$# --var:version=$# --var:mingw=none --main:compiler/nim.nim zip compiler/installer.ini" %
  163. ["tools/niminst/niminst".exe, VersionAsString])
  164. proc ensureCleanGit() =
  165. let (outp, status) = osproc.execCmdEx("git diff")
  166. if outp.len != 0:
  167. quit "Not a clean git repository; 'git diff' not empty!"
  168. if status != 0:
  169. quit "Not a clean git repository; 'git diff' returned non-zero!"
  170. proc xz(latest: bool; args: string) =
  171. ensureCleanGit()
  172. nimexec("cc -r $2 --var:version=$1 --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" %
  173. [VersionAsString, compileNimInst])
  174. exec("$# --var:version=$# --var:mingw=none --main:compiler/nim.nim xz compiler/installer.ini" %
  175. ["tools" / "niminst" / "niminst".exe, VersionAsString])
  176. proc buildTool(toolname, args: string) =
  177. nimexec("cc $# $#" % [args, toolname])
  178. copyFile(dest="bin" / splitFile(toolname).name.exe, source=toolname.exe)
  179. proc buildTools(args: string = "") =
  180. bundleNimsuggest(args)
  181. nimCompileFold("Compile nimgrep", "tools/nimgrep.nim",
  182. options = "-d:release " & args)
  183. when defined(windows): buildVccTool(args)
  184. nimCompileFold("Compile nimpretty", "nimpretty/nimpretty.nim",
  185. options = "-d:release " & args)
  186. nimCompileFold("Compile nimfind", "tools/nimfind.nim",
  187. options = "-d:release " & args)
  188. proc nsis(latest: bool; args: string) =
  189. bundleNimbleExe(latest, args)
  190. bundleNimsuggest(args)
  191. bundleWinTools(args)
  192. # make sure we have generated the niminst executables:
  193. buildTool("tools/niminst/niminst", args)
  194. #buildTool("tools/nimgrep", args)
  195. # produce 'nim_debug.exe':
  196. #exec "nim c compiler" / "nim.nim"
  197. #copyExe("compiler/nim".exe, "bin/nim_debug".exe)
  198. exec(("tools" / "niminst" / "niminst --var:version=$# --var:mingw=mingw$#" &
  199. " nsis compiler/installer.ini") % [VersionAsString, $(sizeof(pointer)*8)])
  200. proc geninstall(args="") =
  201. nimexec("cc -r $# --var:version=$# --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini $#" %
  202. [compileNimInst, VersionAsString, args])
  203. proc install(args: string) =
  204. geninstall()
  205. exec("sh ./install.sh $#" % args)
  206. when false:
  207. proc web(args: string) =
  208. nimexec("js tools/dochack/dochack.nim")
  209. nimexec("cc -r tools/nimweb.nim $# web/website.ini --putenv:nimversion=$#" %
  210. [args, VersionAsString])
  211. proc website(args: string) =
  212. nimexec("cc -r tools/nimweb.nim $# --website web/website.ini --putenv:nimversion=$#" %
  213. [args, VersionAsString])
  214. proc pdf(args="") =
  215. exec("$# cc -r tools/nimweb.nim $# --pdf web/website.ini --putenv:nimversion=$#" %
  216. [findNim(), args, VersionAsString], additionalPATH=findNim().splitFile.dir)
  217. # -------------- boot ---------------------------------------------------------
  218. proc findStartNim: string =
  219. # we try several things before giving up:
  220. # * bin/nim
  221. # * $PATH/nim
  222. # If these fail, we try to build nim with the "build.(sh|bat)" script.
  223. var nim = "nim".exe
  224. result = "bin" / nim
  225. if existsFile(result): return
  226. for dir in split(getEnv("PATH"), PathSep):
  227. if existsFile(dir / nim): return dir / nim
  228. when defined(Posix):
  229. const buildScript = "build.sh"
  230. if existsFile(buildScript):
  231. if tryExec("./" & buildScript): return "bin" / nim
  232. else:
  233. const buildScript = "build.bat"
  234. if existsFile(buildScript):
  235. if tryExec(buildScript): return "bin" / nim
  236. echo("Found no nim compiler and every attempt to build one failed!")
  237. quit("FAILURE")
  238. proc thVersion(i: int): string =
  239. result = ("compiler" / "nim" & $i).exe
  240. proc boot(args: string) =
  241. var output = "compiler" / "nim".exe
  242. var finalDest = "bin" / "nim".exe
  243. # default to use the 'c' command:
  244. let useCpp = getEnv("NIM_COMPILE_TO_CPP", "false") == "true"
  245. let smartNimcache = (if "release" in args or "danger" in args: "nimcache/r_" else: "nimcache/d_") &
  246. hostOS & "_" & hostCPU
  247. let nimStart = findStartNim()
  248. for i in 0..2:
  249. let defaultCommand = if useCpp: "cpp" else: "c"
  250. let bootOptions = if args.len == 0 or args.startsWith("-"): defaultCommand else: ""
  251. echo "iteration: ", i+1
  252. var extraOption = ""
  253. var nimi = i.thVersion
  254. if i == 0:
  255. nimi = nimStart
  256. extraOption.add " --skipUserCfg --skipParentCfg"
  257. # The configs are skipped for bootstrap
  258. # (1st iteration) to prevent newer flags from breaking bootstrap phase.
  259. let ret = execCmdEx(nimStart & " --version")
  260. doAssert ret.exitCode == 0
  261. let version = ret.output.splitLines[0]
  262. if version.startsWith "Nim Compiler Version 0.19.0":
  263. extraOption.add " -d:nimBoostrapCsources0_19_0"
  264. # remove this when csources get updated
  265. # in order to use less memory, we split the build into two steps:
  266. # --compileOnly produces a $project.json file and does not run GCC/Clang.
  267. # jsonbuild then uses the $project.json file to build the Nim binary.
  268. exec "$# $# $# $# --nimcache:$# --compileOnly compiler" / "nim.nim" %
  269. [nimi, bootOptions, extraOption, args, smartNimcache]
  270. exec "$# jsonscript --nimcache:$# compiler" / "nim.nim" %
  271. [nimi, smartNimcache]
  272. if sameFileContent(output, i.thVersion):
  273. copyExe(output, finalDest)
  274. echo "executables are equal: SUCCESS!"
  275. return
  276. copyExe(output, (i+1).thVersion)
  277. copyExe(output, finalDest)
  278. when not defined(windows): echo "[Warning] executables are still not equal"
  279. # -------------- clean --------------------------------------------------------
  280. const
  281. cleanExt = [
  282. ".ppu", ".o", ".obj", ".dcu", ".~pas", ".~inc", ".~dsk", ".~dpr",
  283. ".map", ".tds", ".err", ".bak", ".pyc", ".exe", ".rod", ".pdb", ".idb",
  284. ".idx", ".ilk"
  285. ]
  286. ignore = [
  287. ".bzrignore", "nim", "nim.exe", "koch", "koch.exe", ".gitignore"
  288. ]
  289. proc cleanAux(dir: string) =
  290. for kind, path in walkDir(dir):
  291. case kind
  292. of pcFile:
  293. var (_, name, ext) = splitFile(path)
  294. if ext == "" or cleanExt.contains(ext):
  295. if not ignore.contains(name):
  296. echo "removing: ", path
  297. removeFile(path)
  298. of pcDir:
  299. case splitPath(path).tail
  300. of "nimcache":
  301. echo "removing dir: ", path
  302. removeDir(path)
  303. of "dist", ".git", "icons": discard
  304. else: cleanAux(path)
  305. else: discard
  306. proc removePattern(pattern: string) =
  307. for f in walkFiles(pattern):
  308. echo "removing: ", f
  309. removeFile(f)
  310. proc clean(args: string) =
  311. removePattern("web/*.html")
  312. removePattern("doc/*.html")
  313. cleanAux(getCurrentDir())
  314. for kind, path in walkDir(getCurrentDir() / "build"):
  315. if kind == pcDir:
  316. echo "removing dir: ", path
  317. removeDir(path)
  318. # -------------- builds a release ---------------------------------------------
  319. proc winReleaseArch(arch: string) =
  320. doAssert arch in ["32", "64"]
  321. let cpu = if arch == "32": "i386" else: "amd64"
  322. template withMingw(path, body) =
  323. let prevPath = getEnv("PATH")
  324. putEnv("PATH", (if path.len > 0: path & PathSep else: "") & prevPath)
  325. try:
  326. body
  327. finally:
  328. putEnv("PATH", prevPath)
  329. withMingw r"..\mingw" & arch & r"\bin":
  330. # Rebuilding koch is necessary because it uses its pointer size to
  331. # determine which mingw link to put in the NSIS installer.
  332. inFold "winrelease koch":
  333. nimexec "c --cpu:$# koch" % cpu
  334. kochExecFold("winrelease boot", "boot -d:release --cpu:$#" % cpu)
  335. kochExecFold("winrelease zip", "zip -d:release")
  336. overwriteFile r"build\nim-$#.zip" % VersionAsString,
  337. r"web\upload\download\nim-$#_x$#.zip" % [VersionAsString, arch]
  338. proc winRelease*() =
  339. # Now used from "tools/winrelease" and not directly supported by koch
  340. # anymore!
  341. # Build -docs file:
  342. when true:
  343. inFold "winrelease buildDocs":
  344. buildDocs(gaCode)
  345. withDir "web/upload/" & VersionAsString:
  346. inFold "winrelease zipdocs":
  347. exec "7z a -tzip docs-$#.zip *.html" % VersionAsString
  348. overwriteFile "web/upload/$1/docs-$1.zip" % VersionAsString,
  349. "web/upload/download/docs-$1.zip" % VersionAsString
  350. when true:
  351. inFold "winrelease csource":
  352. csource("-d:release")
  353. when sizeof(pointer) == 4:
  354. winReleaseArch "32"
  355. when sizeof(pointer) == 8:
  356. winReleaseArch "64"
  357. # -------------- tests --------------------------------------------------------
  358. template `|`(a, b): string = (if a.len > 0: a else: b)
  359. proc tests(args: string) =
  360. nimexec "cc --opt:speed testament/tester"
  361. let tester = quoteShell(getCurrentDir() / "testament/tester".exe)
  362. let success = tryExec tester & " " & (args|"all")
  363. if not success:
  364. quit("tests failed", QuitFailure)
  365. proc temp(args: string) =
  366. proc splitArgs(a: string): (string, string) =
  367. # every --options before the command (indicated by starting
  368. # with not a dash) is part of the bootArgs, the rest is part
  369. # of the programArgs:
  370. let args = os.parseCmdLine a
  371. result = ("", "")
  372. var i = 0
  373. while i < args.len and args[i][0] == '-':
  374. result[0].add " " & quoteShell(args[i])
  375. inc i
  376. while i < args.len:
  377. result[1].add " " & quoteShell(args[i])
  378. inc i
  379. let d = getAppDir()
  380. var output = d / "compiler" / "nim".exe
  381. var finalDest = d / "bin" / "nim_temp".exe
  382. # 125 is the magic number to tell git bisect to skip the current commit.
  383. var (bootArgs, programArgs) = splitArgs(args)
  384. if "doc" notin programArgs and
  385. "threads" notin programArgs and
  386. "js" notin programArgs:
  387. bootArgs.add " -d:leanCompiler"
  388. let nimexec = findNim()
  389. exec(nimexec & " c -d:debug --debugger:native -d:nimBetterRun " & bootArgs & " " & (d / "compiler" / "nim"), 125)
  390. copyExe(output, finalDest)
  391. setCurrentDir(origDir)
  392. if programArgs.len > 0: exec(finalDest & " " & programArgs)
  393. proc xtemp(cmd: string) =
  394. let d = getAppDir()
  395. copyExe(d / "bin" / "nim".exe, d / "bin" / "nim_backup".exe)
  396. try:
  397. withDir(d):
  398. temp""
  399. copyExe(d / "bin" / "nim_temp".exe, d / "bin" / "nim".exe)
  400. exec(cmd)
  401. finally:
  402. copyExe(d / "bin" / "nim_backup".exe, d / "bin" / "nim".exe)
  403. proc runCI(cmd: string) =
  404. doAssert cmd.len == 0, cmd # avoid silently ignoring
  405. echo "runCI:", cmd
  406. # note(@araq): Do not replace these commands with direct calls (eg boot())
  407. # as that would weaken our testing efforts.
  408. when defined(posix): # appveyor (on windows) didn't run this
  409. kochExecFold("Boot", "boot")
  410. # boot without -d:nimHasLibFFI to make sure this still works
  411. kochExecFold("Boot in release mode", "boot -d:release -d:danger")
  412. ## build nimble early on to enable remainder to depend on it if needed
  413. kochExecFold("Build Nimble", "nimble")
  414. when false:
  415. execFold("nimble install -y libffi", "nimble install -y libffi")
  416. kochExecFold("boot -d:release -d:nimHasLibFFI", "boot -d:release -d:nimHasLibFFI")
  417. if getEnv("NIM_TEST_PACKAGES", "false") == "true":
  418. execFold("Test selected Nimble packages", "nim c -r testament/tester cat nimble-packages")
  419. else:
  420. buildTools() # altenatively, kochExec "tools --toolsNoNimble"
  421. ## run tests
  422. execFold("Test nimscript", "nim e tests/test_nimscript.nims")
  423. when defined(windows):
  424. # note: will be over-written below
  425. execFold("Compile tester", "nim c -d:nimCoroutines --os:genode -d:posix --compileOnly testament/tester")
  426. # main bottleneck here
  427. execFold("Run tester", "nim c -r -d:nimCoroutines testament/tester --pedantic all -d:nimCoroutines")
  428. execFold("Run nimdoc tests", "nim c -r nimdoc/tester")
  429. execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim")
  430. when defined(posix):
  431. execFold("Run nimsuggest tests", "nim c -r nimsuggest/tester")
  432. ## remaining actions
  433. when defined(posix):
  434. kochExecFold("Docs", "docs --git.commit:devel")
  435. kochExecFold("C sources", "csource")
  436. elif defined(windows):
  437. when false:
  438. kochExec "csource"
  439. kochExec "zip"
  440. proc pushCsources() =
  441. if not dirExists("../csources/.git"):
  442. quit "[Error] no csources git repository found"
  443. csource("-d:release")
  444. let cwd = getCurrentDir()
  445. try:
  446. copyDir("build/c_code", "../csources/c_code")
  447. copyFile("build/build.sh", "../csources/build.sh")
  448. copyFile("build/build.bat", "../csources/build.bat")
  449. copyFile("build/build64.bat", "../csources/build64.bat")
  450. copyFile("build/makefile", "../csources/makefile")
  451. setCurrentDir("../csources")
  452. for kind, path in walkDir("c_code"):
  453. if kind == pcDir:
  454. exec("git add " & path / "*.c")
  455. exec("git commit -am \"updated csources to version " & NimVersion & "\"")
  456. exec("git push origin master")
  457. exec("git tag -am \"Version $1\" v$1" % NimVersion)
  458. exec("git push origin v$1" % NimVersion)
  459. finally:
  460. setCurrentDir(cwd)
  461. proc testUnixInstall(cmdLineRest: string) =
  462. csource("-d:release " & cmdLineRest)
  463. xz(false, cmdLineRest)
  464. let oldCurrentDir = getCurrentDir()
  465. try:
  466. let destDir = getTempDir()
  467. copyFile("build/nim-$1.tar.xz" % VersionAsString,
  468. destDir / "nim-$1.tar.xz" % VersionAsString)
  469. setCurrentDir(destDir)
  470. execCleanPath("tar -xJf nim-$1.tar.xz" % VersionAsString)
  471. setCurrentDir("nim-$1" % VersionAsString)
  472. execCleanPath("sh build.sh")
  473. # first test: try if './bin/nim --version' outputs something sane:
  474. let output = execProcess("./bin/nim --version").splitLines
  475. if output.len > 0 and output[0].contains(VersionAsString):
  476. echo "Version check: success"
  477. execCleanPath("./bin/nim c koch.nim")
  478. execCleanPath("./koch boot -d:release", destDir / "bin")
  479. # check the docs build:
  480. execCleanPath("./koch docs", destDir / "bin")
  481. # check nimble builds:
  482. execCleanPath("./koch tools")
  483. # check the tests work:
  484. putEnv("NIM_EXE_NOT_IN_PATH", "NOT_IN_PATH")
  485. execCleanPath("./koch tests --nim:./bin/nim cat megatest", destDir / "bin")
  486. else:
  487. echo "Version check: failure"
  488. finally:
  489. setCurrentDir oldCurrentDir
  490. proc valgrind(cmd: string) =
  491. # somewhat hacky: '=' sign means "pass to valgrind" else "pass to Nim"
  492. let args = parseCmdLine(cmd)
  493. var nimcmd = ""
  494. var valcmd = ""
  495. for i, a in args:
  496. if i == args.len-1:
  497. # last element is the filename:
  498. valcmd.add ' '
  499. valcmd.add changeFileExt(a, ExeExt)
  500. nimcmd.add ' '
  501. nimcmd.add a
  502. elif '=' in a:
  503. valcmd.add ' '
  504. valcmd.add a
  505. else:
  506. nimcmd.add ' '
  507. nimcmd.add a
  508. exec("nim c" & nimcmd)
  509. let supp = getAppDir() / "tools" / "nimgrind.supp"
  510. exec("valgrind --suppressions=" & supp & valcmd)
  511. proc showHelp() =
  512. quit(HelpText % [VersionAsString & spaces(44-len(VersionAsString)),
  513. CompileDate, CompileTime], QuitSuccess)
  514. when isMainModule:
  515. var op = initOptParser()
  516. var latest = false
  517. while true:
  518. op.next()
  519. case op.kind
  520. of cmdLongOption, cmdShortOption:
  521. case normalize(op.key)
  522. of "latest": latest = true
  523. of "stable": latest = false
  524. else: showHelp()
  525. of cmdArgument:
  526. case normalize(op.key)
  527. of "boot": boot(op.cmdLineRest)
  528. of "clean": clean(op.cmdLineRest)
  529. of "doc", "docs": buildDocs(op.cmdLineRest)
  530. of "doc0", "docs0":
  531. # undocumented command for Araq-the-merciful:
  532. buildDocs(op.cmdLineRest & gaCode)
  533. of "pdf": buildPdfDoc(op.cmdLineRest, "doc/pdf")
  534. of "csource", "csources": csource(op.cmdLineRest)
  535. of "zip": zip(latest, op.cmdLineRest)
  536. of "xz": xz(latest, op.cmdLineRest)
  537. of "nsis": nsis(latest, op.cmdLineRest)
  538. of "geninstall": geninstall(op.cmdLineRest)
  539. of "distrohelper": geninstall()
  540. of "install": install(op.cmdLineRest)
  541. of "testinstall": testUnixInstall(op.cmdLineRest)
  542. of "runci": runCI(op.cmdLineRest)
  543. of "test", "tests": tests(op.cmdLineRest)
  544. of "temp": temp(op.cmdLineRest)
  545. of "xtemp": xtemp(op.cmdLineRest)
  546. of "wintools": bundleWinTools(op.cmdLineRest)
  547. of "nimble": buildNimble(latest, op.cmdLineRest)
  548. of "nimsuggest": bundleNimsuggest(op.cmdLineRest)
  549. of "toolsnonimble":
  550. buildTools(op.cmdLineRest)
  551. of "tools":
  552. buildTools(op.cmdLineRest)
  553. buildNimble(latest, op.cmdLineRest)
  554. of "pushcsource", "pushcsources": pushCsources()
  555. of "valgrind": valgrind(op.cmdLineRest)
  556. of "c2nim": bundleC2nim(op.cmdLineRest)
  557. else: showHelp()
  558. break
  559. of cmdEnd: break