diff options
| author | Joey Yakimowich-Payne <jyapayne@gmail.com> | 2018-07-08 10:59:49 +0900 |
|---|---|---|
| committer | Joey Yakimowich-Payne <jyapayne@gmail.com> | 2018-07-08 10:59:49 +0900 |
| commit | bfd9e50652110a2262e8700fd381dc5e36cf6499 (patch) | |
| tree | 7985b6e28f155984514ac2c57cb57723b128ff0b | |
| parent | f275bc0e352734cf6e8bbe125d56355b7949e432 (diff) | |
| parent | 44294a7513985dafd5aabca790648e85fa5789ef (diff) | |
| download | nimgen-bfd9e50652110a2262e8700fd381dc5e36cf6499.tar.gz nimgen-bfd9e50652110a2262e8700fd381dc5e36cf6499.zip | |
Merge remote-tracking branch 'upstream/master' into configurable_compiler
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | nimgen.nim | 44 | ||||
| -rw-r--r-- | nimgen.nimble | 4 |
3 files changed, 34 insertions, 18 deletions
@@ -28,7 +28,7 @@ Nimble already requires Git so those commands can be assumed to be present to do __Capabilities & Limitations__ -Nimgen supports compiling in C/C++ sources as well as loading in dynamic libraries at this time. Support for static libraries (.a, .lib) are still to come. +Nimgen supports compiling in C/C++ sources and static libraries as well as loading in dynamic libraries. To see examples of nimgen in action check out the following wrappers:- * Link with a dynamic library @@ -147,6 +147,8 @@ The following keys apply to library source code (before processing) and generate ```search``` = search string providing context for following prepend/append/replace directives +```pipe``` = execute a command on a file and store the output of the command as the new file contents. Ex: pipe = "cat $file | grep 'static inline'" + ```prepend``` = string value to prepend into file at beginning or before search ```append``` = string value to append into file at the end or after search @@ -4,6 +4,7 @@ var gDoneRecursive: seq[string] = @[] gDoneInline: seq[string] = @[] + gProjectDir = "" gConfig: Config gFilter = "" gQuotes = true @@ -61,7 +62,7 @@ proc extractZip(zipfile: string) = cmd = "powershell -nologo -noprofile -command \"& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('$#', '.'); }\"" setCurrentDir(gOutput) - defer: setCurrentDir("..") + defer: setCurrentDir(gProjectDir) echo "Extracting " & zipfile discard execProc(cmd % zipfile) @@ -86,7 +87,7 @@ proc gitReset() = echo "Resetting Git repo" setCurrentDir(gOutput) - defer: setCurrentDir("..") + defer: setCurrentDir(gProjectDir) discard execProc("git reset --hard HEAD") @@ -97,7 +98,7 @@ proc gitRemotePull(url: string, pull=true) = return setCurrentDir(gOutput) - defer: setCurrentDir("..") + defer: setCurrentDir(gProjectDir) echo "Setting up Git repo" discard execProc("git init .") @@ -114,7 +115,7 @@ proc gitSparseCheckout(plist: string) = return setCurrentDir(gOutput) - defer: setCurrentDir("..") + defer: setCurrentDir(gProjectDir) discard execProc("git config core.sparsecheckout true") writeFile(sparsefile, plist) @@ -195,15 +196,17 @@ proc search(file: string): string = # ### # Loading / unloading +proc openRetry(file: string, mode: FileMode = fmRead): File = + while true: + try: + result = open(file, mode) + break + except IOError: + sleep(100) + template withFile(file: string, body: untyped): untyped = if fileExists(file): - var f: File - while true: - try: - f = open(file) - break - except: - sleep(100) + var f = openRetry(file) var contentOrig = f.readAll() f.close() @@ -212,7 +215,7 @@ template withFile(file: string, body: untyped): untyped = body if content != contentOrig: - var f = open(file, fmWrite) + f = openRetry(file, fmWrite) write(f, content) f.close() else: @@ -230,6 +233,13 @@ proc prepend(file: string, data: string, search="") = if idx != -1: content = content[0..<idx] & data & content[idx..<content.len()] +proc pipe(file: string, command: string) = + let cmd = command % ["file", file] + let commandResult = execProc(cmd).strip() + if commandResult != "": + withFile(file): + content = commandResult + proc append(file: string, data: string, search="") = withFile(file): if search == "": @@ -411,14 +421,14 @@ proc runPreprocess(file, ppflags, flags: string, inline: bool): string = proc runCtags(file: string): string = var - cmd = "ctags -o - --fields=+S+K --c-kinds=p --file-scope=no " & file + cmd = "ctags -o - --fields=+S+K --c-kinds=+p --file-scope=no " & file fps = execProc(cmd) fdata = "" for line in fps.splitLines(): var spl = line.split(re"\t") if spl.len() > 4: - if spl[0] != "main": + if spl[0] != "main" and spl[3] != "member": var fn = "" var match = spl[2].find(re"/\^(.*?)\(") if match.isSome(): @@ -589,7 +599,7 @@ proc runFile(file: string, cfgin: OrderedTableRef) = if action == "create": createDir(file.splitPath().head) writeFile(file, cfg[act]) - elif action in @["prepend", "append", "replace", "comment", "rename", "compile", "dynlib", "pragma"] and sfile != "": + elif action in @["prepend", "append", "replace", "comment", "rename", "compile", "dynlib", "pragma", "pipe"] and sfile != "": if action == "prepend": if srch != "": prepend(sfile, cfg[act], cfg[srch]) @@ -614,6 +624,8 @@ proc runFile(file: string, cfgin: OrderedTableRef) = c2nimConfig.dynlib.add(cfg[act]) elif action == "pragma": c2nimConfig.pragma.add(cfg[act]) + elif action == "pipe": + pipe(sfile, cfg[act]) srch = "" elif action == "search": srch = act @@ -652,6 +664,8 @@ proc runCfg(cfg: string) = echo "Config doesn't exist: " & cfg quit(1) + gProjectDir = parentDir(cfg.expandFilename()) + gConfig = loadConfig(cfg) if gConfig.hasKey("n.global"): diff --git a/nimgen.nimble b/nimgen.nimble index 4d7106a..2a048b9 100644 --- a/nimgen.nimble +++ b/nimgen.nimble @@ -1,6 +1,6 @@ # Package -version = "0.2.1" +version = "0.2.2" author = "genotrance" description = "c2nim helper to simplify and automate the wrapping of C libraries" license = "MIT" @@ -9,7 +9,7 @@ skipDirs = @["tests"] # Dependencies -requires "nim >= 0.17.2", "c2nim >= 0.9.13" +requires "nim >= 0.17.0", "c2nim >= 0.9.13" bin = @["nimgen"] |
