Index: mojo/tools/mopy/config.py |
diff --git a/mojo/tools/mopy/config.py b/mojo/tools/mopy/config.py |
index 448c7192c8dd9c8cf7d698cadb0a686776b1a0dd..7a3ce194847b3778969bf5cf9e63b5002046e9ec 100644 |
--- a/mojo/tools/mopy/config.py |
+++ b/mojo/tools/mopy/config.py |
@@ -8,6 +8,7 @@ |
import json |
import os.path |
+import platform |
import sys |
@@ -23,6 +24,11 @@ class Config(object): |
OS_MAC = "mac" |
OS_WINDOWS = "windows" |
+ # Valid values for target_arch (None is also valid): |
+ ARCH_X86 = "x86" |
+ ARCH_X64 = "x64" |
+ ARCH_ARM = "arm" |
+ |
# Valid values for sanitizer (None is also valid): |
SANITIZER_ASAN = "asan" |
@@ -33,13 +39,15 @@ class Config(object): |
TEST_TYPE_PERF = "perf" |
TEST_TYPE_INTEGRATION = "integration" |
- def __init__(self, target_os=None, is_debug=True, is_clang=None, |
- sanitizer=None, **kwargs): |
+ def __init__(self, target_os=None, target_arch=None, is_debug=True, |
+ is_clang=None, sanitizer=None, **kwargs): |
"""Constructs a Config with key-value pairs specified via keyword arguments. |
If target_os is not specified, it will be set to the host OS.""" |
assert target_os in (None, Config.OS_ANDROID, Config.OS_CHROMEOS, |
Config.OS_LINUX, Config.OS_MAC, Config.OS_WINDOWS) |
+ assert target_arch in (None, Config.ARCH_X86, Config.ARCH_X64, |
+ Config.ARCH_ARM) |
assert isinstance(is_debug, bool) |
assert is_clang is None or isinstance(is_clang, bool) |
assert sanitizer in (None, Config.SANITIZER_ASAN) |
@@ -49,6 +57,8 @@ class Config(object): |
self.values = {} |
self.values["target_os"] = (self.GetHostOS() if target_os is None else |
target_os) |
+ self.values["target_arch"] = (self.GetHostCPUArch() if target_arch is None |
+ else target_arch) |
self.values["is_debug"] = is_debug |
self.values["is_clang"] = is_clang |
self.values["sanitizer"] = sanitizer |
@@ -65,6 +75,19 @@ class Config(object): |
return Config.OS_WINDOWS |
raise NotImplementedError("Unsupported host OS") |
+ @staticmethod |
+ def GetHostCPUArch(): |
+ # Derived from //native_client/pynacl/platform.py |
+ machine = platform.machine() |
+ if machine in ("x86", "x86-32", "x86_32", "x8632", "i386", "i686", "ia32", |
+ "32"): |
+ return Config.ARCH_X86 |
+ if machine in ("x86-64", "amd64", "x86_64", "x8664", "64"): |
+ return Config.ARCH_X64 |
+ if machine.startswith("arm"): |
+ return Config.ARCH_ARM |
+ raise Exception("Cannot identify CPU arch: %s" % machine) |
+ |
# Getters for standard fields ------------------------------------------------ |
@property |
@@ -73,6 +96,11 @@ class Config(object): |
return self.values["target_os"] |
@property |
+ def target_arch(self): |
+ """CPU arch of the build/test target.""" |
+ return self.values["target_arch"] |
+ |
+ @property |
def is_debug(self): |
"""Is Debug build?""" |
return self.values["is_debug"] |