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

Side by Side Diff: native_client_sdk/src/tools/getos.py

Issue 86053005: [NaCl SDK] Fix "make debug" and "make run" on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback Created 7 years 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 | « native_client_sdk/src/tools/common.mk ('k') | native_client_sdk/src/tools/run.py » ('j') | 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 """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_DEFAULT_PATH = {
24 'win': r'c:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
25 'mac': '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
26 'linux': '/usr/bin/google-chrome',
27 }
24 28
25 29
26 if sys.version_info < (2, 6, 0): 30 if sys.version_info < (2, 6, 0):
27 sys.stderr.write("python 2.6 or later is required run this script\n") 31 sys.stderr.write("python 2.6 or later is required run this script\n")
28 sys.exit(1) 32 sys.exit(1)
29 33
30 34
31 class Error(Exception): 35 class Error(Exception):
32 pass 36 pass
33 37
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 pobj = subprocess.Popen(['uname', '-m'], stdout= subprocess.PIPE) 99 pobj = subprocess.Popen(['uname', '-m'], stdout= subprocess.PIPE)
96 arch = pobj.communicate()[0] 100 arch = pobj.communicate()[0]
97 arch = arch.split()[0] 101 arch = arch.split()[0]
98 if arch.startswith('arm'): 102 if arch.startswith('arm'):
99 arch = 'arm' 103 arch = 'arm'
100 except Exception: 104 except Exception:
101 arch = None 105 arch = None
102 return arch 106 return arch
103 107
104 108
105 def GetChromePath(): 109 def GetChromePath(platform):
110 # If CHROME_PATH is defined and exists, use that.
106 chrome_path = os.environ.get('CHROME_PATH') 111 chrome_path = os.environ.get('CHROME_PATH')
107 if chrome_path: 112 if chrome_path:
108 if not os.path.exists(chrome_path): 113 if not os.path.exists(chrome_path):
109 raise Error('Invalid CHROME_PATH: %s' % chrome_path) 114 raise Error('Invalid CHROME_PATH: %s' % chrome_path)
110 else: 115 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 116
116 return os.path.realpath(chrome_path) 117 # Otherwise look in the PATH environment variable.
118 chrome_path = CHROME_DEFAULT_PATH[platform]
119 basename = os.path.basename(chrome_path)
120 chrome_path = oshelpers.FindExeInPath(basename)
121 if chrome_path:
122 return os.path.realpath(chrome_path)
123
124 # Finally, try the default paths to Chrome.
125 if os.path.exists(chrome_path):
126 return os.path.realpath(chrome_path)
127
128 raise Error('CHROME_PATH is undefined, and %s not found in PATH, nor %s.' % (
129 basename, chrome_path))
117 130
118 131
119 def GetNaClArch(platform): 132 def GetNaClArch(platform):
120 if platform == 'win': 133 if platform == 'win':
121 # On windows the nacl arch always matches to system arch 134 # On windows the nacl arch always matches to system arch
122 return GetSystemArch(platform) 135 return GetSystemArch(platform)
123 elif platform == 'mac': 136 elif platform == 'mac':
124 # On Mac the nacl arch is currently always 32-bit. 137 # On Mac the nacl arch is currently always 32-bit.
125 return 'x86_32' 138 return 'x86_32'
126 139
127 # On linux the nacl arch matches to chrome arch, so we inspect the chrome 140 # On linux the nacl arch matches to chrome arch, so we inspect the chrome
128 # binary using objdump 141 # binary using objdump
129 chrome_path = GetChromePath() 142 chrome_path = GetChromePath(platform)
130 143
131 # If CHROME_PATH is set to point to google-chrome or google-chrome 144 # 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 145 # 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. 146 # is a bash script that points to 'chrome' in the same folder.
134 if os.path.basename(chrome_path) == 'google-chrome': 147 if os.path.basename(chrome_path) == 'google-chrome':
135 chrome_path = os.path.join(os.path.dirname(chrome_path), 'chrome') 148 chrome_path = os.path.join(os.path.dirname(chrome_path), 'chrome')
136 149
137 try: 150 try:
138 pobj = subprocess.Popen(['objdump', '-f', chrome_path], 151 pobj = subprocess.Popen(['objdump', '-f', chrome_path],
139 stdout=subprocess.PIPE, 152 stdout=subprocess.PIPE,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 245
233 if not args: 246 if not args:
234 print platform 247 print platform
235 return 0 248 return 0
236 249
237 if options.arch: 250 if options.arch:
238 out = GetSystemArch(platform) 251 out = GetSystemArch(platform)
239 elif options.nacl_arch: 252 elif options.nacl_arch:
240 out = GetNaClArch(platform) 253 out = GetNaClArch(platform)
241 elif options.chrome: 254 elif options.chrome:
242 out = GetChromePath() 255 out = GetChromePath(platform)
243 elif options.helper: 256 elif options.helper:
244 out = GetHelperPath(platform) 257 out = GetHelperPath(platform)
245 elif options.irtbin: 258 elif options.irtbin:
246 out = GetIrtBinPath(platform) 259 out = GetIrtBinPath(platform)
247 elif options.loader: 260 elif options.loader:
248 out = GetLoaderPath(platform) 261 out = GetLoaderPath(platform)
249 elif options.sdk_version: 262 elif options.sdk_version:
250 out = GetSDKVersion()[0] 263 out = GetSDKVersion()[0]
251 elif options.sdk_revision: 264 elif options.sdk_revision:
252 out = GetSDKVersion()[1] 265 out = GetSDKVersion()[1]
(...skipping 10 matching lines...) Expand all
263 print out 276 print out
264 return 0 277 return 0
265 278
266 279
267 if __name__ == '__main__': 280 if __name__ == '__main__':
268 try: 281 try:
269 sys.exit(main(sys.argv[1:])) 282 sys.exit(main(sys.argv[1:]))
270 except Error as e: 283 except Error as e:
271 sys.stderr.write(str(e) + '\n') 284 sys.stderr.write(str(e) + '\n')
272 sys.exit(1) 285 sys.exit(1)
OLDNEW
« no previous file with comments | « native_client_sdk/src/tools/common.mk ('k') | native_client_sdk/src/tools/run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698