| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (C) 2014 Google Inc. All rights reserved. | 2 # Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 from dart_compiler import IdlCompiler | 44 from dart_compiler import IdlCompiler |
| 45 from code_generator_dart import CodeGeneratorDart | 45 from code_generator_dart import CodeGeneratorDart |
| 46 | 46 |
| 47 | 47 |
| 48 def parse_options(): | 48 def parse_options(): |
| 49 parser = OptionParser() | 49 parser = OptionParser() |
| 50 parser.add_option('--output-directory') | 50 parser.add_option('--output-directory') |
| 51 parser.add_option('--interfaces-info-file') | 51 parser.add_option('--interfaces-info-file') |
| 52 parser.add_option('--write-file-only-if-changed', type='int', default='1') | 52 parser.add_option('--write-file-only-if-changed', type='int', default='1') |
| 53 parser.add_option('--generate-global', type='int') | 53 parser.add_option('--generate-dart-blink', |
| 54 parser.add_option("-p", "--global-pickle-directories", | 54 action='append', |
| 55 action="store", | |
| 56 type='string', | 55 type='string', |
| 57 dest="global_pickle_directories", | 56 dest='blink_global_entries', |
| 57 nargs=3, |
| 58 help="Pickle file directory, idl file list, idl dictionari
es list") |
| 59 |
| 60 parser.add_option('--generate-globals', |
| 61 action='append', |
| 62 type='string', |
| 63 dest='global_entries', |
| 58 nargs=2, | 64 nargs=2, |
| 59 help="Directories to load _globals.pickle files (max 2)") | 65 help="Pickle file directory and idl file list (global clas
s table)") |
| 60 | 66 |
| 61 # ensure output comes last, so command line easy to parse via regexes | 67 # ensure output comes last, so command line easy to parse via regexes |
| 62 parser.disable_interspersed_args() | 68 parser.disable_interspersed_args() |
| 63 | 69 |
| 64 options, args = parser.parse_args() | 70 options, args = parser.parse_args() |
| 65 if options.output_directory is None: | 71 if options.output_directory is None: |
| 66 parser.error('Must specify output directory using --output-directory.') | 72 parser.error('Must specify output directory using --output-directory.') |
| 67 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) | 73 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) |
| 68 options.generate_global = bool(options.generate_global) | 74 if bool(options.global_entries) or bool(options.blink_global_entries): |
| 75 return options, None |
| 69 if len(args) != 1: | 76 if len(args) != 1: |
| 70 # parser.error('Must specify exactly 1 input file as argument, but %d gi
ven.' % len(args)) | 77 parser.error('Must specify exactly 1 input file as argument, but %d give
n.' % len(args)) |
| 71 return options, None | 78 filename = os.path.realpath(args[0]) |
| 72 idl_filename = os.path.realpath(args[0]) | 79 return options, filename |
| 73 return options, idl_filename | |
| 74 | 80 |
| 75 | 81 |
| 76 def idl_filename_to_interface_name(idl_filename): | 82 def idl_filename_to_interface_name(idl_filename): |
| 77 basename = os.path.basename(idl_filename) | 83 basename = os.path.basename(idl_filename) |
| 78 interface_name, _ = os.path.splitext(basename) | 84 interface_name, _ = os.path.splitext(basename) |
| 79 return interface_name | 85 return interface_name |
| 80 | 86 |
| 81 | 87 |
| 82 class IdlCompilerDart(IdlCompiler): | 88 class IdlCompilerDart(IdlCompiler): |
| 83 def __init__(self, *args, **kwargs): | 89 def __init__(self, *args, **kwargs): |
| 84 IdlCompiler.__init__(self, *args, **kwargs) | 90 IdlCompiler.__init__(self, *args, **kwargs) |
| 85 | 91 |
| 86 interfaces_info = self.interfaces_info | 92 interfaces_info = self.interfaces_info |
| 87 self.output_directory = self.output_directory | 93 self.output_directory = self.output_directory |
| 88 | 94 |
| 89 self.code_generator = CodeGeneratorDart(interfaces_info, self.output_dir
ectory) | 95 self.code_generator = CodeGeneratorDart(interfaces_info, self.output_dir
ectory) |
| 90 | 96 |
| 91 def compile_file(self, idl_filename): | 97 def compile_file(self, idl_filename): |
| 92 interface_name = idl_filename_to_interface_name(idl_filename) | 98 interface_name = idl_filename_to_interface_name(idl_filename) |
| 93 header_filename = os.path.join(self.output_directory, | 99 header_filename = os.path.join(self.output_directory, |
| 94 'Dart%s.h' % interface_name) | 100 'Dart%s.h' % interface_name) |
| 95 cpp_filename = os.path.join(self.output_directory, | 101 cpp_filename = os.path.join(self.output_directory, |
| 96 'Dart%s.cpp' % interface_name) | 102 'Dart%s.cpp' % interface_name) |
| 97 self.compile_and_write(idl_filename, (header_filename, cpp_filename)) | 103 self.compile_and_write(idl_filename, (header_filename, cpp_filename)) |
| 98 | 104 |
| 99 def generate_global(self, global_pickle_directories): | 105 def generate_global(self, global_entries): |
| 106 expanded_global_entries = [] |
| 107 for (directory, file_list_file) in global_entries: |
| 108 with open(file_list_file) as input_file: |
| 109 idl_file_list = sorted([line.rstrip('\n') |
| 110 for line in input_file]) |
| 111 expanded_global_entries.append((directory, idl_file_list)) |
| 100 global_header_filename = os.path.join(self.output_directory, 'DartWebkit
ClassIds.h') | 112 global_header_filename = os.path.join(self.output_directory, 'DartWebkit
ClassIds.h') |
| 101 global_cpp_filename = os.path.join(self.output_directory, 'DartWebkitCla
ssIds.cpp') | 113 global_cpp_filename = os.path.join(self.output_directory, 'DartWebkitCla
ssIds.cpp') |
| 102 self.generate_global_and_write(global_pickle_directories, | 114 self.generate_global_and_write(expanded_global_entries, |
| 103 (global_header_filename, global_cpp_filen
ame)) | 115 (global_header_filename, global_cpp_filen
ame)) |
| 104 | 116 |
| 117 def generate_dart_blink(self, global_entries): |
| 118 global_dart_blink_filename = os.path.join(self.output_directory, |
| 119 '_blink_dartium.dart') |
| 120 expanded_global_entries = [] |
| 121 for (directory, file_list_file, file_list_dictionary) in global_entries: |
| 122 with open(file_list_file) as input_file: |
| 123 idl_file_list = sorted([line.rstrip('\n') |
| 124 for line in input_file]) |
| 125 with open(file_list_dictionary) as input_file: |
| 126 dictionary_file_list = sorted([line.rstrip('\n') |
| 127 for line in input_file]) |
| 128 expanded_global_entries.append((directory, idl_file_list)) |
| 129 expanded_global_entries.append((directory, dictionary_file_list)) |
| 130 self.generate_dart_blink_and_write(expanded_global_entries, |
| 131 global_dart_blink_filename) |
| 132 |
| 105 | 133 |
| 106 def main(): | 134 def main(): |
| 107 options, idl_filename = parse_options() | 135 options, filename = parse_options() |
| 108 | 136 idl_compiler = IdlCompilerDart(options.output_directory, |
| 109 if options.generate_global: | 137 interfaces_info_filename=options.interfaces_i
nfo_file, |
| 110 idl_compiler = IdlCompilerDart(options.output_directory, | 138 only_if_changed=options.write_file_only_if_ch
anged) |
| 111 interfaces_info_filename=options.interfac
es_info_file, | 139 if bool(options.global_entries): |
| 112 only_if_changed=options.write_file_only_i
f_changed) | 140 idl_compiler.generate_global(options.global_entries) |
| 113 idl_compiler.generate_global(options.global_pickle_directories) | 141 elif bool(options.blink_global_entries): |
| 142 idl_compiler.generate_dart_blink(options.blink_global_entries) |
| 114 else: | 143 else: |
| 115 idl_compiler = IdlCompilerDart(options.output_directory, | 144 idl_compiler.compile_file(filename) |
| 116 interfaces_info_filename=options.interfac
es_info_file, | |
| 117 only_if_changed=options.write_file_only_i
f_changed) | |
| 118 idl_compiler.compile_file(idl_filename) | |
| 119 | 145 |
| 120 | 146 |
| 121 if __name__ == '__main__': | 147 if __name__ == '__main__': |
| 122 sys.exit(main()) | 148 sys.exit(main()) |
| OLD | NEW |