| Index: recipe_engine/util.py
|
| diff --git a/recipe_engine/util.py b/recipe_engine/util.py
|
| index 7fe739ee862c6d66a3ebfd833dd5e05049ddae29..88f1a92cdef1e7ec655afa8cbe8e20d8fd815e6a 100644
|
| --- a/recipe_engine/util.py
|
| +++ b/recipe_engine/util.py
|
| @@ -2,11 +2,13 @@
|
| # Use of this source code is governed under the Apache License, Version 2.0
|
| # that can be found in the LICENSE file.
|
|
|
| +import collections
|
| import contextlib
|
| import datetime
|
| import functools
|
| import logging
|
| import os
|
| +import platform
|
| import sys
|
| import traceback
|
| import time
|
| @@ -91,6 +93,64 @@ class OutputPlaceholder(Placeholder):
|
| pass
|
|
|
|
|
| +class Platform(collections.namedtuple('Platform', ('name', 'arch', 'bits'))):
|
| + """Normalized operating system platform information."""
|
| +
|
| + # Platform Constants.
|
| + LINUX = 'linux'
|
| + MAC = 'mac'
|
| + WIN = 'win'
|
| +
|
| + @classmethod
|
| + def norm_plat(cls, plat):
|
| + """Returns (str): The platform constant string for the current platform.
|
| +
|
| + Raises:
|
| + ValueError: If the current platform could not be mapped to a constant.
|
| + """
|
| + if plat.startswith('linux'):
|
| + return cls.LINUX
|
| + elif plat.startswith(('win', 'cygwin')):
|
| + return cls.WIN
|
| + elif plat.startswith(('darwin', 'mac')):
|
| + return cls.MAC
|
| + else: # pragma: no cover
|
| + raise ValueError('Don\'t understand platform "%s"' % (plat,))
|
| +
|
| + @staticmethod
|
| + def norm_bits(arch):
|
| + return 64 if '64' in str(arch) else 32
|
| +
|
| + @classmethod
|
| + def probe(cls):
|
| + name = cls.norm_plat(sys.platform)
|
| + bits = cls.norm_bits(platform.machine())
|
| +
|
| + # 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.
|
| + architecture = platform.architecture()[0]
|
| + if (name == cls.LINUX and
|
| + bits == 64 and
|
| + architecture == '32bit'):
|
| + bits = 32
|
| + # On Mac, the inverse of the above is true: the kernel is 32-bit but the
|
| + # CPU and userspace both are capable of running 64-bit programs.
|
| + elif (name == cls.MAC and
|
| + bits == 32 and
|
| + architecture == '64bit'):
|
| + bits = 64
|
| +
|
| + return cls(name=name, arch='intel', bits=bits)
|
| +
|
| + def is_win(self):
|
| + return self.name == self.WIN
|
| +
|
| + def is_posix(self):
|
| + return self.name in (self.MAC, self.LINUX)
|
| +
|
| +
|
| def static_wraps(func):
|
| wrapped_fn = func
|
| if isinstance(func, staticmethod):
|
|
|