OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 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 """Merges multiple OS-specific gyp dependency lists into one that works on all | |
7 of them. | |
8 | |
9 The logic is relatively simple. Takes the current conditions, add more | |
10 condition, find the strict subset. Done. | |
11 """ | |
12 | |
13 import logging | |
14 import sys | |
15 | |
16 from isolate import Configs, DEFAULT_OSES, eval_content, extract_comment | |
17 from isolate import load_isolate_as_config, union, convert_map_to_isolate_dict | |
18 from isolate import reduce_inputs, invert_map, print_all | |
19 import run_test_cases | |
20 | |
21 | |
22 def load_isolates(items, default_oses): | |
23 """Parses each .isolate file and returns the merged results. | |
24 | |
25 It only loads what load_isolate_as_config() can process. | |
26 | |
27 Return values: | |
28 files: dict(filename, set(OS where this filename is a dependency)) | |
29 dirs: dict(dirame, set(OS where this dirname is a dependency)) | |
30 oses: set(all the OSes referenced) | |
31 """ | |
32 configs = Configs(default_oses, None) | |
33 for item in items: | |
34 logging.debug('loading %s' % item) | |
35 with open(item, 'r') as f: | |
36 content = f.read() | |
37 new_config = load_isolate_as_config( | |
38 eval_content(content), extract_comment(content), default_oses) | |
39 logging.debug('has OSes: %s' % ','.join(k for k in new_config.per_os if k)) | |
40 configs = union(configs, new_config) | |
41 logging.debug('Total OSes: %s' % ','.join(k for k in configs.per_os if k)) | |
42 return configs | |
43 | |
44 | |
45 def main(args=None): | |
46 parser = run_test_cases.OptionParserWithLogging( | |
47 usage='%prog <options> [file1] [file2] ...') | |
48 parser.add_option( | |
49 '-o', '--output', help='Output to file instead of stdout') | |
50 parser.add_option( | |
51 '--os', default=','.join(DEFAULT_OSES), | |
52 help='Inject the list of OSes, default: %default') | |
53 | |
54 options, args = parser.parse_args(args) | |
55 | |
56 configs = load_isolates(args, options.os.split(',')) | |
57 data = convert_map_to_isolate_dict( | |
58 *reduce_inputs(*invert_map(configs.flatten()))) | |
59 if options.output: | |
60 with open(options.output, 'wb') as f: | |
61 print_all(configs.file_comment, data, f) | |
62 else: | |
63 print_all(configs.file_comment, data, sys.stdout) | |
64 return 0 | |
65 | |
66 | |
67 if __name__ == '__main__': | |
68 sys.exit(main()) | |
OLD | NEW |