Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / native_client_sdk / src / tools / getos.py
blob9f76633879c159f0ad789554740c9e417a6bfecf
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 """
7 Determine OS
9 Determine the name of the platform used to determine the correct Toolchain to
10 invoke.
11 """
13 import optparse
14 import os
15 import re
16 import subprocess
17 import sys
20 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
23 if sys.version_info < (2, 6, 0):
24 sys.stderr.write("python 2.6 or later is required run this script\n")
25 sys.exit(1)
28 def ErrOut(text):
29 sys.stderr.write(text + '\n')
30 sys.exit(1)
33 def GetSDKPath():
34 return os.getenv('NACL_SDK_ROOT', os.path.dirname(SCRIPT_DIR))
37 def GetPlatform():
38 if sys.platform.startswith('cygwin') or sys.platform.startswith('win'):
39 return 'win'
41 if sys.platform.startswith('darwin'):
42 return 'mac'
44 if sys.platform.startswith('linux'):
45 return 'linux'
46 return None
49 def UseWin64():
50 arch32 = os.environ.get('PROCESSOR_ARCHITECTURE', 'unk')
51 arch64 = os.environ.get('PROCESSOR_ARCHITEW6432', 'unk')
53 if arch32 == 'AMD64' or arch64 == 'AMD64':
54 return True
55 return False
58 def GetSystemArch(platform):
59 if platform == 'win':
60 if UseWin64():
61 return 'x86_64'
62 return 'x86_32'
64 if platform in ['mac', 'linux']:
65 try:
66 pobj = subprocess.Popen(['uname', '-m'], stdout= subprocess.PIPE)
67 arch = pobj.communicate()[0]
68 arch = arch.split()[0]
69 if arch.startswith('arm'):
70 arch = 'arm'
71 except Exception:
72 arch = None
73 return arch
76 def GetChromeArch(platform):
77 if platform == 'win':
78 if UseWin64():
79 return 'x86_64'
80 return 'x86_32'
82 if platform in ['mac', 'linux']:
83 chrome_path = os.getenv('CHROME_PATH', None)
84 if not chrome_path:
85 ErrOut('CHROME_PATH is undefined.')
87 try:
88 pobj = subprocess.Popen(['objdump', '-f', chrome_path],
89 stdout=subprocess.PIPE,
90 stderr=subprocess.PIPE)
91 arch = pobj.communicate()[0]
92 file_format = re.compile(r'(file format) ([a-zA-Z0-9_\-]+)')
93 arch = file_format.search(arch).group(2)
94 if 'arm' in arch:
95 return 'arm'
96 if '64' in arch:
97 return 'x86_64'
98 return 'x86_32'
99 except Exception:
100 print "FAILED"
101 arch = None
102 return arch
105 def GetLoaderPath(platform):
106 sdk_path = GetSDKPath()
107 arch = GetChromeArch(platform)
108 return os.path.join(sdk_path, 'tools', 'sel_ldr_' + arch)
111 def GetHelperPath(platform):
112 sdk_path = GetSDKPath()
113 if platform != 'linux':
114 return ''
115 arch = GetChromeArch(platform)
116 return os.path.join(sdk_path, 'tools', 'nacl_helper_bootstrap_' + arch)
119 def GetIrtBinPath(platform):
120 sdk_path = GetSDKPath()
121 arch = GetChromeArch(platform)
122 return os.path.join(sdk_path, 'tools', 'irt_%s.nexe' % arch)
125 def GetPluginPath(platform):
126 sdk_path = GetSDKPath()
127 arch = GetChromeArch(platform)
128 if platform == 'win':
129 return os.path.join(sdk_path, 'tools', 'ppNaClPlugin_x86_32.dll')
130 else:
131 return os.path.join(sdk_path, 'tools', 'ppNaClPlugin_%s.so' % arch)
134 def main(args):
135 parser = optparse.OptionParser()
136 parser.add_option('--arch', help='Return architecture type.',
137 action='store_true', dest='arch', default=False)
138 parser.add_option('--chrome', help='Return chrome architecture type.',
139 action='store_true', dest='chrome', default=False)
140 parser.add_option('--helper', help='Return chrome helper path.',
141 action='store_true', dest='helper', default=False)
142 parser.add_option('--irtbin', help='Return irt binary path.',
143 action='store_true', dest='irtbin', default=False)
144 parser.add_option('--loader', help='Return NEXE loader path.',
145 action='store_true', dest='loader', default=False)
146 parser.add_option('--plugin', help='Return NaCl plugin path.',
147 action='store_true', dest='plugin', default=False)
149 options, _ = parser.parse_args(args[1:])
151 platform = GetPlatform()
152 if platform is None:
153 print 'Unknown platform.'
154 return 1
156 if len(args) > 2:
157 print 'Only specify one platform item.'
158 return 1
160 if len(args) == 1:
161 print platform
162 return 0
164 if len(args) == 2:
165 if options.arch:
166 out = GetSystemArch(platform)
167 if options.chrome:
168 out = GetChromeArch(platform)
169 if options.helper:
170 out = GetHelperPath(platform)
171 if options.irtbin:
172 out = GetIrtBinPath(platform)
173 if options.loader:
174 out = GetLoaderPath(platform)
175 if options.plugin:
176 out = GetPluginPath(platform)
177 print out
178 return 0
180 print 'Failed with args: ' + ' '.join(args)
181 return 1
184 if __name__ == '__main__':
185 sys.exit(main(sys.argv))