Add function to get host_arch

This commit is contained in:
Cheng Zhao 2015-07-01 09:17:44 +00:00
parent 1b3a8435e5
commit af05f5b329
2 changed files with 27 additions and 1 deletions

View file

@ -3,6 +3,8 @@
import atexit
import contextlib
import errno
import platform
import re
import shutil
import ssl
import subprocess
@ -15,6 +17,29 @@ import zipfile
from config import is_verbose_mode
def get_host_arch():
"""Returns the host architecture with a predictable string."""
host_arch = platform.machine()
# 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'
# 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 tempdir(prefix=''):
directory = tempfile.mkdtemp(prefix=prefix)
atexit.register(shutil.rmtree, directory)