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

Side by Side Diff: testing/test_env.py

Issue 10661019: Remove the linux-only CR_SOURCE_ROOT environment variable override of base::DIR_SOURCE_ROOT. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « base/base_paths_posix.cc ('k') | 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 # 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.
29 - environment variable LANGUAGE to en_US.UTF-8. 28 - environment variable LANGUAGE to en_US.UTF-8.
30 - Reuses sys.executable automatically. 29 - Reuses sys.executable automatically.
31 """ 30 """
32 # Many tests assume a English interface... 31 # Many tests assume a English interface...
33 env['LANGUAGE'] = 'en_US.UTF-8' 32 env['LANGUAGE'] = 'en_US.UTF-8'
34 # Used by base/base_paths_linux.cc
35 env['CR_SOURCE_ROOT'] = os.path.abspath(ROOT_DIR).encode('utf-8')
36 # Ensure paths are correctly separated on windows. 33 # Ensure paths are correctly separated on windows.
37 cmd[0] = cmd[0].replace('/', os.path.sep) 34 cmd[0] = cmd[0].replace('/', os.path.sep)
38 cmd = fix_python_path(cmd) 35 cmd = fix_python_path(cmd)
39 try: 36 try:
40 return subprocess.call(cmd, env=env) 37 return subprocess.call(cmd, env=env)
41 except OSError: 38 except OSError:
42 print >> sys.stderr, 'Failed to start %s' % cmd 39 print >> sys.stderr, 'Failed to start %s' % cmd
43 raise 40 raise
44 41
45 42
46 def main(): 43 def main():
47 return run_executable(sys.argv[1:], os.environ.copy()) 44 return run_executable(sys.argv[1:], os.environ.copy())
48 45
49 46
50 if __name__ == "__main__": 47 if __name__ == "__main__":
51 sys.exit(main()) 48 sys.exit(main())
OLDNEW
« no previous file with comments | « base/base_paths_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698