| 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 14 matching lines...) Expand all Loading... |
| 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 os.path | 30 import os.path |
| 31 import sys | 31 import sys |
| 32 | 32 |
| 33 from in_file import InFile | 33 from in_file import InFile |
| 34 import in_generator | 34 import in_generator |
| 35 import template_expander |
| 35 | 36 |
| 36 | 37 |
| 37 class RuntimeFeatureWriter(in_generator.Writer): | 38 class RuntimeFeatureWriter(in_generator.Writer): |
| 38 class_name = 'RuntimeEnabledFeatures' | 39 class_name = 'RuntimeEnabledFeatures' |
| 39 | 40 |
| 40 # FIXME: valid_values and defaults should probably roll into one object. | 41 # FIXME: valid_values and defaults should probably roll into one object. |
| 41 valid_values = { | 42 valid_values = { |
| 42 'status': ['stable', 'experimental', 'test'], | 43 'status': ['stable', 'experimental', 'test'], |
| 43 } | 44 } |
| 44 defaults = { | 45 defaults = { |
| 45 'condition' : None, | 46 'condition' : None, |
| 46 'depends_on' : [], | 47 'depends_on' : [], |
| 47 'custom': False, | 48 'custom': False, |
| 48 'status': None, | 49 'status': None, |
| 49 } | 50 } |
| 50 | 51 |
| 51 def __init__(self, in_file_path, enabled_conditions): | 52 def __init__(self, in_file_path, enabled_conditions): |
| 52 super(RuntimeFeatureWriter, self).__init__(in_file_path, enabled_conditi
ons) | 53 super(RuntimeFeatureWriter, self).__init__(in_file_path, enabled_conditi
ons) |
| 54 self._outputs = {(self.class_name + ".h"): self.generate_header, |
| 55 (self.class_name + ".cpp"): self.generate_implementatio
n, |
| 56 } |
| 57 |
| 53 self._features = self.in_file.name_dictionaries | 58 self._features = self.in_file.name_dictionaries |
| 54 # Make sure the resulting dictionaries have all the keys we expect. | 59 # Make sure the resulting dictionaries have all the keys we expect. |
| 55 for feature in self._features: | 60 for feature in self._features: |
| 56 feature['first_lowered_name'] = self._lower_first(feature['name']) | 61 feature['first_lowered_name'] = self._lower_first(feature['name']) |
| 57 # Most features just check their isFooEnabled bool | 62 # Most features just check their isFooEnabled bool |
| 58 # but some depend on more than one bool. | 63 # but some depend on more than one bool. |
| 59 enabled_condition = "is%sEnabled" % feature['name'] | 64 enabled_condition = "is%sEnabled" % feature['name'] |
| 60 for dependant_name in feature['depends_on']: | 65 for dependant_name in feature['depends_on']: |
| 61 enabled_condition += " && is%sEnabled" % dependant_name | 66 enabled_condition += " && is%sEnabled" % dependant_name |
| 62 feature['enabled_condition'] = enabled_condition | 67 feature['enabled_condition'] = enabled_condition |
| 63 self._non_custom_features = filter(lambda feature: not feature['custom']
, self._features) | 68 self._non_custom_features = filter(lambda feature: not feature['custom']
, self._features) |
| 64 | 69 |
| 65 def _lower_first(self, string): | 70 def _lower_first(self, string): |
| 66 lowered = string[0].lower() + string[1:] | 71 lowered = string[0].lower() + string[1:] |
| 67 lowered = lowered.replace("cSS", "css") | 72 lowered = lowered.replace("cSS", "css") |
| 68 lowered = lowered.replace("iME", "ime") | 73 lowered = lowered.replace("iME", "ime") |
| 69 lowered = lowered.replace("hTML", "html") | 74 lowered = lowered.replace("hTML", "html") |
| 70 return lowered | 75 return lowered |
| 71 | 76 |
| 72 def _feature_sets(self): | 77 def _feature_sets(self): |
| 73 # 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" |
| 74 # which is how we're referring to them in this generator. | 79 # which is how we're referring to them in this generator. |
| 75 return self.valid_values['status'] | 80 return self.valid_values['status'] |
| 76 | 81 |
| 82 @template_expander.use_jinja(class_name + ".h.tmpl") |
| 77 def generate_header(self): | 83 def generate_header(self): |
| 78 return { | 84 return { |
| 79 'features': self._features, | 85 'features': self._features, |
| 80 'feature_sets': self._feature_sets(), | 86 'feature_sets': self._feature_sets(), |
| 81 } | 87 } |
| 82 | 88 |
| 89 @template_expander.use_jinja(class_name + ".cpp.tmpl") |
| 83 def generate_implementation(self): | 90 def generate_implementation(self): |
| 84 return { | 91 return { |
| 85 'features': self._features, | 92 'features': self._features, |
| 86 'feature_sets': self._feature_sets(), | 93 'feature_sets': self._feature_sets(), |
| 87 } | 94 } |
| 88 | 95 |
| 89 | 96 |
| 90 if __name__ == "__main__": | 97 if __name__ == "__main__": |
| 91 in_generator.Maker(RuntimeFeatureWriter).main(sys.argv) | 98 in_generator.Maker(RuntimeFeatureWriter).main(sys.argv) |
| OLD | NEW |