From 2e894dc90702b92290c226dd683a198b3d092634 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Mon, 18 Jun 2018 19:44:45 +0900 Subject: [PATCH 1/2] Implement relative import support in header files. Fixes #17 --- nimgen.nim | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/nimgen.nim b/nimgen.nim index c132fe1..6baea3b 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -224,6 +224,8 @@ proc search(file: string): string = echo "File doesn't exist: " & file quit(1) + # Only keep relative directory + result = result.replace(gProjectDir & $DirSep, "") return result.replace(re"[\\/]", $DirSep) # ### @@ -376,12 +378,25 @@ proc getIncls(file: string, inline=false): seq[string] = if inline and file in gDoneInline: return + let curPath = splitFile(expandFileName(file)).dir withFile(file): for f in content.findIter(re"(?m)^\s*#\s*include\s+(.*?)$"): var inc = f.captures[0].strip() if ((gQuotes and inc.contains("\"")) or (gFilter != "" and gFilter in inc)) and (not exclude(inc)): - result.add( - inc.replace(re"""[<>"]""", "").replace(re"\/[\*\/].*$", "").strip()) + let addInc = inc.replace(re"""[<>"]""", "").replace(re"\/[\*\/].*$", "").strip() + try: + # Try searching for a local library. expandFilename will throw + # OSError if the file does not exist + let + finc = expandFileName(curPath / addInc) + fname = extractFileName(finc).search() + + if fname.len() > 0: + # only add if the file is non-empty + result.add(fname.search()) + except OSError: + # If it's a system library + result.add(addInc) result = result.deduplicate() From f5e8535ce83c79d66e32e1ebe2d5f1a945f61c77 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Tue, 10 Jul 2018 13:53:53 +0900 Subject: [PATCH 2/2] Fix windows paths --- nimgen.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nimgen.nim b/nimgen.nim index 6baea3b..94fa48c 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -225,8 +225,7 @@ proc search(file: string): string = quit(1) # Only keep relative directory - result = result.replace(gProjectDir & $DirSep, "") - return result.replace(re"[\\/]", $DirSep) + return result.multiReplace([("\\", $DirSep), ("//", $DirSep), (gProjectDir & $DirSep, "")]) # ### # Loading / unloading @@ -389,7 +388,7 @@ proc getIncls(file: string, inline=false): seq[string] = # OSError if the file does not exist let finc = expandFileName(curPath / addInc) - fname = extractFileName(finc).search() + fname = finc.replace(curPath & $DirSep, "") if fname.len() > 0: # only add if the file is non-empty