Implement #10 - per file reset

This commit is contained in:
Ganesh Viswanathan 2018-07-13 02:16:01 -05:00
commit 9e0eb25685
3 changed files with 18 additions and 9 deletions

View file

@ -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 ```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 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 ```compile``` = file or dir of files of source code to {.compile.} into generated .nim

View file

@ -60,15 +60,13 @@ proc gitReset*() =
discard execProc("git reset --hard HEAD") discard execProc("git reset --hard HEAD")
proc gitCheckout*(filename: string) {.used.} = proc gitCheckout*(file: string) =
echo "Resetting file: $#" % [filename] echo " Resetting " & file
setCurrentDir(gOutput) setCurrentDir(gOutput)
defer: setCurrentDir(gProjectDir) defer: setCurrentDir(gProjectDir)
let adjustedFile = filename.replace(gOutput & $DirSep, "") discard execProc("git checkout $#" % file.replace(gOutput & "/", ""))
discard execProc("git checkout $#" % [adjustedFile])
proc gitRemotePull*(url: string, pull=true) = proc gitRemotePull*(url: string, pull=true) =
if dirExists(gOutput/".git"): if dirExists(gOutput/".git"):

View file

@ -24,11 +24,12 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
cfg = cfgin cfg = cfgin
sfile = search(file) sfile = search(file)
if sfile.len() == 0 or sfile in gDoneRecursive: if sfile in gDoneRecursive:
return return
echo "Processing " & sfile if sfile.len() != 0:
gDoneRecursive.add(sfile) echo "Processing " & sfile
gDoneRecursive.add(sfile)
for pattern in gWildcards.keys(): for pattern in gWildcards.keys():
var m: RegexMatch var m: RegexMatch
@ -51,6 +52,7 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
let (action, val) = getKey(act) let (action, val) = getKey(act)
if val == true: if val == true:
if action == "create": if action == "create":
echo "Creating " & file
createDir(file.splitPath().head) createDir(file.splitPath().head)
writeFile(file, cfg[act]) writeFile(file, cfg[act])
elif action in @["prepend", "append", "replace", "comment", elif action in @["prepend", "append", "replace", "comment",
@ -87,7 +89,9 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
srch = act srch = act
if file.splitFile().ext != ".nim": if file.splitFile().ext != ".nim":
var noprocess = false var
noprocess = false
reset = false
for act in cfg.keys(): for act in cfg.keys():
let (action, val) = getKey(act) let (action, val) = getKey(act)
@ -105,6 +109,8 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
c2nimConfig.defines = true c2nimConfig.defines = true
elif action == "noprocess": elif action == "noprocess":
noprocess = true noprocess = true
elif action == "reset":
reset = true
elif action == "flags": elif action == "flags":
c2nimConfig.flags = cfg[act] c2nimConfig.flags = cfg[act]
elif action == "ppflags": elif action == "ppflags":
@ -140,6 +146,9 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
if incout.len() != 0: if incout.len() != 0:
prepend(outfile, incout) prepend(outfile, incout)
if reset:
gitCheckout(sfile)
proc runCfg*(cfg: string) = proc runCfg*(cfg: string) =
if not fileExists(cfg): if not fileExists(cfg):
echo "Config doesn't exist: " & cfg echo "Config doesn't exist: " & cfg