koch.nim 22 KB

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