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.
9 Determine the name of the platform used to determine the correct Toolchain to
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")
29 sys
.stderr
.write(text
+ '\n')
34 return os
.getenv('NACL_SDK_ROOT', os
.path
.dirname(SCRIPT_DIR
))
38 if sys
.platform
.startswith('cygwin') or sys
.platform
.startswith('win'):
41 if sys
.platform
.startswith('darwin'):
44 if sys
.platform
.startswith('linux'):
50 arch32
= os
.environ
.get('PROCESSOR_ARCHITECTURE', 'unk')
51 arch64
= os
.environ
.get('PROCESSOR_ARCHITEW6432', 'unk')
53 if arch32
== 'AMD64' or arch64
== 'AMD64':
58 def GetSystemArch(platform
):
64 if platform
in ['mac', 'linux']:
66 pobj
= subprocess
.Popen(['uname', '-m'], stdout
= subprocess
.PIPE
)
67 arch
= pobj
.communicate()[0]
68 arch
= arch
.split()[0]
69 if arch
.startswith('arm'):
76 def GetChromeArch(platform
):
82 if platform
in ['mac', 'linux']:
83 chrome_path
= os
.getenv('CHROME_PATH', None)
85 ErrOut('CHROME_PATH is undefined.')
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)
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':
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')
131 return os
.path
.join(sdk_path
, 'tools', 'ppNaClPlugin_%s.so' % arch
)
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()
153 print 'Unknown platform.'
157 print 'Only specify one platform item.'
166 out
= GetSystemArch(platform
)
168 out
= GetChromeArch(platform
)
170 out
= GetHelperPath(platform
)
172 out
= GetIrtBinPath(platform
)
174 out
= GetLoaderPath(platform
)
176 out
= GetPluginPath(platform
)
180 print 'Failed with args: ' + ' '.join(args
)
184 if __name__
== '__main__':
185 sys
.exit(main(sys
.argv
))