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 os | |
15 import sys | |
16 | |
17 from isolate import eval_content, extract_comment | |
18 from isolate import load_isolate_as_config, print_all, union | |
19 | |
20 from utils import tools | |
21 | |
22 | |
23 def load_isolates(items): | |
24 """Parses each .isolate file and returns the merged results. | |
25 | |
26 It only loads what load_isolate_as_config() can process. | |
27 | |
28 Return values: | |
29 files: dict(filename, set(OS where this filename is a dependency)) | |
30 dirs: dict(dirame, set(OS where this dirname is a dependency)) | |
31 oses: set(all the OSes referenced) | |
32 """ | |
33 configs = None | |
34 for item in items: | |
35 item = os.path.abspath(item) | |
36 logging.debug('loading %s' % item) | |
37 if item == '-': | |
38 content = sys.stdin.read() | |
39 else: | |
40 with open(item, 'r') as f: | |
41 content = f.read() | |
42 new_config = load_isolate_as_config( | |
43 os.path.dirname(item), | |
44 eval_content(content), | |
45 extract_comment(content)) | |
46 logging.debug('has configs: ' + ','.join(map(repr, new_config.by_config))) | |
47 configs = union(configs, new_config) | |
48 logging.debug('Total configs: ' + ','.join(map(repr, configs.by_config))) | |
49 return configs | |
50 | |
51 | |
52 def main(args=None): | |
53 tools.disable_buffering() | |
54 parser = tools.OptionParserWithLogging( | |
55 usage='%prog <options> [file1] [file2] ...') | |
56 parser.add_option( | |
57 '-o', '--output', help='Output to file instead of stdout') | |
58 | |
59 options, args = parser.parse_args(args) | |
60 | |
61 configs = load_isolates(args) | |
62 data = configs.make_isolate_file() | |
63 if options.output: | |
64 with open(options.output, 'wb') as f: | |
65 print_all(configs.file_comment, data, f) | |
66 else: | |
67 print_all(configs.file_comment, data, sys.stdout) | |
68 return 0 | |
69 | |
70 | |
71 if __name__ == '__main__': | |
72 sys.exit(main()) | |
OLD | NEW |