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 platform | |
11 import sys | 12 import sys |
12 | 13 |
13 | 14 |
14 class Config(object): | 15 class Config(object): |
15 """A Config is basically just a wrapper around a dictionary that species a | 16 """A Config is basically just a wrapper around a dictionary that species a |
16 build/test configuration. The dictionary is accessible through the values | 17 build/test configuration. The dictionary is accessible through the values |
17 member.""" | 18 member.""" |
18 | 19 |
19 # Valid values for target_os (None is also valid): | 20 # Valid values for target_os (None is also valid): |
20 OS_ANDROID = "android" | 21 OS_ANDROID = "android" |
21 OS_CHROMEOS = "chromeos" | 22 OS_CHROMEOS = "chromeos" |
22 OS_LINUX = "linux" | 23 OS_LINUX = "linux" |
23 OS_MAC = "mac" | 24 OS_MAC = "mac" |
24 OS_WINDOWS = "windows" | 25 OS_WINDOWS = "windows" |
25 | 26 |
27 # Valid values for target_arch (None is also valid): | |
28 ARCH_X86 = "x86" | |
29 ARCH_X64 = "x64" | |
30 ARCH_ARM = "arm" | |
31 | |
26 # Valid values for sanitizer (None is also valid): | 32 # Valid values for sanitizer (None is also valid): |
27 SANITIZER_ASAN = "asan" | 33 SANITIZER_ASAN = "asan" |
28 | 34 |
29 # Standard values for test types (test types are arbitrary strings; other | 35 # Standard values for test types (test types are arbitrary strings; other |
30 # values are allowed). | 36 # values are allowed). |
31 TEST_TYPE_DEFAULT = "default" | 37 TEST_TYPE_DEFAULT = "default" |
32 TEST_TYPE_UNIT = "unit" | 38 TEST_TYPE_UNIT = "unit" |
33 TEST_TYPE_PERF = "perf" | 39 TEST_TYPE_PERF = "perf" |
34 TEST_TYPE_INTEGRATION = "integration" | 40 TEST_TYPE_INTEGRATION = "integration" |
35 | 41 |
36 def __init__(self, target_os=None, is_debug=True, is_clang=None, | 42 def __init__(self, target_os=None, target_arch=None, is_debug=True, |
37 sanitizer=None, **kwargs): | 43 is_clang=None, sanitizer=None, **kwargs): |
38 """Constructs a Config with key-value pairs specified via keyword arguments. | 44 """Constructs a Config with key-value pairs specified via keyword arguments. |
39 If target_os is not specified, it will be set to the host OS.""" | 45 If target_os is not specified, it will be set to the host OS.""" |
40 | 46 |
41 assert target_os in (None, Config.OS_ANDROID, Config.OS_CHROMEOS, | 47 assert target_os in (None, Config.OS_ANDROID, Config.OS_CHROMEOS, |
42 Config.OS_LINUX, Config.OS_MAC, Config.OS_WINDOWS) | 48 Config.OS_LINUX, Config.OS_MAC, Config.OS_WINDOWS) |
49 assert target_arch in (None, Config.ARCH_X86, Config.ARCH_X64, | |
50 Config.ARCH_ARM) | |
43 assert isinstance(is_debug, bool) | 51 assert isinstance(is_debug, bool) |
44 assert is_clang is None or isinstance(is_clang, bool) | 52 assert is_clang is None or isinstance(is_clang, bool) |
45 assert sanitizer in (None, Config.SANITIZER_ASAN) | 53 assert sanitizer in (None, Config.SANITIZER_ASAN) |
46 if "test_types" in kwargs: | 54 if "test_types" in kwargs: |
47 assert isinstance(kwargs["test_types"], list) | 55 assert isinstance(kwargs["test_types"], list) |
48 | 56 |
49 self.values = {} | 57 self.values = {} |
50 self.values["target_os"] = (self.GetHostOS() if target_os is None else | 58 self.values["target_os"] = (self.GetHostOS() if target_os is None else |
51 target_os) | 59 target_os) |
60 self.values["target_arch"] = (self.GetHostCPUArch() if target_arch is None | |
61 else target_arch) | |
52 self.values["is_debug"] = is_debug | 62 self.values["is_debug"] = is_debug |
53 self.values["is_clang"] = is_clang | 63 self.values["is_clang"] = is_clang |
54 self.values["sanitizer"] = sanitizer | 64 self.values["sanitizer"] = sanitizer |
55 | 65 |
56 self.values.update(kwargs) | 66 self.values.update(kwargs) |
57 | 67 |
58 @staticmethod | 68 @staticmethod |
59 def GetHostOS(): | 69 def GetHostOS(): |
60 if sys.platform == "linux2": | 70 if sys.platform == "linux2": |
61 return Config.OS_LINUX | 71 return Config.OS_LINUX |
62 if sys.platform == "darwin": | 72 if sys.platform == "darwin": |
63 return Config.OS_MAC | 73 return Config.OS_MAC |
64 if sys.platform == "win32": | 74 if sys.platform == "win32": |
65 return Config.OS_WINDOWS | 75 return Config.OS_WINDOWS |
66 raise NotImplementedError("Unsupported host OS") | 76 raise NotImplementedError("Unsupported host OS") |
67 | 77 |
78 @staticmethod | |
79 def GetHostCPUArch(): | |
80 # Derived from //native_client/pynacl/platform.py | |
81 machine = platform.machine() | |
82 if machine in ('x86', 'x86-32', 'x86_32', 'x8632', 'i386', 'i686', 'ia32', | |
viettrungluu
2015/01/13 21:04:04
nit: Apparently, in this file, we prefer to use "
Nick Bray (chromium)
2015/01/13 21:39:56
Done.
| |
83 '32'): | |
84 return Config.ARCH_X86 | |
85 if machine in ('x86-64', 'amd64', 'x86_64', 'x8664', '64'): | |
viettrungluu
2015/01/13 21:04:04
" (etc.)
Nick Bray (chromium)
2015/01/13 21:39:57
Done.
| |
86 return Config.ARCH_X64 | |
87 if machine.startswith('arm'): | |
88 return Config.ARCH_ARM | |
89 raise Exception("Cannot identify CPU arch: %s" % machine) | |
90 | |
68 # Getters for standard fields ------------------------------------------------ | 91 # Getters for standard fields ------------------------------------------------ |
69 | 92 |
70 @property | 93 @property |
71 def target_os(self): | 94 def target_os(self): |
72 """OS of the build/test target.""" | 95 """OS of the build/test target.""" |
73 return self.values["target_os"] | 96 return self.values["target_os"] |
74 | 97 |
75 @property | 98 @property |
99 def target_arch(self): | |
100 """CPU arch of the build/test target.""" | |
101 return self.values["target_arch"] | |
102 | |
103 @property | |
76 def is_debug(self): | 104 def is_debug(self): |
77 """Is Debug build?""" | 105 """Is Debug build?""" |
78 return self.values["is_debug"] | 106 return self.values["is_debug"] |
79 | 107 |
80 @property | 108 @property |
81 def is_clang(self): | 109 def is_clang(self): |
82 """Should use clang?""" | 110 """Should use clang?""" |
83 return self.values["is_clang"] | 111 return self.values["is_clang"] |
84 | 112 |
85 @property | 113 @property |
86 def sanitizer(self): | 114 def sanitizer(self): |
87 """Sanitizer to use, if any.""" | 115 """Sanitizer to use, if any.""" |
88 return self.values["sanitizer"] | 116 return self.values["sanitizer"] |
89 | 117 |
90 @property | 118 @property |
91 def test_types(self): | 119 def test_types(self): |
92 """List of test types to run.""" | 120 """List of test types to run.""" |
93 return self.values.get("test_types", [Config.TEST_TYPE_DEFAULT]) | 121 return self.values.get("test_types", [Config.TEST_TYPE_DEFAULT]) |
OLD | NEW |