koch: 'update' feature optional for less dependencies
This commit is contained in:
parent
a42a5e8e7c
commit
202972dea0
1 changed files with 63 additions and 51 deletions
114
koch.nim
114
koch.nim
|
|
@ -11,7 +11,10 @@ when defined(gcc) and defined(windows):
|
||||||
{.link: "icons/koch.res".}
|
{.link: "icons/koch.res".}
|
||||||
|
|
||||||
import
|
import
|
||||||
os, strutils, parseopt, osproc, httpclient, streams
|
os, strutils, parseopt, osproc, streams
|
||||||
|
|
||||||
|
when defined(withUpdate):
|
||||||
|
import httpclient
|
||||||
when defined(haveZipLib):
|
when defined(haveZipLib):
|
||||||
import zipfiles
|
import zipfiles
|
||||||
|
|
||||||
|
|
@ -37,6 +40,7 @@ Possible Commands:
|
||||||
inno [options] builds the Inno Setup installer (for Windows)
|
inno [options] builds the Inno Setup installer (for Windows)
|
||||||
tests run the testsuite
|
tests run the testsuite
|
||||||
update updates nimrod to the latest version from github
|
update updates nimrod to the latest version from github
|
||||||
|
(compile koch with -d:withUpdate to enable)
|
||||||
Boot options:
|
Boot options:
|
||||||
-d:release produce a release version of the compiler
|
-d:release produce a release version of the compiler
|
||||||
-d:tinyc include the Tiny C backend (not supported on Windows)
|
-d:tinyc include the Tiny C backend (not supported on Windows)
|
||||||
|
|
@ -183,60 +187,64 @@ proc clean(args: string) =
|
||||||
|
|
||||||
# -------------- update -------------------------------------------------------
|
# -------------- update -------------------------------------------------------
|
||||||
|
|
||||||
proc update(args: string) =
|
when defined(withUpdate):
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
echo("Windows users: Make sure to be running this in Bash. ",
|
{.warning: "Windows users: Make sure to run 'koch update' in Bash.".}
|
||||||
"If you aren't, press CTRL+C now.")
|
|
||||||
|
|
||||||
var thisDir = getAppDir()
|
proc update(args: string) =
|
||||||
var git = findExe("git")
|
when defined(windows):
|
||||||
echo("Checking for git repo and git executable...")
|
echo("Windows users: Make sure to be running this in Bash. ",
|
||||||
if existsDir(thisDir & "/.git") and git != "":
|
"If you aren't, press CTRL+C now.")
|
||||||
echo("Git repo found!")
|
|
||||||
# use git to download latest source
|
var thisDir = getAppDir()
|
||||||
echo("Checking for updates...")
|
var git = findExe("git")
|
||||||
discard startCmd(git & " fetch origin master")
|
echo("Checking for git repo and git executable...")
|
||||||
var procs = startCmd(git & " diff origin/master master")
|
if existsDir(thisDir & "/.git") and git != "":
|
||||||
var errcode = procs.waitForExit()
|
echo("Git repo found!")
|
||||||
var output = readLine(procs.outputStream)
|
# use git to download latest source
|
||||||
echo(output)
|
echo("Checking for updates...")
|
||||||
if errcode == 0:
|
discard startCmd(git & " fetch origin master")
|
||||||
if output == "":
|
var procs = startCmd(git & " diff origin/master master")
|
||||||
# No changes
|
var errcode = procs.waitForExit()
|
||||||
echo("No update. Exiting..")
|
var output = readLine(procs.outputStream)
|
||||||
return
|
echo(output)
|
||||||
else:
|
if errcode == 0:
|
||||||
echo("Fetching updates from repo...")
|
if output == "":
|
||||||
var pullout = execCmdEx(git & " pull origin master")
|
# No changes
|
||||||
if pullout[1] != 0:
|
echo("No update. Exiting..")
|
||||||
quit("An error has occured.")
|
return
|
||||||
else:
|
else:
|
||||||
if pullout[0].startsWith("Already up-to-date."):
|
echo("Fetching updates from repo...")
|
||||||
quit("No new changes fetched from the repo. " &
|
var pullout = execCmdEx(git & " pull origin master")
|
||||||
"Local branch must be ahead of it. Exiting...")
|
if pullout[1] != 0:
|
||||||
|
quit("An error has occured.")
|
||||||
|
else:
|
||||||
|
if pullout[0].startsWith("Already up-to-date."):
|
||||||
|
quit("No new changes fetched from the repo. " &
|
||||||
|
"Local branch must be ahead of it. Exiting...")
|
||||||
|
else:
|
||||||
|
quit("An error has occured.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
quit("An error has occured.")
|
echo("No repo or executable found!")
|
||||||
|
when defined(haveZipLib):
|
||||||
|
echo("Falling back.. Downloading source code from repo...")
|
||||||
|
# use dom96's httpclient to download zip
|
||||||
|
downloadFile("https://github.com/Araq/Nimrod/zipball/master",
|
||||||
|
thisDir / "update.zip")
|
||||||
|
try:
|
||||||
|
echo("Extracting source code from archive...")
|
||||||
|
var zip: TZipArchive
|
||||||
|
discard open(zip, thisDir & "/update.zip", fmRead)
|
||||||
|
extractAll(zip, thisDir & "/")
|
||||||
|
except:
|
||||||
|
quit("Error reading archive.")
|
||||||
|
else:
|
||||||
|
quit("No failback available. Exiting...")
|
||||||
|
|
||||||
else:
|
echo("Starting update...")
|
||||||
echo("No repo or executable found!")
|
boot(args)
|
||||||
when defined(haveZipLib):
|
echo("Update complete!")
|
||||||
echo("Falling back.. Downloading source code from repo...")
|
|
||||||
# use dom96's httpclient to download zip
|
|
||||||
downloadFile("https://github.com/Araq/Nimrod/zipball/master",
|
|
||||||
thisDir / "update.zip")
|
|
||||||
try:
|
|
||||||
echo("Extracting source code from archive...")
|
|
||||||
var zip: TZipArchive
|
|
||||||
discard open(zip, thisDir & "/update.zip", fmRead)
|
|
||||||
extractAll(zip, thisDir & "/")
|
|
||||||
except:
|
|
||||||
quit("Error reading archive.")
|
|
||||||
else:
|
|
||||||
quit("No failback available. Exiting...")
|
|
||||||
|
|
||||||
echo("Starting update...")
|
|
||||||
boot(args)
|
|
||||||
echo("Update complete!")
|
|
||||||
|
|
||||||
# -------------- tests --------------------------------------------------------
|
# -------------- tests --------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -268,7 +276,11 @@ of cmdArgument:
|
||||||
of "inno": inno(op.cmdLineRest)
|
of "inno": inno(op.cmdLineRest)
|
||||||
of "install": install(op.cmdLineRest)
|
of "install": install(op.cmdLineRest)
|
||||||
of "test", "tests": tests(op.cmdLineRest)
|
of "test", "tests": tests(op.cmdLineRest)
|
||||||
of "update": update(op.cmdLineRest)
|
of "update":
|
||||||
|
when defined(withUpdate):
|
||||||
|
update(op.cmdLineRest)
|
||||||
|
else:
|
||||||
|
quit "this Koch has not been compiled with -d:withUpdate"
|
||||||
else: showHelp()
|
else: showHelp()
|
||||||
of cmdEnd: showHelp()
|
of cmdEnd: showHelp()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue