summary refs log tree commit diff stats
path: root/koch.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <andreas@andreas-desktop>2009-12-22 01:28:20 +0100
committerAndreas Rumpf <andreas@andreas-desktop>2009-12-22 01:28:20 +0100
commit2169fd63bdf9caf539ca7ca5b661ee703206500c (patch)
treee8d531ac9984699054744ad654c972acf5463062 /koch.nim
parent9dda24e475bbdb3e33ae22d745bfaca552e18465 (diff)
downloadNim-2169fd63bdf9caf539ca7ca5b661ee703206500c.tar.gz
version 0.8.6
Diffstat (limited to 'koch.nim')
-rwxr-xr-xkoch.nim16
1 files changed, 10 insertions, 6 deletions
diff --git a/koch.nim b/koch.nim
index bb9d84d8e..e79ab9a36 100755
--- a/koch.nim
+++ b/koch.nim
@@ -79,7 +79,6 @@ const
   bootOptions = "" # options to pass to the bootstrap process
 
 proc findStartNimrod: string = 
-  const buildScript = "build.sh"
   # we try several things before giving up:
   # * bin/nimrod
   # * $PATH/nimrod
@@ -95,6 +94,7 @@ proc findStartNimrod: string =
   result = "bin" / "nim".exe
   if ExistsFile(result): return
   when defined(Posix):
+    const buildScript = "build.sh"
     if ExistsFile(buildScript): 
       if tryExec("./" & buildScript): return "bin" / nimrod
   
@@ -102,16 +102,20 @@ proc findStartNimrod: string =
   echo("Found no nimrod compiler and every attempt to build one failed!")
   quit("FAILURE")
 
+proc safeRemove(filename: string) = 
+  if existsFile(filename): removeFile(filename)
+
 proc bootIteration(args: string): bool = 
   var nimrod1 = "rod" / "nimrod1".exe
-  moveFile nimrod1, "rod" / "nimrod".exe
+  safeRemove(nimrod1)
+  moveFile(nimrod1, "rod" / "nimrod".exe)
   exec "rod" / "nimrod1 cc $# $# rod/nimrod.nim" % [bootOptions, args]
   # Nimrod does not produce an executable again if nothing changed. That's ok:
   result = sameFileContent("rod" / "nimrod".exe, nimrod1)
-  if result:
-    moveFile "bin" / "nimrod".exe, "rod" / "nimrod".exe
-    echo "executables are equal: SUCCESS!"
-  removeFile nimrod1
+  safeRemove("bin" / "nimrod".exe)
+  copyFile("bin" / "nimrod".exe, "rod" / "nimrod".exe)
+  safeRemove(nimrod1)
+  if result: echo "executables are equal: SUCCESS!"
 
 proc boot(args: string) =
   echo "iteration: 1"