summary refs log tree commit diff stats
path: root/koch.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2017-02-07 01:04:38 +0100
committerAraq <rumpf_a@web.de>2017-02-07 01:04:38 +0100
commit2d3385c22204091fa5fc2963b5c009ec0182715d (patch)
treeb255665a098e036d8ac5b1c9cd1ed6a902f3a6a6 /koch.nim
parent2e65b48b6298ca3aa1de593d17c50d0d7e2ee709 (diff)
downloadNim-2d3385c22204091fa5fc2963b5c009ec0182715d.tar.gz
koch.nim: winrelease without nasty batch files
Diffstat (limited to 'koch.nim')
-rw-r--r--koch.nim61
1 files changed, 58 insertions, 3 deletions
diff --git a/koch.nim b/koch.nim
index 25c2c6f06..1d0ece5ff 100644
--- a/koch.nim
+++ b/koch.nim
@@ -70,6 +70,8 @@ Web options:
                            build the official docs, use UA-48159761-1
 """
 
+const gaCode = " --googleAnalytics:UA-48159761-1"
+
 proc exe(f: string): string =
   result = addFileExt(f, ExeExt)
   when defined(windows):
@@ -380,8 +382,61 @@ proc clean(args: string) =
 
 # -------------- builds a release ---------------------------------------------
 
+proc patchConfig(lookFor, replaceBy: string) =
+  const
+    cfgFile = "config/nim.cfg"
+  try:
+    let cfg = readFile(cfgFile)
+    let newCfg = cfg.replace(lookFor, replaceBy)
+    if newCfg == cfg:
+      echo "Could not patch 'config/nim.cfg' [Error]"
+      echo "Reason: patch substring not found:"
+      echo lookFor
+    else:
+      writeFile(cfgFile, newCfg)
+  except IOError:
+    quit "Could not access 'config/nim.cfg' [Error]"
+
+proc winReleaseArch(arch: string) =
+  doAssert arch in ["32", "64"]
+  let cpu = if arch == "32": "i386" else: "amd64"
+
+  template withMingw(path, body) =
+    const orig = """#gcc.path = r"$nim\dist\mingw\bin""""
+    let replacePattern = """gcc.path = r"..\mingw$1\bin" # winrelease""" % arch
+    patchConfig(orig, replacePattern)
+    try:
+      body
+    finally:
+      patchConfig(replacePattern, orig)
+
+  withMingw r"..\mingw" & arch & r"\bin":
+    # Rebuilding koch is necessary because it uses its pointer size to
+    # determine which mingw link to put in the NSIS installer.
+    nimexec "c --out:koch_temp --cpu:$# koch" % cpu
+    exec "koch_temp boot -d:release --cpu:$#" % cpu
+    exec "koch_temp nsis -d:release"
+    exec "koch_temp zip -d:release"
+
+    moveFile r"build\nim_$#.exe" % VersionAsString,
+             r"web\upload\download\nim-$#_x$#.exe" % [VersionAsString, arch]
+    moveFile r"build\nim-$#.zip" % VersionAsString,
+             r"web\upload\download\nim-$#_x$#.zip" % [VersionAsString, arch]
+
 proc winRelease() =
-  exec(r"call ci\nsis_build.bat " & VersionAsString)
+  # Build -docs file:
+  when true:
+    web(gaCode)
+    withDir "web/upload/" & VersionAsString:
+      exec "7z a -tzip docs-$#.zip *.html" % VersionAsString
+    moveFile "web/upload/$1/docs-$1.zip" % VersionAsString,
+             "web/upload/download/docs-$1.zip" % VersionAsString
+  when true:
+    csource("-d:release")
+  when true:
+    winReleaseArch "32"
+  when true:
+    winReleaseArch "64"
 
 # -------------- tests --------------------------------------------------------
 
@@ -463,10 +518,10 @@ of cmdArgument:
   of "web": web(op.cmdLineRest)
   of "doc", "docs": web("--onlyDocs " & op.cmdLineRest)
   of "json2": web("--json2 " & op.cmdLineRest)
-  of "website": website(op.cmdLineRest & " --googleAnalytics:UA-48159761-1")
+  of "website": website(op.cmdLineRest & gaCode)
   of "web0":
     # undocumented command for Araq-the-merciful:
-    web(op.cmdLineRest & " --googleAnalytics:UA-48159761-1")
+    web(op.cmdLineRest & gaCode)
   of "pdf": pdf()
   of "csource", "csources": csource(op.cmdLineRest)
   of "zip": zip(op.cmdLineRest)