| # Copyright 2023 The Chromium Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("//testing/test.gni") |
| |
| template("private_code_test") { |
| testonly = true |
| assert(!is_component_build, "Guard your test behind if (!is_component_build)") |
| |
| _linker_inputs_dep = invoker.linker_inputs_dep |
| _dir = get_label_info(_linker_inputs_dep, "root_out_dir") |
| |
| if (defined(invoker.executable_name)) { |
| _executable_path = "$_dir/${invoker.executable_name}" |
| } else { |
| if (is_android) { |
| _dir += "/lib.unstripped" |
| } |
| if (shlib_prefix != "") { |
| _so_name = shlib_prefix + get_label_info(_linker_inputs_dep, "name") |
| _so_name = string_replace(_so_name, |
| "${shlib_prefix}${shlib_prefix}", |
| shlib_prefix) |
| } |
| _executable_path = "$_dir/${_so_name}$shlib_extension" |
| } |
| |
| _collect_sources_output = "$target_gen_dir/$target_name.json" |
| _collect_sources_target_name = "${target_name}__parse_ninja" |
| action(_collect_sources_target_name) { |
| script = "//build/private_code_test/ninja_parser.py" |
| outputs = [ _collect_sources_output ] |
| inputs = [ "//build/action_helpers.py" ] |
| depfile = "$target_gen_dir/$target_name.d" |
| |
| # The script does not read this file, so the dep is not really required. |
| # It is needed only in the case where the target is in a different |
| # toolchain, and would not be added to build.ninja otherwise. |
| if (get_label_info(_linker_inputs_dep, "toolchain") != default_toolchain) { |
| deps = [ _linker_inputs_dep ] |
| } |
| args = [ |
| "--executable", |
| rebase_path(_executable_path, root_build_dir), |
| "--result-json", |
| rebase_path(_collect_sources_output, root_build_dir), |
| "--depfile", |
| rebase_path(depfile, root_build_dir), |
| ] |
| } |
| |
| isolated_script_test(target_name) { |
| script = "//build/private_code_test/private_code_test.py" |
| if (defined(invoker.private_paths_dep)) { |
| _private_paths_dep = invoker.private_paths_dep |
| _private_paths_file = invoker.private_paths_file |
| } else { |
| _private_paths_dep = |
| "//build/private_code_test:private_paths($default_toolchain)" |
| _private_paths_file = |
| get_label_info(_private_paths_dep, "target_gen_dir") + |
| "/private_paths.txt" |
| } |
| |
| data_deps = [ |
| ":$_collect_sources_target_name", |
| _private_paths_dep, |
| ] |
| args = [ |
| "--collect-sources-json", |
| "@WrappedPath(" + rebase_path(_collect_sources_output, root_build_dir) + |
| ")", |
| "--private-paths-file", |
| "@WrappedPath(" + rebase_path(_private_paths_file, root_build_dir) + ")", |
| "--root-out-dir", |
| rebase_path(get_label_info(_linker_inputs_dep, "root_out_dir"), |
| root_build_dir), |
| ] |
| if (defined(invoker.allowed_violations)) { |
| foreach(_glob, invoker.allowed_violations) { |
| args += [ |
| "--allow-violation", |
| _glob, |
| ] |
| } |
| } |
| if (defined(invoker.expect_failure) && invoker.expect_failure) { |
| args += [ "--expect-failure" ] |
| } |
| } |
| } |