From 2fc12b8577c42d7fb23e8f7d1fea2591ef0e5da9 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Mon, 18 Jun 2018 19:53:54 +0900 Subject: 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. Fixes #12 --- nimgen.nim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nimgen.nim b/nimgen.nim index acf94da..7137dcd 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -488,13 +488,14 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = outpragma = "" passC = "import strutils\n" - for inc in gIncludes: - passC &= ("""{.passC: "-I\"" & gorge("nimble path $#").strip() & "/$#\"".}""" % [gOutput, inc]) & "\n" + passC &= "import ospaths\n" for prag in c2nimConfig.pragma: outpragma &= "{." & prag & ".}\n" let fname = file.splitFile().name.replace(re"[\.\-]", "_") + let fincl = file.replace(gOutput, "") + if c2nimConfig.dynlib.len() != 0: let win = "when defined(Windows):\n" @@ -524,7 +525,12 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = if outlib != "": extflags &= " --dynlib:dynlib$#" % fname else: - passC &= "const header$# = \"$#\"\n" % [fname, fl] + if file.isAbsolute(): + passC &= "const header$# = \"$#\"\n" % [fname, fincl] + else: + # based on the current source directory, get the include path + # works for nimble installations and local repo clones + passC &= "const header$# = currentSourcePath().splitPath().head & \"/$#\"\n" % [fname, fincl] extflags = "--header:header$#" % fname # Run c2nim on generated file -- cgit v1.2.3 From 4c45a5f5b2a7e75da707f450c330a20d8126ae9b Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 8 Jul 2018 22:43:17 +0900 Subject: Combine passC and absolute imports --- nimgen.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nimgen.nim b/nimgen.nim index 7137dcd..8693a7c 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -490,11 +490,18 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = passC = "import strutils\n" passC &= "import ospaths\n" + for inc in gIncludes: + let relativeInc = inc.replace(gOutput & $DirSep, "") + passC &= ( + """{.passC: "-I\"" & currentSourcePath().splitPath().head & "/$#\"".}""" % + [relativeInc] + ) & "\n" + for prag in c2nimConfig.pragma: outpragma &= "{." & prag & ".}\n" let fname = file.splitFile().name.replace(re"[\.\-]", "_") - let fincl = file.replace(gOutput, "") + let fincl = file.replace(gOutput & $DirSep, "") if c2nimConfig.dynlib.len() != 0: let -- cgit v1.2.3 From 15d417d2c5f6b3a5d25aaa5506a60201dc4f36cc Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 8 Jul 2018 22:50:34 +0900 Subject: Remove dir sep from replace --- nimgen.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nimgen.nim b/nimgen.nim index 8693a7c..a432ab6 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -491,7 +491,7 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = passC &= "import ospaths\n" for inc in gIncludes: - let relativeInc = inc.replace(gOutput & $DirSep, "") + let relativeInc = inc.replace(gOutput, "") passC &= ( """{.passC: "-I\"" & currentSourcePath().splitPath().head & "/$#\"".}""" % [relativeInc] @@ -501,7 +501,7 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = outpragma &= "{." & prag & ".}\n" let fname = file.splitFile().name.replace(re"[\.\-]", "_") - let fincl = file.replace(gOutput & $DirSep, "") + let fincl = file.replace(gOutput, "") if c2nimConfig.dynlib.len() != 0: let -- cgit v1.2.3 From 512cdd3a9f64d2be1a6fd338fe6d7fddeceaebae Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 8 Jul 2018 22:56:36 +0900 Subject: Add check for absolute directories --- nimgen.nim | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nimgen.nim b/nimgen.nim index a432ab6..75461bc 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -491,11 +491,14 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = passC &= "import ospaths\n" for inc in gIncludes: - let relativeInc = inc.replace(gOutput, "") - passC &= ( - """{.passC: "-I\"" & currentSourcePath().splitPath().head & "/$#\"".}""" % - [relativeInc] - ) & "\n" + if inc.isAbsolute: + passC &= ("""{.passC: "-I\"$#\"".}""" % [inc]) & "\n" + else: + let relativeInc = inc.replace(gOutput, "") + passC &= ( + """{.passC: "-I\"" & currentSourcePath().splitPath().head & "/$#\"".}""" % + [relativeInc] + ) & "\n" for prag in c2nimConfig.pragma: outpragma &= "{." & prag & ".}\n" -- cgit v1.2.3 From c846bf106a2b32ab6a0113fd8ce31f2d31463280 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Sun, 8 Jul 2018 16:01:54 -0500 Subject: Fixes to work with all wrappers --- nimgen.nim | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/nimgen.nim b/nimgen.nim index 75461bc..2bb3e16 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -438,6 +438,9 @@ proc runCtags(file: string): string = proc runFile(file: string, cfgin: OrderedTableRef) +template relativePath(path: untyped): untyped = + path.multiReplace([(gOutput, ""), ("\\", "/"), ("//", "/")]) + proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = var file = search(fl) if file == "": @@ -487,24 +490,18 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = outlib = "" outpragma = "" - passC = "import strutils\n" - passC &= "import ospaths\n" + passC = "import ospaths, strutils\n" for inc in gIncludes: - if inc.isAbsolute: - passC &= ("""{.passC: "-I\"$#\"".}""" % [inc]) & "\n" - else: - let relativeInc = inc.replace(gOutput, "") - passC &= ( - """{.passC: "-I\"" & currentSourcePath().splitPath().head & "/$#\"".}""" % - [relativeInc] - ) & "\n" + passC &= ( + """{.passC: "-I\"" & currentSourcePath().splitPath().head & "$#\"".}""" % + inc.relativePath() + ) & "\n" for prag in c2nimConfig.pragma: outpragma &= "{." & prag & ".}\n" let fname = file.splitFile().name.replace(re"[\.\-]", "_") - let fincl = file.replace(gOutput, "") if c2nimConfig.dynlib.len() != 0: let @@ -535,12 +532,8 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) = if outlib != "": extflags &= " --dynlib:dynlib$#" % fname else: - if file.isAbsolute(): - passC &= "const header$# = \"$#\"\n" % [fname, fincl] - else: - # based on the current source directory, get the include path - # works for nimble installations and local repo clones - passC &= "const header$# = currentSourcePath().splitPath().head & \"/$#\"\n" % [fname, fincl] + passC &= "const header$# = currentSourcePath().splitPath().head & \"$#\"\n" % + [fname, file.relativePath()] extflags = "--header:header$#" % fname # Run c2nim on generated file -- cgit v1.2.3