summaryrefslogtreecommitdiff
path: root/coreconf/detect_host_arch.py
diff options
context:
space:
mode:
authorTed Mielczarek <ted@mielczarek.org>2016-11-04 14:35:25 -0400
committerTed Mielczarek <ted@mielczarek.org>2016-11-04 14:35:25 -0400
commit1fe740562c17822c4a856a9d7ca9c52a6d511b64 (patch)
treea617eb9c8425f22b16abed58f6e3af6a98f31fe8 /coreconf/detect_host_arch.py
parent2da6129f570659a35dd0c83895d7791e04fa699e (diff)
downloadnss-hg-1fe740562c17822c4a856a9d7ca9c52a6d511b64.tar.gz
bug 1311919 - rewrite detect_host_arch. r=franziskus
Diffstat (limited to 'coreconf/detect_host_arch.py')
-rw-r--r--coreconf/detect_host_arch.py50
1 files changed, 21 insertions, 29 deletions
diff --git a/coreconf/detect_host_arch.py b/coreconf/detect_host_arch.py
index 9820c85ae..f161d3c89 100644
--- a/coreconf/detect_host_arch.py
+++ b/coreconf/detect_host_arch.py
@@ -1,33 +1,25 @@
#!/usr/bin/env python
-# Copyright 2014 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-"""Outputs host CPU architecture in format recognized by gyp."""
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import print_function
+
+import fnmatch
import platform
-import re
-def HostArch():
- """Returns the host architecture with a predictable string."""
- host_arch = platform.machine().lower()
- # Convert machine type to format recognized by gyp.
- if re.match(r'i.86', host_arch) or host_arch == 'i86pc':
- host_arch = 'ia32'
- elif host_arch in ['x86_64', 'amd64']:
- host_arch = 'x64'
- elif host_arch.startswith('arm'):
- host_arch = 'arm'
- elif host_arch.startswith('mips'):
- host_arch = 'mips'
- # platform.machine is based on running kernel. It's possible to use 64-bit
- # kernel with 32-bit userland, e.g. to give linker slightly more memory.
- # Distinguish between different userland bitness by querying
- # the python binary.
- if host_arch == 'x64' and platform.architecture()[0] == '32bit':
- host_arch = 'ia32'
- return host_arch
-def DoMain(_):
- """Hook to be called from gyp without starting a separate python
- interpreter."""
- return HostArch()
+def main():
+ host_arch = platform.machine().lower()
+ if host_arch in ('amd64', 'x86_64'):
+ host_arch = 'x64'
+ elif fnmatch.fnmatch(host_arch, 'i?86') or host_arch == 'i86pc':
+ host_arch = 'x64'
+ elif host_arch.startswith('arm'):
+ host_arch = 'arm'
+ elif host_arch.startswith('mips'):
+ host_arch = 'mips'
+ print(host_arch)
+
if __name__ == '__main__':
- print DoMain([])
+ main()