koch: code cleanups, easier testing for 'testinstall' and 'winrelease'

This commit is contained in:
Araq 2018-09-19 15:03:14 +02:00
commit 2e477979a4

105
koch.nim
View file

@ -16,9 +16,9 @@ when defined(gcc) and defined(windows):
{.link: "icons/koch_icon.o".} {.link: "icons/koch_icon.o".}
when defined(amd64) and defined(windows) and defined(vcc): when defined(amd64) and defined(windows) and defined(vcc):
{.link: "icons/koch-amd64-windows-vcc.res" .} {.link: "icons/koch-amd64-windows-vcc.res".}
when defined(i386) and defined(windows) and defined(vcc): when defined(i386) and defined(windows) and defined(vcc):
{.link: "icons/koch-i386-windows-vcc.res" .} {.link: "icons/koch-i386-windows-vcc.res".}
import import
os, strutils, parseopt, osproc, streams os, strutils, parseopt, osproc, streams
@ -40,6 +40,7 @@ Usage:
koch [options] command [options for command] koch [options] command [options for command]
Options: Options:
--help, -h shows this help and quits --help, -h shows this help and quits
--latest bundle the installers with a bleeding edge Nimble
Possible Commands: Possible Commands:
boot [options] bootstraps with given command line options boot [options] bootstraps with given command line options
distrohelper [bindir] helper for distro packagers distrohelper [bindir] helper for distro packagers
@ -98,17 +99,18 @@ proc csource(args: string) =
"--main:compiler/nim.nim compiler/installer.ini $1") % "--main:compiler/nim.nim compiler/installer.ini $1") %
[args, VersionAsString, compileNimInst]) [args, VersionAsString, compileNimInst])
proc bundleNimbleSrc() = proc bundleNimbleSrc(latest: bool) =
## bunldeNimbleSrc() bundles a specific Nimble commit with the tarball. We ## bunldeNimbleSrc() bundles a specific Nimble commit with the tarball. We
## always bundle the latest official release. ## always bundle the latest official release.
if not dirExists("dist/nimble/.git"): if not dirExists("dist/nimble/.git"):
exec("git clone https://github.com/nim-lang/nimble.git dist/nimble") exec("git clone https://github.com/nim-lang/nimble.git dist/nimble")
withDir("dist/nimble"): if not latest:
exec("git checkout -f stable") withDir("dist/nimble"):
exec("git pull") exec("git checkout -f stable")
exec("git pull")
proc bundleNimbleExe() = proc bundleNimbleExe(latest: bool) =
bundleNimbleSrc() bundleNimbleSrc(latest)
# now compile Nimble and copy it to $nim/bin for the installer.ini # now compile Nimble and copy it to $nim/bin for the installer.ini
# to pick it up: # to pick it up:
nimexec("c -d:release --nilseqs:on dist/nimble/src/nimble.nim") nimexec("c -d:release --nilseqs:on dist/nimble/src/nimble.nim")
@ -162,8 +164,8 @@ proc bundleWinTools() =
nimexec(r"c --cc:vcc --app:gui -o:bin\downloader.exe -d:ssl --noNimblePath " & nimexec(r"c --cc:vcc --app:gui -o:bin\downloader.exe -d:ssl --noNimblePath " &
r"--path:..\ui tools\downloader.nim") r"--path:..\ui tools\downloader.nim")
proc zip(args: string) = proc zip(latest: bool; args: string) =
bundleNimbleExe() bundleNimbleExe(latest)
bundleNimsuggest(true) bundleNimsuggest(true)
bundleWinTools() bundleWinTools()
nimexec("cc -r $2 --var:version=$1 --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" % nimexec("cc -r $2 --var:version=$1 --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" %
@ -178,9 +180,9 @@ proc ensureCleanGit() =
if status != 0: if status != 0:
quit "Not a clean git repository; 'git diff' returned non-zero!" quit "Not a clean git repository; 'git diff' returned non-zero!"
proc xz(args: string) = proc xz(latest: bool; args: string) =
ensureCleanGit() ensureCleanGit()
bundleNimbleSrc() bundleNimbleSrc(latest)
bundleNimsuggest(false) bundleNimsuggest(false)
nimexec("cc -r $2 --var:version=$1 --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" % nimexec("cc -r $2 --var:version=$1 --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" %
[VersionAsString, compileNimInst]) [VersionAsString, compileNimInst])
@ -202,8 +204,8 @@ proc buildTools(latest: bool) =
buildNimble(latest) buildNimble(latest)
proc nsis(args: string) = proc nsis(latest: bool; args: string) =
bundleNimbleExe() bundleNimbleExe(latest)
bundleNimsuggest(true) bundleNimsuggest(true)
bundleWinTools() bundleWinTools()
# make sure we have generated the niminst executables: # make sure we have generated the niminst executables:
@ -349,7 +351,7 @@ proc winReleaseArch(arch: string) =
# determine which mingw link to put in the NSIS installer. # determine which mingw link to put in the NSIS installer.
nimexec "c --cpu:$# koch" % cpu nimexec "c --cpu:$# koch" % cpu
exec "koch boot -d:release --cpu:$#" % cpu exec "koch boot -d:release --cpu:$#" % cpu
exec "koch zip -d:release" exec "koch --latest zip -d:release"
overwriteFile r"build\nim-$#.zip" % VersionAsString, overwriteFile r"build\nim-$#.zip" % VersionAsString,
r"web\upload\download\nim-$#_x$#.zip" % [VersionAsString, arch] r"web\upload\download\nim-$#_x$#.zip" % [VersionAsString, arch]
@ -449,7 +451,7 @@ proc pushCsources() =
proc testUnixInstall(cmdLineRest: string) = proc testUnixInstall(cmdLineRest: string) =
csource("-d:release " & cmdLineRest) csource("-d:release " & cmdLineRest)
xz(cmdLineRest) xz(false, cmdLineRest)
let oldCurrentDir = getCurrentDir() let oldCurrentDir = getCurrentDir()
try: try:
let destDir = getTempDir() let destDir = getTempDir()
@ -468,7 +470,7 @@ proc testUnixInstall(cmdLineRest: string) =
# check the docs build: # check the docs build:
execCleanPath("./koch docs", destDir / "bin") execCleanPath("./koch docs", destDir / "bin")
# check nimble builds: # check nimble builds:
execCleanPath("./koch testtools") execCleanPath("./koch --latest tools")
# check the tests work: # check the tests work:
putEnv("NIM_EXE_NOT_IN_PATH", "NOT_IN_PATH") putEnv("NIM_EXE_NOT_IN_PATH", "NOT_IN_PATH")
execCleanPath("./koch tests", destDir / "bin") execCleanPath("./koch tests", destDir / "bin")
@ -506,35 +508,40 @@ proc showHelp() =
when isMainModule: when isMainModule:
var op = initOptParser() var op = initOptParser()
op.next() var latest = false
case op.kind while true:
of cmdLongOption, cmdShortOption: showHelp() op.next()
of cmdArgument: case op.kind
case normalize(op.key) of cmdLongOption, cmdShortOption:
of "boot": boot(op.cmdLineRest) case normalize(op.key)
of "clean": clean(op.cmdLineRest) of "latest": latest = true
of "doc", "docs": buildDocs(op.cmdLineRest) else: showHelp()
of "doc0", "docs0": of cmdArgument:
# undocumented command for Araq-the-merciful: case normalize(op.key)
buildDocs(op.cmdLineRest & gaCode) of "boot": boot(op.cmdLineRest)
of "pdf": buildPdfDoc(op.cmdLineRest, "doc/pdf") of "clean": clean(op.cmdLineRest)
of "csource", "csources": csource(op.cmdLineRest) of "doc", "docs": buildDocs(op.cmdLineRest)
of "zip": zip(op.cmdLineRest) of "doc0", "docs0":
of "xz": xz(op.cmdLineRest) # undocumented command for Araq-the-merciful:
of "nsis": nsis(op.cmdLineRest) buildDocs(op.cmdLineRest & gaCode)
of "geninstall": geninstall(op.cmdLineRest) of "pdf": buildPdfDoc(op.cmdLineRest, "doc/pdf")
of "distrohelper": geninstall() of "csource", "csources": csource(op.cmdLineRest)
of "install": install(op.cmdLineRest) of "zip": zip(latest, op.cmdLineRest)
of "testinstall": testUnixInstall(op.cmdLineRest) of "xz": xz(latest, op.cmdLineRest)
of "test", "tests": tests(op.cmdLineRest) of "nsis": nsis(latest, op.cmdLineRest)
of "temp": temp(op.cmdLineRest) of "geninstall": geninstall(op.cmdLineRest)
of "xtemp": xtemp(op.cmdLineRest) of "distrohelper": geninstall()
of "wintools": bundleWinTools() of "install": install(op.cmdLineRest)
of "nimble": buildNimble(existsDir(".git")) of "testinstall": testUnixInstall(op.cmdLineRest)
of "nimsuggest": bundleNimsuggest(buildExe=true) of "test", "tests": tests(op.cmdLineRest)
of "tools": buildTools(existsDir(".git")) of "temp": temp(op.cmdLineRest)
of "testtools": buildTools(true) of "xtemp": xtemp(op.cmdLineRest)
of "pushcsource", "pushcsources": pushCsources() of "wintools": bundleWinTools()
of "valgrind": valgrind(op.cmdLineRest) of "nimble": buildNimble(existsDir(".git") or latest)
else: showHelp() of "nimsuggest": bundleNimsuggest(buildExe=true)
of cmdEnd: showHelp() of "tools": buildTools(existsDir(".git") or latest)
of "pushcsource", "pushcsources": pushCsources()
of "valgrind": valgrind(op.cmdLineRest)
else: showHelp()
break
of cmdEnd: break