| 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 SDK_DIR = os.path.join(SCRIPT_DIR, os.path.pardir, os.path.pardir) | |
| 16 sys.path.insert(0, os.path.join(SCRIPT_DIR, 'pylib')) | |
| 17 | |
| 18 from mojom.error import Error | |
| 19 from mojom.parse import parser_runner | |
| 20 from mojom.generate import mojom_translator | |
| 21 | |
| 22 def mojom_path(name, namespace, attributes): | |
| 23 package_name = 'mojom' | |
| 24 if attributes and attributes.get('DartPackage'): | |
| 25 package_name = attributes['DartPackage'] | |
| 26 elements = [package_name, 'lib'] | |
| 27 elements.extend(namespace.split('.')) | |
| 28 elements.append("%s.dart" % name) | |
| 29 return os.path.join(*elements) | |
| 30 | |
| 31 | |
| 32 def process_mojom(path_to_mojom): | |
| 33 filename = os.path.abspath(path_to_mojom) | |
| 34 | |
| 35 # Parse | |
| 36 mojom_file_graph = parser_runner.ParseToMojomFileGraph(SDK_DIR, [filename], | |
| 37 meta_data_only=True) | |
| 38 if mojom_file_graph is None: | |
| 39 print("Error parsing %s" % filename) | |
| 40 mojom_dict = mojom_translator.TranslateFileGraph(mojom_file_graph) | |
| 41 mojom = mojom_dict[filename] | |
| 42 | |
| 43 # Output path | |
| 44 attributes = mojom.attributes | |
| 45 print(mojom_path(mojom.name, mojom.namespace, attributes)) | |
| 46 | |
| 47 | |
| 48 def main(): | |
| 49 parser = argparse.ArgumentParser(description='Output list of ') | |
| 50 parser.add_argument('--mojoms', | |
| 51 metavar='mojoms', | |
| 52 nargs='+', | |
| 53 required=True) | |
| 54 args = parser.parse_args() | |
| 55 | |
| 56 for mojom in args.mojoms: | |
| 57 process_mojom(mojom) | |
| 58 | |
| 59 return 0 | |
| 60 | |
| 61 | |
| 62 if __name__ == '__main__': | |
| 63 sys.exit(main()) | |
| OLD | NEW |