Chromium Code Reviews| 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 """Determine OS and various other system properties. | 6 """Determine OS and various other system properties. |
| 7 | 7 |
| 8 Determine the name of the platform used and other system properties such as | 8 Determine the name of the platform used and other system properties such as |
| 9 the location of Chrome. This is used, for example, to determine the correct | 9 the location of Chrome. This is used, for example, to determine the correct |
| 10 Toolchain to invoke. | 10 Toolchain to invoke. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import optparse | 13 import optparse |
| 14 import os | 14 import os |
| 15 import re | 15 import re |
| 16 import subprocess | 16 import subprocess |
| 17 import sys | 17 import sys |
| 18 | 18 |
| 19 import oshelpers | 19 import oshelpers |
| 20 | 20 |
| 21 | 21 |
| 22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 23 CHROME_EXE_BASENAME = 'google-chrome' | 23 CHROME_EXE_BASENAME = { |
| 24 'win': 'chrome.exe', | |
| 25 'mac': 'Google Chrome', | |
| 26 'linux': 'google-chrome', | |
| 27 } | |
| 28 CHROME_DEFAULT_PATH = { | |
| 29 'win': r'c:\Program Files (x86)\Google\Chrome\Application\chrome.exe', | |
| 30 'mac': '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', | |
| 31 'linux': '/usr/bin/google-chrome', | |
| 32 } | |
|
Sam Clegg
2013/12/02 22:46:50
Isn't this information duplicated here.
Also, I'm
binji
2013/12/03 00:33:59
Done.
| |
| 24 | 33 |
| 25 | 34 |
| 26 if sys.version_info < (2, 6, 0): | 35 if sys.version_info < (2, 6, 0): |
| 27 sys.stderr.write("python 2.6 or later is required run this script\n") | 36 sys.stderr.write("python 2.6 or later is required run this script\n") |
| 28 sys.exit(1) | 37 sys.exit(1) |
| 29 | 38 |
| 30 | 39 |
| 31 class Error(Exception): | 40 class Error(Exception): |
| 32 pass | 41 pass |
| 33 | 42 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 pobj = subprocess.Popen(['uname', '-m'], stdout= subprocess.PIPE) | 104 pobj = subprocess.Popen(['uname', '-m'], stdout= subprocess.PIPE) |
| 96 arch = pobj.communicate()[0] | 105 arch = pobj.communicate()[0] |
| 97 arch = arch.split()[0] | 106 arch = arch.split()[0] |
| 98 if arch.startswith('arm'): | 107 if arch.startswith('arm'): |
| 99 arch = 'arm' | 108 arch = 'arm' |
| 100 except Exception: | 109 except Exception: |
| 101 arch = None | 110 arch = None |
| 102 return arch | 111 return arch |
| 103 | 112 |
| 104 | 113 |
| 105 def GetChromePath(): | 114 def GetChromePath(platform): |
| 115 # If CHROME_PATH is defined and exists, use that. | |
| 106 chrome_path = os.environ.get('CHROME_PATH') | 116 chrome_path = os.environ.get('CHROME_PATH') |
| 107 if chrome_path: | 117 if chrome_path: |
| 108 if not os.path.exists(chrome_path): | 118 if not os.path.exists(chrome_path): |
| 109 raise Error('Invalid CHROME_PATH: %s' % chrome_path) | 119 raise Error('Invalid CHROME_PATH: %s' % chrome_path) |
| 110 else: | 120 return os.path.realpath(chrome_path) |
| 111 chrome_path = oshelpers.FindExeInPath(CHROME_EXE_BASENAME) | |
| 112 if not chrome_path: | |
| 113 raise Error('CHROME_PATH is undefined, and %s not found in PATH.' % | |
| 114 CHROME_EXE_BASENAME) | |
| 115 | 121 |
| 116 return os.path.realpath(chrome_path) | 122 # Otherwise look in the PATH environment variable. |
| 123 basename = CHROME_EXE_BASENAME[platform] | |
| 124 chrome_path = oshelpers.FindExeInPath(basename) | |
| 125 if chrome_path: | |
| 126 return os.path.realpath(chrome_path) | |
| 127 | |
| 128 # Finally, try the default paths to Chrome. | |
| 129 chrome_path = CHROME_DEFAULT_PATH[platform] | |
| 130 if os.path.exists(chrome_path): | |
| 131 return os.path.realpath(chrome_path) | |
| 132 | |
| 133 raise Error('CHROME_PATH is undefined, and %s not found in PATH, nor %s.' % ( | |
| 134 basename, chrome_path)) | |
| 117 | 135 |
| 118 | 136 |
| 119 def GetNaClArch(platform): | 137 def GetNaClArch(platform): |
| 120 if platform == 'win': | 138 if platform == 'win': |
| 121 # On windows the nacl arch always matches to system arch | 139 # On windows the nacl arch always matches to system arch |
| 122 return GetSystemArch(platform) | 140 return GetSystemArch(platform) |
| 123 elif platform == 'mac': | 141 elif platform == 'mac': |
| 124 # On Mac the nacl arch is currently always 32-bit. | 142 # On Mac the nacl arch is currently always 32-bit. |
| 125 return 'x86_32' | 143 return 'x86_32' |
| 126 | 144 |
| 127 # On linux the nacl arch matches to chrome arch, so we inspect the chrome | 145 # On linux the nacl arch matches to chrome arch, so we inspect the chrome |
| 128 # binary using objdump | 146 # binary using objdump |
| 129 chrome_path = GetChromePath() | 147 chrome_path = GetChromePath(platform) |
| 130 | 148 |
| 131 # If CHROME_PATH is set to point to google-chrome or google-chrome | 149 # If CHROME_PATH is set to point to google-chrome or google-chrome |
| 132 # was found in the PATH and we are running on UNIX then google-chrome | 150 # was found in the PATH and we are running on UNIX then google-chrome |
| 133 # is a bash script that points to 'chrome' in the same folder. | 151 # is a bash script that points to 'chrome' in the same folder. |
| 134 if os.path.basename(chrome_path) == 'google-chrome': | 152 if os.path.basename(chrome_path) == 'google-chrome': |
| 135 chrome_path = os.path.join(os.path.dirname(chrome_path), 'chrome') | 153 chrome_path = os.path.join(os.path.dirname(chrome_path), 'chrome') |
| 136 | 154 |
| 137 try: | 155 try: |
| 138 pobj = subprocess.Popen(['objdump', '-f', chrome_path], | 156 pobj = subprocess.Popen(['objdump', '-f', chrome_path], |
| 139 stdout=subprocess.PIPE, | 157 stdout=subprocess.PIPE, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 | 250 |
| 233 if not args: | 251 if not args: |
| 234 print platform | 252 print platform |
| 235 return 0 | 253 return 0 |
| 236 | 254 |
| 237 if options.arch: | 255 if options.arch: |
| 238 out = GetSystemArch(platform) | 256 out = GetSystemArch(platform) |
| 239 elif options.nacl_arch: | 257 elif options.nacl_arch: |
| 240 out = GetNaClArch(platform) | 258 out = GetNaClArch(platform) |
| 241 elif options.chrome: | 259 elif options.chrome: |
| 242 out = GetChromePath() | 260 out = GetChromePath(platform) |
| 243 elif options.helper: | 261 elif options.helper: |
| 244 out = GetHelperPath(platform) | 262 out = GetHelperPath(platform) |
| 245 elif options.irtbin: | 263 elif options.irtbin: |
| 246 out = GetIrtBinPath(platform) | 264 out = GetIrtBinPath(platform) |
| 247 elif options.loader: | 265 elif options.loader: |
| 248 out = GetLoaderPath(platform) | 266 out = GetLoaderPath(platform) |
| 249 elif options.sdk_version: | 267 elif options.sdk_version: |
| 250 out = GetSDKVersion()[0] | 268 out = GetSDKVersion()[0] |
| 251 elif options.sdk_revision: | 269 elif options.sdk_revision: |
| 252 out = GetSDKVersion()[1] | 270 out = GetSDKVersion()[1] |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 263 print out | 281 print out |
| 264 return 0 | 282 return 0 |
| 265 | 283 |
| 266 | 284 |
| 267 if __name__ == '__main__': | 285 if __name__ == '__main__': |
| 268 try: | 286 try: |
| 269 sys.exit(main(sys.argv[1:])) | 287 sys.exit(main(sys.argv[1:])) |
| 270 except Error as e: | 288 except Error as e: |
| 271 sys.stderr.write(str(e) + '\n') | 289 sys.stderr.write(str(e) + '\n') |
| 272 sys.exit(1) | 290 sys.exit(1) |
| OLD | NEW |