From 71699332be05b7a5aed93c4d9d80c4333f7692c3 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sat, 16 Jun 2018 15:22:16 +0900 Subject: Allow for deeper than one directory paths --- nimgen.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nimgen.nim b/nimgen.nim index d804657..e601153 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -4,6 +4,7 @@ var gDoneRecursive: seq[string] = @[] gDoneInline: seq[string] = @[] + gProjectDir = getCurrentDir() gConfig: Config gFilter = "" gQuotes = true @@ -59,7 +60,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) @@ -84,7 +85,7 @@ proc gitReset() = echo "Resetting Git repo" setCurrentDir(gOutput) - defer: setCurrentDir("..") + defer: setCurrentDir(gProjectDir) discard execProc("git reset --hard HEAD") @@ -95,7 +96,7 @@ proc gitRemotePull(url: string, pull=true) = return setCurrentDir(gOutput) - defer: setCurrentDir("..") + defer: setCurrentDir(gProjectDir) echo "Setting up Git repo" discard execProc("git init .") @@ -112,7 +113,7 @@ proc gitSparseCheckout(plist: string) = return setCurrentDir(gOutput) - defer: setCurrentDir("..") + defer: setCurrentDir(gProjectDir) discard execProc("git config core.sparsecheckout true") writeFile(sparsefile, plist) -- cgit v1.2.3 From e371546d522b1ce39a1009552a43de614368279a Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sat, 16 Jun 2018 15:33:47 +0900 Subject: Add support for executing a command on a file. $file in the command string references the file name. The stdout of the command will become the file's new contents. This is useful for doing things that nimgen might not support, like using sed or grep or some other command line tool. --- README.md | 2 ++ nimgen.nim | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d47239e..0c4bb89 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,8 @@ The following keys apply to library source code (before processing) and generate ```search``` = search string providing context for following prepend/append/replace directives +```execute``` = execute a command on a file and store the output of the command as the new file contents. Ex: execute = "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 diff --git a/nimgen.nim b/nimgen.nim index d804657..cff48e3 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -228,6 +228,12 @@ proc prepend(file: string, data: string, search="") = if idx != -1: content = content[0.. Date: Sat, 23 Jun 2018 12:08:48 -0500 Subject: Fix #2 - ctags not working --- nimgen.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nimgen.nim b/nimgen.nim index d804657..9535dc6 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -409,14 +409,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(): -- cgit v1.2.3 From 2f2b26d269ba690ffe90708d1cb16f415cc673cb Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 24 Jun 2018 07:50:47 +0900 Subject: Change project dir based on nimgen cfg file --- nimgen.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nimgen.nim b/nimgen.nim index e601153..14ece01 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -4,7 +4,7 @@ var gDoneRecursive: seq[string] = @[] gDoneInline: seq[string] = @[] - gProjectDir = getCurrentDir() + gProjectDir = "" gConfig: Config gFilter = "" gQuotes = true @@ -651,6 +651,8 @@ proc runCfg(cfg: string) = echo "Config doesn't exist: " & cfg quit(1) + gProjectDir = parentDir(cfg) + gConfig = loadConfig(cfg) if gConfig.hasKey("n.global"): -- cgit v1.2.3 From 4a83f6d5a1177396cd9f0287bc3f99e9ca0a7e87 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 24 Jun 2018 08:21:50 +0900 Subject: Fix issue if cfg file is local gProject dir will be an empty string --- nimgen.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nimgen.nim b/nimgen.nim index 14ece01..376e0eb 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -651,7 +651,7 @@ proc runCfg(cfg: string) = echo "Config doesn't exist: " & cfg quit(1) - gProjectDir = parentDir(cfg) + gProjectDir = parentDir(cfg.expandFilename()) gConfig = loadConfig(cfg) -- cgit v1.2.3 From a7edd8525d93ef07b3d1134067c3ab42a311d1bc Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Wed, 27 Jun 2018 22:22:38 +0900 Subject: Rename execute to pipe --- README.md | 2 +- nimgen.nim | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0c4bb89..a92a5dc 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ The following keys apply to library source code (before processing) and generate ```search``` = search string providing context for following prepend/append/replace directives -```execute``` = execute a command on a file and store the output of the command as the new file contents. Ex: execute = "cat $file | grep 'static inline'" +```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 diff --git a/nimgen.nim b/nimgen.nim index cff48e3..82b072a 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -228,11 +228,12 @@ proc prepend(file: string, data: string, search="") = if idx != -1: content = content[0.. Date: Sat, 7 Jul 2018 15:03:14 -0500 Subject: Fix IOErrors --- nimgen.nim | 6 ++++++ nimgen.nimble | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/nimgen.nim b/nimgen.nim index 545c3be..ac61767 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -476,6 +476,9 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = cfile = "temp-$#.c" % [outfile.extractFilename()] writeFile(cfile, runCtags(file)) + while not fileExists(cfile): + sleep(10) + if c2nimConfig.defines and (c2nimConfig.preprocess or c2nimConfig.ctags): prepend(cfile, getDefines(file, c2nimConfig.inline)) @@ -531,6 +534,9 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = cmd = "cmd /c " & cmd discard execProc(cmd) + while not fileExists(outfile): + sleep(10) + if c2nimConfig.preprocess or c2nimConfig.ctags: try: removeFile(cfile) diff --git a/nimgen.nimble b/nimgen.nimble index 4d7106a..e0833ef 100644 --- a/nimgen.nimble +++ b/nimgen.nimble @@ -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"] -- cgit v1.2.3 From a0369758afda24a0332f776c7a9d52a4ea9275ce Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Sat, 7 Jul 2018 16:57:23 -0500 Subject: Support 0.17.0 onwards, fix IOError --- nimgen.nim | 24 ++++++++++-------------- nimgen.nimble | 2 +- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/nimgen.nim b/nimgen.nim index ac61767..acf94da 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -194,15 +194,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() @@ -211,7 +213,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: @@ -476,9 +478,6 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = cfile = "temp-$#.c" % [outfile.extractFilename()] writeFile(cfile, runCtags(file)) - while not fileExists(cfile): - sleep(10) - if c2nimConfig.defines and (c2nimConfig.preprocess or c2nimConfig.ctags): prepend(cfile, getDefines(file, c2nimConfig.inline)) @@ -534,9 +533,6 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = cmd = "cmd /c " & cmd discard execProc(cmd) - while not fileExists(outfile): - sleep(10) - if c2nimConfig.preprocess or c2nimConfig.ctags: try: removeFile(cfile) diff --git a/nimgen.nimble b/nimgen.nimble index e0833ef..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" -- cgit v1.2.3 From 44294a7513985dafd5aabca790648e85fa5789ef Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Sat, 7 Jul 2018 17:47:55 -0500 Subject: Readme fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a92a5dc..1e95d0a 100644 --- a/README.md +++ b/README.md @@ -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 -- cgit v1.2.3