OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Generates the list of dart source file outputs from a mojom.Module.""" |
| 7 |
| 8 import argparse |
| 9 import os |
| 10 import re |
| 11 import shutil |
| 12 import sys |
| 13 |
| 14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 15 sys.path.insert(0, os.path.join(SCRIPT_DIR, 'pylib')) |
| 16 |
| 17 from mojom.error import Error |
| 18 from mojom.parse.parser import Parse |
| 19 from mojom.parse.translate import Translate |
| 20 |
| 21 def mojom_path(name, namespace, attributes): |
| 22 package_name = attributes['DartPackage'] |
| 23 if package_name == None: |
| 24 package_name = 'mojom' |
| 25 elements = [package_name, 'lib'] |
| 26 elements.extend(namespace.split('.')) |
| 27 elements.append("%s.dart" % name) |
| 28 return os.path.join(*elements) |
| 29 |
| 30 |
| 31 def process_mojom(path_to_mojom): |
| 32 filename = os.path.abspath(path_to_mojom) |
| 33 name = os.path.basename(filename) |
| 34 |
| 35 # Read in mojom file. |
| 36 try: |
| 37 with open(filename) as f: |
| 38 source = f.read() |
| 39 except IOError: |
| 40 print("Error reading %s" % filename) |
| 41 sys.exit(2) |
| 42 |
| 43 # Parse |
| 44 try: |
| 45 tree = Parse(source, name) |
| 46 except Error: |
| 47 print("Error parsing %s" % filename) |
| 48 sys.exit(2) |
| 49 |
| 50 mojom = Translate(tree, name) |
| 51 |
| 52 # Output path |
| 53 print(mojom_path(mojom['name'], mojom['namespace'], mojom['attributes'])) |
| 54 |
| 55 |
| 56 def main(): |
| 57 parser = argparse.ArgumentParser(description='Output list of ') |
| 58 parser.add_argument('--mojoms', |
| 59 metavar='mojoms', |
| 60 nargs='+', |
| 61 required=True) |
| 62 args = parser.parse_args() |
| 63 |
| 64 for mojom in args.mojoms: |
| 65 process_mojom(mojom) |
| 66 |
| 67 return 0 |
| 68 |
| 69 |
| 70 if __name__ == '__main__': |
| 71 sys.exit(main()) |
OLD | NEW |