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

Side by Side Diff: Source/bindings/scripts/compute_dependencies.py

Issue 124913002: IDL compiler: Pickle interface information (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (C) 2013 Google Inc. All rights reserved. 3 # Copyright (C) 2013 Google Inc. All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are 6 # modification, are permitted provided that the following conditions are
7 # met: 7 # met:
8 # 8 #
9 # * Redistributions of source code must retain the above copyright 9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer. 10 # notice, this list of conditions and the following disclaimer.
(...skipping 12 matching lines...) Expand all
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 import optparse 31 import optparse
32 import os 32 import os
33 import cPickle as pickle
33 import posixpath 34 import posixpath
34 import re 35 import re
35 import string 36 import string
36 37
37 38
38 class IdlBadFilenameError(Exception): 39 class IdlBadFilenameError(Exception):
39 """Raised if an IDL filename disagrees with the interface name in the file." "" 40 """Raised if an IDL filename disagrees with the interface name in the file." ""
40 pass 41 pass
41 42
42 43
43 class IdlInterfaceFileNotFoundError(Exception): 44 class IdlInterfaceFileNotFoundError(Exception):
44 """Raised if the IDL file implementing an interface cannot be found.""" 45 """Raised if the IDL file implementing an interface cannot be found."""
45 pass 46 pass
46 47
47 48
48 def parse_options(): 49 def parse_options():
49 parser = optparse.OptionParser() 50 parser = optparse.OptionParser()
50 parser.add_option('--event-names-file', help='output file') 51 parser.add_option('--event-names-file', help='output file')
51 parser.add_option('--main-idl-files-list', help='file listing main (compiled to Blink) IDL files') 52 parser.add_option('--main-idl-files-list', help='file listing main (compiled to Blink) IDL files')
52 parser.add_option('--support-idl-files-list', help='file listing support IDL files (not compiled to Blink, e.g. testing)') 53 parser.add_option('--support-idl-files-list', help='file listing support IDL files (not compiled to Blink, e.g. testing)')
53 parser.add_option('--interface-dependencies-file', help='output file') 54 parser.add_option('--interface-dependencies-file', help='output file')
55 parser.add_option('--interfaces-file', help='output pickle file')
haraken 2014/01/06 13:26:48 --interface-structures-file ?
54 parser.add_option('--bindings-derived-sources-file', help='output file') 56 parser.add_option('--bindings-derived-sources-file', help='output file')
55 parser.add_option('--window-constructors-file', help='output file') 57 parser.add_option('--window-constructors-file', help='output file')
56 parser.add_option('--workerglobalscope-constructors-file', help='output file ') 58 parser.add_option('--workerglobalscope-constructors-file', help='output file ')
57 parser.add_option('--sharedworkerglobalscope-constructors-file', help='outpu t file') 59 parser.add_option('--sharedworkerglobalscope-constructors-file', help='outpu t file')
58 parser.add_option('--dedicatedworkerglobalscope-constructors-file', help='ou tput file') 60 parser.add_option('--dedicatedworkerglobalscope-constructors-file', help='ou tput file')
59 parser.add_option('--serviceworkerglobalscope-constructors-file', help='outp ut file') 61 parser.add_option('--serviceworkerglobalscope-constructors-file', help='outp ut file')
60 parser.add_option('--write-file-only-if-changed', type='int', help='if true, do not write an output file if it would be identical to the existing one, which avoids unnecessary rebuilds in ninja') 62 parser.add_option('--write-file-only-if-changed', type='int', help='if true, do not write an output file if it would be identical to the existing one, which avoids unnecessary rebuilds in ninja')
61 options, args = parser.parse_args() 63 options, args = parser.parse_args()
62 if options.event_names_file is None: 64 if options.event_names_file is None:
63 parser.error('Must specify an output file using --event-names-file.') 65 parser.error('Must specify an output file using --event-names-file.')
64 if options.interface_dependencies_file is None: 66 if options.interface_dependencies_file is None:
65 parser.error('Must specify an output file using --interface-dependencies -file.') 67 parser.error('Must specify an output file using --interface-dependencies -file.')
68 if options.interfaces_file is None:
69 parser.error('Must specify an output file using --interfaces-file.')
66 if options.bindings_derived_sources_file is None: 70 if options.bindings_derived_sources_file is None:
67 parser.error('Must specify an output file using --bindings-derived-sourc es-file.') 71 parser.error('Must specify an output file using --bindings-derived-sourc es-file.')
68 if options.window_constructors_file is None: 72 if options.window_constructors_file is None:
69 parser.error('Must specify an output file using --window-constructors-fi le.') 73 parser.error('Must specify an output file using --window-constructors-fi le.')
70 if options.workerglobalscope_constructors_file is None: 74 if options.workerglobalscope_constructors_file is None:
71 parser.error('Must specify an output file using --workerglobalscope-cons tructors-file.') 75 parser.error('Must specify an output file using --workerglobalscope-cons tructors-file.')
72 if options.sharedworkerglobalscope_constructors_file is None: 76 if options.sharedworkerglobalscope_constructors_file is None:
73 parser.error('Must specify an output file using --sharedworkerglobalscop e-constructors-file.') 77 parser.error('Must specify an output file using --sharedworkerglobalscop e-constructors-file.')
74 if options.dedicatedworkerglobalscope_constructors_file is None: 78 if options.dedicatedworkerglobalscope_constructors_file is None:
75 parser.error('Must specify an output file using --dedicatedworkerglobals cope-constructors-file.') 79 parser.error('Must specify an output file using --dedicatedworkerglobals cope-constructors-file.')
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 event_names[interface_name_to_idl_file['Event']] = interface_extended_at tribute['Event'] 349 event_names[interface_name_to_idl_file['Event']] = interface_extended_at tribute['Event']
346 for interface, parent in parent_interface.iteritems(): 350 for interface, parent in parent_interface.iteritems():
347 while parent in parent_interface: 351 while parent in parent_interface:
348 parent = parent_interface[parent] 352 parent = parent_interface[parent]
349 if parent == 'Event': 353 if parent == 'Event':
350 event_names[interface_name_to_idl_file[interface]] = interface_exten ded_attribute[interface] 354 event_names[interface_name_to_idl_file[interface]] = interface_exten ded_attribute[interface]
351 355
352 return interfaces, dependencies, bindings_derived_sources, global_constructo rs, event_names 356 return interfaces, dependencies, bindings_derived_sources, global_constructo rs, event_names
353 357
354 358
355 def write_dependency_file(filename, dependencies, only_if_changed): 359 def write_dependency_file(dependencies_filename, interfaces_filename, dependenci es, only_if_changed):
356 """Write the interface dependencies file. 360 """Write the interface dependencies file.
357 361
358 The format is as follows: 362 The format is as follows:
359 363
360 Document.idl P.idl 364 Document.idl P.idl
361 Event.idl 365 Event.idl
362 Window.idl Q.idl R.idl S.idl 366 Window.idl Q.idl R.idl S.idl
363 ... 367 ...
364 368
365 The above indicates that: 369 The above indicates that:
366 Document.idl depends on P.idl, 370 Document.idl depends on P.idl,
367 Event.idl depends on no other IDL files, and 371 Event.idl depends on no other IDL files, and
368 Window.idl depends on Q.idl, R.idl, and S.idl. 372 Window.idl depends on Q.idl, R.idl, and S.idl.
369 373
370 An IDL that is a dependency of another IDL (e.g. P.idl) does not have its 374 An IDL that is a dependency of another IDL (e.g. P.idl) does not have its
371 own line in the dependency file. 375 own line in the dependency file.
372 """ 376 """
377 # FIXME: remove text format once Perl gone (Python uses pickle)
373 lines = ['%s %s\n' % (idl_file, ' '.join(sorted(dependency_files))) 378 lines = ['%s %s\n' % (idl_file, ' '.join(sorted(dependency_files)))
374 for idl_file, dependency_files in sorted(dependencies.iteritems())] 379 for idl_file, dependency_files in sorted(dependencies.iteritems())]
375 write_file(lines, filename, only_if_changed) 380 write_file(lines, dependencies_filename, only_if_changed)
381
382 if not interfaces_filename:
383 return
384 interfaces = {}
385 for idl_filename, dependency_files in dependencies.iteritems():
386 idl_basename = os.path.basename(idl_filename)
387 interface_name, _ = os.path.splitext(idl_basename)
388 interfaces[interface_name] = dependency_files
389
390 if only_if_changed and os.path.isfile(interfaces_filename):
391 with open(interfaces_filename, 'r+') as pickle_file:
392 if pickle.load(pickle_file) == interfaces:
393 return
394 pickle_file.seek(0)
395 pickle.dump(interfaces, pickle_file)
396 return
397 with open(interfaces_filename, 'w') as pickle_file:
398 pickle.dump(interfaces, pickle_file)
376 399
377 400
378 def main(): 401 def main():
379 options = parse_options() 402 options = parse_options()
380 with open(options.main_idl_files_list) as idl_files_list: 403 with open(options.main_idl_files_list) as idl_files_list:
381 main_idl_files = [string.rstrip(line, '\n') for line in idl_files_list] 404 main_idl_files = [string.rstrip(line, '\n') for line in idl_files_list]
382 with open(options.support_idl_files_list) as idl_files_list: 405 with open(options.support_idl_files_list) as idl_files_list:
383 support_idl_files = [string.rstrip(line, '\n') for line in idl_files_lis t] 406 support_idl_files = [string.rstrip(line, '\n') for line in idl_files_lis t]
384 only_if_changed = options.write_file_only_if_changed 407 only_if_changed = options.write_file_only_if_changed
385 global_constructors_filenames = { 408 global_constructors_filenames = {
386 'Window': options.window_constructors_file, 409 'Window': options.window_constructors_file,
387 'WorkerGlobalScope': options.workerglobalscope_constructors_file, 410 'WorkerGlobalScope': options.workerglobalscope_constructors_file,
388 'SharedWorkerGlobalScope': options.sharedworkerglobalscope_constructors_ file, 411 'SharedWorkerGlobalScope': options.sharedworkerglobalscope_constructors_ file,
389 'DedicatedWorkerGlobalScope': options.dedicatedworkerglobalscope_constru ctors_file, 412 'DedicatedWorkerGlobalScope': options.dedicatedworkerglobalscope_constru ctors_file,
390 'ServiceWorkerGlobalScope': options.serviceworkerglobalscope_constructor s_file, 413 'ServiceWorkerGlobalScope': options.serviceworkerglobalscope_constructor s_file,
391 } 414 }
392 415
393 interfaces, dependencies, bindings_derived_sources, global_constructors, eve nt_names = parse_idl_files(main_idl_files, support_idl_files, global_constructor s_filenames) 416 interfaces, dependencies, bindings_derived_sources, global_constructors, eve nt_names = parse_idl_files(main_idl_files, support_idl_files, global_constructor s_filenames)
394 417
395 write_dependency_file(options.interface_dependencies_file, dependencies, onl y_if_changed) 418 write_dependency_file(options.interface_dependencies_file, options.interface s_file, dependencies, only_if_changed)
396 write_dependency_file(options.bindings_derived_sources_file, bindings_derive d_sources, only_if_changed) 419 write_dependency_file(options.bindings_derived_sources_file, None, bindings_ derived_sources, only_if_changed)
397 for interface_name, filename in global_constructors_filenames.iteritems(): 420 for interface_name, filename in global_constructors_filenames.iteritems():
398 if interface_name in interfaces: 421 if interface_name in interfaces:
399 generate_global_constructors_partial_interface(interface_name, filen ame, global_constructors[interface_name], only_if_changed) 422 generate_global_constructors_partial_interface(interface_name, filen ame, global_constructors[interface_name], only_if_changed)
400 generate_event_names_file(options.event_names_file, event_names, only_if_cha nged) 423 generate_event_names_file(options.event_names_file, event_names, only_if_cha nged)
401 424
402 425
403 if __name__ == '__main__': 426 if __name__ == '__main__':
404 main() 427 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698