Fixed a bug in options processing, which was breaking xproto -> proto
conversion. Also re-enabled the corresponding test.
Change-Id: I7d38e8ac612d4ca3d5c5ebc6fc96c65f7de259d2
diff --git a/xos/genx/tool/lib.py b/xos/genx/tool/lib.py
index 6a5409b..54a2b08 100644
--- a/xos/genx/tool/lib.py
+++ b/xos/genx/tool/lib.py
@@ -29,6 +29,11 @@
return plural
+def xproto_unquote(s):
+ if (s.startswith('"') and s.endswith('"')):
+ s = s[1:-1]
+ return s
+
def django_content_type_string(xptags):
# Check possibility of KeyError in caller
content_type = xptags['content_type']
diff --git a/xos/genx/tool/tests/proto_generator_test.py b/xos/genx/tool/tests/proto_generator_test.py
index f9c2d69..151edcc 100644
--- a/xos/genx/tool/tests/proto_generator_test.py
+++ b/xos/genx/tool/tests/proto_generator_test.py
@@ -2,11 +2,7 @@
# Generate Protobuf from Xproto and then parse the resulting Protobuf
class XProtoProtobufGeneratorTest(XProtoTest):
- # This test is disabled because of a bug in Protobuf generation from xproto
- # Namely, options appear with repeated double quotes: foo=""bar""
- # TODO: Fix this bug, and re-enable this test
-
- def __disabled_test_proto_generator(self):
+ def test_proto_generator(self):
xproto = \
"""
message VRouterPort (XOSBase){
@@ -22,7 +18,7 @@
message {{ m.name }} {
option bases = "{{ m.bases | join(",") }}";
{%- for f in m.fields %}
- {{ f.modifier }} {{f.type}} {{f.name}} = {{ f.id }}{% if f.options %} [{% for k,v in f.options.iteritems() %} {{ k }} = "{{ v}}"{% if not loop.last %},{% endif %} {% endfor %}]{% endif %};
+ {{ f.modifier }} {{f.type}} {{f.name}} = {{ f.id }}{% if f.options %} [{% for k,v in f.options.iteritems() %} {{ k }} = "{{ xproto_unquote(v)}}"{% if not loop.last %},{% endif %} {% endfor %}]{% endif %};
{%- endfor %}
}
{% endfor %}
@@ -31,6 +27,7 @@
self.generate(xproto = xproto, target = target)
self.generate(xproto = self.get_output(), target = "{{ proto }}")
output = self.get_output()
+ self.assertIn("VRouterService", output)
if __name__ == '__main__':
unittest.main()
diff --git a/xos/genx/tool/xos2jinja.py b/xos/genx/tool/xos2jinja.py
index 2a20612..727c097 100644
--- a/xos/genx/tool/xos2jinja.py
+++ b/xos/genx/tool/xos2jinja.py
@@ -178,6 +178,13 @@
n = self.count_stack.pop()
for i in range(0, n):
k,v = self.stack.pop()
+
+ # The two lines below may be added to eliminate "" around an option.
+ # Right now, this is handled in targets. FIXME
+ #
+ # if (v.startswith('"') and v.endswith('"')):
+ # v = v[1:-1]
+
opts[k] = v
s['options'] = opts