diff options
author | Simon Feltman <sfeltman@src.gnome.org> | 2013-12-29 05:29:24 -0800 |
---|---|---|
committer | Simon Feltman <sfeltman@src.gnome.org> | 2014-06-03 13:06:32 -0700 |
commit | a882381f83f0acc6aaf7bfa03e1faa1c41a7ba00 (patch) | |
tree | b697160893d04f93a805f6ddd82cd66758834409 /giscanner | |
parent | dd0af8ef0145b1b1a323b06206c8e5528c6f8e1c (diff) | |
download | gobject-introspection-a882381f83f0acc6aaf7bfa03e1faa1c41a7ba00.tar.gz |
scanner: Add --identifier-filter-cmd
Add the command line flag --identifier-filter-cmd to g-ir-scanner which
allows running identifier names through a filtering shell command. The
identifier is sent as stdin to the filter command and expects a filtered
result written to stdout.
https://bugzilla.gnome.org/show_bug.cgi?706898
Diffstat (limited to 'giscanner')
-rwxr-xr-x | giscanner/scannermain.py | 8 | ||||
-rw-r--r-- | giscanner/transformer.py | 15 |
2 files changed, 21 insertions, 2 deletions
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 98d56878..ac340305 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -156,6 +156,11 @@ and --symbol-prefix.""") help="""Remove this prefix from C identifiers (structure typedefs, etc.). May be specified multiple times. This is also used as the default for --symbol-prefix if the latter is not specified.""") + parser.add_option("", "--identifier-filter-cmd", + action="store", dest="identifier_filter_cmd", default='', + help='Filter identifiers (struct and union typedefs) through the given ' + 'shell command which will receive the identifier name as input ' + 'to stdin and is expected to output the filtered results to stdout.') parser.add_option("", "--symbol-prefix", action="append", dest="symbol_prefixes", default=[], help="Remove this prefix from C symbols (function names)") @@ -334,7 +339,8 @@ see --identifier-prefix and --symbol-prefix.""" def create_transformer(namespace, options): transformer = Transformer(namespace, - accept_unprefixed=options.accept_unprefixed) + accept_unprefixed=options.accept_unprefixed, + identifier_filter_cmd=options.identifier_filter_cmd) transformer.set_include_paths(options.include_paths) if options.passthrough_gir: transformer.disable_cache() diff --git a/giscanner/transformer.py b/giscanner/transformer.py index 80265dd8..8c5e9087 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -20,6 +20,7 @@ import os import sys +import subprocess from . import ast from . import message @@ -49,7 +50,7 @@ if os.name != 'nt': class Transformer(object): namespace = property(lambda self: self._namespace) - def __init__(self, namespace, accept_unprefixed=False): + def __init__(self, namespace, accept_unprefixed=False, identifier_filter_cmd=''): self._cachestore = CacheStore() self._accept_unprefixed = accept_unprefixed self._namespace = namespace @@ -58,6 +59,7 @@ class Transformer(object): self._parsed_includes = {} # <string namespace -> Namespace> self._includepaths = [] self._passthrough_mode = False + self._identifier_filter_cmd = identifier_filter_cmd # Cache a list of struct/unions in C's "tag namespace". This helps # manage various orderings of typedefs and structs. See: @@ -293,6 +295,17 @@ raise ValueError.""" return matches[-1] def strip_identifier(self, ident): + if self._identifier_filter_cmd: + proc = subprocess.Popen(self._identifier_filter_cmd, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True) + ident, err = proc.communicate(ident) + if proc.returncode: + raise ValueError('filter: "%s" exited: %d with error: %s' % + (self._identifier_filter_cmd, proc.returncode, err)) + hidden = ident.startswith('_') if hidden: ident = ident[1:] |