OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Build/test configurations, which are just dictionaries. This | 5 """Build/test configurations, which are just dictionaries. This |
6 "defines" the schema and provides some wrappers.""" | 6 "defines" the schema and provides some wrappers.""" |
7 | 7 |
8 | 8 |
9 import json | 9 import json |
10 import os.path | 10 import os.path |
11 import sys | 11 import sys |
12 | 12 |
13 | 13 |
14 def _GetHostOS(): | 14 def _GetHostOS(): |
15 if sys.platform == "linux2": | 15 if sys.platform == "linux2": |
16 return Config.OS_LINUX | 16 return Config.OS_LINUX |
17 if sys.platform == "darwin": | 17 if sys.platform == "darwin": |
18 return Config.OS_MAC | 18 return Config.OS_MAC |
19 if sys.platform == "win32": | 19 if sys.platform == "win32": |
20 return Config.OS_WINDOWS | 20 return Config.OS_WINDOWS |
21 raise NotImplementedError | 21 raise NotImplementedError |
22 | 22 |
23 | 23 |
24 class Config(object): | 24 class Config(object): |
25 """A Config is basically just a wrapper around a dictionary that species a | 25 """A Config is basically just a wrapper around a dictionary that species a |
26 build/test configuration. The dictionary is accessible through the values | 26 build/test configuration. The dictionary is accessible through the values |
27 member.""" | 27 member.""" |
28 | 28 |
29 # Valid values for target_os: | 29 # Valid values for target_os (None is also valid): |
30 OS_ANDROID = "android" | 30 OS_ANDROID = "android" |
31 OS_CHROMEOS = "chromeos" | 31 OS_CHROMEOS = "chromeos" |
32 OS_LINUX = "linux" | 32 OS_LINUX = "linux" |
33 OS_MAC = "mac" | 33 OS_MAC = "mac" |
34 OS_WINDOWS = "windows" | 34 OS_WINDOWS = "windows" |
35 | 35 |
36 # TODO(vtl): Add clang vs gcc. | 36 # Valid values for sanitizer (None is also valid): |
37 # TODO(vtl): Add ASan/TSan/etc. | 37 SANITIZER_ASAN = "asan" |
38 | 38 |
39 def __init__(self, target_os=None, is_debug=True, **kwargs): | 39 def __init__(self, target_os=None, is_debug=True, is_clang=None, |
| 40 sanitizer=None, **kwargs): |
40 """Constructs a Config with key-value pairs specified via keyword arguments. | 41 """Constructs a Config with key-value pairs specified via keyword arguments. |
41 If target_os is not specified, it will be set to the host OS.""" | 42 If target_os is not specified, it will be set to the host OS.""" |
42 | 43 |
43 assert target_os in (None, Config.OS_ANDROID, Config.OS_CHROMEOS, | 44 assert target_os in (None, Config.OS_ANDROID, Config.OS_CHROMEOS, |
44 Config.OS_LINUX, Config.OS_MAC, Config.OS_WINDOWS) | 45 Config.OS_LINUX, Config.OS_MAC, Config.OS_WINDOWS) |
45 assert isinstance(is_debug, bool) | 46 assert isinstance(is_debug, bool) |
| 47 assert is_clang is None or isinstance(is_clang, bool) |
| 48 assert sanitizer in (None, Config.SANITIZER_ASAN) |
46 | 49 |
47 self.values = {} | 50 self.values = {} |
48 self.values["target_os"] = _GetHostOS() if target_os is None else target_os | 51 self.values["target_os"] = _GetHostOS() if target_os is None else target_os |
49 self.values["is_debug"] = is_debug | 52 self.values["is_debug"] = is_debug |
| 53 self.values["is_clang"] = is_clang |
| 54 self.values["sanitizer"] = sanitizer |
50 | 55 |
51 self.values.update(kwargs) | 56 self.values.update(kwargs) |
52 | 57 |
53 # Getters for standard fields ------------------------------------------------ | 58 # Getters for standard fields ------------------------------------------------ |
54 | 59 |
55 @property | 60 @property |
56 def target_os(self): | 61 def target_os(self): |
57 """OS of the build/test target.""" | 62 """OS of the build/test target.""" |
58 return self.values["target_os"] | 63 return self.values["target_os"] |
59 | 64 |
60 @property | 65 @property |
61 def is_debug(self): | 66 def is_debug(self): |
62 """Is Debug build?""" | 67 """Is Debug build?""" |
63 return self.values.get("is_debug") | 68 return self.values["is_debug"] |
| 69 |
| 70 @property |
| 71 def is_clang(self): |
| 72 """Should use clang?""" |
| 73 return self.values["is_clang"] |
| 74 |
| 75 @property |
| 76 def sanitizer(self): |
| 77 """Sanitizer to use, if any.""" |
| 78 return self.values["sanitizer"] |
OLD | NEW |