aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgenotrance <dev@genotrance.com>2018-07-10 01:57:39 -0500
committerGitHub <noreply@github.com>2018-07-10 01:57:39 -0500
commit9c2c252f043e93e4cf59b31b6cb7a4d1897f69ec (patch)
tree5e0ea66cfa61b74512bbb9359cc4e9d39f0b10ad
parent84894bfa0c2eb82e719c73a512c07d0ca595aff1 (diff)
parentf5e8535ce83c79d66e32e1ebe2d5f1a945f61c77 (diff)
downloadnimgen-9c2c252f043e93e4cf59b31b6cb7a4d1897f69ec.tar.gz
nimgen-9c2c252f043e93e4cf59b31b6cb7a4d1897f69ec.zip
Merge pull request #18 from jyapayne/allow_relative_imports
Implement relative import support in header files.
-rw-r--r--nimgen.nim20
1 files changed, 17 insertions, 3 deletions
diff --git a/nimgen.nim b/nimgen.nim
index c132fe1..94fa48c 100644
--- a/nimgen.nim
+++ b/nimgen.nim
@@ -224,7 +224,8 @@ proc search(file: string): string =
echo "File doesn't exist: " & file
quit(1)
- return result.replace(re"[\\/]", $DirSep)
+ # Only keep relative directory
+ return result.multiReplace([("\\", $DirSep), ("//", $DirSep), (gProjectDir & $DirSep, "")])
# ###
# Loading / unloading
@@ -376,12 +377,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 = finc.replace(curPath & $DirSep, "")
+
+ 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()