diff options
author | Garrett Regier <garrett.regier@riftio.com> | 2015-02-14 11:15:50 -0800 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2015-04-20 16:47:36 -0400 |
commit | 7e5a553e7b597a7d53e901307c5f46a660b9c124 (patch) | |
tree | 3e8a4f49d66091ef28396492d0cddd506ed6e5f7 /giscanner | |
parent | 564e3b1baf8cad0c08f88bef09bbb14272fd65e2 (diff) | |
download | gobject-introspection-7e5a553e7b597a7d53e901307c5f46a660b9c124.tar.gz |
scanner: Add --symbol-filter-cmd
Add the command line flag --symbol-filter-cmd to g-ir-scanner
which allows running symbol names through a filtering shell
command. The symbol is sent as stdin to the filter command
and expects a filtered result written to stdout.
https://bugzilla.gnome.org/show_bug.cgi?id=744534
Signed-off-by: Garrett Regier <garrett.regier@riftio.com>
Diffstat (limited to 'giscanner')
-rwxr-xr-x | giscanner/scannermain.py | 8 | ||||
-rw-r--r-- | giscanner/transformer.py | 16 |
2 files changed, 22 insertions, 2 deletions
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index b36284da..6be958ed 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -164,6 +164,11 @@ the latter is not specified.""") parser.add_option("", "--symbol-prefix", action="append", dest="symbol_prefixes", default=[], help="Remove this prefix from C symbols (function names)") + parser.add_option("", "--symbol-filter-cmd", + action="store", dest="symbol_filter_cmd", default='', + help='Filter symbols (function names) through the given ' + 'shell command which will receive the symbol name as input ' + 'to stdin and is expected to output the filtered results to stdout.') parser.add_option("", "--accept-unprefixed", action="store_true", dest="accept_unprefixed", default=False, help="""If specified, accept symbols and identifiers that do not @@ -367,7 +372,8 @@ see --identifier-prefix and --symbol-prefix.""" def create_transformer(namespace, options): transformer = Transformer(namespace, accept_unprefixed=options.accept_unprefixed, - identifier_filter_cmd=options.identifier_filter_cmd) + identifier_filter_cmd=options.identifier_filter_cmd, + symbol_filter_cmd=options.symbol_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 b8bdfba2..6ae63897 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -50,7 +50,8 @@ if os.name != 'nt': class Transformer(object): namespace = property(lambda self: self._namespace) - def __init__(self, namespace, accept_unprefixed=False, identifier_filter_cmd=''): + def __init__(self, namespace, accept_unprefixed=False, + identifier_filter_cmd='', symbol_filter_cmd=''): self._cachestore = CacheStore() self._accept_unprefixed = accept_unprefixed self._namespace = namespace @@ -60,6 +61,7 @@ class Transformer(object): self._includepaths = [] self._passthrough_mode = False self._identifier_filter_cmd = identifier_filter_cmd + self._symbol_filter_cmd = symbol_filter_cmd # Cache a list of struct/unions in C's "tag namespace". This helps # manage various orderings of typedefs and structs. See: @@ -242,6 +244,18 @@ currently-scanned namespace is first.""" return cmp(x[2], y[2]) def _split_c_string_for_namespace_matches(self, name, is_identifier=False): + if not is_identifier and self._symbol_filter_cmd: + proc = subprocess.Popen(self._symbol_filter_cmd, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True) + _name = name + name, err = proc.communicate(name) + if proc.returncode: + raise ValueError('filter: "%s" exited: %d with error: %s' % + (self._symbol_filter_cmd, proc.returncode, err)) + matches = [] # Namespaces which might contain this name unprefixed_namespaces = [] # Namespaces with no prefix, last resort for ns in self._iter_namespaces(): |