OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # coding=utf-8 | 2 # coding=utf-8 |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Runs strace or dtrace on a test and processes the logs to extract the | 7 """Runs strace or dtrace on a test and processes the logs to extract the |
8 dependencies from the source tree. | 8 dependencies from the source tree. |
9 | 9 |
10 Automatically extracts directories where all the files are used to make the | 10 Automatically extracts directories where all the files are used to make the |
11 dependencies list more compact. | 11 dependencies list more compact. |
12 """ | 12 """ |
13 | 13 |
14 import codecs | 14 import codecs |
15 import csv | 15 import csv |
16 import logging | 16 import logging |
17 import optparse | 17 import optparse |
18 import os | 18 import os |
| 19 import posixpath |
19 import re | 20 import re |
20 import subprocess | 21 import subprocess |
21 import sys | 22 import sys |
22 | 23 |
23 | 24 |
24 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 25 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
25 ROOT_DIR = os.path.dirname(os.path.dirname(BASE_DIR)) | 26 ROOT_DIR = os.path.dirname(os.path.dirname(BASE_DIR)) |
26 | 27 |
27 KEY_TRACKED = 'isolate_dependency_tracked' | 28 KEY_TRACKED = 'isolate_dependency_tracked' |
28 KEY_UNTRACKED = 'isolate_dependency_untracked' | 29 KEY_UNTRACKED = 'isolate_dependency_untracked' |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 def fix_python_path(cmd): | 126 def fix_python_path(cmd): |
126 """Returns the fixed command line to call the right python executable.""" | 127 """Returns the fixed command line to call the right python executable.""" |
127 out = cmd[:] | 128 out = cmd[:] |
128 if out[0] == 'python': | 129 if out[0] == 'python': |
129 out[0] = sys.executable | 130 out[0] = sys.executable |
130 elif out[0].endswith('.py'): | 131 elif out[0].endswith('.py'): |
131 out.insert(0, sys.executable) | 132 out.insert(0, sys.executable) |
132 return out | 133 return out |
133 | 134 |
134 | 135 |
| 136 def posix_relpath(path, root): |
| 137 """posix.relpath() that keeps trailing slash.""" |
| 138 out = posixpath.relpath(path, root) |
| 139 if path.endswith('/'): |
| 140 out += '/' |
| 141 return out |
| 142 |
| 143 |
135 class Strace(object): | 144 class Strace(object): |
136 """strace implies linux.""" | 145 """strace implies linux.""" |
137 IGNORED = ( | 146 IGNORED = ( |
138 '/bin', | 147 '/bin', |
139 '/dev', | 148 '/dev', |
140 '/etc', | 149 '/etc', |
141 '/lib', | 150 '/lib', |
142 '/proc', | 151 '/proc', |
143 '/sys', | 152 '/sys', |
144 '/tmp', | 153 '/tmp', |
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 | 1296 |
1288 def fix(f): | 1297 def fix(f): |
1289 """Bases the file on the most restrictive variable.""" | 1298 """Bases the file on the most restrictive variable.""" |
1290 logging.debug('fix(%s)' % f) | 1299 logging.debug('fix(%s)' % f) |
1291 # Important, GYP stores the files with / and not \. | 1300 # Important, GYP stores the files with / and not \. |
1292 if sys.platform == 'win32': | 1301 if sys.platform == 'win32': |
1293 f = f.replace('\\', '/') | 1302 f = f.replace('\\', '/') |
1294 | 1303 |
1295 if product_dir and f.startswith(product_dir): | 1304 if product_dir and f.startswith(product_dir): |
1296 return '<(PRODUCT_DIR)/%s' % f[len(product_dir):] | 1305 return '<(PRODUCT_DIR)/%s' % f[len(product_dir):] |
1297 elif cwd_dir and f.startswith(cwd_dir): | 1306 else: |
1298 # cwd_dir is usually the directory containing the gyp file. It may be | 1307 # cwd_dir is usually the directory containing the gyp file. It may be |
1299 # empty if the whole directory containing the gyp file is needed. | 1308 # empty if the whole directory containing the gyp file is needed. |
1300 return f[len(cwd_dir):] or './' | 1309 return posix_relpath(f, cwd_dir) or './' |
1301 else: | |
1302 return '<(DEPTH)/%s' % f | |
1303 | 1310 |
1304 corrected = [fix(f) for f in simplified] | 1311 corrected = [fix(f) for f in simplified] |
1305 tracked = [f for f in corrected if not f.endswith('/') and ' ' not in f] | 1312 tracked = [f for f in corrected if not f.endswith('/') and ' ' not in f] |
1306 untracked = [f for f in corrected if f.endswith('/') or ' ' in f] | 1313 untracked = [f for f in corrected if f.endswith('/') or ' ' in f] |
1307 variables = {} | 1314 variables = {} |
1308 if tracked: | 1315 if tracked: |
1309 variables[KEY_TRACKED] = tracked | 1316 variables[KEY_TRACKED] = tracked |
1310 if untracked: | 1317 if untracked: |
1311 variables[KEY_UNTRACKED] = untracked | 1318 variables[KEY_UNTRACKED] = untracked |
1312 value = { | 1319 value = { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 os.path.abspath(options.log), | 1373 os.path.abspath(options.log), |
1367 args, | 1374 args, |
1368 options.root_dir, | 1375 options.root_dir, |
1369 options.cwd, | 1376 options.cwd, |
1370 options.product_dir, | 1377 options.product_dir, |
1371 options.force) | 1378 options.force) |
1372 | 1379 |
1373 | 1380 |
1374 if __name__ == '__main__': | 1381 if __name__ == '__main__': |
1375 sys.exit(main()) | 1382 sys.exit(main()) |
OLD | NEW |