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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 return False | 251 return False |
252 for combination in self.combinations(specifiers_list, size): | 252 for combination in self.combinations(specifiers_list, size): |
253 if self.symmetric_difference(combination) in collapsing_sets: | 253 if self.symmetric_difference(combination) in collapsing_sets: |
254 for item in combination: | 254 for item in combination: |
255 specifiers_list.remove(item) | 255 specifiers_list.remove(item) |
256 specifiers_list.append(frozenset(self.intersect_combination(
combination))) | 256 specifiers_list.append(frozenset(self.intersect_combination(
combination))) |
257 return True | 257 return True |
258 return False | 258 return False |
259 | 259 |
260 # 2) Collapse specifier sets with common specifiers: | 260 # 2) Collapse specifier sets with common specifiers: |
261 # (xp, release), (xp, debug) --> (xp, x86) | 261 # (win7, release), (win7, debug) --> (win7, x86) |
262 for size, collapsing_sets in self._collapsing_sets_by_size.items(): | 262 for size, collapsing_sets in self._collapsing_sets_by_size.items(): |
263 while try_collapsing(size, collapsing_sets): | 263 while try_collapsing(size, collapsing_sets): |
264 pass | 264 pass |
265 | 265 |
266 def try_abbreviating(collapsing_sets): | 266 def try_abbreviating(collapsing_sets): |
267 if len(specifiers_list) < 2: | 267 if len(specifiers_list) < 2: |
268 return False | 268 return False |
269 for combination in self.combinations(specifiers_list, 2): | 269 for combination in self.combinations(specifiers_list, 2): |
270 for collapsing_set in collapsing_sets: | 270 for collapsing_set in collapsing_sets: |
271 diff = self.symmetric_difference(combination) | 271 diff = self.symmetric_difference(combination) |
272 if diff <= collapsing_set: | 272 if diff <= collapsing_set: |
273 common = self.intersect_combination(combination) | 273 common = self.intersect_combination(combination) |
274 for item in combination: | 274 for item in combination: |
275 specifiers_list.remove(item) | 275 specifiers_list.remove(item) |
276 specifiers_list.append(frozenset(common | diff)) | 276 specifiers_list.append(frozenset(common | diff)) |
277 return True | 277 return True |
278 return False | 278 return False |
279 | 279 |
280 # 3) Abbreviate specifier sets by combining specifiers across categories
. | 280 # 3) Abbreviate specifier sets by combining specifiers across categories
. |
281 # (xp, release), (win7, release) --> (xp, win7, release) | 281 # (win7, release), (win10, release) --> (win7, win10, release) |
282 while try_abbreviating(self._collapsing_sets_by_size.values()): | 282 while try_abbreviating(self._collapsing_sets_by_size.values()): |
283 pass | 283 pass |
284 | 284 |
285 | 285 |
286 # 4) Substitute specifier subsets that match macros witin each set: | 286 # 4) Substitute specifier subsets that match macros witin each set: |
287 # (xp, win7, release) -> (win, release) | 287 # (win7, win10, release) -> (win, release) |
288 self.collapse_macros(self._configuration_macros, specifiers_list) | 288 self.collapse_macros(self._configuration_macros, specifiers_list) |
289 | 289 |
290 macro_keys = set(self._configuration_macros.keys()) | 290 macro_keys = set(self._configuration_macros.keys()) |
291 | 291 |
292 # 5) Collapsing macros may have created combinations the can now be abbr
eviated. | 292 # 5) Collapsing macros may have created combinations the can now be abbr
eviated. |
293 # (xp, release), (linux, x86, release), (linux, x86_64, release) --> (
xp, release), (linux, release) --> (xp, linux, release) | 293 # (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]): | 294 while try_abbreviating([self._collapsing_sets_by_category['version'] | m
acro_keys]): |
295 pass | 295 pass |
296 | 296 |
297 # 6) Remove cases where we have collapsed but have all macros. | 297 # 6) Remove cases where we have collapsed but have all macros. |
298 # (android, win, mac, linux, release) --> (release) | 298 # (android, win, mac, linux, release) --> (release) |
299 specifiers_to_remove = [] | 299 specifiers_to_remove = [] |
300 for specifier_set in specifiers_list: | 300 for specifier_set in specifiers_list: |
301 if macro_keys <= specifier_set: | 301 if macro_keys <= specifier_set: |
302 specifiers_to_remove.append(specifier_set) | 302 specifiers_to_remove.append(specifier_set) |
303 | 303 |
304 for specifier_set in specifiers_to_remove: | 304 for specifier_set in specifiers_to_remove: |
305 specifiers_list.remove(specifier_set) | 305 specifiers_list.remove(specifier_set) |
306 specifiers_list.append(frozenset(specifier_set - macro_keys)) | 306 specifiers_list.append(frozenset(specifier_set - macro_keys)) |
307 | 307 |
308 return specifiers_list | 308 return specifiers_list |
OLD | NEW |