1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
# Copyright 2015 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//v8/gni/snapshot_toolchain.gni")
import("//v8/gni/v8.gni")
assert(is_chromeos)
# Libraries required to generate the custom test library built with js2gtest.
# Changing the size or the order of files in this array also requires changing
# src/chrome/test/base/ash/v8sh.py.
js2gtest_js_input_libraries = [
"//chrome/test/data/webui/chromeos/test_api.js",
"//chrome/test/base/ash/js2gtest.js",
]
# Additional libraries loaded at test runtime.
js2gtest_runtime_js_libraries =
[ "//chrome/test/data/webui/chromeos/chai_v4.js" ]
js2gtest_js_libraries =
js2gtest_js_input_libraries + js2gtest_runtime_js_libraries
# Variables:
# test_type: One of 'webui', 'unit' or 'extension' indicating what
# environment the test runs under.
# sources: List of javascript test source files.
# deps_js: Javascript file with closure library dependencies. Only needed
# if the test fixtures use closureModuleDeps.
# gen_include_files: List of javascript files used in GEN_INCLUDE calls
# in the tests and therefore considered input to the C++ generation step.
# extra_js_files: List of javascript files needed by the test at runtime,
# typically listed in the extraLibraries member of the test fixture.
# data
# defines
# deps
# visibility
template("js2gtest") {
assert(defined(invoker.test_type) &&
(invoker.test_type == "webui" || invoker.test_type == "unit" ||
invoker.test_type == "extension" ||
invoker.test_type == "mojo_lite_webui" ||
invoker.test_type == "mojo_webui"))
action_name = target_name + "_action"
source_set_name = target_name
# The mapping from sources to the copied version.
copied_source_pattern = "$root_out_dir/test_data/{{source_root_relative_dir}}/{{source_file_part}}"
gen_source_pattern = "{{source_gen_dir}}/{{source_name_part}}-gen.cc"
data = []
if (defined(invoker.data)) {
data += invoker.data
}
action_foreach(action_name) {
testonly = true
visibility = [ ":$source_set_name" ]
script = "//chrome/test/base/ash/v8sh.py"
sources = invoker.sources
v8_toolchain = v8_snapshot_toolchain
if (target_os == "mac" && host_os == "mac" && target_cpu == "x64" &&
host_cpu == "arm64") {
# This step runs V8 on the host in cross-builds. For x86_64 -> arm64
# cross-builds, this is fine since V8 has an arm64 emulator. For
# arm64 -> x86_64, we need a V8 that runs on arm64 natively.
v8_toolchain = "//build/toolchain/mac:clang_arm64_v8_arm64"
}
v8_shell_path = get_label_info("//v8:v8_shell($v8_toolchain)",
"root_out_dir") + "/v8_shell"
if (host_os == "win") {
v8_shell_path += ".exe"
}
inputs = [ v8_shell_path ] + js2gtest_js_input_libraries
if (v8_use_external_startup_data) {
inputs += [ "$root_out_dir/snapshot_blob.bin" ]
}
if (defined(invoker.deps_js)) {
inputs += [ invoker.deps_js ]
}
if (defined(invoker.gen_include_files)) {
inputs += invoker.gen_include_files
}
# Outputs. The script will copy the source files to the output directory,
# which then must be treated as runtime data. The generated .cc file isn't
# data, it will be compiled in a step below.
outputs = [
copied_source_pattern,
gen_source_pattern,
]
data += process_file_template(sources, [ copied_source_pattern ])
args = []
if (defined(invoker.deps_js)) {
args += [
"--deps_js",
rebase_path(invoker.deps_js, root_build_dir),
]
}
args += [
# Need "./" for script to find binary (cur dir is not on path).
"./" + rebase_path(v8_shell_path, root_build_dir),
]
args += rebase_path(js2gtest_js_input_libraries, root_build_dir)
if (defined(invoker.parameterized)) {
parameterized = invoker.parameterized
} else {
parameterized = "false"
}
args += [
invoker.test_type,
parameterized,
"{{source}}",
rebase_path("//", root_build_dir), # Path to source root.
gen_source_pattern,
rebase_path(copied_source_pattern, root_build_dir),
]
deps = [ "//v8:v8_shell($v8_toolchain)" ]
if (v8_use_external_startup_data) {
deps += [ "//v8:run_mksnapshot_default" ]
}
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
if (defined(invoker.extra_js_files)) {
copy_target_name = target_name + "_copy"
copy(copy_target_name) {
if (defined(invoker.deps)) {
deps = invoker.deps
}
visibility = [ ":$source_set_name" ]
sources = invoker.extra_js_files
outputs = [ copied_source_pattern ]
}
}
source_set(source_set_name) {
testonly = true
forward_variables_from(invoker,
[
"defines",
"visibility",
])
sources = process_file_template(invoker.sources, [ gen_source_pattern ])
# This empty public header is intentional to remove unnecessary build
# dependency.
public = []
deps = [
":$action_name",
# The generator implicitly makes includes from these targets.
"//build/config/coverage:buildflags",
"//chrome/test:test_support",
"//testing/gmock",
"//testing/gtest",
"//url",
]
if (defined(invoker.deps)) {
deps += invoker.deps
}
if (defined(invoker.gen_include_files)) {
data += invoker.gen_include_files
}
if (defined(invoker.extra_js_files)) {
data_deps = [ ":$copy_target_name" ]
}
}
}
|