OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright 2016 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 """Creates an .isolate given a list of files. | |
7 | |
8 """ | |
9 | |
10 import argparse | |
11 import os | |
12 import pprint | |
13 import re | |
14 import sys | |
15 | |
16 | |
17 _UNIVERSAL_BLACKLIST = ( | |
18 r'.*OWNERS', # Should never be included. | |
19 ) | |
20 | |
21 _ANDROID_BLACKLIST = ( | |
22 r'.*\.so', # Libraries packed into .apk. | |
23 r'.*\.mojom.js', # Some test_support targets include python deps. | |
24 r'.*Mojo.*manifest\.json', # Some source_set()s pull these in. | |
25 r'.*jni_generator_tests', # Exists just to test the compile, not to be run. | |
26 ) | |
27 | |
28 _DEVICE_BLACKLIST = ( | |
29 r'.*\.py', # Some test_support targets include python deps. | |
30 ) | |
31 | |
32 _ASSERT_WHITELIST = ( | |
33 r'.*\.pak', | |
34 r'.*/', # Assume directories are always included on purpose. | |
35 ) | |
36 | |
37 | |
38 def _IsExecutable(path): | |
39 return os.path.isfile(path) and os.access(path, os.X_OK) | |
40 | |
41 | |
42 def _MatchesAny(path, patterns): | |
43 return any(re.match(p, path) for p in patterns) | |
44 | |
45 | |
46 def main(): | |
47 parser = argparse.ArgumentParser(description=__doc__) | |
48 parser.add_argument('--command', | |
49 help='The command to put in the .isolate (optional)') | |
50 parser.add_argument('--runtime-deps-file', required=True, | |
51 help='Input .runtime_deps file.') | |
52 parser.add_argument('--output-directory', required=True, | |
53 help='Location of the ninja output directory') | |
54 parser.add_argument('--out-file', help='Write to file rather than stdout.') | |
55 parser.add_argument('--apply-android-filters', action='store_true', | |
56 help='Filter files not required for Android.') | |
57 parser.add_argument('--apply-device-filters', action='store_true', | |
58 help='Filter files not required in *.device.isolate.') | |
59 parser.add_argument('--assert-no-odd-data', action='store_true', | |
60 help='Fail if any data deps exist (after filtering) ' | |
61 'that are not a part of the _ASSERT_WHITELIST. Use ' | |
62 'this to prevent unexpected runtime_deps from ' | |
63 'creeping in') | |
64 options = parser.parse_args() | |
65 | |
66 deps = [] | |
67 with open(options.runtime_deps_file) as deps_file: | |
68 for path in deps_file: | |
69 if path.startswith('./'): | |
70 path = path[2:] | |
71 deps.append(path.rstrip()) | |
72 | |
73 deps = (d for d in deps if not _MatchesAny(d, _UNIVERSAL_BLACKLIST)) | |
74 | |
75 if options.apply_android_filters: | |
76 deps = (d for d in deps if not _MatchesAny(d, _ANDROID_BLACKLIST)) | |
77 | |
78 if options.apply_device_filters: | |
79 deps = (d for d in deps if not _MatchesAny(d, _DEVICE_BLACKLIST)) | |
80 # Breakpad tests have a helper exe, which is packaged in the _dist. | |
81 deps = (d for d in deps if not _IsExecutable(d)) | |
82 | |
83 # Make them relative to out-file. | |
84 if options.out_file: | |
85 subdir = os.path.relpath(options.output_directory, | |
86 os.path.dirname(options.out_file)) | |
87 deps = (os.path.join(subdir, d) for d in deps) | |
88 | |
89 deps = sorted(deps) | |
90 | |
91 if options.assert_no_odd_data: | |
92 odd_files = [d for d in deps if not _MatchesAny(d, _ASSERT_WHITELIST)] | |
93 assert not odd_files, ('Found possibly undesired file in runtime_deps: %s' % | |
94 odd_files) | |
95 | |
96 isolate_dict = { | |
97 'variables': { | |
98 'files': deps, | |
99 } | |
100 } | |
101 if options.command: | |
102 isolate_dict['variables']['command'] = [options.command] | |
103 | |
104 isolate_data = pprint.pformat(isolate_dict) | |
105 if options.out_file: | |
106 with open(options.out_file, 'w') as f: | |
107 f.write(isolate_data + '\n') | |
108 else: | |
109 print isolate_data | |
110 | |
111 | |
112 if __name__ == '__main__': | |
113 sys.exit(main()) | |
114 | |
OLD | NEW |