| OLD | NEW |
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 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 23 matching lines...) Expand all Loading... |
| 34 from in_file import InFile | 34 from in_file import InFile |
| 35 | 35 |
| 36 | 36 |
| 37 class Writer(object): | 37 class Writer(object): |
| 38 # Subclasses should override. | 38 # Subclasses should override. |
| 39 class_name = None | 39 class_name = None |
| 40 defaults = None | 40 defaults = None |
| 41 valid_values = None | 41 valid_values = None |
| 42 default_parameters = None | 42 default_parameters = None |
| 43 | 43 |
| 44 def __init__(self, in_files, enabled_conditions): | 44 def __init__(self, in_files): |
| 45 if isinstance(in_files, basestring): | 45 if isinstance(in_files, basestring): |
| 46 in_files = [in_files] | 46 in_files = [in_files] |
| 47 if in_files: | 47 if in_files: |
| 48 self.in_file = InFile.load_from_files(in_files, self.defaults, self.
valid_values, self.default_parameters) | 48 self.in_file = InFile.load_from_files(in_files, self.defaults, self.
valid_values, self.default_parameters) |
| 49 else: | 49 else: |
| 50 self.in_file = None | 50 self.in_file = None |
| 51 self._enabled_conditions = enabled_conditions | |
| 52 self._outputs = {} # file_name -> generator | 51 self._outputs = {} # file_name -> generator |
| 53 | 52 |
| 54 def wrap_with_condition(self, string, condition): | 53 def wrap_with_condition(self, string, condition): |
| 55 if not condition: | 54 if not condition: |
| 56 return string | 55 return string |
| 57 return "#if ENABLE(%(condition)s)\n%(string)s\n#endif" % { 'condition' :
condition, 'string' : string } | 56 return "#if ENABLE(%(condition)s)\n%(string)s\n#endif" % { 'condition' :
condition, 'string' : string } |
| 58 | 57 |
| 59 def _forcibly_create_text_file_at_path_with_contents(self, file_path, conten
ts): | 58 def _forcibly_create_text_file_at_path_with_contents(self, file_path, conten
ts): |
| 60 # FIXME: This method can be made less force-full anytime after 6/1/2013. | 59 # FIXME: This method can be made less force-full anytime after 6/1/2013. |
| 61 # A gyp error was briefly checked into the tree, causing | 60 # A gyp error was briefly checked into the tree, causing |
| (...skipping 15 matching lines...) Expand all Loading... |
| 77 | 76 |
| 78 def write_files(self, output_dir): | 77 def write_files(self, output_dir): |
| 79 for file_name, generator in self._outputs.items(): | 78 for file_name, generator in self._outputs.items(): |
| 80 self._write_file(output_dir, generator(), file_name) | 79 self._write_file(output_dir, generator(), file_name) |
| 81 | 80 |
| 82 | 81 |
| 83 class Maker(object): | 82 class Maker(object): |
| 84 def __init__(self, writer_class): | 83 def __init__(self, writer_class): |
| 85 self._writer_class = writer_class | 84 self._writer_class = writer_class |
| 86 | 85 |
| 87 def _enabled_conditions_from_defines(self, defines_arg_string): | |
| 88 if not defines_arg_string: | |
| 89 return [] | |
| 90 | |
| 91 defines_strings = shlex.split(defines_arg_string) | |
| 92 | |
| 93 # We only care about feature defines. | |
| 94 enable_prefix = 'ENABLE_' | |
| 95 | |
| 96 enabled_conditions = [] | |
| 97 for define_string in defines_strings: | |
| 98 split_define = define_string.split('=') | |
| 99 if split_define[1] != '1': | |
| 100 continue | |
| 101 define = split_define[0] | |
| 102 if not define.startswith(enable_prefix): | |
| 103 continue | |
| 104 enabled_conditions.append(define[len(enable_prefix):]) | |
| 105 return enabled_conditions | |
| 106 | |
| 107 def main(self, argv): | 86 def main(self, argv): |
| 108 script_name = os.path.basename(argv[0]) | 87 script_name = os.path.basename(argv[0]) |
| 109 args = argv[1:] | 88 args = argv[1:] |
| 110 if len(args) < 1: | 89 if len(args) < 1: |
| 111 print "USAGE: %s INPUT_FILES" % script_name | 90 print "USAGE: %s INPUT_FILES" % script_name |
| 112 exit(1) | 91 exit(1) |
| 113 | 92 |
| 114 parser = optparse.OptionParser() | 93 parser = optparse.OptionParser() |
| 115 parser.add_option("--defines") | 94 parser.add_option("--defines") |
| 116 parser.add_option("--output_dir", default=os.getcwd()) | 95 parser.add_option("--output_dir", default=os.getcwd()) |
| 117 (options, args) = parser.parse_args() | 96 (options, args) = parser.parse_args() |
| 118 | 97 |
| 119 enabled_conditions = self._enabled_conditions_from_defines(options.defin
es) | 98 writer = self._writer_class(args) |
| 120 | |
| 121 writer = self._writer_class(args, enabled_conditions) | |
| 122 writer.write_files(options.output_dir) | 99 writer.write_files(options.output_dir) |
| OLD | NEW |