OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 """A helper script to print paths of NaCl binaries, includes, libs, etc. | 6 """A helper script to print paths of NaCl binaries, includes, libs, etc. |
7 | 7 |
8 It is similar in behavior to pkg-config or sdl-config. | 8 It is similar in behavior to pkg-config or sdl-config. |
9 """ | 9 """ |
10 | 10 |
11 import optparse | 11 import optparse |
12 import os | 12 import os |
13 import posixpath | 13 import posixpath |
14 import sys | 14 import sys |
15 | 15 |
16 import getos | 16 import getos |
17 | 17 |
18 | 18 |
19 if sys.version_info < (2, 6, 0): | 19 if sys.version_info < (2, 6, 0): |
20 sys.stderr.write("python 2.6 or later is required run this script\n") | 20 sys.stderr.write("python 2.6 or later is required run this script\n") |
21 sys.exit(1) | 21 sys.exit(1) |
22 | 22 |
23 | 23 |
24 VALID_ARCHES = ('arm', 'x86_32', 'x86_64', 'i686') | 24 VALID_ARCHES = ('arm', 'x86_32', 'x86_64', 'i686') |
| 25 VALID_PNACL_ARCHES = (None, 'pnacl') |
25 ARCH_NAME = { | 26 ARCH_NAME = { |
26 'arm': 'arm', | 27 'arm': 'arm', |
27 'x86_32': 'i686', | 28 'x86_32': 'i686', |
28 'i686': 'i686', | 29 'i686': 'i686', |
29 'x86_64': 'x86_64' | 30 'x86_64': 'x86_64' |
30 } | 31 } |
31 | 32 |
32 ARCH_ALT_NAME = { | 33 ARCH_ALT_NAME = { |
33 'arm': 'arm', | 34 'arm': 'arm', |
34 'x86_32': 'x86_32', | 35 'x86_32': 'x86_32', |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 85 |
85 def ExpectToolchain(toolchain, expected_toolchains): | 86 def ExpectToolchain(toolchain, expected_toolchains): |
86 Expect(toolchain in expected_toolchains, | 87 Expect(toolchain in expected_toolchains, |
87 'Expected toolchain to be one of [%s], not %s.' % ( | 88 'Expected toolchain to be one of [%s], not %s.' % ( |
88 ', '.join(expected_toolchains), toolchain)) | 89 ', '.join(expected_toolchains), toolchain)) |
89 | 90 |
90 | 91 |
91 def ExpectArch(arch, expected_arches): | 92 def ExpectArch(arch, expected_arches): |
92 Expect(arch in expected_arches, | 93 Expect(arch in expected_arches, |
93 'Expected arch to be one of [%s], not %s.' % ( | 94 'Expected arch to be one of [%s], not %s.' % ( |
94 ', '.join(expected_arches), arch)) | 95 ', '.join(map(str, expected_arches)), arch)) |
95 | 96 |
96 | 97 |
97 def CheckValidToolchainArch(toolchain, arch, arch_required=False): | 98 def CheckValidToolchainArch(toolchain, arch, arch_required=False): |
98 if toolchain or arch or arch_required: | 99 if toolchain or arch or arch_required: |
99 ExpectToolchain(toolchain, VALID_TOOLCHAINS) | 100 ExpectToolchain(toolchain, VALID_TOOLCHAINS) |
100 | 101 |
101 if toolchain in HOST_TOOLCHAINS: | 102 if toolchain in HOST_TOOLCHAINS: |
102 Expect(arch is None, | 103 Expect(arch is None, |
103 'Expected no arch for host toolchain %r. Got %r.' % ( | 104 'Expected no arch for host toolchain %r. Got %r.' % ( |
104 toolchain, arch)) | 105 toolchain, arch)) |
105 elif toolchain == 'pnacl': | 106 elif toolchain == 'pnacl': |
106 Expect(arch is None, | 107 Expect(arch is None or arch == 'pnacl', |
107 'Expected no arch for toolchain %r. Got %r.' % (toolchain, arch)) | 108 'Expected no arch for toolchain %r. Got %r.' % (toolchain, arch)) |
108 elif arch_required: | 109 elif arch_required: |
109 Expect(arch is not None, | 110 Expect(arch is not None, |
110 'Expected arch to be one of [%s] for toolchain %r.\n' | 111 'Expected arch to be one of [%s] for toolchain %r.\n' |
111 'Use the -a or --arch flags to specify one.\n' % ( | 112 'Use the -a or --arch flags to specify one.\n' % ( |
112 ', '.join(VALID_ARCHES), toolchain)) | 113 ', '.join(VALID_ARCHES), toolchain)) |
113 | 114 |
114 if arch: | 115 if arch: |
115 ExpectArch(arch, VALID_ARCHES) | 116 if toolchain == 'pnacl': |
| 117 ExpectArch(arch, VALID_PNACL_ARCHES) |
| 118 else: |
| 119 ExpectArch(arch, VALID_ARCHES) |
| 120 |
116 if arch == 'arm': | 121 if arch == 'arm': |
117 Expect(toolchain == 'newlib', 'The arm arch only supports newlib.') | 122 Expect(toolchain == 'newlib', 'The arm arch only supports newlib.') |
118 | 123 |
119 | 124 |
120 def GetArchName(arch): | 125 def GetArchName(arch): |
121 return ARCH_NAME.get(arch) | 126 return ARCH_NAME.get(arch) |
122 | 127 |
123 | 128 |
124 def GetArchAltName(arch): | 129 def GetArchAltName(arch): |
125 return ARCH_ALT_NAME.get(arch) | 130 return ARCH_ALT_NAME.get(arch) |
(...skipping 15 matching lines...) Expand all Loading... |
141 return sdk_path.replace('\\', '/') | 146 return sdk_path.replace('\\', '/') |
142 else: | 147 else: |
143 return sdk_path | 148 return sdk_path |
144 | 149 |
145 | 150 |
146 def GetToolchainDir(toolchain, arch=None): | 151 def GetToolchainDir(toolchain, arch=None): |
147 ExpectToolchain(toolchain, NACL_TOOLCHAINS) | 152 ExpectToolchain(toolchain, NACL_TOOLCHAINS) |
148 root = GetPosixSDKPath() | 153 root = GetPosixSDKPath() |
149 platform = getos.GetPlatform() | 154 platform = getos.GetPlatform() |
150 if toolchain == 'pnacl': | 155 if toolchain == 'pnacl': |
151 assert arch is None | |
152 subdir = '%s_pnacl' % platform | 156 subdir = '%s_pnacl' % platform |
153 else: | 157 else: |
154 assert arch is not None | 158 assert arch is not None |
155 subdir = '%s_%s_%s' % (platform, GetArchBaseName(arch), toolchain) | 159 subdir = '%s_%s_%s' % (platform, GetArchBaseName(arch), toolchain) |
156 | 160 |
157 return posixpath.join(root, 'toolchain', subdir) | 161 return posixpath.join(root, 'toolchain', subdir) |
158 | 162 |
159 | 163 |
160 def GetToolchainArchDir(toolchain, arch): | 164 def GetToolchainArchDir(toolchain, arch): |
161 ExpectToolchain(toolchain, NACL_TOOLCHAINS) | 165 ExpectToolchain(toolchain, NACL_TOOLCHAINS) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 263 |
260 return 0 | 264 return 0 |
261 | 265 |
262 | 266 |
263 if __name__ == '__main__': | 267 if __name__ == '__main__': |
264 try: | 268 try: |
265 sys.exit(main(sys.argv[1:])) | 269 sys.exit(main(sys.argv[1:])) |
266 except Error as e: | 270 except Error as e: |
267 sys.stderr.write(str(e) + '\n') | 271 sys.stderr.write(str(e) + '\n') |
268 sys.exit(1) | 272 sys.exit(1) |
OLD | NEW |