OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Checks that released mojom.dart files in the source tree are up to date""" | 6 """Checks that released mojom.dart files in the source tree are up to date""" |
7 | 7 |
8 import argparse | 8 import argparse |
9 import os | 9 import os |
10 import subprocess | 10 import subprocess |
11 import sys | 11 import sys |
12 | 12 |
13 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 13 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
14 SRC_DIR = os.path.dirname( | 14 SRC_DIR = os.path.dirname( |
15 os.path.dirname( | 15 os.path.dirname( |
16 os.path.dirname( | 16 os.path.dirname( |
17 os.path.dirname(SCRIPT_DIR)))) | 17 os.path.dirname(SCRIPT_DIR)))) |
18 | 18 |
19 # Insert path to mojom parsing library. | 19 # Insert path to mojom parsing library. |
20 sys.path.insert(0, os.path.join(SRC_DIR, | 20 sys.path.insert(0, os.path.join(SRC_DIR, |
21 'mojo', | 21 'mojo', |
22 'public', | 22 'public', |
23 'tools', | 23 'tools', |
24 'bindings', | 24 'bindings', |
25 'pylib')) | 25 'pylib')) |
26 | 26 |
27 from mojom.error import Error | 27 from mojom.error import Error |
28 from mojom.parse.parser import Parse | 28 from mojom.parse import parser_runner |
29 from mojom.parse.translate import Translate | 29 from mojom.generate import mojom_translator |
30 | 30 |
31 PACKAGES_DIR = os.path.join(SRC_DIR, 'mojo', 'dart', 'packages') | 31 PACKAGES_DIR = os.path.join(SRC_DIR, 'mojo', 'dart', 'packages') |
| 32 SDK_DIR = os.path.join(SRC_DIR, 'mojo', 'public') |
32 | 33 |
33 # Script that calculates mojom output paths. | 34 # Script that calculates mojom output paths. |
34 DART_OUTPUTS_SCRIPT = os.path.join(SRC_DIR, | 35 DART_OUTPUTS_SCRIPT = os.path.join(SDK_DIR, |
35 'mojo', | |
36 'public', | |
37 'tools', | 36 'tools', |
38 'bindings', | 37 'bindings', |
39 'mojom_list_dart_outputs.py') | 38 'mojom_list_dart_outputs.py') |
40 | 39 |
41 # Runs command line in args from cwd. Returns the output as a string. | 40 # Runs command line in args from cwd. Returns the output as a string. |
42 def run(cwd, args): | 41 def run(cwd, args): |
43 return subprocess.check_output(args, cwd=cwd) | 42 return subprocess.check_output(args, cwd=cwd) |
44 | 43 |
45 | 44 |
46 # Given a parsed mojom, return the path of the .mojom.dart relative to its | 45 # Given a mojom.Module, return the path of the .mojom.dart relative to its |
47 # package directory. | 46 # package directory. |
48 def _mojom_output_path(mojom): | 47 def _mojom_output_path(mojom): |
49 name = mojom['name'] | 48 name = mojom.name |
50 namespace = mojom['namespace'] | 49 namespace = mojom.namespace |
51 elements = ['lib'] | 50 elements = ['lib'] |
52 elements.extend(namespace.split('.')) | 51 elements.extend(namespace.split('.')) |
53 elements.append("%s.dart" % name) | 52 elements.append("%s.dart" % name) |
54 return os.path.join(*elements) | 53 return os.path.join(*elements) |
55 | 54 |
56 | 55 |
57 # Given a parsed mojom, return the package or None. | 56 # Given a mojom.Module, return the package or None. |
58 def _mojom_package(mojom): | 57 def _mojom_package(mojom): |
59 attributes = mojom.get('attributes', {}) | 58 if mojom.attributes: |
60 return attributes.get('DartPackage') | 59 return mojom.attributes.get('DartPackage') |
61 | 60 |
62 | 61 # Load and parse a .mojom file. Returns the mojom.Module or raises an Exception |
63 # Load and parse a .mojom file. Returns the parsed mojom. | 62 # if there was an error. |
64 def _load_mojom(path_to_mojom): | 63 def _load_mojom(path_to_mojom): |
65 filename = os.path.abspath(path_to_mojom) | 64 filename = os.path.abspath(path_to_mojom) |
66 name = os.path.basename(filename) | |
67 | 65 |
68 # Read in mojom file. | |
69 with open(filename) as f: | |
70 source = f.read() | |
71 # Parse | 66 # Parse |
72 tree = Parse(source, name) | 67 mojom_file_graph = parser_runner.ParseToMojomFileGraph(SDK_DIR, [filename], |
73 mojom = Translate(tree, name) | 68 meta_data_only=True) |
74 return mojom | 69 if mojom_file_graph is None: |
75 | 70 raise Exception |
| 71 mojom_dict = mojom_translator.TranslateFileGraph(mojom_file_graph) |
| 72 return mojom_dict[filename] |
76 | 73 |
77 def _print_regenerate_message(package): | 74 def _print_regenerate_message(package): |
78 print(""" | 75 print(""" |
79 *** Dart Generated Bindings Check Failed for package: %s | 76 *** Dart Generated Bindings Check Failed for package: %s |
80 | 77 |
81 To regenerate all bindings, from the src directory, run: | 78 To regenerate all bindings, from the src directory, run: |
82 | 79 |
83 ./mojo/dart/tools/bindings/generate.py | 80 ./mojo/dart/tools/bindings/generate.py |
84 """ % (package)) | 81 """ % (package)) |
85 | 82 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 if args.affected_files: | 399 if args.affected_files: |
403 check_failure = presubmit_check(packages, args.affected_files) | 400 check_failure = presubmit_check(packages, args.affected_files) |
404 else: | 401 else: |
405 check_failure = global_check(packages) | 402 check_failure = global_check(packages) |
406 if check_failure: | 403 if check_failure: |
407 return 2 | 404 return 2 |
408 return 0 | 405 return 0 |
409 | 406 |
410 if __name__ == '__main__': | 407 if __name__ == '__main__': |
411 sys.exit(main()) | 408 sys.exit(main()) |
OLD | NEW |