Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: tools-webrtc/gn_check_autofix.py

Issue 2589223002: Fixing relative paths and adding a docstring (Closed)
Patch Set: Removing dependency from `src` as current working directory Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
4 # 4 #
5 # Use of this source code is governed by a BSD-style license 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 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 7 # tree. An additional intellectual property rights grant can be found
8 # in the file PATENTS. All contributing project authors may 8 # in the file PATENTS. All contributing project authors may
9 # be found in the AUTHORS file in the root of the source tree. 9 # be found in the AUTHORS file in the root of the source tree.
10 10
11 """
12 This tool tries to fix (some) errors reported by `gn gen --check` or
13 `gn check`.
14 It will run `mb gen` in a temporary directory and it is really useful to
15 check for different configurations.
16
17 Usage:
18 $ python tools-webrtc/gn_check_autofix.py -m some_mater -b some_bot
19 or
20 $ python tools-webrtc/gn_check_autofix.py -c some_mb_config
21 """
22
11 import os 23 import os
12 import re 24 import re
13 import shutil 25 import shutil
14 import subprocess 26 import subprocess
15 import sys 27 import sys
16 import tempfile 28 import tempfile
17 29
18 from collections import defaultdict 30 from collections import defaultdict
19 31
32 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
33
20 TARGET_RE = re.compile( 34 TARGET_RE = re.compile(
21 r'(?P<indentation_level>\s*)\w*\("(?P<target_name>\w*)"\) {$') 35 r'(?P<indentation_level>\s*)\w*\("(?P<target_name>\w*)"\) {$')
22 36
23 class TemporaryDirectory(object): 37 class TemporaryDirectory(object):
24 def __init__(self): 38 def __init__(self):
25 self._closed = False 39 self._closed = False
26 self._name = None 40 self._name = None
27 self._name = tempfile.mkdtemp() 41 self._name = tempfile.mkdtemp()
28 42
29 def __enter__(self): 43 def __enter__(self):
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 base_path = base_path[first_difference:] 103 base_path = base_path[first_difference:]
90 dependency_path = dependency_path[first_difference:] 104 dependency_path = dependency_path[first_difference:]
91 return (os.path.sep.join((['..'] * len(base_path)) + dependency_path) + 105 return (os.path.sep.join((['..'] * len(base_path)) + dependency_path) +
92 ':' + dependency) 106 ':' + dependency)
93 107
94 def main(): 108 def main():
95 deleted_sources = set() 109 deleted_sources = set()
96 errors_by_file = defaultdict(lambda: defaultdict(set)) 110 errors_by_file = defaultdict(lambda: defaultdict(set))
97 111
98 with TemporaryDirectory() as tmp_dir: 112 with TemporaryDirectory() as tmp_dir:
113 mb_script_path = os.path.join(SCRIPT_DIR, 'mb', 'mb.py')
114 mb_config_file_path = os.path.join(SCRIPT_DIR, 'mb', 'mb_config.pyl')
99 mb_gen_command = ([ 115 mb_gen_command = ([
100 'tools/mb/mb.py', 'gen', 116 mb_script_path, 'gen',
101 tmp_dir, 117 tmp_dir,
102 '--config-file', 'webrtc/build/mb_config.pyl', 118 '--config-file', mb_config_file_path,
103 ] + sys.argv[1:]) 119 ] + sys.argv[1:])
104 120
105 mb_output = Run(mb_gen_command) 121 mb_output = Run(mb_gen_command)
106 errors = mb_output[0].split('ERROR')[1:] 122 errors = mb_output[0].split('ERROR')[1:]
107 123
108 if mb_output[1]: 124 if mb_output[1]:
109 print mb_output[1] 125 print mb_output[1]
110 return 1 126 return 1
111 127
112 for error in errors: 128 for error in errors:
(...skipping 20 matching lines...) Expand all
133 print '\n'.join(error) 149 print '\n'.join(error)
134 continue 150 continue
135 151
136 for path, missing_deps in errors_by_file.items(): 152 for path, missing_deps in errors_by_file.items():
137 FixErrors(path, missing_deps, deleted_sources) 153 FixErrors(path, missing_deps, deleted_sources)
138 154
139 return 0 155 return 0
140 156
141 if __name__ == '__main__': 157 if __name__ == '__main__':
142 sys.exit(main()) 158 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698