aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2018-07-13 02:16:01 -0500
committerGanesh Viswanathan <dev@genotrance.com>2018-07-13 02:16:01 -0500
commit9e0eb256857b9dce6895b3dcb0e3f6a9dd2b5def (patch)
tree946eae418bed10d202b43ea3871e5ba6ce67365c
parent1a2ef870873f134e0df767d729ba89ecd7e1f01c (diff)
downloadnimgen-9e0eb256857b9dce6895b3dcb0e3f6a9dd2b5def.tar.gz
nimgen-9e0eb256857b9dce6895b3dcb0e3f6a9dd2b5def.zip
Implement #10 - per file reset
-rw-r--r--README.md2
-rw-r--r--src/nimgen/external.nim8
-rw-r--r--src/nimgen/runcfg.nim17
3 files changed, 18 insertions, 9 deletions
diff --git a/README.md b/README.md
index 1d7b574..df949b8 100644
--- a/README.md
+++ b/README.md
@@ -160,6 +160,8 @@ The following keys apply to library source code and help with generating the .ni
```noprocess``` = do not process this source file with c2nim [default: false] - this is useful if a file only needs to be manipulated
+```reset``` = reset the file back to original state after all processing [default: false]
+
Multiple entries for the all following keys are possible by appending any .string to the key. E.g. dynlib.win, compile.dir
```compile``` = file or dir of files of source code to {.compile.} into generated .nim
diff --git a/src/nimgen/external.nim b/src/nimgen/external.nim
index f642cfb..2c4a12e 100644
--- a/src/nimgen/external.nim
+++ b/src/nimgen/external.nim
@@ -60,15 +60,13 @@ proc gitReset*() =
discard execProc("git reset --hard HEAD")
-proc gitCheckout*(filename: string) {.used.} =
- echo "Resetting file: $#" % [filename]
+proc gitCheckout*(file: string) =
+ echo " Resetting " & file
setCurrentDir(gOutput)
defer: setCurrentDir(gProjectDir)
- let adjustedFile = filename.replace(gOutput & $DirSep, "")
-
- discard execProc("git checkout $#" % [adjustedFile])
+ discard execProc("git checkout $#" % file.replace(gOutput & "/", ""))
proc gitRemotePull*(url: string, pull=true) =
if dirExists(gOutput/".git"):
diff --git a/src/nimgen/runcfg.nim b/src/nimgen/runcfg.nim
index a702e47..a641150 100644
--- a/src/nimgen/runcfg.nim
+++ b/src/nimgen/runcfg.nim
@@ -24,11 +24,12 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
cfg = cfgin
sfile = search(file)
- if sfile.len() == 0 or sfile in gDoneRecursive:
+ if sfile in gDoneRecursive:
return
- echo "Processing " & sfile
- gDoneRecursive.add(sfile)
+ if sfile.len() != 0:
+ echo "Processing " & sfile
+ gDoneRecursive.add(sfile)
for pattern in gWildcards.keys():
var m: RegexMatch
@@ -51,6 +52,7 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
let (action, val) = getKey(act)
if val == true:
if action == "create":
+ echo "Creating " & file
createDir(file.splitPath().head)
writeFile(file, cfg[act])
elif action in @["prepend", "append", "replace", "comment",
@@ -87,7 +89,9 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
srch = act
if file.splitFile().ext != ".nim":
- var noprocess = false
+ var
+ noprocess = false
+ reset = false
for act in cfg.keys():
let (action, val) = getKey(act)
@@ -105,6 +109,8 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
c2nimConfig.defines = true
elif action == "noprocess":
noprocess = true
+ elif action == "reset":
+ reset = true
elif action == "flags":
c2nimConfig.flags = cfg[act]
elif action == "ppflags":
@@ -140,6 +146,9 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
if incout.len() != 0:
prepend(outfile, incout)
+ if reset:
+ gitCheckout(sfile)
+
proc runCfg*(cfg: string) =
if not fileExists(cfg):
echo "Config doesn't exist: " & cfg