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 """Sets environment variables needed to run a chromium unit test.""" | 6 """Sets environment variables needed to run a chromium unit test.""" |
7 | 7 |
8 import os | 8 import os |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
11 | 11 |
12 # This is hardcoded to be src/ relative to this script. | 12 # This is hardcoded to be src/ relative to this script. |
13 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 13 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
14 | 14 |
15 | 15 |
16 def fix_python_path(cmd): | 16 def fix_python_path(cmd): |
17 """Returns the fixed command line to call the right python executable.""" | 17 """Returns the fixed command line to call the right python executable.""" |
18 out = cmd[:] | 18 out = cmd[:] |
19 if out[0] == 'python': | 19 if out[0] == 'python': |
20 out[0] = sys.executable | 20 out[0] = sys.executable |
21 elif out[0].endswith('.py'): | 21 elif out[0].endswith('.py'): |
22 out.insert(0, sys.executable) | 22 out.insert(0, sys.executable) |
23 return out | 23 return out |
24 | 24 |
25 | 25 |
26 def run_executable(cmd, env): | 26 def run_executable(cmd, env): |
27 """Runs an executable with: | 27 """Runs an executable with: |
| 28 - environment variable CR_SOURCE_ROOT set to the root directory. |
28 - environment variable LANGUAGE to en_US.UTF-8. | 29 - environment variable LANGUAGE to en_US.UTF-8. |
29 - Reuses sys.executable automatically. | 30 - Reuses sys.executable automatically. |
30 """ | 31 """ |
31 # Many tests assume a English interface... | 32 # Many tests assume a English interface... |
32 env['LANGUAGE'] = 'en_US.UTF-8' | 33 env['LANGUAGE'] = 'en_US.UTF-8' |
| 34 # Used by base/base_paths_linux.cc as an override. Just make sure the default |
| 35 # logic is used. |
| 36 env.pop('CR_SOURCE_ROOT', None) |
33 # Ensure paths are correctly separated on windows. | 37 # Ensure paths are correctly separated on windows. |
34 cmd[0] = cmd[0].replace('/', os.path.sep) | 38 cmd[0] = cmd[0].replace('/', os.path.sep) |
35 cmd = fix_python_path(cmd) | 39 cmd = fix_python_path(cmd) |
36 try: | 40 try: |
37 return subprocess.call(cmd, env=env) | 41 return subprocess.call(cmd, env=env) |
38 except OSError: | 42 except OSError: |
39 print >> sys.stderr, 'Failed to start %s' % cmd | 43 print >> sys.stderr, 'Failed to start %s' % cmd |
40 raise | 44 raise |
41 | 45 |
42 | 46 |
43 def main(): | 47 def main(): |
44 return run_executable(sys.argv[1:], os.environ.copy()) | 48 return run_executable(sys.argv[1:], os.environ.copy()) |
45 | 49 |
46 | 50 |
47 if __name__ == "__main__": | 51 if __name__ == "__main__": |
48 sys.exit(main()) | 52 sys.exit(main()) |
OLD | NEW |