Remove unused parameter.
[chromium-blink-merge.git] / mojo / tools / mopy / config.py
blob7c8caddfde28285677e8e1c26b713768c8990e0d
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Build/test configurations, which are just dictionaries. This
6 "defines" the schema and provides some wrappers."""
9 import json
10 import os.path
11 import platform
12 import sys
15 class Config(object):
16 """A Config is basically just a wrapper around a dictionary that species a
17 build/test configuration. The dictionary is accessible through the values
18 member."""
20 # Valid values for target_os (None is also valid):
21 OS_ANDROID = "android"
22 OS_CHROMEOS = "chromeos"
23 OS_LINUX = "linux"
24 OS_MAC = "mac"
25 OS_WINDOWS = "windows"
27 # Valid values for target_cpu (None is also valid):
28 ARCH_X86 = "x86"
29 ARCH_X64 = "x64"
30 ARCH_ARM = "arm"
32 # Valid values for sanitizer (None is also valid):
33 SANITIZER_ASAN = "asan"
35 # Standard values for test types (test types are arbitrary strings; other
36 # values are allowed).
37 TEST_TYPE_DEFAULT = "default"
38 TEST_TYPE_UNIT = "unit"
39 TEST_TYPE_PERF = "perf"
40 TEST_TYPE_INTEGRATION = "integration"
42 def __init__(self, target_os=None, target_cpu=None, is_debug=True,
43 is_clang=None, sanitizer=None, dcheck_always_on=False,
44 **kwargs):
45 """Constructs a Config with key-value pairs specified via keyword arguments.
46 If target_os is not specified, it will be set to the host OS."""
48 assert target_os in (None, Config.OS_ANDROID, Config.OS_CHROMEOS,
49 Config.OS_LINUX, Config.OS_MAC, Config.OS_WINDOWS)
50 assert target_cpu in (None, Config.ARCH_X86, Config.ARCH_X64,
51 Config.ARCH_ARM)
52 assert isinstance(is_debug, bool)
53 assert is_clang is None or isinstance(is_clang, bool)
54 assert sanitizer in (None, Config.SANITIZER_ASAN)
55 if "test_types" in kwargs:
56 assert isinstance(kwargs["test_types"], list)
58 self.values = {}
59 self.values["target_os"] = (self.GetHostOS() if target_os is None else
60 target_os)
62 if target_cpu is None:
63 if target_os == Config.OS_ANDROID:
64 target_cpu = Config.ARCH_ARM
65 else:
66 target_cpu = self.GetHostCPUArch()
67 self.values["target_cpu"] = target_cpu
69 self.values["is_debug"] = is_debug
70 self.values["is_clang"] = is_clang
71 self.values["sanitizer"] = sanitizer
72 self.values["dcheck_always_on"] = dcheck_always_on
74 self.values.update(kwargs)
76 @staticmethod
77 def GetHostOS():
78 if sys.platform == "linux2":
79 return Config.OS_LINUX
80 if sys.platform == "darwin":
81 return Config.OS_MAC
82 if sys.platform == "win32":
83 return Config.OS_WINDOWS
84 raise NotImplementedError("Unsupported host OS")
86 @staticmethod
87 def GetHostCPUArch():
88 # Derived from //native_client/pynacl/platform.py
89 machine = platform.machine()
90 if machine in ("x86", "x86-32", "x86_32", "x8632", "i386", "i686", "ia32",
91 "32"):
92 return Config.ARCH_X86
93 if machine in ("x86-64", "amd64", "x86_64", "x8664", "64"):
94 return Config.ARCH_X64
95 if machine.startswith("arm"):
96 return Config.ARCH_ARM
97 raise Exception("Cannot identify CPU arch: %s" % machine)
99 # Getters for standard fields ------------------------------------------------
101 @property
102 def target_os(self):
103 """OS of the build/test target."""
104 return self.values["target_os"]
106 @property
107 def target_cpu(self):
108 """CPU arch of the build/test target."""
109 return self.values["target_cpu"]
111 @property
112 def is_debug(self):
113 """Is Debug build?"""
114 return self.values["is_debug"]
116 @property
117 def dcheck_always_on(self):
118 """DCHECK and MOJO_DCHECK are fatal even in release builds"""
119 return self.values["dcheck_always_on"]
121 @property
122 def is_clang(self):
123 """Should use clang?"""
124 return self.values["is_clang"]
126 @property
127 def sanitizer(self):
128 """Sanitizer to use, if any."""
129 return self.values["sanitizer"]
131 @property
132 def test_types(self):
133 """List of test types to run."""
134 return self.values.get("test_types", [Config.TEST_TYPE_DEFAULT])