OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Enables directory-specific presubmit checks to run at upload and/or commit. | 6 """Enables directory-specific presubmit checks to run at upload and/or commit. |
7 """ | 7 """ |
8 | 8 |
9 __version__ = '1.8.0' | 9 __version__ = '1.8.0' |
10 | 10 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 | 306 |
307 # To easily fork python. | 307 # To easily fork python. |
308 self.python_executable = sys.executable | 308 self.python_executable = sys.executable |
309 self.environ = os.environ | 309 self.environ = os.environ |
310 | 310 |
311 # InputApi.platform is the platform you're currently running on. | 311 # InputApi.platform is the platform you're currently running on. |
312 self.platform = sys.platform | 312 self.platform = sys.platform |
313 | 313 |
314 self.cpu_count = multiprocessing.cpu_count() | 314 self.cpu_count = multiprocessing.cpu_count() |
315 | 315 |
316 # this is done here because in RunTests, the current working directory has | |
317 # changed, which causes Pool() to explode fantastically when run on windows | |
318 # (because it tries to load the __main__ module, which imports lots of | |
319 # things relative to the current working directory). | |
320 self._run_tests_pool = multiprocessing.Pool(self.cpu_count) | |
iannucci
2015/06/28 19:47:43
this is so we pick up the mocked cpu_count
| |
321 | |
316 # The local path of the currently-being-processed presubmit script. | 322 # The local path of the currently-being-processed presubmit script. |
317 self._current_presubmit_path = os.path.dirname(presubmit_path) | 323 self._current_presubmit_path = os.path.dirname(presubmit_path) |
318 | 324 |
319 # We carry the canned checks so presubmit scripts can easily use them. | 325 # We carry the canned checks so presubmit scripts can easily use them. |
320 self.canned_checks = presubmit_canned_checks | 326 self.canned_checks = presubmit_canned_checks |
321 | 327 |
322 # TODO(dpranke): figure out a list of all approved owners for a repo | 328 # TODO(dpranke): figure out a list of all approved owners for a repo |
323 # in order to be able to handle wildcard OWNERS files? | 329 # in order to be able to handle wildcard OWNERS files? |
324 self.owners_db = owners.Database(change.RepositoryRoot(), | 330 self.owners_db = owners.Database(change.RepositoryRoot(), |
325 fopen=file, os_path=self.os_path, glob=self.glob) | 331 fopen=file, os_path=self.os_path, glob=self.glob) |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 msgs = [] | 491 msgs = [] |
486 for t in tests_mix: | 492 for t in tests_mix: |
487 if isinstance(t, OutputApi.PresubmitResult): | 493 if isinstance(t, OutputApi.PresubmitResult): |
488 msgs.append(t) | 494 msgs.append(t) |
489 else: | 495 else: |
490 assert issubclass(t.message, _PresubmitResult) | 496 assert issubclass(t.message, _PresubmitResult) |
491 tests.append(t) | 497 tests.append(t) |
492 if self.verbose: | 498 if self.verbose: |
493 t.info = _PresubmitNotifyResult | 499 t.info = _PresubmitNotifyResult |
494 if len(tests) > 1 and parallel: | 500 if len(tests) > 1 and parallel: |
495 pool = multiprocessing.Pool() | |
496 # async recipe works around multiprocessing bug handling Ctrl-C | 501 # async recipe works around multiprocessing bug handling Ctrl-C |
497 msgs.extend(pool.map_async(CallCommand, tests).get(99999)) | 502 msgs.extend(self._run_tests_pool.map_async(CallCommand, tests).get(99999)) |
498 pool.close() | |
499 pool.join() | |
500 else: | 503 else: |
501 msgs.extend(map(CallCommand, tests)) | 504 msgs.extend(map(CallCommand, tests)) |
502 return [m for m in msgs if m] | 505 return [m for m in msgs if m] |
503 | 506 |
504 | 507 |
505 class _DiffCache(object): | 508 class _DiffCache(object): |
506 """Caches diffs retrieved from a particular SCM.""" | 509 """Caches diffs retrieved from a particular SCM.""" |
507 def __init__(self, upstream=None): | 510 def __init__(self, upstream=None): |
508 """Stores the upstream revision against which all diffs will be computed.""" | 511 """Stores the upstream revision against which all diffs will be computed.""" |
509 self._upstream = upstream | 512 self._upstream = upstream |
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1748 return 2 | 1751 return 2 |
1749 | 1752 |
1750 | 1753 |
1751 if __name__ == '__main__': | 1754 if __name__ == '__main__': |
1752 fix_encoding.fix_encoding() | 1755 fix_encoding.fix_encoding() |
1753 try: | 1756 try: |
1754 sys.exit(main()) | 1757 sys.exit(main()) |
1755 except KeyboardInterrupt: | 1758 except KeyboardInterrupt: |
1756 sys.stderr.write('interrupted\n') | 1759 sys.stderr.write('interrupted\n') |
1757 sys.exit(1) | 1760 sys.exit(1) |
OLD | NEW |