OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 """Runs a google-test shard. | |
7 | |
8 This makes a simple interface to run a shard on the command line independent of | |
9 the interpreter, e.g. cmd.exe vs bash. | |
10 """ | |
11 | |
12 import optparse | |
13 import os | |
14 import subprocess | |
15 import sys | |
16 | |
17 | |
18 def fix_python_path(cmd): | |
19 """Returns the fixed command line to call the right python executable.""" | |
20 out = cmd[:] | |
21 if out[0] == 'python': | |
22 out[0] = sys.executable | |
23 elif out[0].endswith('.py'): | |
24 out.insert(0, sys.executable) | |
25 return out | |
26 | |
27 | |
28 def main(): | |
29 parser = optparse.OptionParser(usage='%prog <options> [gtest]') | |
30 parser.disable_interspersed_args() | |
31 parser.add_option( | |
32 '-I', '--index', | |
33 type='int', | |
34 default=os.environ.get('GTEST_SHARD_INDEX'), | |
35 help='Shard index to run') | |
36 parser.add_option( | |
37 '-S', '--shards', | |
38 type='int', | |
39 default=os.environ.get('GTEST_TOTAL_SHARDS'), | |
40 help='Total number of shards to calculate from the --index to run') | |
41 options, args = parser.parse_args() | |
42 env = os.environ.copy() | |
43 env['GTEST_TOTAL_SHARDS'] = str(options.shards) | |
44 env['GTEST_SHARD_INDEX'] = str(options.index) | |
45 return subprocess.call(fix_python_path(args), env=env) | |
46 | |
47 | |
48 if __name__ == '__main__': | |
49 sys.exit(main()) | |
OLD | NEW |