summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgiscanner/scannermain.py7
-rw-r--r--giscanner/transformer.py12
-rw-r--r--tests/scanner/meson.build11
-rw-r--r--tests/scanner/test_transformer.py38
4 files changed, 39 insertions, 29 deletions
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index acb2eba0..2f1d9095 100755
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -34,6 +34,7 @@ import subprocess
import sys
import tempfile
import platform
+import shlex
import giscanner
from giscanner import message
@@ -382,10 +383,12 @@ see --identifier-prefix and --symbol-prefix.""")
def create_transformer(namespace, options):
+ identifier_filter_cmd = shlex.split(options.identifier_filter_cmd)
+ symbol_filter_cmd = shlex.split(options.symbol_filter_cmd)
transformer = Transformer(namespace,
accept_unprefixed=options.accept_unprefixed,
- identifier_filter_cmd=options.identifier_filter_cmd,
- symbol_filter_cmd=options.symbol_filter_cmd)
+ identifier_filter_cmd=identifier_filter_cmd,
+ symbol_filter_cmd=symbol_filter_cmd)
transformer.set_include_paths(options.include_paths)
if options.passthrough_gir or options.reparse_validate_gir:
transformer.disable_cache()
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index f5a2f477..1a27aa3c 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -50,7 +50,7 @@ class Transformer(object):
namespace = property(lambda self: self._namespace)
def __init__(self, namespace, accept_unprefixed=False,
- identifier_filter_cmd='', symbol_filter_cmd=''):
+ identifier_filter_cmd=None, symbol_filter_cmd=None):
self._cachestore = CacheStore()
self._accept_unprefixed = accept_unprefixed
self._namespace = namespace
@@ -259,12 +259,11 @@ currently-scanned namespace is first."""
proc = subprocess.Popen(self._symbol_filter_cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- shell=True)
+ stderr=subprocess.PIPE)
_name = name
proc_name, err = proc.communicate(name.encode())
if proc.returncode:
- raise ValueError('filter: "%s" exited: %d with error: %s' %
+ raise ValueError('filter: %r exited: %d with error: %s' %
(self._symbol_filter_cmd, proc.returncode, err))
name = proc_name.decode('ascii')
name = name.strip()
@@ -326,11 +325,10 @@ raise ValueError."""
proc = subprocess.Popen(self._identifier_filter_cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- shell=True)
+ stderr=subprocess.PIPE)
proc_ident, err = proc.communicate(ident.encode())
if proc.returncode:
- raise ValueError('filter: "%s" exited: %d with error: %s' %
+ raise ValueError('filter: %r exited: %d with error: %s' %
(self._identifier_filter_cmd, proc.returncode, err))
ident = proc_ident.decode('ascii').strip()
diff --git a/tests/scanner/meson.build b/tests/scanner/meson.build
index 86c7d5da..07df91a9 100644
--- a/tests/scanner/meson.build
+++ b/tests/scanner/meson.build
@@ -6,17 +6,14 @@ scanner_test_files = [
'test_shlibs.py',
]
-# FIXME: Windows
-if host_system != 'windows'
- scanner_test_files += ['test_transformer.py']
-endif
-
# FIXME: MSVC
if cc.get_id() != 'msvc'
- scanner_test_files += ['test_sourcescanner.py']
+ scanner_test_files += [
+ 'test_sourcescanner.py',
+ 'test_transformer.py',
+ ]
endif
foreach f : scanner_test_files
test(f, python, args: files(f), env: scanner_test_env)
endforeach
-
diff --git a/tests/scanner/test_transformer.py b/tests/scanner/test_transformer.py
index 13b0b669..467f0c5c 100644
--- a/tests/scanner/test_transformer.py
+++ b/tests/scanner/test_transformer.py
@@ -42,16 +42,15 @@ def load_namespace_from_source_string(namespace, source):
class TestIdentifierFilter(unittest.TestCase):
def test_underscore_t_identifier_filter(self):
- cmd = textwrap.dedent(r"""
- python -c '
- import sys, re
- for line in sys.stdin:
- line = re.sub(r"^test_t$", "TestContext", line)
- line = re.sub(r"_t$", "", line)
- line = re.sub(r"^test_", "Test_", line)
- line = re.sub(r"_([a-z])", lambda m: m.group(1).title(),
- line)
- sys.stdout.write(line)'""")
+ cmd = [sys.executable, '-c', textwrap.dedent("""
+ import sys, re
+ for line in sys.stdin:
+ line = re.sub(r"^test_t$", "TestContext", line)
+ line = re.sub(r"_t$", "", line)
+ line = re.sub(r"^test_", "Test_", line)
+ line = re.sub(r"_([a-z])", lambda m: m.group(1).title(),
+ line)
+ sys.stdout.write(line)""")]
namespace = ast.Namespace('Test', '1.0')
xformer = Transformer(namespace, identifier_filter_cmd=cmd)
@@ -63,18 +62,31 @@ class TestIdentifierFilter(unittest.TestCase):
self.assertEqual(xformer.strip_identifier('test_foo_tart'), 'FooTart')
def test_invalid_command(self):
- cmd = r'this-is-not-a-real-command'
+ cmd = ['this-is-not-a-real-command']
namespace = ast.Namespace('Test', '1.0')
xformer = Transformer(namespace, identifier_filter_cmd=cmd)
- self.assertRaises(ValueError, xformer.strip_identifier, 'test_t')
+ self.assertRaises(OSError, xformer.strip_identifier, 'test_t')
def test_invalid_argument(self):
- cmd = r'sed --not-a-valid-argument'
+ cmd = [sys.executable, '--not-a-valid-argument']
namespace = ast.Namespace('Test', '1.0')
xformer = Transformer(namespace, identifier_filter_cmd=cmd)
self.assertRaises(ValueError, xformer.strip_identifier, 'test_t')
+class TestSymbolFilter(unittest.TestCase):
+
+ def test_split_csymbol(self):
+ cmd = [
+ sys.executable, '-c',
+ 'import sys; sys.stdout.write("test_" + sys.stdin.read())']
+ namespace = ast.Namespace('Test', '1.0')
+ xformer = Transformer(namespace, symbol_filter_cmd=cmd)
+
+ self.assertEqual(
+ xformer.split_csymbol('foo_bar_quux')[1], "foo_bar_quux")
+
+
class TestStructTypedefs(unittest.TestCase):
def setUp(self):
# Hack to set logging singleton