| 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 11 matching lines...) Expand all Loading... |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 import sys | 30 import sys |
| 31 | 31 |
| 32 import in_generator | 32 import json5_generator |
| 33 import name_utilities | 33 import name_utilities |
| 34 from name_utilities import lower_first | 34 from name_utilities import lower_first |
| 35 import template_expander | 35 import template_expander |
| 36 | 36 |
| 37 | 37 |
| 38 class RuntimeFeatureWriter(in_generator.Writer): | 38 class RuntimeFeatureWriter(json5_generator.Writer): |
| 39 class_name = 'RuntimeEnabledFeatures' | 39 class_name = 'RuntimeEnabledFeatures' |
| 40 | 40 |
| 41 # FIXME: valid_values and defaults should probably roll into one object. | 41 def __init__(self, json5_file_path): |
| 42 valid_values = { | 42 super(RuntimeFeatureWriter, self).__init__(json5_file_path) |
| 43 'status': ['stable', 'experimental', 'test'], | |
| 44 } | |
| 45 defaults = { | |
| 46 'condition': None, | |
| 47 'custom': False, | |
| 48 'depends_on': [], | |
| 49 'feature_policy': None, | |
| 50 'implied_by': [], | |
| 51 'origin_trial_feature_name': None, | |
| 52 'origin_trial_os': [], | |
| 53 'settable_from_internals': False, | |
| 54 'status': None, | |
| 55 } | |
| 56 | |
| 57 def __init__(self, in_file_path): | |
| 58 super(RuntimeFeatureWriter, self).__init__(in_file_path) | |
| 59 self._outputs = {(self.class_name + '.h'): self.generate_header, | 43 self._outputs = {(self.class_name + '.h'): self.generate_header, |
| 60 (self.class_name + '.cpp'): self.generate_implementatio
n, | 44 (self.class_name + '.cpp'): self.generate_implementatio
n, |
| 61 } | 45 } |
| 62 | 46 |
| 63 self._features = self.in_file.name_dictionaries | 47 self._features = self.json5_file.name_dictionaries |
| 64 # Make sure the resulting dictionaries have all the keys we expect. | 48 # Make sure the resulting dictionaries have all the keys we expect. |
| 65 for feature in self._features: | 49 for feature in self._features: |
| 66 feature['first_lowered_name'] = lower_first(feature['name']) | 50 feature['first_lowered_name'] = lower_first(feature['name']) |
| 67 # Most features just check their isFooEnabled bool | 51 # Most features just check their isFooEnabled bool |
| 68 # but some depend on or are implied by other bools. | 52 # but some depend on or are implied by other bools. |
| 69 enabled_condition = 'is%sEnabled' % feature['name'] | 53 enabled_condition = 'is%sEnabled' % feature['name'] |
| 70 assert not feature['implied_by'] or not feature['depends_on'], 'Only
one of implied_by and depends_on is allowed' | 54 assert not feature['implied_by'] or not feature['depends_on'], 'Only
one of implied_by and depends_on is allowed' |
| 71 for implied_by_name in feature['implied_by']: | 55 for implied_by_name in feature['implied_by']: |
| 72 enabled_condition += ' || is%sEnabled' % implied_by_name | 56 enabled_condition += ' || is%sEnabled' % implied_by_name |
| 73 for dependant_name in feature['depends_on']: | 57 for dependant_name in feature['depends_on']: |
| 74 enabled_condition += ' && is%sEnabled' % dependant_name | 58 enabled_condition += ' && is%sEnabled' % dependant_name |
| 75 feature['enabled_condition'] = enabled_condition | 59 feature['enabled_condition'] = enabled_condition |
| 76 self._standard_features = [feature for feature in self._features if not
feature['custom']] | 60 self._standard_features = [feature for feature in self._features if not
feature['custom']] |
| 77 | 61 |
| 78 def _feature_sets(self): | 62 def _feature_sets(self): |
| 79 # Another way to think of the status levels is as "sets of features" | 63 # Another way to think of the status levels is as "sets of features" |
| 80 # which is how we're referring to them in this generator. | 64 # which is how we're referring to them in this generator. |
| 81 return list(self.valid_values['status']) | 65 return self.json5_file.parameters['status']['valid_values'] |
| 82 | 66 |
| 83 def _template_inputs(self): | 67 def _template_inputs(self): |
| 84 return { | 68 return { |
| 85 'features': self._features, | 69 'features': self._features, |
| 86 'feature_sets': self._feature_sets(), | 70 'feature_sets': self._feature_sets(), |
| 87 'standard_features': self._standard_features, | 71 'standard_features': self._standard_features, |
| 88 } | 72 } |
| 89 | 73 |
| 90 @template_expander.use_jinja(class_name + '.h.tmpl') | 74 @template_expander.use_jinja(class_name + '.h.tmpl') |
| 91 def generate_header(self): | 75 def generate_header(self): |
| 92 return self._template_inputs() | 76 return self._template_inputs() |
| 93 | 77 |
| 94 @template_expander.use_jinja(class_name + '.cpp.tmpl') | 78 @template_expander.use_jinja(class_name + '.cpp.tmpl') |
| 95 def generate_implementation(self): | 79 def generate_implementation(self): |
| 96 return self._template_inputs() | 80 return self._template_inputs() |
| 97 | 81 |
| 98 | 82 |
| 99 if __name__ == '__main__': | 83 if __name__ == '__main__': |
| 100 in_generator.Maker(RuntimeFeatureWriter).main(sys.argv) | 84 json5_generator.Maker(RuntimeFeatureWriter).main() |
| OLD | NEW |