koch.nim 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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 = "4007b2a778429a978e12307bf13a038029b4c4d9" # 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 bundleNimpretty(args: string) =
  147. nimCompileFold("Compile nimpretty", "nimpretty/nimpretty.nim",
  148. options = "-d:release " & args)
  149. proc bundleWinTools(args: string) =
  150. nimCompile("tools/finish.nim", outputDir = "", options = args)
  151. buildVccTool(args)
  152. nimCompile("tools/nimgrab.nim", options = "-d:ssl " & args)
  153. nimCompile("tools/nimgrep.nim", options = args)
  154. bundleC2nim(args)
  155. nimCompile("testament/testament.nim", options = args)
  156. when false:
  157. # not yet a tool worth including
  158. nimCompile(r"tools\downloader.nim",
  159. options = r"--cc:vcc --app:gui -d:ssl --noNimblePath --path:..\ui " & args)
  160. proc zip(latest: bool; args: string) =
  161. bundleNimbleExe(latest, args)
  162. bundleNimsuggest(args)
  163. bundleNimpretty(args)
  164. bundleWinTools(args)
  165. nimexec("cc -r $2 --var:version=$1 --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" %
  166. [VersionAsString, compileNimInst])
  167. exec("$# --var:version=$# --var:mingw=none --main:compiler/nim.nim zip compiler/installer.ini" %
  168. ["tools/niminst/niminst".exe, VersionAsString])
  169. proc ensureCleanGit() =
  170. let (outp, status) = osproc.execCmdEx("git diff")
  171. if outp.len != 0:
  172. quit "Not a clean git repository; 'git diff' not empty!"
  173. if status != 0:
  174. quit "Not a clean git repository; 'git diff' returned non-zero!"
  175. proc xz(latest: bool; args: string) =
  176. ensureCleanGit()
  177. nimexec("cc -r $2 --var:version=$1 --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" %
  178. [VersionAsString, compileNimInst])
  179. exec("$# --var:version=$# --var:mingw=none --main:compiler/nim.nim xz compiler/installer.ini" %
  180. ["tools" / "niminst" / "niminst".exe, VersionAsString])
  181. proc buildTool(toolname, args: string) =
  182. nimexec("cc $# $#" % [args, toolname])
  183. copyFile(dest="bin" / splitFile(toolname).name.exe, source=toolname.exe)
  184. proc buildTools(args: string = "") =
  185. bundleNimsuggest(args)
  186. nimCompileFold("Compile nimgrep", "tools/nimgrep.nim",
  187. options = "-d:release " & args)
  188. when defined(windows): buildVccTool(args)
  189. bundleNimpretty(args)
  190. nimCompileFold("Compile nimfind", "tools/nimfind.nim",
  191. options = "-d:release " & args)
  192. nimCompileFold("Compile testament", "testament/testament.nim",
  193. options = "-d:release " & args)
  194. proc nsis(latest: bool; args: string) =
  195. bundleNimbleExe(latest, args)
  196. bundleNimsuggest(args)
  197. bundleWinTools(args)
  198. # make sure we have generated the niminst executables:
  199. buildTool("tools/niminst/niminst", args)
  200. #buildTool("tools/nimgrep", args)
  201. # produce 'nim_debug.exe':
  202. #exec "nim c compiler" / "nim.nim"
  203. #copyExe("compiler/nim".exe, "bin/nim_debug".exe)
  204. exec(("tools" / "niminst" / "niminst --var:version=$# --var:mingw=mingw$#" &
  205. " nsis compiler/installer.ini") % [VersionAsString, $(sizeof(pointer)*8)])
  206. proc geninstall(args="") =
  207. nimexec("cc -r $# --var:version=$# --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini $#" %
  208. [compileNimInst, VersionAsString, args])
  209. proc install(args: string) =
  210. geninstall()
  211. exec("sh ./install.sh $#" % args)
  212. when false:
  213. proc web(args: string) =
  214. nimexec("js tools/dochack/dochack.nim")
  215. nimexec("cc -r tools/nimweb.nim $# web/website.ini --putenv:nimversion=$#" %
  216. [args, VersionAsString])
  217. proc website(args: string) =
  218. nimexec("cc -r tools/nimweb.nim $# --website web/website.ini --putenv:nimversion=$#" %
  219. [args, VersionAsString])
  220. proc pdf(args="") =
  221. exec("$# cc -r tools/nimweb.nim $# --pdf web/website.ini --putenv:nimversion=$#" %
  222. [findNim(), args, VersionAsString], additionalPATH=findNim().splitFile.dir)
  223. # -------------- boot ---------------------------------------------------------
  224. proc findStartNim: string =
  225. # we try several things before giving up:
  226. # * bin/nim
  227. # * $PATH/nim
  228. # If these fail, we try to build nim with the "build.(sh|bat)" script.
  229. var nim = "nim".exe
  230. result = "bin" / nim
  231. if existsFile(result): return
  232. for dir in split(getEnv("PATH"), PathSep):
  233. if existsFile(dir / nim): return dir / nim
  234. when defined(Posix):
  235. const buildScript = "build.sh"
  236. if existsFile(buildScript):
  237. if tryExec("./" & buildScript): return "bin" / nim
  238. else:
  239. const buildScript = "build.bat"
  240. if existsFile(buildScript):
  241. if tryExec(buildScript): return "bin" / nim
  242. echo("Found no nim compiler and every attempt to build one failed!")
  243. quit("FAILURE")
  244. proc thVersion(i: int): string =
  245. result = ("compiler" / "nim" & $i).exe
  246. proc boot(args: string) =
  247. var output = "compiler" / "nim".exe
  248. var finalDest = "bin" / "nim".exe
  249. # default to use the 'c' command:
  250. let useCpp = getEnv("NIM_COMPILE_TO_CPP", "false") == "true"
  251. let smartNimcache = (if "release" in args or "danger" in args: "nimcache/r_" else: "nimcache/d_") &
  252. hostOS & "_" & hostCPU
  253. let nimStart = findStartNim()
  254. for i in 0..2:
  255. let defaultCommand = if useCpp: "cpp" else: "c"
  256. let bootOptions = if args.len == 0 or args.startsWith("-"): defaultCommand else: ""
  257. echo "iteration: ", i+1
  258. var extraOption = ""
  259. var nimi = i.thVersion
  260. if i == 0:
  261. nimi = nimStart
  262. extraOption.add " --skipUserCfg --skipParentCfg"
  263. # The configs are skipped for bootstrap
  264. # (1st iteration) to prevent newer flags from breaking bootstrap phase.
  265. let ret = execCmdEx(nimStart & " --version")
  266. doAssert ret.exitCode == 0
  267. let version = ret.output.splitLines[0]
  268. if version.startsWith "Nim Compiler Version 0.19.0":
  269. extraOption.add " -d:nimBoostrapCsources0_19_0"
  270. # remove this when csources get updated
  271. # in order to use less memory, we split the build into two steps:
  272. # --compileOnly produces a $project.json file and does not run GCC/Clang.
  273. # jsonbuild then uses the $project.json file to build the Nim binary.
  274. exec "$# $# $# $# --nimcache:$# --compileOnly compiler" / "nim.nim" %
  275. [nimi, bootOptions, extraOption, args, smartNimcache]
  276. exec "$# jsonscript $# --nimcache:$# compiler" / "nim.nim" %
  277. [nimi, args, smartNimcache]
  278. if sameFileContent(output, i.thVersion):
  279. copyExe(output, finalDest)
  280. echo "executables are equal: SUCCESS!"
  281. return
  282. copyExe(output, (i+1).thVersion)
  283. copyExe(output, finalDest)
  284. when not defined(windows): echo "[Warning] executables are still not equal"
  285. # -------------- clean --------------------------------------------------------
  286. const
  287. cleanExt = [
  288. ".ppu", ".o", ".obj", ".dcu", ".~pas", ".~inc", ".~dsk", ".~dpr",
  289. ".map", ".tds", ".err", ".bak", ".pyc", ".exe", ".rod", ".pdb", ".idb",
  290. ".idx", ".ilk"
  291. ]
  292. ignore = [
  293. ".bzrignore", "nim", "nim.exe", "koch", "koch.exe", ".gitignore"
  294. ]
  295. proc cleanAux(dir: string) =
  296. for kind, path in walkDir(dir):
  297. case kind
  298. of pcFile:
  299. var (_, name, ext) = splitFile(path)
  300. if ext == "" or cleanExt.contains(ext):
  301. if not ignore.contains(name):
  302. echo "removing: ", path
  303. removeFile(path)
  304. of pcDir:
  305. case splitPath(path).tail
  306. of "nimcache":
  307. echo "removing dir: ", path
  308. removeDir(path)
  309. of "dist", ".git", "icons": discard
  310. else: cleanAux(path)
  311. else: discard
  312. proc removePattern(pattern: string) =
  313. for f in walkFiles(pattern):
  314. echo "removing: ", f
  315. removeFile(f)
  316. proc clean(args: string) =
  317. removePattern("web/*.html")
  318. removePattern("doc/*.html")
  319. cleanAux(getCurrentDir())
  320. for kind, path in walkDir(getCurrentDir() / "build"):
  321. if kind == pcDir:
  322. echo "removing dir: ", path
  323. removeDir(path)
  324. # -------------- builds a release ---------------------------------------------
  325. proc winReleaseArch(arch: string) =
  326. doAssert arch in ["32", "64"]
  327. let cpu = if arch == "32": "i386" else: "amd64"
  328. template withMingw(path, body) =
  329. let prevPath = getEnv("PATH")
  330. putEnv("PATH", (if path.len > 0: path & PathSep else: "") & prevPath)
  331. try:
  332. body
  333. finally:
  334. putEnv("PATH", prevPath)
  335. withMingw r"..\mingw" & arch & r"\bin":
  336. # Rebuilding koch is necessary because it uses its pointer size to
  337. # determine which mingw link to put in the NSIS installer.
  338. inFold "winrelease koch":
  339. nimexec "c --cpu:$# koch" % cpu
  340. kochExecFold("winrelease boot", "boot -d:release --cpu:$#" % cpu)
  341. kochExecFold("winrelease zip", "zip -d:release")
  342. overwriteFile r"build\nim-$#.zip" % VersionAsString,
  343. r"web\upload\download\nim-$#_x$#.zip" % [VersionAsString, arch]
  344. proc winRelease*() =
  345. # Now used from "tools/winrelease" and not directly supported by koch
  346. # anymore!
  347. # Build -docs file:
  348. when true:
  349. inFold "winrelease buildDocs":
  350. buildDocs(gaCode)
  351. withDir "web/upload/" & VersionAsString:
  352. inFold "winrelease zipdocs":
  353. exec "7z a -tzip docs-$#.zip *.html" % VersionAsString
  354. overwriteFile "web/upload/$1/docs-$1.zip" % VersionAsString,
  355. "web/upload/download/docs-$1.zip" % VersionAsString
  356. when true:
  357. inFold "winrelease csource":
  358. csource("-d:release")
  359. when sizeof(pointer) == 4:
  360. winReleaseArch "32"
  361. when sizeof(pointer) == 8:
  362. winReleaseArch "64"
  363. # -------------- tests --------------------------------------------------------
  364. template `|`(a, b): string = (if a.len > 0: a else: b)
  365. proc tests(args: string) =
  366. nimexec "cc --opt:speed testament/testament"
  367. let tester = quoteShell(getCurrentDir() / "testament/testament".exe)
  368. let success = tryExec tester & " " & (args|"all")
  369. if not success:
  370. quit("tests failed", QuitFailure)
  371. proc temp(args: string) =
  372. proc splitArgs(a: string): (string, string) =
  373. # every --options before the command (indicated by starting
  374. # with not a dash) is part of the bootArgs, the rest is part
  375. # of the programArgs:
  376. let args = os.parseCmdLine a
  377. result = ("", "")
  378. var i = 0
  379. while i < args.len and args[i][0] == '-':
  380. result[0].add " " & quoteShell(args[i])
  381. inc i
  382. while i < args.len:
  383. result[1].add " " & quoteShell(args[i])
  384. inc i
  385. let d = getAppDir()
  386. var output = d / "compiler" / "nim".exe
  387. var finalDest = d / "bin" / "nim_temp".exe
  388. # 125 is the magic number to tell git bisect to skip the current commit.
  389. var (bootArgs, programArgs) = splitArgs(args)
  390. if "doc" notin programArgs and
  391. "threads" notin programArgs and
  392. "js" notin programArgs:
  393. bootArgs.add " -d:leanCompiler"
  394. let nimexec = findNim()
  395. exec(nimexec & " c -d:debug --debugger:native -d:nimBetterRun " & bootArgs & " " & (d / "compiler" / "nim"), 125)
  396. copyExe(output, finalDest)
  397. setCurrentDir(origDir)
  398. if programArgs.len > 0: exec(finalDest & " " & programArgs)
  399. proc xtemp(cmd: string) =
  400. let d = getAppDir()
  401. copyExe(d / "bin" / "nim".exe, d / "bin" / "nim_backup".exe)
  402. try:
  403. withDir(d):
  404. temp""
  405. copyExe(d / "bin" / "nim_temp".exe, d / "bin" / "nim".exe)
  406. exec(cmd)
  407. finally:
  408. copyExe(d / "bin" / "nim_backup".exe, d / "bin" / "nim".exe)
  409. proc runCI(cmd: string) =
  410. doAssert cmd.len == 0, cmd # avoid silently ignoring
  411. echo "runCI:", cmd
  412. # note(@araq): Do not replace these commands with direct calls (eg boot())
  413. # as that would weaken our testing efforts.
  414. when defined(posix): # appveyor (on windows) didn't run this
  415. kochExecFold("Boot", "boot")
  416. # boot without -d:nimHasLibFFI to make sure this still works
  417. kochExecFold("Boot in release mode", "boot -d:release -d:danger")
  418. ## build nimble early on to enable remainder to depend on it if needed
  419. kochExecFold("Build Nimble", "nimble")
  420. when false:
  421. execFold("nimble install -y libffi", "nimble install -y libffi")
  422. kochExecFold("boot -d:release -d:nimHasLibFFI", "boot -d:release -d:nimHasLibFFI")
  423. if getEnv("NIM_TEST_PACKAGES", "false") == "true":
  424. execFold("Test selected Nimble packages", "nim c -r testament/testament cat nimble-packages")
  425. else:
  426. buildTools() # altenatively, kochExec "tools --toolsNoNimble"
  427. ## run tests
  428. execFold("Test nimscript", "nim e tests/test_nimscript.nims")
  429. when defined(windows):
  430. # note: will be over-written below
  431. execFold("Compile tester", "nim c -d:nimCoroutines --os:genode -d:posix --compileOnly testament/testament")
  432. # main bottleneck here
  433. execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic all -d:nimCoroutines")
  434. execFold("Run nimdoc tests", "nim c -r nimdoc/tester")
  435. execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim")
  436. when defined(posix):
  437. execFold("Run nimsuggest tests", "nim c -r nimsuggest/tester")
  438. ## remaining actions
  439. when defined(posix):
  440. kochExecFold("Docs", "docs --git.commit:devel")
  441. kochExecFold("C sources", "csource")
  442. elif defined(windows):
  443. when false:
  444. kochExec "csource"
  445. kochExec "zip"
  446. proc pushCsources() =
  447. if not dirExists("../csources/.git"):
  448. quit "[Error] no csources git repository found"
  449. csource("-d:release")
  450. let cwd = getCurrentDir()
  451. try:
  452. copyDir("build/c_code", "../csources/c_code")
  453. copyFile("build/build.sh", "../csources/build.sh")
  454. copyFile("build/build.bat", "../csources/build.bat")
  455. copyFile("build/build64.bat", "../csources/build64.bat")
  456. copyFile("build/makefile", "../csources/makefile")
  457. setCurrentDir("../csources")
  458. for kind, path in walkDir("c_code"):
  459. if kind == pcDir:
  460. exec("git add " & path / "*.c")
  461. exec("git commit -am \"updated csources to version " & NimVersion & "\"")
  462. exec("git push origin master")
  463. exec("git tag -am \"Version $1\" v$1" % NimVersion)
  464. exec("git push origin v$1" % NimVersion)
  465. finally:
  466. setCurrentDir(cwd)
  467. proc testUnixInstall(cmdLineRest: string) =
  468. csource("-d:release " & cmdLineRest)
  469. xz(false, cmdLineRest)
  470. let oldCurrentDir = getCurrentDir()
  471. try:
  472. let destDir = getTempDir()
  473. copyFile("build/nim-$1.tar.xz" % VersionAsString,
  474. destDir / "nim-$1.tar.xz" % VersionAsString)
  475. setCurrentDir(destDir)
  476. execCleanPath("tar -xJf nim-$1.tar.xz" % VersionAsString)
  477. setCurrentDir("nim-$1" % VersionAsString)
  478. execCleanPath("sh build.sh")
  479. # first test: try if './bin/nim --version' outputs something sane:
  480. let output = execProcess("./bin/nim --version").splitLines
  481. if output.len > 0 and output[0].contains(VersionAsString):
  482. echo "Version check: success"
  483. execCleanPath("./bin/nim c koch.nim")
  484. execCleanPath("./koch boot -d:release", destDir / "bin")
  485. # check the docs build:
  486. execCleanPath("./koch docs", destDir / "bin")
  487. # check nimble builds:
  488. execCleanPath("./koch tools")
  489. # check the tests work:
  490. putEnv("NIM_EXE_NOT_IN_PATH", "NOT_IN_PATH")
  491. execCleanPath("./koch tests --nim:./bin/nim cat megatest", destDir / "bin")
  492. else:
  493. echo "Version check: failure"
  494. finally:
  495. setCurrentDir oldCurrentDir
  496. proc valgrind(cmd: string) =
  497. # somewhat hacky: '=' sign means "pass to valgrind" else "pass to Nim"
  498. let args = parseCmdLine(cmd)
  499. var nimcmd = ""
  500. var valcmd = ""
  501. for i, a in args:
  502. if i == args.len-1:
  503. # last element is the filename:
  504. valcmd.add ' '
  505. valcmd.add changeFileExt(a, ExeExt)
  506. nimcmd.add ' '
  507. nimcmd.add a
  508. elif '=' in a:
  509. valcmd.add ' '
  510. valcmd.add a
  511. else:
  512. nimcmd.add ' '
  513. nimcmd.add a
  514. exec("nim c" & nimcmd)
  515. let supp = getAppDir() / "tools" / "nimgrind.supp"
  516. exec("valgrind --suppressions=" & supp & valcmd)
  517. proc showHelp() =
  518. quit(HelpText % [VersionAsString & spaces(44-len(VersionAsString)),
  519. CompileDate, CompileTime], QuitSuccess)
  520. when isMainModule:
  521. var op = initOptParser()
  522. var latest = false
  523. while true:
  524. op.next()
  525. case op.kind
  526. of cmdLongOption, cmdShortOption:
  527. case normalize(op.key)
  528. of "latest": latest = true
  529. of "stable": latest = false
  530. else: showHelp()
  531. of cmdArgument:
  532. case normalize(op.key)
  533. of "boot": boot(op.cmdLineRest)
  534. of "clean": clean(op.cmdLineRest)
  535. of "doc", "docs": buildDocs(op.cmdLineRest)
  536. of "doc0", "docs0":
  537. # undocumented command for Araq-the-merciful:
  538. buildDocs(op.cmdLineRest & gaCode)
  539. of "pdf": buildPdfDoc(op.cmdLineRest, "doc/pdf")
  540. of "csource", "csources": csource(op.cmdLineRest)
  541. of "zip": zip(latest, op.cmdLineRest)
  542. of "xz": xz(latest, op.cmdLineRest)
  543. of "nsis": nsis(latest, op.cmdLineRest)
  544. of "geninstall": geninstall(op.cmdLineRest)
  545. of "distrohelper": geninstall()
  546. of "install": install(op.cmdLineRest)
  547. of "testinstall": testUnixInstall(op.cmdLineRest)
  548. of "runci": runCI(op.cmdLineRest)
  549. of "test", "tests": tests(op.cmdLineRest)
  550. of "temp": temp(op.cmdLineRest)
  551. of "xtemp": xtemp(op.cmdLineRest)
  552. of "wintools": bundleWinTools(op.cmdLineRest)
  553. of "nimble": buildNimble(latest, op.cmdLineRest)
  554. of "nimsuggest": bundleNimsuggest(op.cmdLineRest)
  555. of "toolsnonimble":
  556. buildTools(op.cmdLineRest)
  557. of "tools":
  558. buildTools(op.cmdLineRest)
  559. buildNimble(latest, op.cmdLineRest)
  560. of "pushcsource", "pushcsources": pushCsources()
  561. of "valgrind": valgrind(op.cmdLineRest)
  562. of "c2nim": bundleC2nim(op.cmdLineRest)
  563. else: showHelp()
  564. break
  565. of cmdEnd: break