Takuto Ikuta | 3dab32e0 | 2023-01-12 18:52:00 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Avi Drissman | 73a09d1 | 2022-09-08 20:33:38 | [diff] [blame] | 2 | # Copyright 2014 The Chromium Authors |
phajdan.jr@chromium.org | 25a967e | 2014-01-31 17:23:56 | [diff] [blame] | 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 | |
Raul Tambre | 9e24293b | 2019-05-12 06:11:07 | [diff] [blame] | 8 | |
phajdan.jr@chromium.org | 25a967e | 2014-01-31 17:23:56 | [diff] [blame] | 9 | import platform |
| 10 | import re |
| 11 | import sys |
| 12 | |
| 13 | |
kaliamoorthi@chromium.org | d6bdd54 | 2014-07-09 12:06:21 | [diff] [blame] | 14 | defHostArch(): |
| 15 | """Returns the host architecture with a predictable string.""" |
phajdan.jr@chromium.org | 25a967e | 2014-01-31 17:23:56 | [diff] [blame] | 16 | host_arch= platform.machine() |
| 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='ia32' |
tsergeant | 9cc67cbe | 2016-09-29 03:28:24 | [diff] [blame] | 21 | elif host_archin['x86_64','amd64']: |
phajdan.jr@chromium.org | 25a967e | 2014-01-31 17:23:56 | [diff] [blame] | 22 | host_arch='x64' |
| 23 | elif host_arch.startswith('arm'): |
| 24 | host_arch='arm' |
Pierre Langlois | f7b3931 | 2017-11-07 14:26:17 | [diff] [blame] | 25 | elif host_arch.startswith('aarch64'): |
| 26 | host_arch='arm64' |
Wang Qing | d25f7cc | 2018-09-05 06:01:04 | [diff] [blame] | 27 | elif host_arch.startswith('mips64'): |
| 28 | host_arch='mips64' |
brendan.kirby | a321aeb23 | 2016-06-15 15:48:03 | [diff] [blame] | 29 | elif host_arch.startswith('mips'): |
| 30 | host_arch='mips' |
bjaideep | d572de4 | 2016-09-30 02:07:45 | [diff] [blame] | 31 | elif host_arch.startswith('ppc'): |
| 32 | host_arch='ppc' |
| 33 | elif host_arch.startswith('s390'): |
| 34 | host_arch='s390' |
| 35 | |
phajdan.jr@chromium.org | 25a967e | 2014-01-31 17:23:56 | [diff] [blame] | 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='ia32' |
Pierre Langlois | f7b3931 | 2017-11-07 14:26:17 | [diff] [blame] | 43 | if host_arch=='arm64'and platform.architecture()[0]=='32bit': |
| 44 | host_arch='arm' |
phajdan.jr@chromium.org | 25a967e | 2014-01-31 17:23:56 | [diff] [blame] | 45 | |
bratell@opera.com | d2f38924 | 2014-06-06 09:56:44 | [diff] [blame] | 46 | return host_arch |
phajdan.jr@chromium.org | 25a967e | 2014-01-31 17:23:56 | [diff] [blame] | 47 | |
kaliamoorthi@chromium.org | d6bdd54 | 2014-07-09 12:06:21 | [diff] [blame] | 48 | defDoMain(_): |
| 49 | """Hook to be called from gyp without starting a separate python |
| 50 | interpreter.""" |
| 51 | returnHostArch() |
| 52 | |
phajdan.jr@chromium.org | 25a967e | 2014-01-31 17:23:56 | [diff] [blame] | 53 | if __name__=='__main__': |
Raul Tambre | 9e24293b | 2019-05-12 06:11:07 | [diff] [blame] | 54 | print(DoMain([])) |