| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2012 The Native Client 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 import driver_env | 6 import driver_env |
| 7 import os | 7 import os |
| 8 from os.path import dirname | 8 from os.path import dirname |
| 9 import platform | 9 import platform |
| 10 import sys | 10 import sys |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 def _SetupLinuxHostDir(env, nacl_dir): | 24 def _SetupLinuxHostDir(env, nacl_dir): |
| 25 # Use the 32-bit path by default, but fall back to 64-bit if the 32-bit does | 25 # Use the 32-bit path by default, but fall back to 64-bit if the 32-bit does |
| 26 # not exist. | 26 # not exist. |
| 27 dir_template = os.path.join(nacl_dir, 'toolchain', 'pnacl_linux_x86', | 27 dir_template = os.path.join(nacl_dir, 'toolchain', 'pnacl_linux_x86', |
| 28 'host_%s') | 28 'host_%s') |
| 29 dir_32 = dir_template % 'x86_32' | 29 dir_32 = dir_template % 'x86_32' |
| 30 dir_64 = dir_template % 'x86_64' | 30 dir_64 = dir_template % 'x86_64' |
| 31 env.set('BASE_HOST', dir_32 if os.path.exists(dir_32) else dir_64) | 31 env.set('BASE_HOST', dir_32 if os.path.exists(dir_32) else dir_64) |
| 32 | 32 |
| 33 def SetupNaClDir(env): |
| 34 test_dir = os.path.abspath(dirname(__file__)) |
| 35 nacl_dir = dirname(dirname(dirname(test_dir))) |
| 36 env.set('BASE_NACL', nacl_dir) |
| 37 |
| 38 def SetupToolchainDir(env): |
| 39 test_dir = os.path.abspath(dirname(__file__)) |
| 40 nacl_dir = dirname(dirname(dirname(test_dir))) |
| 41 toolchain_dir = os.path.join(nacl_dir, 'toolchain') |
| 42 env.set('BASE_TOOLCHAIN', toolchain_dir) |
| 43 |
| 33 def SetupHostDir(env): | 44 def SetupHostDir(env): |
| 34 # Some of the tools require 'BASE_HOST' to be set, because they end up | 45 # Some of the tools require 'BASE_HOST' to be set, because they end up |
| 35 # running one of the host binaries. | 46 # running one of the host binaries. |
| 36 test_dir = os.path.abspath(dirname(__file__)) | 47 test_dir = os.path.abspath(dirname(__file__)) |
| 37 nacl_dir = dirname(dirname(dirname(test_dir))) | 48 nacl_dir = dirname(dirname(dirname(test_dir))) |
| 38 if sys.platform == 'darwin': | 49 if sys.platform == 'darwin': |
| 39 os_shortname = 'mac' | 50 os_shortname = 'mac' |
| 40 host_arch = 'x86_64' | 51 host_arch = 'x86_64' |
| 41 elif sys.platform.startswith('linux'): | 52 elif sys.platform.startswith('linux'): |
| 42 _SetupLinuxHostDir(env, nacl_dir) | 53 _SetupLinuxHostDir(env, nacl_dir) |
| 43 return | 54 return |
| 44 elif sys.platform in ('cygwin', 'win32'): | 55 elif sys.platform in ('cygwin', 'win32'): |
| 45 os_shortname = 'win' | 56 os_shortname = 'win' |
| 46 host_arch= 'x86_32' | 57 host_arch= 'x86_32' |
| 47 host_dir = os.path.join(nacl_dir, 'toolchain', | 58 host_dir = os.path.join(nacl_dir, 'toolchain', |
| 48 'pnacl_%s_x86' % os_shortname, | 59 'pnacl_%s_x86' % os_shortname, |
| 49 'host_%s' % host_arch) | 60 'host_%s' % host_arch) |
| 50 env.set('BASE_HOST', host_dir) | 61 env.set('BASE_HOST', host_dir) |
| 51 | 62 |
| 52 | |
| 53 # A collection of override methods that mock driver_env.Environment. | 63 # A collection of override methods that mock driver_env.Environment. |
| 54 | 64 |
| 55 # One thing is we prevent having to read a driver.conf file, | 65 # One thing is we prevent having to read a driver.conf file, |
| 56 # so instead we have a base group of variables set for testing. | 66 # so instead we have a base group of variables set for testing. |
| 57 def TestEnvReset(self): | 67 def TestEnvReset(self): |
| 58 # Call to "super" class method (assumed to be driver_env.Environment). | 68 # Call to "super" class method (assumed to be driver_env.Environment). |
| 59 # TODO(jvoung): We may want a different way of overriding things. | 69 # TODO(jvoung): We may want a different way of overriding things. |
| 60 driver_env.Environment.reset(self) | 70 driver_env.Environment.reset(self) |
| 61 # The overrides. | 71 # The overrides. |
| 62 self.set('LIBMODE', 'newlib') | 72 self.set('LIBMODE', 'newlib') |
| 63 self.set('PNACL_RUNNING_UNITTESTS', '1') | 73 self.set('PNACL_RUNNING_UNITTESTS', '1') |
| 74 SetupNaClDir(self) |
| 75 SetupToolchainDir(self) |
| 64 SetupHostDir(self) | 76 SetupHostDir(self) |
| 65 | 77 |
| 66 | |
| 67 def ApplyTestEnvOverrides(env): | 78 def ApplyTestEnvOverrides(env): |
| 68 """Register all the override methods and reset the env to a testable state. | 79 """Register all the override methods and reset the env to a testable state. |
| 69 """ | 80 """ |
| 70 driver_env.override_env('reset', TestEnvReset) | 81 driver_env.override_env('reset', TestEnvReset) |
| 71 env.reset() | 82 env.reset() |
| OLD | NEW |