Tom Anderson | c31ae0b | 2018-02-06 14:48:56 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2014 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. |
| 5 | |
| 6 | """Outputs host CPU architecture in format recognized by gyp.""" |
| 7 | |
| 8 | import platform |
| 9 | import re |
| 10 | import sys |
| 11 | |
| 12 | |
| 13 | def HostArch(): |
| 14 | """Returns the host architecture with a predictable string.""" |
Edward Lemur | 4ac892e | 2018-10-18 00:41:56 +0000 | [diff] [blame] | 15 | host_arch = platform.machine().lower() |
Milad Farazmand | 973788f | 2019-03-11 19:44:11 +0000 | [diff] [blame] | 16 | host_processor = platform.processor().lower() |
Tom Anderson | c31ae0b | 2018-02-06 14:48:56 -0800 | [diff] [blame] | 17 | |
| 18 | # Convert machine type to format recognized by gyp. |
| 19 | if re.match(r'i.86', host_arch) or host_arch == 'i86pc': |
| 20 | host_arch = 'x86' |
| 21 | elif host_arch in ['x86_64', 'amd64']: |
| 22 | host_arch = 'x64' |
| 23 | elif host_arch.startswith('arm'): |
| 24 | host_arch = 'arm' |
| 25 | elif host_arch.startswith('aarch64'): |
| 26 | host_arch = 'arm64' |
Wang Qing | 254538b | 2018-07-26 02:23:53 +0000 | [diff] [blame] | 27 | elif host_arch.startswith('mips64'): |
| 28 | host_arch = 'mips64' |
Tom Anderson | c31ae0b | 2018-02-06 14:48:56 -0800 | [diff] [blame] | 29 | elif host_arch.startswith('mips'): |
| 30 | host_arch = 'mips' |
Milad Farazmand | 973788f | 2019-03-11 19:44:11 +0000 | [diff] [blame] | 31 | elif host_arch.startswith('ppc') or host_processor == 'powerpc': |
Tom Anderson | c31ae0b | 2018-02-06 14:48:56 -0800 | [diff] [blame] | 32 | host_arch = 'ppc' |
| 33 | elif host_arch.startswith('s390'): |
| 34 | host_arch = 's390' |
| 35 | |
| 36 | |
| 37 | # platform.machine is based on running kernel. It's possible to use 64-bit |
| 38 | # kernel with 32-bit userland, e.g. to give linker slightly more memory. |
| 39 | # Distinguish between different userland bitness by querying |
| 40 | # the python binary. |
| 41 | if host_arch == 'x64' and platform.architecture()[0] == '32bit': |
| 42 | host_arch = 'x86' |
| 43 | if host_arch == 'arm64' and platform.architecture()[0] == '32bit': |
| 44 | host_arch = 'arm' |
| 45 | |
| 46 | return host_arch |
| 47 | |
| 48 | def DoMain(_): |
| 49 | """Hook to be called from gyp without starting a separate python |
| 50 | interpreter.""" |
| 51 | return HostArch() |
| 52 | |
| 53 | if __name__ == '__main__': |
| 54 | print DoMain([]) |