OLD | NEW |
1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 12 matching lines...) Expand all Loading... |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 import copy | 29 import copy |
30 | 30 |
31 | 31 |
32 class TestConfiguration(object): | 32 class TestConfiguration(object): |
| 33 |
33 def __init__(self, version, architecture, build_type): | 34 def __init__(self, version, architecture, build_type): |
34 self.version = version | 35 self.version = version |
35 self.architecture = architecture | 36 self.architecture = architecture |
36 self.build_type = build_type | 37 self.build_type = build_type |
37 | 38 |
38 @classmethod | 39 @classmethod |
39 def category_order(cls): | 40 def category_order(cls): |
40 """The most common human-readable order in which the configuration prope
rties are listed.""" | 41 """The most common human-readable order in which the configuration prope
rties are listed.""" |
41 return ['version', 'architecture', 'build_type'] | 42 return ['version', 'architecture', 'build_type'] |
42 | 43 |
(...skipping 15 matching lines...) Expand all Loading... |
58 | 59 |
59 def __eq__(self, other): | 60 def __eq__(self, other): |
60 return self.__hash__() == other.__hash__() | 61 return self.__hash__() == other.__hash__() |
61 | 62 |
62 def values(self): | 63 def values(self): |
63 """Returns the configuration values of this instance as a tuple.""" | 64 """Returns the configuration values of this instance as a tuple.""" |
64 return self.__dict__.values() | 65 return self.__dict__.values() |
65 | 66 |
66 | 67 |
67 class SpecifierSorter(object): | 68 class SpecifierSorter(object): |
| 69 |
68 def __init__(self, all_test_configurations=None, macros=None): | 70 def __init__(self, all_test_configurations=None, macros=None): |
69 self._specifier_to_category = {} | 71 self._specifier_to_category = {} |
70 | 72 |
71 if not all_test_configurations: | 73 if not all_test_configurations: |
72 return | 74 return |
73 for test_configuration in all_test_configurations: | 75 for test_configuration in all_test_configurations: |
74 for category, specifier in test_configuration.items(): | 76 for category, specifier in test_configuration.items(): |
75 self.add_specifier(category, specifier) | 77 self.add_specifier(category, specifier) |
76 | 78 |
77 self.add_macros(macros) | 79 self.add_macros(macros) |
(...skipping 24 matching lines...) Expand all Loading... |
102 category_slots[self.specifier_priority(specifier)].append(specifier) | 104 category_slots[self.specifier_priority(specifier)].append(specifier) |
103 | 105 |
104 def sort_and_return(result, specifier_list): | 106 def sort_and_return(result, specifier_list): |
105 specifier_list.sort() | 107 specifier_list.sort() |
106 return result + specifier_list | 108 return result + specifier_list |
107 | 109 |
108 return reduce(sort_and_return, category_slots, []) | 110 return reduce(sort_and_return, category_slots, []) |
109 | 111 |
110 | 112 |
111 class TestConfigurationConverter(object): | 113 class TestConfigurationConverter(object): |
| 114 |
112 def __init__(self, all_test_configurations, configuration_macros=None): | 115 def __init__(self, all_test_configurations, configuration_macros=None): |
113 self._all_test_configurations = all_test_configurations | 116 self._all_test_configurations = all_test_configurations |
114 self._configuration_macros = configuration_macros or {} | 117 self._configuration_macros = configuration_macros or {} |
115 self._specifier_to_configuration_set = {} | 118 self._specifier_to_configuration_set = {} |
116 self._specifier_sorter = SpecifierSorter() | 119 self._specifier_sorter = SpecifierSorter() |
117 self._collapsing_sets_by_size = {} | 120 self._collapsing_sets_by_size = {} |
118 self._junk_specifier_combinations = {} | 121 self._junk_specifier_combinations = {} |
119 self._collapsing_sets_by_category = {} | 122 self._collapsing_sets_by_category = {} |
120 matching_sets_by_category = {} | 123 matching_sets_by_category = {} |
121 for configuration in all_test_configurations: | 124 for configuration in all_test_configurations: |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 specifiers_list.remove(item) | 278 specifiers_list.remove(item) |
276 specifiers_list.append(frozenset(common | diff)) | 279 specifiers_list.append(frozenset(common | diff)) |
277 return True | 280 return True |
278 return False | 281 return False |
279 | 282 |
280 # 3) Abbreviate specifier sets by combining specifiers across categories
. | 283 # 3) Abbreviate specifier sets by combining specifiers across categories
. |
281 # (win7, release), (win10, release) --> (win7, win10, release) | 284 # (win7, release), (win10, release) --> (win7, win10, release) |
282 while try_abbreviating(self._collapsing_sets_by_size.values()): | 285 while try_abbreviating(self._collapsing_sets_by_size.values()): |
283 pass | 286 pass |
284 | 287 |
285 | |
286 # 4) Substitute specifier subsets that match macros witin each set: | 288 # 4) Substitute specifier subsets that match macros witin each set: |
287 # (win7, win10, release) -> (win, release) | 289 # (win7, win10, release) -> (win, release) |
288 self.collapse_macros(self._configuration_macros, specifiers_list) | 290 self.collapse_macros(self._configuration_macros, specifiers_list) |
289 | 291 |
290 macro_keys = set(self._configuration_macros.keys()) | 292 macro_keys = set(self._configuration_macros.keys()) |
291 | 293 |
292 # 5) Collapsing macros may have created combinations the can now be abbr
eviated. | 294 # 5) Collapsing macros may have created combinations the can now be abbr
eviated. |
293 # (win7, release), (linux, x86, release), (linux, x86_64, release) -->
(win7, release), (linux, release) --> (win7, linux, release) | 295 # (win7, release), (linux, x86, release), (linux, x86_64, release) -->
(win7, release), (linux, release) --> (win7, linux, release) |
294 while try_abbreviating([self._collapsing_sets_by_category['version'] | m
acro_keys]): | 296 while try_abbreviating([self._collapsing_sets_by_category['version'] | m
acro_keys]): |
295 pass | 297 pass |
296 | 298 |
297 # 6) Remove cases where we have collapsed but have all macros. | 299 # 6) Remove cases where we have collapsed but have all macros. |
298 # (android, win, mac, linux, release) --> (release) | 300 # (android, win, mac, linux, release) --> (release) |
299 specifiers_to_remove = [] | 301 specifiers_to_remove = [] |
300 for specifier_set in specifiers_list: | 302 for specifier_set in specifiers_list: |
301 if macro_keys <= specifier_set: | 303 if macro_keys <= specifier_set: |
302 specifiers_to_remove.append(specifier_set) | 304 specifiers_to_remove.append(specifier_set) |
303 | 305 |
304 for specifier_set in specifiers_to_remove: | 306 for specifier_set in specifiers_to_remove: |
305 specifiers_list.remove(specifier_set) | 307 specifiers_list.remove(specifier_set) |
306 specifiers_list.append(frozenset(specifier_set - macro_keys)) | 308 specifiers_list.append(frozenset(specifier_set - macro_keys)) |
307 | 309 |
308 return specifiers_list | 310 return specifiers_list |
OLD | NEW |