diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2020-05-12 22:01:42 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2020-05-12 23:02:04 -0500 |
| commit | 37fa2ad7fb69553ec37d5e4b46988feaca7f80f1 (patch) | |
| tree | f4658a06ccf140db46e0f7f009181b3aa77fcf90 | |
| parent | 8e052269c996ac1e50bce6643604ab8128e921c3 (diff) | |
| download | nimterop-clifile.tar.gz nimterop-clifile.zip | |
Add CLI file featureclifile
| -rw-r--r-- | CHANGES.md | 3 | ||||
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | nimterop.nimble | 4 | ||||
| -rw-r--r-- | nimterop/ast2.nim | 14 | ||||
| -rw-r--r-- | nimterop/toast.nim | 26 | ||||
| -rw-r--r-- | tests/toast.cfg | 2 |
6 files changed, 35 insertions, 18 deletions
@@ -58,6 +58,8 @@ https://github.com/nimterop/nimterop/compare/v0.4.4...v0.5.0 - `toast` also includes `--typeMap | -T` to map C types to another type. E.g. `--typeMap:GLint64=int64` generates a wrapper where all instances of `GLint64` are remapped to the Nim type `int64` and `GLint64` is not defined. (since v0.5.2) +- CLI flags can now be specified one or more per line in a file and path provided to `toast`. They will be expanded in place. [#196][i196] (since v0.5.3) + - Nimterop is now able to detect Nim configuration of projects and can better handle cases where defaults such as `nimcacheDir` or `nimblePath` are overridden. This especially enables better interop with workflows that do not depend on Nimble. [#151][i151] [#153][i153] - Nimterop defaults to `cmake`, followed by `autoconf` for building libraries with `getHeader()`. It is now possible to change the order of discovery with the `buildType` value. [#200][i200] @@ -78,5 +80,6 @@ https://github.com/nimterop/nimterop/compare/v0.4.4...v0.5.0 [i174]: https://github.com/nimterop/nimterop/issues/174 [i176]: https://github.com/nimterop/nimterop/issues/176 [i181]: https://github.com/nimterop/nimterop/issues/181 +[i196]: https://github.com/nimterop/nimterop/issues/196 [i197]: https://github.com/nimterop/nimterop/issues/197 [i200]: https://github.com/nimterop/nimterop/issues/200
\ No newline at end of file @@ -195,14 +195,14 @@ Nimterop also provides a [docs](https://nimterop.github.io/nimterop/docs.html) A ### Command line API -The `toast` binary can also be used directly on the CLI, similar to `c2nim`. The `cPlugin()` interface +The `toast` binary can also be used directly on the CLI, similar to `c2nim`. These flags can be specified on the command line or via a file, one or more flags per line, and the path provided to `toast` instead, or a combination. The file contents will be expanded in place. Note: unlike the wrapper API, the `-p | --preprocess` flag is not enabled by default but is *highly* recommended. ``` > toast -h Usage: - main [optional-params] C/C++ source/header + main [optional-params] C/C++ source/header(s) and command line file(s) Options: -h, --help print this cligen-erated help --help-syntax advanced: prepend,plurals,.. diff --git a/nimterop.nimble b/nimterop.nimble index 2a8c269..4ec024c 100644 --- a/nimterop.nimble +++ b/nimterop.nimble @@ -59,8 +59,8 @@ task test, "Test": execTest "tests/tnimterop_c.nim", "-d:FLAGS=\"-f:ast2 -H\"" execCmd "nim cpp --hints:off -f -r tests/tnimterop_cpp.nim" - execCmd "./nimterop/toast -pnk -E=_ tests/include/toast.h" - execCmd "./nimterop/toast -pnk -E=_ -f:ast2 tests/include/toast.h" + execCmd "./nimterop/toast tests/toast.cfg tests/include/toast.h" + execCmd "./nimterop/toast tests/toast.cfg -f:ast2 tests/include/toast.h" execTest "tests/tpcre.nim" execTest "tests/tpcre.nim", "-d:FLAGS=\"-f:ast2\"" diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim index d1e691b..4a9b048 100644 --- a/nimterop/ast2.nim +++ b/nimterop/ast2.nim @@ -139,7 +139,7 @@ proc newConstDef(gState: State, node: TSNode, fname = "", fval = ""): PNode = else: gecho &"# const '{origname}' is duplicate, skipped" else: - gecho &"# const '{origname}' has invalid value '{val}'" + gecho &"# const '{origname}' has unsupported value '{val}'" gState.skippedSyms.incl origname proc addConst(gState: State, node: TSNode) = @@ -1736,19 +1736,9 @@ proc setupPragmas(gState: State, root: TSNode, fullpath: string) = # Add `{.experimental: "codeReordering".} for #206 gState.pragmaSection.add gState.newPragma(root, "experimental", newStrNode(nkStrLit, "codeReordering")) -proc printNimHeader*(gState: State) = - # Top level output with context info - gecho """# Generated at $1 -# Command line: -# $2 $3 - -{.hint[ConvFromXtoItselfNotNeeded]: off.} - -import nimterop/types -""" % [$now(), getAppFilename(), commandLineParams().join(" ")] - proc initNim*(gState: State) = # Initialize for parseNim() one time + gecho "import nimterop/types\n" # Track identifiers already rendered and corresponding PNodes gState.identifiers = newTable[string, string]() diff --git a/nimterop/toast.nim b/nimterop/toast.nim index 3a58749..b1f910c 100644 --- a/nimterop/toast.nim +++ b/nimterop/toast.nim @@ -141,7 +141,6 @@ proc main( elif source.nBl: # Print source after preprocess or Nim output if gState.pnim: - gState.printNimHeader() gState.initNim() for src in source: gState.process(src.expandSymlinkAbs(), astTable) @@ -199,6 +198,29 @@ proc main( if check and output.len == 0: stdout.write outputFile.readFile() +proc mergeParams(cmdNames: seq[string], cmdLine = commandLineParams()): seq[string] = + # Load command-line params from `source` if it is a .cfg file + if cmdNames.len != 0: + # https://github.com/c-blake/cligen/issues/149 + for param in cmdLine: + if param.fileExists() and param.splitFile().ext == ".cfg": + echo &"# Loading flags from '{param}'" + for line in param.readFile().splitLines(): + let + line = line.strip() + if line.len > 1 and line[0] != '#': + result.add line.parseCmdLine() + else: + result.add param + + if result.len != 0 and "-h" notin result and "--help" notin result: + echo &"""# Generated @ {$now()} +# Command line: +# {getAppFilename()} {result.join(" ")} +""" + else: + result = cmdLine + when isMainModule: # Setup cligen command line help and short flags import cligen @@ -223,7 +245,7 @@ when isMainModule: "preprocess": "run preprocessor on header", "recurse": "process #include files", "replace": "replace X with Y in identifiers, X1=Y1,X2=Y2, @X for regex", - "source" : "C/C++ source/header", + "source" : "C/C++ source/header(s) and command line file(s)", "stub": "stub out undefined type references as objects", "suffix": "strip suffix from identifiers", "symOverride": "skip generating specified symbols", diff --git a/tests/toast.cfg b/tests/toast.cfg new file mode 100644 index 0000000..8c37f3c --- /dev/null +++ b/tests/toast.cfg @@ -0,0 +1,2 @@ +--preprocess +-nk -E=_
\ No newline at end of file |
