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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/generate_event_interfaces.py

Issue 2367303002: [Bindings] Remove a redundant option write-file-if-only-changed in bindings (Closed)
Patch Set: Rebase Created 4 years, 2 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
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 'RuntimeEnabled', 52 'RuntimeEnabled',
53 ) 53 )
54 module_path = os.path.dirname(os.path.realpath(__file__)) 54 module_path = os.path.dirname(os.path.realpath(__file__))
55 source_dir = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) 55 source_dir = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir))
56 56
57 57
58 def parse_options(): 58 def parse_options():
59 parser = OptionParser() 59 parser = OptionParser()
60 parser.add_option('--event-idl-files-list', help='file listing event IDL fil es') 60 parser.add_option('--event-idl-files-list', help='file listing event IDL fil es')
61 parser.add_option('--event-interfaces-file', help='output file') 61 parser.add_option('--event-interfaces-file', help='output file')
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')
63 parser.add_option('--suffix', help='specify a suffix to the namespace, i.e., "Modules". Default is None.') 62 parser.add_option('--suffix', help='specify a suffix to the namespace, i.e., "Modules". Default is None.')
64 63
65 options, args = parser.parse_args() 64 options, args = parser.parse_args()
66 if options.event_idl_files_list is None: 65 if options.event_idl_files_list is None:
67 parser.error('Must specify a file listing event IDL files using --event- idl-files-list.') 66 parser.error('Must specify a file listing event IDL files using --event- idl-files-list.')
68 if options.event_interfaces_file is None: 67 if options.event_interfaces_file is None:
69 parser.error('Must specify an output file using --event-interfaces-file. ') 68 parser.error('Must specify an output file using --event-interfaces-file. ')
70 if options.write_file_only_if_changed is None:
71 parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.')
72 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
73 if args: 69 if args:
74 parser.error('No arguments allowed, but %d given.' % len(args)) 70 parser.error('No arguments allowed, but %d given.' % len(args))
75 return options 71 return options
76 72
77 73
78 def write_event_interfaces_file(event_idl_files, destination_filename, only_if_c hanged, suffix): 74 def write_event_interfaces_file(event_idl_files, destination_filename, suffix):
79 def extended_attribute_string(name, value): 75 def extended_attribute_string(name, value):
80 if name == 'RuntimeEnabled': 76 if name == 'RuntimeEnabled':
81 value += 'Enabled' 77 value += 'Enabled'
82 return name + '=' + value 78 return name + '=' + value
83 79
84 def interface_line(full_path): 80 def interface_line(full_path):
85 relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, sou rce_dir)) 81 relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, sou rce_dir))
86 relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep) 82 relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep)
87 83
88 idl_file_contents = get_file_contents(full_path) 84 idl_file_contents = get_file_contents(full_path)
(...skipping 10 matching lines...) Expand all
99 if suffix: 95 if suffix:
100 lines.append('suffix="' + suffix + '"\n') 96 lines.append('suffix="' + suffix + '"\n')
101 lines.append('export=%s_EXPORT\n' % suffix.upper()) 97 lines.append('export=%s_EXPORT\n' % suffix.upper())
102 else: 98 else:
103 lines.append('export=CORE_EXPORT\n') 99 lines.append('export=CORE_EXPORT\n')
104 lines.append('\n') 100 lines.append('\n')
105 interface_lines = [interface_line(event_idl_file) 101 interface_lines = [interface_line(event_idl_file)
106 for event_idl_file in event_idl_files] 102 for event_idl_file in event_idl_files]
107 interface_lines.sort() 103 interface_lines.sort()
108 lines.extend(interface_lines) 104 lines.extend(interface_lines)
109 write_file(''.join(lines), destination_filename, only_if_changed) 105 write_file(''.join(lines), destination_filename)
110 106
111 107
112 ################################################################################ 108 ################################################################################
113 109
114 def main(): 110 def main():
115 options = parse_options() 111 options = parse_options()
116 event_idl_files = read_file_to_list(options.event_idl_files_list) 112 event_idl_files = read_file_to_list(options.event_idl_files_list)
117 write_event_interfaces_file(event_idl_files, 113 write_event_interfaces_file(event_idl_files,
118 options.event_interfaces_file, 114 options.event_interfaces_file,
119 options.write_file_only_if_changed,
120 options.suffix) 115 options.suffix)
121 116
122 117
123 if __name__ == '__main__': 118 if __name__ == '__main__':
124 sys.exit(main()) 119 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698