summaryrefslogtreecommitdiff
path: root/giscanner/transformer.py
diff options
context:
space:
mode:
authorGarrett Regier <garrett.regier@riftio.com>2015-02-14 11:15:50 -0800
committerColin Walters <walters@verbum.org>2015-04-20 16:47:36 -0400
commit7e5a553e7b597a7d53e901307c5f46a660b9c124 (patch)
tree3e8a4f49d66091ef28396492d0cddd506ed6e5f7 /giscanner/transformer.py
parent564e3b1baf8cad0c08f88bef09bbb14272fd65e2 (diff)
downloadgobject-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/transformer.py')
-rw-r--r--giscanner/transformer.py16
1 files changed, 15 insertions, 1 deletions
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():