Home | History | Annotate | Download | only in scripts
      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 #   output_file = pickle file to write
     31 #
     32 # FIXME: Note the static/generated split is for consistency with GYP. This
     33 # split is not necessary in the GN build and could be combined into a single
     34 # "sources".
     35 template("compute_interfaces_info_individual") {
     36   action(target_name) {
     37     script = "$bindings_scripts_dir/compute_interfaces_info_individual.py"
     38     if (defined(invoker.visibility)) {
     39       visibility = invoker.visibility
     40     }
     41 
     42     # Save static list to temp file to avoid blowing out command-line length
     43     # limit.
     44     file_list = "$target_gen_dir/${target_name}_file_list.txt"
     45     write_file(file_list, rebase_path(invoker.sources_static, root_build_dir))
     46 
     47     source_prereqs = [
     48       "$bindings_scripts_dir/utilities.py",
     49       file_list,
     50     ] + invoker.sources_static + invoker.sources_generated
     51 
     52     outputs = [
     53       invoker.output_file
     54     ]
     55 
     56     args = [
     57       "--component-dir", invoker.component_dir,
     58       "--idl-files-list", rebase_path(file_list, root_build_dir),
     59       "--interfaces-info-file",
     60       rebase_path(invoker.output_file, root_build_dir),
     61       "--write-file-only-if-changed=1",
     62       "--",
     63     ] + rebase_path(invoker.sources_generated, root_build_dir)
     64 
     65     deps = [
     66       # FIXME: should be {modules|core}_generated_idls
     67       # http://crbug.com/358074
     68       "//third_party/WebKit/Source/bindings:generated_idls",
     69     ]
     70   }
     71 }
     72 
     73 # Calls generate_event_interfaces
     74 #
     75 # Parameters:
     76 #   sources = A list of IDL files to process.
     77 #   output_file = The .in file to write, relative to the blink_gen_dir.
     78 #   suffix = (Optional) String to be passed to script via --suffix
     79 template("generate_event_interfaces") {
     80   action(target_name) {
     81     # Write the file list to a unique temp file to avoid blowing out the
     82     # command line length limit.
     83     idl_files_list = "$target_gen_dir/${target_name}_file_list.tmp"
     84     write_file(idl_files_list,
     85                rebase_path(invoker.sources, root_build_dir))
     86 
     87     source_prereqs = [
     88       "//third_party/WebKit/Source/bindings/scripts/utilities.py",
     89       idl_files_list,
     90     ] + invoker.sources
     91 
     92     output_file = "$root_gen_dir/blink/" + invoker.output_file
     93     outputs = [ output_file ]
     94 
     95     script = "//third_party/WebKit/Source/bindings/scripts/generate_event_interfaces.py"
     96     args = [
     97       "--event-idl-files-list",
     98       rebase_path(idl_files_list, root_build_dir),
     99       "--event-interfaces-file",
    100       rebase_path(output_file, root_build_dir),
    101       "--write-file-only-if-changed=1",  # Always true for Ninja.
    102     ]
    103 
    104     if (defined(invoker.suffix)) {
    105       args += [ "--suffix", invoker.suffix ]
    106     }
    107   }
    108 }
    109 
    110 # Runs the idl_compiler script over a list of sources.
    111 #
    112 # Parameters:
    113 #   sources = list of IDL files to compile
    114 #   output_dir = string containing the directory to put the output files.
    115 template("idl_compiler") {
    116   output_dir = invoker.output_dir
    117 
    118   action_foreach(target_name) {
    119     # TODO(brettw) GYP adds a "-S before the script name to skip "import site" to
    120     # speed up startup. Figure out if we need this and do something similar (not
    121     # really expressible in GN now).
    122     script = "//third_party/WebKit/Source/bindings/scripts/idl_compiler.py"
    123 
    124     source_prereqs =
    125       idl_lexer_parser_files +  # to be explicit (covered by parsetab)
    126       idl_compiler_files
    127     source_prereqs += [
    128       "$bindings_scripts_output_dir/lextab.py",
    129       "$bindings_scripts_output_dir/parsetab.pickle",
    130       "$bindings_scripts_output_dir/cached_jinja_templates.stamp",
    131       "$bindings_dir/IDLExtendedAttributes.txt",
    132       # If the dependency structure or public interface info (e.g.,
    133       # [ImplementedAs]) changes, we rebuild all files, since we're not
    134       # computing dependencies file-by-file in the build.
    135       # This data is generally stable.
    136       "$bindings_modules_output_dir/InterfacesInfoModules.pickle",
    137     ]
    138     # Further, if any dependency (partial interface or implemented
    139     # interface) changes, rebuild everything, since every IDL potentially
    140     # depends on them, because we're not computing dependencies
    141     # file-by-file.
    142     # FIXME: This is too conservative, and causes excess rebuilds:
    143     # compute this file-by-file.  http://crbug.com/341748
    144     # This should theoretically just be the IDL files passed in.
    145     source_prereqs += all_dependency_idl_files
    146 
    147     sources = invoker.sources
    148     outputs = [
    149       "$output_dir/V8{{source_name_part}}.cpp",
    150       "$output_dir/V8{{source_name_part}}.h",
    151     ]
    152 
    153     args = [
    154       "--cache-dir",
    155       rebase_path(bindings_scripts_output_dir, root_build_dir),
    156       "--output-dir",
    157       rebase_path(output_dir, root_build_dir),
    158       "--interfaces-info",
    159       rebase_path("$bindings_modules_output_dir/InterfacesInfoModules.pickle",
    160                   root_build_dir),
    161       "--write-file-only-if-changed=1",  # Always true for Ninja.
    162       "{{source}}",
    163     ]
    164 
    165     deps = [
    166       # FIXME: should be interfaces_info_core (w/o modules)
    167       # http://crbug.com/358074
    168       "//third_party/WebKit/Source/bindings/modules:interfaces_info",
    169 
    170       "//third_party/WebKit/Source/bindings/scripts:cached_lex_yacc_tables",
    171       "//third_party/WebKit/Source/bindings/scripts:cached_jinja_templates",
    172       "//third_party/WebKit/Source/core:generated_testing_idls",
    173     ]
    174   }
    175 }
    176 
    177 # Calls the aggregate_generated_bindings script.
    178 #
    179 # Parameters:
    180 #   sources = a list of source IDL files.
    181 #   component_dir = Name of directory for these files (one word, no slashes).
    182 #   outputs = a list of files to write to.
    183 template("aggregate_generated_bindings") {
    184   action(target_name) {
    185     script = "//third_party/WebKit/Source/bindings/scripts/aggregate_generated_bindings.py"
    186 
    187     # Write lists of main IDL files to a file, so that the command lines don't
    188     # exceed OS length limits.
    189     idl_files_list = "$target_gen_dir/${target_name}_file_list.tmp"
    190     write_file(idl_files_list, rebase_path(invoker.sources, root_build_dir))
    191 
    192     source_prereqs = [ idl_files_list ] + invoker.sources
    193     outputs = invoker.outputs
    194 
    195     args = [
    196       invoker.component_dir,
    197       rebase_path(idl_files_list, root_build_dir),
    198       "--",
    199     ]
    200     args += rebase_path(invoker.outputs, root_build_dir)
    201   }
    202 }
    203