aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools/vppapigen/vppapigen_json.py
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2018-09-12 13:40:13 -0700
committerDamjan Marion <dmarion@me.com>2018-09-13 00:32:35 +0000
commit9ce6a21aaa76cd40c95ebbcb5fc6e48a8f5dfdb9 (patch)
tree5656afec4a81b93dcda22b5af8b41c051f246bd8 /src/tools/vppapigen/vppapigen_json.py
parentb1232555e91b286feab5667b5a22f29aa8e96626 (diff)
Fix: vppapigen make build fails on fresh install
Steps to reproduce: vagrant@localhost:/vagrant$ build-root/vagrant/build.sh ... @@@@ Building vpp in /vagrant/build-root/build-vpp-native/vpp @@@@ [51/1169] Generating API header /vagrant/build-root/build-vpp-native/vpp/vlibmemory/memclnt.api.json FAILED: cd /vagrant/build-root/build-vpp-native/vpp/vlibmemory && mkdir -p /vagrant/build-root/build-vpp-native/vpp/vlibmemory && /vagrant/src/tools/vppapigen/vppapigen --includedir /vagrant/src --input /vagrant/src/vlibmemory/memclnt.api JSON --output /vagrant/build-root/build-vpp-native/vpp/vlibmemory/memclnt.api.json AttributeError: 'module' object has no attribute 'dumps' This seems to be due to JSON.py namespace colliding with the standard lib json.py Change-Id: If389e4e05ef0c166b0c2b3bef7ec0185298679a8 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'src/tools/vppapigen/vppapigen_json.py')
-rw-r--r--src/tools/vppapigen/vppapigen_json.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/tools/vppapigen/vppapigen_json.py b/src/tools/vppapigen/vppapigen_json.py
new file mode 100644
index 00000000000..2991bec57ac
--- /dev/null
+++ b/src/tools/vppapigen/vppapigen_json.py
@@ -0,0 +1,69 @@
+# JSON generation
+import json
+
+
+def walk_enums(s):
+ r = []
+ for e in s:
+ d = []
+ d.append(e.name)
+ for b in e.block:
+ d.append(b)
+ d.append({'enumtype': e.enumtype})
+ r.append(d)
+ return r
+
+
+def walk_services(s):
+ r = {}
+ for e in s:
+ d = {'reply': e.reply}
+ if e.stream:
+ d['stream'] = True
+ if e.events:
+ d['events'] = e.events
+ r[e.caller] = d
+ return r
+
+
+def walk_defs(s):
+ r = []
+ for t in s:
+ d = []
+ d.append(t.name)
+ for b in t.block:
+ f = []
+ if b.type == 'Field':
+ f = [b.fieldtype, b.fieldname]
+ elif b.type == 'Array':
+ if b.lengthfield:
+ f = [b.fieldtype, b.fieldname, b.length, b.lengthfield]
+ else:
+ f = [b.fieldtype, b.fieldname, b.length]
+ elif b.type == 'Union':
+ print('UNION')
+ else:
+ raise ValueError("Error in processing array type %s" % b)
+ d.append(f)
+ if t.crc:
+ c = {}
+ c['crc'] = "{0:#0{1}x}".format(t.crc, 10)
+ d.append(c)
+
+ r.append(d)
+ return r
+
+
+#
+# Plugin entry point
+#
+def run(filename, s, file_crc):
+ j = {}
+
+ j['types'] = walk_defs([o for o in s['types'] if o.__class__.__name__ == 'Typedef'])
+ j['messages'] = walk_defs(s['Define'])
+ j['unions'] = walk_defs([o for o in s['types'] if o.__class__.__name__ == 'Union'])
+ j['enums'] = walk_enums([o for o in s['types'] if o.__class__.__name__ == 'Enum'])
+ j['services'] = walk_services(s['Service'])
+ j['vl_api_version'] = hex(file_crc)
+ return json.dumps(j, indent=4, separators=(',', ': '))