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."""
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
20 # Valid values for target_os (None is also valid):
21 OS_ANDROID
= "android"
22 OS_CHROMEOS
= "chromeos"
25 OS_WINDOWS
= "windows"
27 # Valid values for target_cpu (None is also valid):
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,
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
,
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)
59 self
.values
["target_os"] = (self
.GetHostOS() if target_os
is None else
62 if target_cpu
is None:
63 if target_os
== Config
.OS_ANDROID
:
64 target_cpu
= Config
.ARCH_ARM
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
)
78 if sys
.platform
== "linux2":
79 return Config
.OS_LINUX
80 if sys
.platform
== "darwin":
82 if sys
.platform
== "win32":
83 return Config
.OS_WINDOWS
84 raise NotImplementedError("Unsupported host OS")
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",
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 ------------------------------------------------
103 """OS of the build/test target."""
104 return self
.values
["target_os"]
107 def target_cpu(self
):
108 """CPU arch of the build/test target."""
109 return self
.values
["target_cpu"]
113 """Is Debug build?"""
114 return self
.values
["is_debug"]
117 def dcheck_always_on(self
):
118 """DCHECK and MOJO_DCHECK are fatal even in release builds"""
119 return self
.values
["dcheck_always_on"]
123 """Should use clang?"""
124 return self
.values
["is_clang"]
128 """Sanitizer to use, if any."""
129 return self
.values
["sanitizer"]
132 def test_types(self
):
133 """List of test types to run."""
134 return self
.values
.get("test_types", [Config
.TEST_TYPE_DEFAULT
])