Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: bindings/dart/scripts/dart_compiler.py

Issue 540533002: Roll IDL to Dartium37 (r181268) (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (C) 2013 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29
30 """Compile an .idl file to Blink C++ bindings (.h and .cpp files) for Dart:HTML.
31
32 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
33 """
34
35 import abc
36 from optparse import OptionParser
37 import os
38 import cPickle as pickle
39
40 from idl_reader import IdlReader
41 from utilities import write_file
42
43
44 # TODO(terry): Temporary whitelist of IDL files to skip code generating. e.g.,
45 # adding 'Animation.idl' to this list will skip that IDL file.
46 SKIP_IDL_FILES = ['']
47
48
49 def parse_options():
50 parser = OptionParser()
51 parser.add_option('--idl-attributes-file',
52 help="location of bindings/IDLExtendedAttributes.txt")
53 parser.add_option('--output-directory')
54 parser.add_option('--interfaces-info-file')
55 parser.add_option('--write-file-only-if-changed', type='int')
56 # ensure output comes last, so command line easy to parse via regexes
57 parser.disable_interspersed_args()
58
59 options, args = parser.parse_args()
60 if options.output_directory is None:
61 parser.error('Must specify output directory using --output-directory.')
62 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
63 if len(args) != 1:
64 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args))
65 idl_filename = os.path.realpath(args[0])
66 return options, idl_filename
67
68
69 def idl_filename_to_interface_name(idl_filename):
70 basename = os.path.basename(idl_filename)
71 interface_name, _ = os.path.splitext(basename)
72 return interface_name
73
74
75 class IdlCompiler(object):
76 """Abstract Base Class for IDL compilers.
77
78 In concrete classes:
79 * self.code_generator must be set, implementing generate_code()
80 (returning a list of output code), and
81 * compile_file() must be implemented (handling output filenames).
82 """
83 __metaclass__ = abc.ABCMeta
84
85 def __init__(self, output_directory, code_generator=None,
86 interfaces_info=None, interfaces_info_filename='',
87 only_if_changed=False):
88 """
89 Args:
90 interfaces_info:
91 interfaces_info dict
92 (avoids auxiliary file in run-bindings-tests)
93 interfaces_info_file: filename of pickled interfaces_info
94 """
95 self.code_generator = code_generator
96 if interfaces_info_filename:
97 with open(interfaces_info_filename) as interfaces_info_file:
98 interfaces_info = pickle.load(interfaces_info_file)
99 self.interfaces_info = interfaces_info
100
101 self.only_if_changed = only_if_changed
102 self.output_directory = output_directory
103 self.reader = IdlReader(interfaces_info, output_directory)
104
105 def compile_and_write(self, idl_filename, output_filenames):
106 interface_name = idl_filename_to_interface_name(idl_filename)
107 idl_pickle_filename = os.path.join(self.output_directory,
108 '%s_globals.pickle' % interface_name)
109 definitions = self.reader.read_idl_definitions(idl_filename)
110 output_code_list = self.code_generator.generate_code(definitions,
111 interface_name,
112 idl_pickle_filename ,
113 self.only_if_change d)
114
115 # TODO(terry): Temporary to disable code generating an IDL.
116 base_idl_filename = os.path.basename(idl_filename)
117 if base_idl_filename in SKIP_IDL_FILES:
118 print "----- Skipping %s -----" % base_idl_filename
119 else:
120 for output_code, output_filename in zip(output_code_list, output_fil enames):
121 write_file(output_code, output_filename, self.only_if_changed)
122
123 def generate_global_and_write(self, global_pickle_directories, output_filena mes):
124 output_code_list = self.code_generator.generate_globals(global_pickle_di rectories,
125 self.output_dire ctory)
126 for output_code, output_filename in zip(output_code_list, output_filenam es):
127 write_file(output_code, output_filename, self.only_if_changed)
128
129 @abc.abstractmethod
130 def compile_file(self, idl_filename):
131 pass
OLDNEW
« no previous file with comments | « bindings/dart/scripts/dart_callback_interface.py ('k') | bindings/dart/scripts/dart_interface.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698