blob: 69c50f870377bfbcdcaa581daa0428fe901070af [file] [log] [blame]
Tom Andersonc31ae0b2018-02-06 14:48:56 -08001#!/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
Raul Tambreb946b232019-03-26 14:48:46 +00008from __future__ import print_function
9
Tom Andersonc31ae0b2018-02-06 14:48:56 -080010import platform
11import re
12import sys
13
14
15def HostArch():
16 """Returns the host architecture with a predictable string."""
Edward Lemur4ac892e2018-10-18 00:41:56 +000017 host_arch = platform.machine().lower()
Milad Farazmand973788f2019-03-11 19:44:11 +000018 host_processor = platform.processor().lower()
Tom Andersonc31ae0b2018-02-06 14:48:56 -080019
20 # Convert machine type to format recognized by gyp.
21 if re.match(r'i.86', host_arch) or host_arch == 'i86pc':
22 host_arch = 'x86'
23 elif host_arch in ['x86_64', 'amd64']:
24 host_arch = 'x64'
25 elif host_arch.startswith('arm'):
26 host_arch = 'arm'
27 elif host_arch.startswith('aarch64'):
28 host_arch = 'arm64'
Wang Qing254538b2018-07-26 02:23:53 +000029 elif host_arch.startswith('mips64'):
30 host_arch = 'mips64'
Tom Andersonc31ae0b2018-02-06 14:48:56 -080031 elif host_arch.startswith('mips'):
32 host_arch = 'mips'
Milad Farazmand973788f2019-03-11 19:44:11 +000033 elif host_arch.startswith('ppc') or host_processor == 'powerpc':
Tom Andersonc31ae0b2018-02-06 14:48:56 -080034 host_arch = 'ppc'
35 elif host_arch.startswith('s390'):
36 host_arch = 's390'
37
38
39 # platform.machine is based on running kernel. It's possible to use 64-bit
40 # kernel with 32-bit userland, e.g. to give linker slightly more memory.
41 # Distinguish between different userland bitness by querying
42 # the python binary.
43 if host_arch == 'x64' and platform.architecture()[0] == '32bit':
44 host_arch = 'x86'
45 if host_arch == 'arm64' and platform.architecture()[0] == '32bit':
46 host_arch = 'arm'
47
48 return host_arch
49
50def DoMain(_):
51 """Hook to be called from gyp without starting a separate python
52 interpreter."""
53 return HostArch()
54
55if __name__ == '__main__':
Raul Tambreb946b232019-03-26 14:48:46 +000056 print(DoMain([]))