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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 self.in_file = InFile.load_from_path(in_file_path, self.defaults, self.d
efault_parameters) | 42 self.in_file = InFile.load_from_path(in_file_path, self.defaults, self.d
efault_parameters) |
43 | 43 |
44 # Subclasses should override. | 44 # Subclasses should override. |
45 def generate_header(self): | 45 def generate_header(self): |
46 raise NotImplementedError | 46 raise NotImplementedError |
47 | 47 |
48 # Subclasses should override. | 48 # Subclasses should override. |
49 def generate_implementation(self): | 49 def generate_implementation(self): |
50 raise NotImplementedError | 50 raise NotImplementedError |
51 | 51 |
| 52 def wrap_with_condition(self, string, condition): |
| 53 if not condition: |
| 54 return string |
| 55 return "#if ENABLE(%(condition)s)\n%(string)s\n#endif" % { 'condition' :
condition, 'string' : string } |
| 56 |
52 def _forcibly_create_text_file_at_path_with_contents(self, file_path, conten
ts): | 57 def _forcibly_create_text_file_at_path_with_contents(self, file_path, conten
ts): |
53 # FIXME: This method can be made less force-full anytime after 6/1/2013. | 58 # FIXME: This method can be made less force-full anytime after 6/1/2013. |
54 # A gyp error was briefly checked into the tree, causing | 59 # A gyp error was briefly checked into the tree, causing |
55 # a directory to have been generated in place of one of | 60 # a directory to have been generated in place of one of |
56 # our output files. Clean up after that error so that | 61 # our output files. Clean up after that error so that |
57 # all users don't need to clobber their output directories. | 62 # all users don't need to clobber their output directories. |
58 shutil.rmtree(file_path, ignore_errors=True) | 63 shutil.rmtree(file_path, ignore_errors=True) |
59 # The build system should ensure our output directory exists, but just i
n case. | 64 # The build system should ensure our output directory exists, but just i
n case. |
60 directory = os.path.dirname(file_path) | 65 directory = os.path.dirname(file_path) |
61 if not os.path.exists(directory): | 66 if not os.path.exists(directory): |
62 os.makedirs(directory) | 67 os.makedirs(directory) |
63 | 68 |
64 with open(file_path, "w") as file_to_write: | 69 with open(file_path, "w") as file_to_write: |
65 file_to_write.write(contents) | 70 file_to_write.write(contents) |
66 | 71 |
67 def write_header(self, output_dir): | 72 def write_header(self, output_dir): |
68 header_path = os.path.join(output_dir, self.class_name + ".h") | 73 contents = self.generate_header() |
69 self._forcibly_create_text_file_at_path_with_contents(header_path, self.
generate_header()) | 74 if not contents: |
| 75 return |
| 76 path = os.path.join(output_dir, self.class_name + ".h") |
| 77 self._forcibly_create_text_file_at_path_with_contents(path, contents) |
70 | 78 |
71 def write_implmentation(self, output_dir): | 79 def write_implmentation(self, output_dir): |
72 implmentation_path = os.path.join(output_dir, self.class_name + ".cpp") | 80 contents = self.generate_implementation() |
73 self._forcibly_create_text_file_at_path_with_contents(implmentation_path
, self.generate_implementation()) | 81 if not contents: |
| 82 return |
| 83 path = os.path.join(output_dir, self.class_name + ".cpp") |
| 84 self._forcibly_create_text_file_at_path_with_contents(path, contents) |
74 | 85 |
75 | 86 |
76 class Maker(object): | 87 class Maker(object): |
77 def __init__(self, writer_class): | 88 def __init__(self, writer_class): |
78 self._writer_class = writer_class | 89 self._writer_class = writer_class |
79 | 90 |
80 def main(self, argv): | 91 def main(self, argv): |
81 script_name = os.path.basename(argv[0]) | 92 script_name = os.path.basename(argv[0]) |
82 args = argv[1:] | 93 args = argv[1:] |
83 if len(args) < 1: | 94 if len(args) < 1: |
84 print "USAGE: %i INPUT_FILE [OUTPUT_DIRECTORY]" % script_name | 95 print "USAGE: %i INPUT_FILE [OUTPUT_DIRECTORY]" % script_name |
85 exit(1) | 96 exit(1) |
86 output_dir = args[1] if len(args) > 1 else os.getcwd() | 97 output_dir = args[1] if len(args) > 1 else os.getcwd() |
87 | 98 |
88 writer = self._writer_class(args[0]) | 99 writer = self._writer_class(args[0]) |
89 writer.write_header(output_dir) | 100 writer.write_header(output_dir) |
90 writer.write_implmentation(output_dir) | 101 writer.write_implmentation(output_dir) |
OLD | NEW |