OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env 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 """ | 6 """ |
7 Determine OS | 7 Determine OS |
8 | 8 |
9 Determine the name of the platform used to determine the correct Toolchain to | 9 Determine the name of the platform used to determine the correct Toolchain to |
10 invoke. | 10 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 | 19 |
20 TOOL_PATH=os.path.dirname(os.path.abspath(__file__)) | 20 TOOL_PATH = os.path.dirname(os.path.abspath(__file__)) |
21 | 21 |
22 | 22 |
23 def ErrOut(text): | 23 def ErrOut(text): |
24 sys.stderr.write(text + '\n') | 24 sys.stderr.write(text + '\n') |
25 sys.exit(1) | 25 sys.exit(1) |
26 | 26 |
27 | 27 |
28 | 28 |
29 def GetSDKPath(): | 29 def GetSDKPath(): |
30 return os.getenv('NACL_SDK_ROOT', os.path.dirname(TOOL_PATH)) | 30 return os.getenv('NACL_SDK_ROOT', os.path.dirname(TOOL_PATH)) |
(...skipping 21 matching lines...) Expand all Loading... |
52 | 52 |
53 | 53 |
54 def GetSystemArch(platform): | 54 def GetSystemArch(platform): |
55 if platform == 'win': | 55 if platform == 'win': |
56 if UseWin64(): | 56 if UseWin64(): |
57 return 'x86_64' | 57 return 'x86_64' |
58 return 'x86_32' | 58 return 'x86_32' |
59 | 59 |
60 if platform in ['mac', 'linux']: | 60 if platform in ['mac', 'linux']: |
61 try: | 61 try: |
62 pobj = subprocess.Popen(['uname', '-m'],stdout= subprocess.PIPE) | 62 pobj = subprocess.Popen(['uname', '-m'], stdout= subprocess.PIPE) |
63 arch, serr = pobj.communicate() | 63 arch = pobj.communicate()[0] |
64 arch = arch.split()[0] | 64 arch = arch.split()[0] |
65 except: | 65 except Exception: |
66 arch = None | 66 arch = None |
67 return arch | 67 return arch |
68 | 68 |
69 | 69 |
70 def GetChromeArch(platform): | 70 def GetChromeArch(platform): |
71 if platform == 'win': | 71 if platform == 'win': |
72 if UseWin64(): | 72 if UseWin64(): |
73 return 'x86_64' | 73 return 'x86_64' |
74 return 'x86_32' | 74 return 'x86_32' |
75 | 75 |
76 if platform in ['mac', 'linux']: | 76 if platform in ['mac', 'linux']: |
77 chrome_path = os.getenv('CHROME_PATH', None) | 77 chrome_path = os.getenv('CHROME_PATH', None) |
78 if not chrome_path: | 78 if not chrome_path: |
79 ErrOut('CHROME_PATH is undefined.') | 79 ErrOut('CHROME_PATH is undefined.') |
80 | 80 |
81 try: | 81 try: |
82 pobj = subprocess.Popen(['objdump', '-f', chrome_path], | 82 pobj = subprocess.Popen(['objdump', '-f', chrome_path], |
83 stdout=subprocess.PIPE, | 83 stdout=subprocess.PIPE, |
84 stderr=subprocess.PIPE) | 84 stderr=subprocess.PIPE) |
85 arch, serr = pobj.communicate() | 85 arch = pobj.communicate()[0] |
86 format = re.compile(r'(file format) ([a-zA-Z0-9_\-]+)') | 86 file_format = re.compile(r'(file format) ([a-zA-Z0-9_\-]+)') |
87 arch = format.search(arch).group(2) | 87 arch = file_format.search(arch).group(2) |
88 if '64' in arch: | 88 if '64' in arch: |
89 return 'x86_64' | 89 return 'x86_64' |
90 return 'x86_32' | 90 return 'x86_32' |
91 except: | 91 except Exception: |
92 print "FAILED" | 92 print "FAILED" |
93 arch = None | 93 arch = None |
94 return arch | 94 return arch |
95 | 95 |
96 | 96 |
97 def GetLoaderPath(platform): | 97 def GetLoaderPath(platform): |
98 sdk_path = GetSDKPath() | 98 sdk_path = GetSDKPath() |
99 arch = GetChromeArch(platform) | 99 arch = GetChromeArch(platform) |
100 return os.path.join(sdk_path, 'tools', 'sel_ldr_' + arch) | 100 return os.path.join(sdk_path, 'tools', 'sel_ldr_' + arch) |
101 | 101 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 out = GetPluginPath(platform) | 168 out = GetPluginPath(platform) |
169 print out | 169 print out |
170 return 0 | 170 return 0 |
171 | 171 |
172 print 'Failed with args: ' + ' '.join(args) | 172 print 'Failed with args: ' + ' '.join(args) |
173 return 1 | 173 return 1 |
174 | 174 |
175 | 175 |
176 if __name__ == '__main__': | 176 if __name__ == '__main__': |
177 sys.exit(main(sys.argv)) | 177 sys.exit(main(sys.argv)) |
OLD | NEW |