Index: tools/gn_check_autofix.py |
diff --git a/tools/gn_check_autofix.py b/tools/gn_check_autofix.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f06504bbd4b007d0633ed51680d4cfb7ee06d02a |
--- /dev/null |
+++ b/tools/gn_check_autofix.py |
@@ -0,0 +1,79 @@ |
+#!/usr/bin/env python |
+ |
+# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+# |
+# Use of this source code is governed by a BSD-style license |
+# that can be found in the LICENSE file in the root of the source |
+# tree. An additional intellectual property rights grant can be found |
+# in the file PATENTS. All contributing project authors may |
+# be found in the AUTHORS file in the root of the source tree. |
+ |
+import os |
kjellander_webrtc
2016/12/07 12:31:38
Add module documentation that at least mentions th
|
+import pprint |
+import re |
+import subprocess |
+import sys |
+ |
+from collections import defaultdict |
+ |
kjellander_webrtc
2016/12/07 12:31:38
nit: Two blank lines between top-level definitions
|
+def Run(cmd): |
+ sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
+ return sub.communicate() |
+ |
+def fix_missing(filename, missing): |
kjellander_webrtc
2016/12/07 12:31:38
Rename to FixMissing, according to http://dev.chro
|
+ with open(filename) as f: |
+ contents = f.readlines() |
+ 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
|
+ blocks = "" |
kjellander_webrtc
2016/12/07 12:31:38
Use single-quotes consistently for strings.
From
|
+ seen_deps = False |
+ last_indentation_level = None |
+ for line in contents: |
+ match = target_re.match(line) |
+ if match: |
+ last_target = match.group('target_name') |
+ if last_target in missing: |
+ last_indentation_level = match.group('indentation_level') |
+ elif last_indentation_level is not None: |
+ match = re.match(last_indentation_level + '}$', line) |
+ if match: |
+ deps = ((['deps += [\n'] if seen_deps else ['deps = [']) + |
+ map(lambda x: ' "' + x + '",\n', list(missing[last_target])) + |
+ [']\n']) |
+ deps = map(lambda x: last_indentation_level + ' ' + x, deps) |
+ deps = ''.join(deps) |
+ blocks += deps |
+ seen_deps = False |
+ last_indentation_level = None |
+ elif line.strip().startswith('deps'): |
+ seen_deps = True |
+ blocks += line |
+ with open(filename, 'w') as f: |
+ f.write(blocks) |
+ Run(['gn', 'format', filename]) |
+ |
+missing = defaultdict(lambda: defaultdict(set)) |
kjellander_webrtc
2016/12/07 12:31:38
Use a main() function instead: http://google.githu
|
+ |
+errors = Run(['gn', 'gen', 'out/gn', '--check'])[0] |
+errors = errors.split('ERROR at //')[1:] |
+for error in errors: |
+ error = error.splitlines() |
+ target_msg = 'The target:' |
+ if target_msg not in error: |
+ # print '\n'.join(error) |
+ continue |
+ index = error.index(target_msg) + 1 |
+ path, target = error[index].strip().split(':') |
+ path = os.path.join(path[2:], 'BUILD.gn') |
+ dep = error[index+2].strip() |
+ 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
|
+ print '\n'.join(error) |
+ continue |
+ if ':' not in dep: |
+ print '\n'.join(error) |
+ continue |
+ if target == "audio_decoder_unittests_bundle_data": |
kjellander_webrtc
2016/12/07 12:31:38
Is this needed? I suggest keeping hardcoded assump
|
+ print path, target, dep |
+ missing[path][target].add(dep) |
+ |
+for path, missing_deps in missing.items(): |
+ fix_missing(path, missing_deps) |