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

Side by Side Diff: bindings/dart/scripts/test/main.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
« no previous file with comments | « bindings/dart/scripts/test/__init__.py ('k') | bindings/scripts/__init__.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (C) 2010 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
6 # are met:
7 # 1. Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 #
13 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 #
25
26 import traceback
27
28 import fnmatch
29 from optparse import OptionParser
30 import os
31 import shutil
32 import sys
33 import tempfile
34
35 import compute_interfaces_info_individual
36 from compute_interfaces_info_individual import compute_info_individual, info_ind ividual
37 import compute_interfaces_info_overall
38 from compute_interfaces_info_overall import compute_interfaces_info_overall, int erfaces_info
39 from compiler import IdlCompilerDart
40
41 # TODO(terry): Temporary solution list of IDLs to parse and IDL as dependencies.
42 from idl_files import full_path_core_idl_files, full_path_core_dependency_idl_fi les, full_path_modules_idl_files, full_path_modules_dependency_idl_files
43
44 #from dart_tests import run_dart_tests
45
46
47 EXTENDED_ATTRIBUTES_FILE = 'bindings/IDLExtendedAttributes.txt'
48
49 idl_compiler = None
50
51
52 def parse_options():
53 parser = OptionParser()
54
55 parser.add_option("--output-directory",
56 action="store",
57 type="string",
58 dest="output_directory",
59 help="Generate output to a known directory")
60 parser.add_option("-v", "--verbose",
61 action="store_true",
62 dest="verbose",
63 default=False,
64 help="Show all information messages")
65 parser.add_option("-k", "--keep",
66 action="store_true",
67 dest="keep",
68 default=False,
69 help="Don't delete the temporary directory on exit")
70 parser.add_option("--compute-idls", type='int', help="Compile IDLs interface s and dependencies (GYP)")
71 parser.add_option('--globals-only', type='int', help="Generate the globals")
72
73 options, args = parser.parse_args()
74
75 options.compute_idls = bool(options.compute_idls)
76 options.globals_only = bool(options.globals_only)
77
78 return options
79
80
81 class ScopedTempFileProvider(object):
82 def __init__(self, keep=False):
83 self.keep = keep
84 self.dir_paths = []
85
86 def __enter__(self):
87 return self
88
89 def __exit__(self, exc_type, exc_value, traceback):
90 if not self.keep:
91 for dir_path in self.dir_paths:
92 # Temporary directories are used as output directories, so they
93 # contains unknown files (they aren't empty), hence use rmtree
94 shutil.rmtree(dir_path)
95
96 def new_temp_dir(self):
97 dir_path = tempfile.mkdtemp()
98 self.dir_paths.append(dir_path)
99 return dir_path
100
101
102 class DirectoryProvider(object):
103 def __init__(self, path=""):
104 self.dir_path = path
105
106 def __enter__(self):
107 return self
108
109 def new_temp_dir(self):
110 return self.dir_path
111
112
113 def idl_paths_recursive(directory):
114 idl_paths = []
115 for dirpath, _, files in os.walk(directory):
116 idl_paths.extend(os.path.join(dirpath, filename)
117 for filename in fnmatch.filter(files, '*.idl'))
118 return idl_paths
119
120
121 class Build():
122 def __init__(self, provider):
123 self.output_directory = provider.new_temp_dir()
124
125 attrib_file = os.path.join('Source', EXTENDED_ATTRIBUTES_FILE)
126 # Create compiler.
127 self.idl_compiler = IdlCompilerDart(self.output_directory,
128 attrib_file,
129 interfaces_info=interfaces_info,
130 only_if_changed=True)
131
132 def format_exception(self, e):
133 exception_list = traceback.format_stack()
134 exception_list = exception_list[:-2]
135 exception_list.extend(traceback.format_tb(sys.exc_info()[2]))
136 exception_list.extend(traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1]))
137
138 exception_str = "Traceback (most recent call last):\n"
139 exception_str += "".join(exception_list)
140 # Removing the last \n
141 exception_str = exception_str[:-1]
142
143 return exception_str
144
145 def generate_from_idl(self, idl_file):
146 try:
147 idl_file_fullpath = os.path.realpath(idl_file)
148 self.idl_compiler.compile_file(idl_file_fullpath)
149 except Exception as err:
150 print 'ERROR: idl_compiler.py: ' + os.path.basename(idl_file)
151 print err
152 print
153 print 'Stack Dump:'
154 print self.format_exception(err)
155
156 return 1
157
158 def generate_global(self):
159 try:
160 self.idl_compiler.generate_global()
161 except Exception as err:
162 print 'ERROR: idl_compiler.py generate global'
163 print err
164 print
165 print 'Stack Dump:'
166 print self.format_exception(err)
167
168 return 1
169
170 return 0
171
172
173 def main(argv):
174 '''
175 Runs Dart IDL code generator; IDL files. IDL files same as GYP files in
176 Source/bindings/core/core.gypi and Source/bindings/modules/modules.gypi (see
177 idl_files.py on list of files).
178
179 To run the PYTHONPATH should have the directories:
180
181 Source/bindings/scripts
182 Source/bindings/scripts/dart
183 '''
184
185 options = parse_options()
186
187 if options.compute_idls:
188 # TODO(terry): Assumes CWD is third_party/WebKit so any call to
189 # full_path_NNNN is prefixing 'Source/core' to path.
190 core_idls = full_path_core_idl_files()
191 core_dependency_idls = full_path_core_dependency_idl_files()
192 modules_idls = full_path_modules_idl_files()
193 modules_dependency_idls = full_path_modules_dependency_idl_files()
194
195 all_interfaces = core_idls + modules_idls
196 all_dependencies = core_dependency_idls + modules_dependency_idls
197 all_files = all_interfaces + all_dependencies
198
199 # 2-stage computation: individual, then overall
200 for idl_filename in all_files:
201 compute_info_individual(idl_filename, 'dart')
202 info_individuals = [info_individual()]
203 compute_interfaces_info_overall(info_individuals)
204
205 # Compile just IDLs with interfaces (no dependencies).
206 if (options.output_directory == None):
207 with ScopedTempFileProvider(keep=options.keep) as provider:
208 build = Build(provider)
209 else:
210 provider = DirectoryProvider(path=options.output_directory)
211 build = Build(provider)
212
213 if options.verbose and options.keep:
214 print 'Output directory %s created' % build.output_directory
215
216 # Compile IDLs
217 for filename in all_interfaces:
218 if not filename.endswith('.idl'):
219 continue
220 if build.generate_from_idl(filename):
221 return False
222
223 if options.verbose:
224 print '%s IDLs with interfaces processed' % len(all_interfaces)
225
226 if options.verbose and not options.keep:
227 print 'Output directory %s deleted' % build.output_directory
228
229 if options.globals_only:
230 if (options.output_directory == None):
231 with ScopedTempFileProvider(keep=options.keep) as provider:
232 build = Build(provider)
233 else:
234 provider = DirectoryProvider(path=options.output_directory)
235 build = Build(provider)
236
237 if options.verbose:
238 print 'Generating global...'
239
240 build.generate_global()
241
242 if options.verbose:
243 print 'Created DartWebkitClassIds .h/.cpp'
244
245
246 if __name__ == '__main__':
247 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « bindings/dart/scripts/test/__init__.py ('k') | bindings/scripts/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698