Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1865)

Unified Diff: mojo/public/tools/bindings/generate_type_mappings.py

Issue 1832703002: Mojo: Simplify typemap usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-bindings-variant-import
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generate_type_mappings.py
diff --git a/mojo/public/tools/bindings/generate_type_mappings.py b/mojo/public/tools/bindings/generate_type_mappings.py
new file mode 100644
index 0000000000000000000000000000000000000000..103410d7f4a9961c754ed2a561945359e5db6cd2
--- /dev/null
+++ b/mojo/public/tools/bindings/generate_type_mappings.py
@@ -0,0 +1,57 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import argparse
+import os
+import json
+
+
+def ReadTypemap(path):
+ with open(path) as f:
+ return json.load(f)['c++']
+
+
+def ParseTypemapArgs(args):
+ typemaps = [s for s in '\n'.join(args).split('--start-typemap\n') if s]
+ result = {}
+ for typemap in typemaps:
+ result.update(ParseTypemap(typemap))
+ return result
+
+
+def ParseTypemap(typemap):
+ values = {'type_mappings': [], 'public_headers': [], 'traits_headers': []}
+ for line in typemap.split('\n'):
+ if not line:
+ continue
+ key, _, value = line.partition('=')
+ values[key].append(value.lstrip('/'))
+ result = {}
+ for typename in values['type_mappings']:
+ mojom_type, _, native_type = typename.partition('=')
+ result[mojom_type] = {
+ 'typename': native_type,
+ 'public_headers': values['public_headers'],
+ 'traits_headers': values['traits_headers'],
+ }
+ return result
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--dependency', type=str, action='append', default=[])
+ parser.add_argument('--output', type=str, required=True)
+ params, typemap_params = parser.parse_known_args()
+ typemaps = ParseTypemapArgs(typemap_params)
+ missing = [path for path in params.dependency if not os.path.exists(path)]
+ if missing:
+ raise IOError('Missing dependencies: %s' % ', '.join(missing))
+ for path in params.dependency:
+ typemaps.update(ReadTypemap(path))
+ with open(params.output, 'w') as f:
+ json.dump({'c++': typemaps}, f)
+
+
+if __name__ == '__main__':
+ main()

Powered by Google App Engine
This is Rietveld 408576698