1 # Copyright 2015 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.
5 import("//build/module_args/v8.gni")
8 # test_type: One of 'webui', 'unit' or 'extension' indicating what
9 # environment the test runs under.
10 # sources: List of javascript test source files.
11 # deps_js: Javascript file with closure library dependencies. Only needed
12 # if the test fixtures use closureModuleDeps.
13 # gen_include_files: List of javascript files used in GEN_INCLUDE calls
14 # in the tests and therefore considered input to the C++ generation step.
15 # extra_js_files: List of javascript files needed by the test at runtime,
16 # typically listed in the extraLibraries member of the test fixture.
20 template("js2gtest") {
21 assert(defined(invoker.test_type) &&
22 (invoker.test_type == "webui" || invoker.test_type == "unit" ||
23 invoker.test_type == "extension"))
24 action_name = target_name + "_action"
25 source_set_name = target_name
27 # The mapping from sources to the copied version.
28 copied_source_pattern = "$root_out_dir/test_data/{{source_root_relative_dir}}/{{source_file_part}}"
30 action_foreach(action_name) {
32 visibility = [ ":$source_set_name" ]
33 script = "//tools/gypv8sh.py"
35 sources = invoker.sources
37 d8_path = get_label_info("//v8:d8($host_toolchain)", "root_out_dir") + "/d8"
43 "//chrome/third_party/mock4js/mock4js.js",
44 "//chrome/test/data/webui/test_api.js",
45 "//chrome/test/base/js2gtest.js",
47 inputs = [ d8_path ] + input_js
48 if (defined(invoker.deps_js)) {
49 inputs += [ invoker.deps_js ]
51 if (defined(invoker.gen_include_files)) {
52 inputs += invoker.gen_include_files
55 # Outputs. The script will copy the source files to the output directory,
56 # which then must be treated as runtime data. The generated .cc file isn't
57 # data, it will be compiled in a step below.
59 "$target_gen_dir/{{source_name_part}}-gen.cc",
60 copied_source_pattern,
62 data = process_file_template(sources, [ copied_source_pattern ])
65 if (defined(invoker.deps_js)) {
68 rebase_path(invoker.deps_js, root_build_dir),
72 # Need "./" for script to find binary (cur dir is not on path).
73 "./" + rebase_path(d8_path, root_build_dir),
75 args += rebase_path(input_js, root_build_dir) + [ invoker.test_type ]
76 if (v8_use_external_startup_data) {
77 args += [ "--external=y" ]
79 args += [ "--external=n" ]
83 "{{source_root_relative_dir}}/{{source_file_part}}",
85 args += rebase_path(outputs, root_build_dir)
88 "//v8:d8($host_toolchain)",
90 if (defined(invoker.deps)) {
95 if (defined(invoker.extra_js_files)) {
96 copy_target_name = target_name + "_copy"
97 copy(copy_target_name) {
98 visibility = [ ":$source_set_name" ]
99 sources = invoker.extra_js_files
101 copied_source_pattern,
106 source_set(source_set_name) {
108 forward_variables_from(invoker,
113 sources = get_target_outputs(":$action_name")
117 # The generator implicitly makes includes from these targets.
118 "//chrome/test:test_support",
123 if (defined(invoker.deps)) {
126 if (defined(invoker.extra_js_files)) {
127 data_deps = [ ":$copy_target_name" ]