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

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

Issue 1449203002: Check in generated Dart bindings and add presubmit script (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_dart_generator.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/tools/bindings/mojom_list_dart_outputs.py
diff --git a/mojo/public/tools/bindings/mojom_list_dart_outputs.py b/mojo/public/tools/bindings/mojom_list_dart_outputs.py
new file mode 100755
index 0000000000000000000000000000000000000000..3580cf1c703ff888c55c2ea359055fedb4de663d
--- /dev/null
+++ b/mojo/public/tools/bindings/mojom_list_dart_outputs.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+# Copyright 2014 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.
+
+"""Generates the list of dart source file outputs from a mojom.Module."""
+
+import argparse
+import os
+import re
+import shutil
+import sys
+
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(0, os.path.join(SCRIPT_DIR, 'pylib'))
+
+from mojom.error import Error
+from mojom.parse.parser import Parse
+from mojom.parse.translate import Translate
+
+def mojom_path(name, namespace, attributes):
+ package_name = attributes['DartPackage']
+ if package_name == None:
+ package_name = 'mojom'
+ elements = [package_name, 'lib']
+ elements.extend(namespace.split('.'))
+ elements.append("%s.dart" % name)
+ return os.path.join(*elements)
+
+
+def process_mojom(path_to_mojom):
+ filename = os.path.abspath(path_to_mojom)
+ name = os.path.basename(filename)
+
+ # Read in mojom file.
+ try:
+ with open(filename) as f:
+ source = f.read()
+ except IOError:
+ print("Error reading %s" % filename)
+ sys.exit(2)
+
+ # Parse
+ try:
+ tree = Parse(source, name)
+ except Error:
+ print("Error parsing %s" % filename)
+ sys.exit(2)
+
+ mojom = Translate(tree, name)
+
+ # Output path
+ print(mojom_path(mojom['name'], mojom['namespace'], mojom['attributes']))
+
+
+def main():
+ parser = argparse.ArgumentParser(description='Output list of ')
+ parser.add_argument('--mojoms',
+ metavar='mojoms',
+ nargs='+',
+ required=True)
+ args = parser.parse_args()
+
+ for mojom in args.mojoms:
+ process_mojom(mojom)
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_dart_generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698