| OLD | NEW | 
|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python | 
| 2 # Copyright (C) 2013 Google Inc. All rights reserved. | 2 # Copyright (C) 2013 Google Inc. All rights reserved. | 
| 3 # | 3 # | 
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without | 
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are | 
| 6 # met: | 6 # met: | 
| 7 # | 7 # | 
| 8 #     * Redistributions of source code must retain the above copyright | 8 #     * Redistributions of source code must retain the above copyright | 
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. | 
| 10 #     * Redistributions in binary form must reproduce the above | 10 #     * Redistributions in binary form must reproduce the above | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 36 | 36 | 
| 37 | 37 | 
| 38 class RuntimeFeatureWriter(in_generator.Writer): | 38 class RuntimeFeatureWriter(in_generator.Writer): | 
| 39     class_name = 'RuntimeEnabledFeatures' | 39     class_name = 'RuntimeEnabledFeatures' | 
| 40     filters = { | 40     filters = { | 
| 41         'enable_conditional': name_utilities.enable_conditional_if_endif, | 41         'enable_conditional': name_utilities.enable_conditional_if_endif, | 
| 42     } | 42     } | 
| 43 | 43 | 
| 44     # FIXME: valid_values and defaults should probably roll into one object. | 44     # FIXME: valid_values and defaults should probably roll into one object. | 
| 45     valid_values = { | 45     valid_values = { | 
| 46         'status': ['stable', 'experimental', 'test', 'deprecated'], | 46         'status': ['stable', 'experimental', 'test'], | 
| 47     } | 47     } | 
| 48     defaults = { | 48     defaults = { | 
| 49         'condition': None, | 49         'condition': None, | 
| 50         'implied_by': [], | 50         'implied_by': [], | 
| 51         'depends_on': [], | 51         'depends_on': [], | 
| 52         'custom': False, | 52         'custom': False, | 
| 53         'status': None, | 53         'status': None, | 
| 54     } | 54     } | 
| 55 | 55 | 
| 56     _status_aliases = { |  | 
| 57         'deprecated': 'test', |  | 
| 58     } |  | 
| 59 |  | 
| 60     def __init__(self, in_file_path): | 56     def __init__(self, in_file_path): | 
| 61         super(RuntimeFeatureWriter, self).__init__(in_file_path) | 57         super(RuntimeFeatureWriter, self).__init__(in_file_path) | 
| 62         self._outputs = {(self.class_name + '.h'): self.generate_header, | 58         self._outputs = {(self.class_name + '.h'): self.generate_header, | 
| 63                          (self.class_name + '.cpp'): self.generate_implementatio
     n, | 59                          (self.class_name + '.cpp'): self.generate_implementatio
     n, | 
| 64                         } | 60                         } | 
| 65 | 61 | 
| 66         self._features = self.in_file.name_dictionaries | 62         self._features = self.in_file.name_dictionaries | 
| 67         # Make sure the resulting dictionaries have all the keys we expect. | 63         # Make sure the resulting dictionaries have all the keys we expect. | 
| 68         for feature in self._features: | 64         for feature in self._features: | 
| 69             feature['first_lowered_name'] = lower_first(feature['name']) | 65             feature['first_lowered_name'] = lower_first(feature['name']) | 
| 70             feature['status'] = self._status_aliases.get(feature['status'], feat
     ure['status']) |  | 
| 71             # Most features just check their isFooEnabled bool | 66             # Most features just check their isFooEnabled bool | 
| 72             # but some depend on or are implied by other bools. | 67             # but some depend on or are implied by other bools. | 
| 73             enabled_condition = 'is%sEnabled' % feature['name'] | 68             enabled_condition = 'is%sEnabled' % feature['name'] | 
| 74             assert not feature['implied_by'] or not feature['depends_on'], 'Only
      one of implied_by and depends_on is allowed' | 69             assert not feature['implied_by'] or not feature['depends_on'], 'Only
      one of implied_by and depends_on is allowed' | 
| 75             for implied_by_name in feature['implied_by']: | 70             for implied_by_name in feature['implied_by']: | 
| 76                 enabled_condition += ' || is%sEnabled' % implied_by_name | 71                 enabled_condition += ' || is%sEnabled' % implied_by_name | 
| 77             for dependant_name in feature['depends_on']: | 72             for dependant_name in feature['depends_on']: | 
| 78                 enabled_condition += ' && is%sEnabled' % dependant_name | 73                 enabled_condition += ' && is%sEnabled' % dependant_name | 
| 79             feature['enabled_condition'] = enabled_condition | 74             feature['enabled_condition'] = enabled_condition | 
| 80         self._non_custom_features = filter(lambda feature: not feature['custom']
     , self._features) | 75         self._non_custom_features = filter(lambda feature: not feature['custom']
     , self._features) | 
| 81 | 76 | 
| 82     def _feature_sets(self): | 77     def _feature_sets(self): | 
| 83         # Another way to think of the status levels is as "sets of features" | 78         # Another way to think of the status levels is as "sets of features" | 
| 84         # which is how we're referring to them in this generator. | 79         # which is how we're referring to them in this generator. | 
| 85         return [status for status in self.valid_values['status'] if status not i
     n self._status_aliases] | 80         return list(self.valid_values['status']) | 
| 86 | 81 | 
| 87     @template_expander.use_jinja(class_name + '.h.tmpl', filters=filters) | 82     @template_expander.use_jinja(class_name + '.h.tmpl', filters=filters) | 
| 88     def generate_header(self): | 83     def generate_header(self): | 
| 89         return { | 84         return { | 
| 90             'features': self._features, | 85             'features': self._features, | 
| 91             'feature_sets': self._feature_sets(), | 86             'feature_sets': self._feature_sets(), | 
| 92         } | 87         } | 
| 93 | 88 | 
| 94     @template_expander.use_jinja(class_name + '.cpp.tmpl', filters=filters) | 89     @template_expander.use_jinja(class_name + '.cpp.tmpl', filters=filters) | 
| 95     def generate_implementation(self): | 90     def generate_implementation(self): | 
| 96         return { | 91         return { | 
| 97             'features': self._features, | 92             'features': self._features, | 
| 98             'feature_sets': self._feature_sets(), | 93             'feature_sets': self._feature_sets(), | 
| 99         } | 94         } | 
| 100 | 95 | 
| 101 | 96 | 
| 102 if __name__ == '__main__': | 97 if __name__ == '__main__': | 
| 103     in_generator.Maker(RuntimeFeatureWriter).main(sys.argv) | 98     in_generator.Maker(RuntimeFeatureWriter).main(sys.argv) | 
| OLD | NEW | 
|---|