Only include necessary file for include libs

The previous behavior caused a "Too many files open" error when
referrencing lots of libs because of the call to "gorge". This
modification retains the old behavior and also works if the library is
compiled locally.
This commit is contained in:
Joey Yakimowich-Payne 2018-06-18 19:53:54 +09:00
commit 0449f548dc

View file

@ -501,13 +501,14 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
outpragma = "" outpragma = ""
passC = "import strutils\n" passC = "import strutils\n"
for inc in gIncludes: passC &= "import ospaths\n"
passC &= ("""{.passC: "-I\"" & gorge("nimble path $#").strip() & "/$#\"".}""" % [gOutput, inc]) & "\n"
for prag in c2nimConfig.pragma: for prag in c2nimConfig.pragma:
outpragma &= "{." & prag & ".}\n" outpragma &= "{." & prag & ".}\n"
let fname = file.splitFile().name.replace(re"[\.\-]", "_") let fname = file.splitFile().name.replace(re"[\.\-]", "_")
let fincl = file.replace(gOutput, "")
if c2nimConfig.dynlib.len() != 0: if c2nimConfig.dynlib.len() != 0:
let let
win = "when defined(Windows):\n" win = "when defined(Windows):\n"
@ -537,7 +538,10 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
if outlib != "": if outlib != "":
extflags &= " --dynlib:dynlib$#" % fname extflags &= " --dynlib:dynlib$#" % fname
else: else:
passC &= "const header$# = \"$#\"\n" % [fname, fl] if file.isAbsolute():
passC &= "const header$# = \"$#\"\n" % [fname, fincl]
else:
passC &= "const header$# = currentSourcePath().splitPath().head & \"/$#\"\n" % [fname, fincl]
extflags = "--header:header$#" % fname extflags = "--header:header$#" % fname
# Run c2nim on generated file # Run c2nim on generated file