Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / scripts / scripts.gni
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import("//third_party/WebKit/Source/bindings/core/v8/generated.gni")
6 import("//third_party/WebKit/Source/bindings/modules/idl.gni")
7 import("//third_party/WebKit/Source/bindings/modules/modules.gni")
8
9 bindings_scripts_dir = get_path_info(".", "abspath")
10 bindings_scripts_output_dir = "$root_gen_dir/blink/bindings/scripts"
11
12 # Replacing <(DEPTH) with "/" makes paths like "<(DEPTH)/foo" absolute.
13 _gypi = exec_script(
14     "//build/gypi_to_gn.py",
15     [ rebase_path("scripts.gypi"),
16       "--replace=<(DEPTH)=/" ],
17     "scope",
18     [ "scripts.gypi" ])
19
20 jinja_module_files = get_path_info(_gypi.jinja_module_files, "abspath")
21 idl_lexer_parser_files = get_path_info(_gypi.idl_lexer_parser_files, "abspath")
22 idl_compiler_files = get_path_info(_gypi.idl_compiler_files, "abspath")
23
24 # Calls the compute_interfaces_info_individual script.
25 #
26 # Parameters:
27 #   sources_static = list of IDL files to pass as inputs
28 #   sources_generated = list of generated IDL files to pass as inputs
29 #   component_dir = name if subdirectory (one word, no slashes) of component.
30 #   interfaces_info_file = output pickle file for interfaces info.
31 #   component_wide_info_file = output pickle file for component wide info.
32 #   deps = dependencies
33 #
34 # FIXME: Note the static/generated split is for consistency with GYP. This
35 # split is not necessary in the GN build and could be combined into a single
36 # "sources".
37 template("compute_interfaces_info_individual") {
38   action(target_name) {
39     script = "$bindings_scripts_dir/compute_interfaces_info_individual.py"
40     if (defined(invoker.visibility)) {
41       visibility = invoker.visibility
42     }
43
44     # Save static list to temp file to avoid blowing out command-line length
45     # limit.
46     file_list = "$target_gen_dir/${target_name}_file_list.txt"
47     write_file(file_list, rebase_path(invoker.sources_static, root_build_dir))
48
49     inputs = [
50       "$bindings_scripts_dir/utilities.py",
51       file_list,
52     ] + invoker.sources_static + invoker.sources_generated
53
54     outputs = [
55       invoker.interfaces_info_file,
56       invoker.component_wide_info_file,
57     ]
58
59     args = [
60       "--cache-directory",
61       rebase_path(bindings_scripts_output_dir, root_build_dir),
62       "--idl-files-list", rebase_path(file_list, root_build_dir),
63       "--interfaces-info-file",
64       rebase_path(invoker.interfaces_info_file, root_build_dir),
65       "--component-info-file",
66       rebase_path(invoker.component_wide_info_file, root_build_dir),
67       "--write-file-only-if-changed=1",
68       "--",
69     ] + rebase_path(invoker.sources_generated, root_build_dir)
70
71     deps = [
72       "//third_party/WebKit/Source/bindings/scripts:cached_lex_yacc_tables",
73     ] + invoker.deps
74   }
75 }
76
77 # Calls generate_event_interfaces
78 #
79 # Parameters:
80 #   sources = A list of IDL files to process.
81 #   output_file = The .in file to write, relative to the blink_gen_dir.
82 #   suffix = (Optional) String to be passed to script via --suffix
83 template("generate_event_interfaces") {
84   action(target_name) {
85     # Write the file list to a unique temp file to avoid blowing out the
86     # command line length limit.
87     idl_files_list = "$target_gen_dir/${target_name}_file_list.tmp"
88     write_file(idl_files_list,
89                rebase_path(invoker.sources, root_build_dir))
90
91     inputs = [
92       "//third_party/WebKit/Source/bindings/scripts/utilities.py",
93       idl_files_list,
94     ] + invoker.sources
95
96     output_file = "$root_gen_dir/blink/" + invoker.output_file
97     outputs = [ output_file ]
98
99     script = "//third_party/WebKit/Source/bindings/scripts/generate_event_interfaces.py"
100     args = [
101       "--event-idl-files-list",
102       rebase_path(idl_files_list, root_build_dir),
103       "--event-interfaces-file",
104       rebase_path(output_file, root_build_dir),
105       "--write-file-only-if-changed=1",  # Always true for Ninja.
106     ]
107
108     if (defined(invoker.suffix)) {
109       args += [ "--suffix", invoker.suffix ]
110     }
111   }
112 }
113
114 # Runs the idl_compiler script over a list of sources.
115 #
116 # Parameters:
117 #   sources = list of IDL files to compile
118 #   output_dir = string containing the directory to put the output files.
119 #   output_name_suffix = a suffix after the basename of the output file names.
120 #   target_component = component to generate code for.
121 template("idl_compiler") {
122   output_dir = invoker.output_dir
123   output_name_suffix = invoker.output_name_suffix
124
125   action_foreach(target_name) {
126     # TODO(brettw) GYP adds a "-S before the script name to skip "import site" to
127     # speed up startup. Figure out if we need this and do something similar (not
128     # really expressible in GN now).
129     script = "//third_party/WebKit/Source/bindings/scripts/idl_compiler.py"
130
131     inputs =
132       idl_lexer_parser_files +  # to be explicit (covered by parsetab)
133       idl_compiler_files
134     inputs += [
135       "$bindings_scripts_output_dir/lextab.py",
136       "$bindings_scripts_output_dir/parsetab.pickle",
137       "$bindings_scripts_output_dir/cached_jinja_templates.stamp",
138       "$bindings_dir/IDLExtendedAttributes.txt",
139       # If the dependency structure or public interface info (e.g.,
140       # [ImplementedAs]) changes, we rebuild all files, since we're not
141       # computing dependencies file-by-file in the build.
142       # This data is generally stable.
143       "$bindings_modules_output_dir/InterfacesInfoOverall.pickle",
144     ]
145     # Further, if any dependency (partial interface or implemented
146     # interface) changes, rebuild everything, since every IDL potentially
147     # depends on them, because we're not computing dependencies
148     # file-by-file.
149     # FIXME: This is too conservative, and causes excess rebuilds:
150     # compute this file-by-file.  http://crbug.com/341748
151     # This should theoretically just be the IDL files passed in.
152     inputs += all_dependency_idl_files
153
154     sources = invoker.sources
155     outputs = [
156       "$output_dir/V8{{source_name_part}}${output_name_suffix}.cpp",
157       "$output_dir/V8{{source_name_part}}${output_name_suffix}.h",
158     ]
159
160     args = [
161       "--cache-dir",
162       rebase_path(bindings_scripts_output_dir, root_build_dir),
163       "--output-dir",
164       rebase_path(output_dir, root_build_dir),
165       "--interfaces-info",
166       rebase_path("$bindings_modules_output_dir/InterfacesInfoOverall.pickle",
167                   root_build_dir),
168       "--write-file-only-if-changed=1",  # Always true for Ninja.
169       "--target-component",
170       invoker.target_component,
171       "{{source}}",
172     ]
173
174     deps = [
175       # FIXME: should be interfaces_info_core (w/o modules)
176       # http://crbug.com/358074
177       "//third_party/WebKit/Source/bindings/modules:interfaces_info",
178
179       "//third_party/WebKit/Source/bindings/scripts:cached_lex_yacc_tables",
180       "//third_party/WebKit/Source/bindings/scripts:cached_jinja_templates",
181       "//third_party/WebKit/Source/core:generated_testing_idls",
182     ]
183   }
184 }
185
186 # Runs the idl_compiler to generate IDL dictionary and union impl files.
187 #
188 # Parameters:
189 #   sources = a list of IDL files to process
190 #   outputs = a list of files to write to
191 #   output_dir = the directory to put the output files
192 #   component_wide_info = a filename of pickle file which contains component
193 #     wide information
194 #   target_component = component to generate code for
195 template("idl_impl") {
196   dictionary_impl_output_dir = "$root_gen_dir/blink/"
197
198   action(target_name) {
199     script = "//third_party/WebKit/Source/bindings/scripts/idl_compiler.py"
200     idl_files_list = "$target_gen_dir/${target_name}_file_list.tmp"
201     write_file(idl_files_list, rebase_path(invoker.sources, root_build_dir))
202
203     inputs = [ idl_files_list ] + invoker.sources
204     outputs = invoker.outputs
205
206     args = [
207       "--cache-dir",
208       rebase_path(bindings_scripts_output_dir, root_build_dir),
209       "--output-dir",
210       rebase_path(invoker.output_dir, root_build_dir),
211       "--impl-output-dir",
212       rebase_path(dictionary_impl_output_dir, root_build_dir),
213       "--interfaces-info",
214       rebase_path("$bindings_modules_output_dir/InterfacesInfoOverall.pickle",
215                   root_build_dir),
216       "--component-info",
217       rebase_path(invoker.component_wide_info, root_build_dir),
218       "--target-component",
219       invoker.target_component,
220       "--write-file-only-if-changed=1",
221       "--generate-impl",
222       rebase_path(idl_files_list, root_build_dir),
223     ]
224
225     deps = [
226       # FIXME: should be interfaces_info_core (w/o modules)
227       # http://crbug.com/358074
228       "//third_party/WebKit/Source/bindings/core:interfaces_info_individual_core",
229       "//third_party/WebKit/Source/bindings/modules:interfaces_info",
230       "//third_party/WebKit/Source/bindings/modules:interfaces_info_individual_modules",
231       "//third_party/WebKit/Source/bindings/scripts:cached_lex_yacc_tables",
232       "//third_party/WebKit/Source/bindings/scripts:cached_jinja_templates",
233     ]
234   }
235 }
236
237 # Calls the aggregate_generated_bindings script.
238 #
239 # Parameters:
240 #   sources = a list of source IDL files.
241 #   component_dir = Name of directory for these files (one word, no slashes).
242 #   outputs = a list of files to write to.
243 template("aggregate_generated_bindings") {
244   action(target_name) {
245     script = "//third_party/WebKit/Source/bindings/scripts/aggregate_generated_bindings.py"
246
247     # Write lists of main IDL files to a file, so that the command lines don't
248     # exceed OS length limits.
249     idl_files_list = "$target_gen_dir/${target_name}_file_list.tmp"
250     write_file(idl_files_list, rebase_path(invoker.sources, root_build_dir))
251
252     inputs = [ idl_files_list ] + invoker.sources
253     outputs = invoker.outputs
254
255     args = [
256       invoker.component_dir,
257       rebase_path(idl_files_list, root_build_dir),
258       "--",
259     ]
260     args += rebase_path(invoker.outputs, root_build_dir)
261   }
262 }
263
264 # Calls the compute_global_objects script.
265 #
266 # Parameters:
267 #   sources = a list of source IDL files.
268 #   sources_generated = a list of generated pickle sources.
269 #   output_file = a pickle file to write to (need to specify directory)
270 #
271 template("compute_global_objects") {
272   action(target_name) {
273     script = "//third_party/WebKit/Source/bindings/scripts/compute_global_objects.py"
274
275     # Write the file list to a unique temp file to avoid blowing out the
276     # command line length limit.
277     idl_files_list = "$target_gen_dir/${target_name}_file_list.tmp"
278     write_file(idl_files_list,
279                rebase_path(invoker.sources, root_build_dir))
280
281     inputs = [
282       "//third_party/WebKit/Source/bindings/scripts/utilities.py",
283       idl_files_list,
284     ] + invoker.sources_generated + invoker.sources
285
286     outputs = [ invoker.output_file ]
287
288     args = [
289       "--idl-files-list",
290       rebase_path(idl_files_list, root_build_dir),
291       "--write-file-only-if-changed=1",  # Always true for Ninja.
292       "--",
293     ]
294     args += rebase_path(invoker.sources_generated, root_build_dir)
295     args += [ rebase_path(invoker.output_file, root_build_dir) ]
296
297     deps = invoker.deps
298   }
299 }
300
301 # Calls the generate_global_constructors script.
302 #
303 # Parameters:
304 #   sources = a list of source IDL files.
305 #   global_objects_file = a global objects file generated by compute_global_objects
306 #   interfaces = interfaces to generate global constructors for.
307 #   component = component to generate global constructors for.
308 #   output_dir = output directory to generate idl files and header files.
309 #   deps = dependencies
310 #
311 template("generate_global_constructors") {
312   action(target_name) {
313     script = "//third_party/WebKit/Source/bindings/scripts/generate_global_constructors.py"
314
315     # Write the file list to a unique temp file to avoid blowing out the
316     # command line length limit.
317     idl_files_list = "$target_gen_dir/${target_name}_file_list.tmp"
318     write_file(idl_files_list,
319                rebase_path(invoker.sources, root_build_dir))
320
321     inputs = [
322       "//third_party/WebKit/Source/bindings/scripts/utilities.py",
323       idl_files_list,
324       invoker.global_objects_file,
325     ] + invoker.sources
326
327     args = [
328       "--idl-files-list",
329       rebase_path(idl_files_list, root_build_dir),
330       "--global-objects-file",
331       rebase_path(invoker.global_objects_file, root_build_dir),
332       "--write-file-only-if-changed=1",  # Always true for Ninja.
333       "--",
334     ]
335
336     output_dir = invoker.output_dir
337     component = invoker.component
338
339     # generate outputs from invoker.interfaces.
340     output_idl_files = []
341     output_header_files = []
342     foreach(interface, invoker.interfaces) {
343       args += [ interface ]
344       output_idl_file = "$output_dir/${interface}${component}Constructors.idl"
345       args += [ rebase_path(output_idl_file, root_build_dir) ]
346       output_idl_files += [ output_idl_file ]
347       output_header_files += [
348         "$output_dir/${interface}${component}Constructors.h"
349       ]
350     }
351
352     outputs = output_idl_files + output_header_files
353     deps = invoker.deps
354   }
355 }
356