OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/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 # This script scans a directory tree for any .mojom files and outputs a | 6 # This script scans a directory tree for any .mojom files and outputs a |
7 # list of url_mapping command line arguments for embedder-package: imports. | 7 # list of url_mapping command line arguments for embedder-package: imports. |
8 # These url_mapping arguments can be passed to gen_snapshot. | 8 # These url_mapping arguments can be passed to gen_snapshot. |
9 | 9 |
10 # an example output line: | 10 # an example output line: |
11 # --url_mapping=dart:_mojom/mojo/service.mojom.dart, \ | 11 # --url_mapping=dart:_mojom/mojo/service.mojom.dart, \ |
12 # /.../src/out/Debug/gen/dart_embedder_packages/mojo/service.mojom.dart | 12 # /.../src/out/Debug/gen/dart_embedder_packages/mojo/service.mojom.dart |
13 | 13 |
14 import argparse | 14 import argparse |
15 import os | 15 import os |
16 import sys | 16 import sys |
17 | 17 |
18 def scan(package_root, directory, mapped_to): | 18 def scan(package_root, directory, mapped_to): |
19 for dirname, _, filenames in os.walk(directory): | 19 for dirname, _, filenames in os.walk(directory): |
20 # Ignore tests. | 20 # Ignore tests. |
21 if dirname.endswith('tests'): | 21 if dirname.endswith('tests'): |
22 continue; | 22 continue; |
23 # filter for .mojom files. | 23 # filter for .mojom files. |
24 filenames = [f for f in filenames if f.endswith('.mojom')] | 24 filenames = [f for f in filenames if f.endswith('.mojom')] |
25 for f in filenames: | 25 for f in filenames: |
26 path = os.path.join(mapped_to, f) | 26 path = os.path.join(mapped_to, f) |
| 27 |
| 28 # Note: This is incorrect for the files in the mojo.bindings.types |
| 29 # module. We rectify the embedder url mapping by adding bindings/types. |
| 30 if f.endswith('service_describer.mojom') or \ |
| 31 f.endswith('mojom_files.mojom') or f.endswith('mojom_types.mojom'): |
| 32 path = os.path.join(mapped_to, 'bindings/types', f) |
| 33 |
27 # Append .dart. | 34 # Append .dart. |
28 path += '.dart' | 35 path += '.dart' |
29 print('--url_mapping=dart:_' + path + ',' + | 36 print('--url_mapping=dart:_' + path + ',' + |
30 os.path.join(package_root, path)) | 37 os.path.join(package_root, path)) |
31 | 38 |
32 def main(args): | 39 def main(args): |
33 parser = argparse.ArgumentParser( | 40 parser = argparse.ArgumentParser( |
34 description='Generates --url_mapping arguments suitable for gen_snapshot') | 41 description='Generates --url_mapping arguments suitable for gen_snapshot') |
35 parser.add_argument('package_directory_root', | 42 parser.add_argument('package_directory_root', |
36 metavar='package_directory_root', | 43 metavar='package_directory_root', |
37 help='Path to directory containing target .dart ' | 44 help='Path to directory containing target .dart ' |
38 'files.') | 45 'files.') |
39 parser.add_argument('packages', | 46 parser.add_argument('packages', |
40 metavar='packages', | 47 metavar='packages', |
41 nargs='+', | 48 nargs='+', |
42 help='Paths to package(s) directories.') | 49 help='Paths to package(s) directories.') |
43 args = parser.parse_args() | 50 args = parser.parse_args() |
44 package_root = os.path.abspath(args.package_directory_root) | 51 package_root = os.path.abspath(args.package_directory_root) |
45 packages = args.packages | 52 packages = args.packages |
46 for package in packages: | 53 for package in packages: |
47 mapping = package.split(',', 1) | 54 mapping = package.split(',', 1) |
48 directory = os.path.abspath(mapping[0]) | 55 directory = os.path.abspath(mapping[0]) |
49 mapped_to = mapping[1] | 56 mapped_to = mapping[1] |
50 scan(package_root, directory, mapped_to) | 57 scan(package_root, directory, mapped_to) |
51 | 58 |
52 if __name__ == '__main__': | 59 if __name__ == '__main__': |
53 sys.exit(main(sys.argv[1:])) | 60 sys.exit(main(sys.argv[1:])) |
OLD | NEW |