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

Side by Side Diff: Source/bindings/scripts/unstable/idl_compiler.py

Issue 137993002: IDL compiler: Move include path handling to compute_dependencies (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
« no previous file with comments | « Source/bindings/scripts/unstable/code_generator_v8.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (C) 2013 Google Inc. All rights reserved. 2 # Copyright (C) 2013 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 21 matching lines...) Expand all
32 FIXME: Not currently used in build. 32 FIXME: Not currently used in build.
33 This is a rewrite of the Perl IDL compiler in Python, but is not complete. 33 This is a rewrite of the Perl IDL compiler in Python, but is not complete.
34 Once it is complete, we will switch all IDL files over to Python at once. 34 Once it is complete, we will switch all IDL files over to Python at once.
35 Until then, please work on the Perl IDL compiler. 35 Until then, please work on the Perl IDL compiler.
36 For details, see bug http://crbug.com/239771 36 For details, see bug http://crbug.com/239771
37 """ 37 """
38 38
39 import optparse 39 import optparse
40 import os 40 import os
41 import cPickle as pickle 41 import cPickle as pickle
42 import posixpath
43 import shlex 42 import shlex
44 import sys 43 import sys
45 44
46 import code_generator_v8 45 import code_generator_v8
47 import idl_reader 46 import idl_reader
48 47
49 module_path, _ = os.path.split(__file__)
50 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir, o s.pardir))
51
52
53 def parse_options(): 48 def parse_options():
54 parser = optparse.OptionParser() 49 parser = optparse.OptionParser()
55 parser.add_option('--additional-idl-files') 50 parser.add_option('--additional-idl-files')
56 # FIXME: The --dump-json-and-pickle option is only for debugging and will 51 # FIXME: The --dump-json-and-pickle option is only for debugging and will
57 # be removed once we complete migrating all IDL files from the Perl flow to 52 # be removed once we complete migrating all IDL files from the Perl flow to
58 # the Python flow. 53 # the Python flow.
59 parser.add_option('--dump-json-and-pickle', action='store_true', default=Fal se) 54 parser.add_option('--dump-json-and-pickle', action='store_true', default=Fal se)
60 parser.add_option('--idl-attributes-file') 55 parser.add_option('--idl-attributes-file')
61 parser.add_option('--include', dest='idl_directories', action='append') 56 parser.add_option('--include', dest='idl_directories', action='append')
62 parser.add_option('--output-directory') 57 parser.add_option('--output-directory')
(...skipping 11 matching lines...) Expand all
74 else: 69 else:
75 # additional_idl_files is passed as a string with varied (shell-style) 70 # additional_idl_files is passed as a string with varied (shell-style)
76 # quoting, hence needs parsing. 71 # quoting, hence needs parsing.
77 options.additional_idl_files = shlex.split(options.additional_idl_files) 72 options.additional_idl_files = shlex.split(options.additional_idl_files)
78 if len(args) != 1: 73 if len(args) != 1:
79 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args)) 74 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args))
80 options.idl_filename = os.path.realpath(args[0]) 75 options.idl_filename = os.path.realpath(args[0])
81 return options 76 return options
82 77
83 78
84 def get_relative_dir_posix(filename):
85 """Returns directory of a local file relative to Source, in POSIX format."""
86 relative_path_local = os.path.relpath(filename, source_path)
87 relative_dir_local = os.path.dirname(relative_path_local)
88 return relative_dir_local.replace(os.path.sep, posixpath.sep)
89
90
91 def write_json_and_pickle(definitions, interface_name, output_directory): 79 def write_json_and_pickle(definitions, interface_name, output_directory):
92 json_string = definitions.to_json() 80 json_string = definitions.to_json()
93 json_basename = interface_name + '.json' 81 json_basename = interface_name + '.json'
94 json_filename = os.path.join(output_directory, json_basename) 82 json_filename = os.path.join(output_directory, json_basename)
95 with open(json_filename, 'w') as json_file: 83 with open(json_filename, 'w') as json_file:
96 json_file.write(json_string) 84 json_file.write(json_string)
97 pickle_basename = interface_name + '.pkl' 85 pickle_basename = interface_name + '.pkl'
98 pickle_filename = os.path.join(output_directory, pickle_basename) 86 pickle_filename = os.path.join(output_directory, pickle_basename)
99 with open(pickle_filename, 'wb') as pickle_file: 87 with open(pickle_filename, 'wb') as pickle_file:
100 pickle.dump(definitions, pickle_file) 88 pickle.dump(definitions, pickle_file)
101 89
102 90
103 def main(): 91 def main():
104 options = parse_options() 92 options = parse_options()
105 idl_filename = options.idl_filename 93 idl_filename = options.idl_filename
106 basename = os.path.basename(idl_filename) 94 basename = os.path.basename(idl_filename)
107 interface_name, _ = os.path.splitext(basename) 95 interface_name, _ = os.path.splitext(basename)
108 output_directory = options.output_directory 96 output_directory = options.output_directory
109 verbose = options.verbose 97 verbose = options.verbose
110 if verbose: 98 if verbose:
111 print idl_filename 99 print idl_filename
112 relative_dir_posix = get_relative_dir_posix(idl_filename)
113 100
114 interfaces_info_filename = options.interfaces_info_file 101 interfaces_info_filename = options.interfaces_info_file
115 if interfaces_info_filename: 102 if interfaces_info_filename:
116 with open(interfaces_info_filename) as interfaces_info_file: 103 with open(interfaces_info_filename) as interfaces_info_file:
117 interfaces_info = pickle.load(interfaces_info_file) 104 interfaces_info = pickle.load(interfaces_info_file)
118 else: 105 else:
119 interfaces_info = None 106 interfaces_info = None
120 107
121 reader = idl_reader.IdlReader(interfaces_info, options.additional_idl_files, options.idl_attributes_file, output_directory, verbose) 108 reader = idl_reader.IdlReader(interfaces_info, options.additional_idl_files, options.idl_attributes_file, output_directory, verbose)
122 definitions = reader.read_idl_definitions(idl_filename) 109 definitions = reader.read_idl_definitions(idl_filename)
123 code_generator = code_generator_v8.CodeGeneratorV8(definitions, interface_na me, interfaces_info, options.output_directory, relative_dir_posix, options.idl_d irectories, verbose) 110 code_generator = code_generator_v8.CodeGeneratorV8(definitions, interface_na me, interfaces_info, options.output_directory, options.idl_directories, verbose)
124 if not definitions: 111 if not definitions:
125 # We generate dummy .h and .cpp files just to tell build scripts 112 # We generate dummy .h and .cpp files just to tell build scripts
126 # that outputs have been created. 113 # that outputs have been created.
127 code_generator.write_dummy_header_and_cpp() 114 code_generator.write_dummy_header_and_cpp()
128 return 115 return
129 if options.dump_json_and_pickle: 116 if options.dump_json_and_pickle:
130 write_json_and_pickle(definitions, interface_name, output_directory) 117 write_json_and_pickle(definitions, interface_name, output_directory)
131 return 118 return
132 code_generator.write_header_and_cpp() 119 code_generator.write_header_and_cpp()
133 120
134 121
135 if __name__ == '__main__': 122 if __name__ == '__main__':
136 sys.exit(main()) 123 sys.exit(main())
OLDNEW
« no previous file with comments | « Source/bindings/scripts/unstable/code_generator_v8.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698