Index: recipe_engine/util.py |
diff --git a/recipe_engine/util.py b/recipe_engine/util.py |
index 7fe739ee862c6d66a3ebfd833dd5e05049ddae29..75fd5f1428c3a28eeaa742eaab979f6df6aea1d3 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,60 @@ class OutputPlaceholder(Placeholder): |
pass |
+class Platform(collections.namedtuple('Platform', ('name', 'arch', 'bits'))): |
+ """Normalized operating system platform information.""" |
+ |
+ @staticmethod |
+ def norm_plat(plat): |
+ if plat.startswith('linux'): |
+ return 'linux' |
+ elif plat.startswith(('win', 'cygwin')): |
+ return 'win' |
+ elif plat.startswith(('darwin', 'mac')): |
+ return '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 == '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 == 'mac' and |
+ bits == 32 and |
+ architecture == '64bit'): |
+ bits = 64 |
+ |
+ return cls(name=name, arch='intel', bits=bits) |
+ |
+ def is_win(self): |
+ return self.name == 'win' |
+ |
+ def is_mac(self): |
+ return self.name == 'mac' |
+ |
+ def is_linux(self): |
+ return self.name == 'linux' |
+ |
+ def is_posix(self): |
+ return self.name in ('mac', 'linux') |
+ |
+ |
def static_wraps(func): |
wrapped_fn = func |
if isinstance(func, staticmethod): |