OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 | |
3 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
4 # | |
5 # Use of this source code is governed by a BSD-style license | |
6 # that can be found in the LICENSE file in the root of the source | |
7 # tree. An additional intellectual property rights grant can be found | |
8 # in the file PATENTS. All contributing project authors may | |
9 # be found in the AUTHORS file in the root of the source tree. | |
10 | |
11 import os | |
kjellander_webrtc
2016/12/07 12:31:38
Add module documentation that at least mentions th
| |
12 import pprint | |
13 import re | |
14 import subprocess | |
15 import sys | |
16 | |
17 from collections import defaultdict | |
18 | |
kjellander_webrtc
2016/12/07 12:31:38
nit: Two blank lines between top-level definitions
| |
19 def Run(cmd): | |
20 sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
21 return sub.communicate() | |
22 | |
23 def fix_missing(filename, missing): | |
kjellander_webrtc
2016/12/07 12:31:38
Rename to FixMissing, according to http://dev.chro
| |
24 with open(filename) as f: | |
25 contents = f.readlines() | |
26 target_re = re.compile(r'(?P<indentation_level>\s*)\w*\("(?P<target_name>\w*)" \) {$') | |
kjellander_webrtc
2016/12/07 12:31:38
Wrap at column 80
| |
27 blocks = "" | |
kjellander_webrtc
2016/12/07 12:31:38
Use single-quotes consistently for strings.
From
| |
28 seen_deps = False | |
29 last_indentation_level = None | |
30 for line in contents: | |
31 match = target_re.match(line) | |
32 if match: | |
33 last_target = match.group('target_name') | |
34 if last_target in missing: | |
35 last_indentation_level = match.group('indentation_level') | |
36 elif last_indentation_level is not None: | |
37 match = re.match(last_indentation_level + '}$', line) | |
38 if match: | |
39 deps = ((['deps += [\n'] if seen_deps else ['deps = [']) + | |
40 map(lambda x: ' "' + x + '",\n', list(missing[last_target])) + | |
41 [']\n']) | |
42 deps = map(lambda x: last_indentation_level + ' ' + x, deps) | |
43 deps = ''.join(deps) | |
44 blocks += deps | |
45 seen_deps = False | |
46 last_indentation_level = None | |
47 elif line.strip().startswith('deps'): | |
48 seen_deps = True | |
49 blocks += line | |
50 with open(filename, 'w') as f: | |
51 f.write(blocks) | |
52 Run(['gn', 'format', filename]) | |
53 | |
54 missing = defaultdict(lambda: defaultdict(set)) | |
kjellander_webrtc
2016/12/07 12:31:38
Use a main() function instead: http://google.githu
| |
55 | |
56 errors = Run(['gn', 'gen', 'out/gn', '--check'])[0] | |
57 errors = errors.split('ERROR at //')[1:] | |
58 for error in errors: | |
59 error = error.splitlines() | |
60 target_msg = 'The target:' | |
61 if target_msg not in error: | |
62 # print '\n'.join(error) | |
63 continue | |
64 index = error.index(target_msg) + 1 | |
65 path, target = error[index].strip().split(':') | |
66 path = os.path.join(path[2:], 'BUILD.gn') | |
67 dep = error[index+2].strip() | |
68 if 'rtc_base' in dep and not 'rtc_base_approved' in dep: | |
kjellander_webrtc
2016/12/07 12:31:38
Let's remove this as we decided to drop the PRESUB
| |
69 print '\n'.join(error) | |
70 continue | |
71 if ':' not in dep: | |
72 print '\n'.join(error) | |
73 continue | |
74 if target == "audio_decoder_unittests_bundle_data": | |
kjellander_webrtc
2016/12/07 12:31:38
Is this needed? I suggest keeping hardcoded assump
| |
75 print path, target, dep | |
76 missing[path][target].add(dep) | |
77 | |
78 for path, missing_deps in missing.items(): | |
79 fix_missing(path, missing_deps) | |
OLD | NEW |