xts_tools/build/suite_lite.gni

428 lines
12 KiB
Plaintext
Raw Normal View History

2021-03-11 10:41:47 +00:00
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2020-09-08 02:21:39 +00:00
import("//build/lite/config/component/lite_component.gni")
2021-03-11 10:41:47 +00:00
import("//test/xts/tools/lite/build/common.gni")
2020-09-08 02:21:39 +00:00
declare_args() {
ohos_xts_test_args = ""
}
template("testsuite_base") {
assert(defined(invoker.project_type),
"project_type is required in target ${target_name}")
assert(defined(invoker.suite_name),
"suite_name is required in target ${target_name}")
_project_type = invoker.project_type
_suite_name = invoker.suite_name
_module_target_name = "module_${target_name}"
_deps = []
if (_project_type == "hctest") {
_module_name = "${target_name}"
if (defined(invoker.output_name)) {
_module_name = "${invoker.output_name}"
}
_output_file =
rebase_path("${root_out_dir}/libs/libmodule_${_module_name}.a")
2020-09-08 02:21:39 +00:00
_archive_filename = "lib${_module_name}.a"
target("static_library", "${_module_target_name}") {
forward_variables_from(invoker, "*")
}
} else if (_project_type == "hcpptest") {
_module_name = "${target_name}"
if (defined(invoker.output_name)) {
_module_name = "${invoker.output_name}"
}
_extension = ""
2020-09-08 02:21:39 +00:00
if (defined(invoker.output_extension)) {
_extension = ".${invoker.output_extension}"
}
_output_file =
rebase_path("${root_out_dir}/bin/${_module_target_name}${_extension}")
2020-09-08 02:21:39 +00:00
_archive_filename = "${_module_name}${_extension}"
target("executable", "${_module_target_name}") {
forward_variables_from(invoker, "*")
}
} else if (_project_type == "hctest_prebuilt") {
_output_file =
rebase_path("${root_out_dir}/libs/lib${_module_target_name}.a")
2020-09-08 02:21:39 +00:00
_archive_filename = "lib${_module_target_name}.a"
2021-03-11 10:41:47 +00:00
_deps += [ "//test/xts/tools/lite/hctest:hctest" ]
2020-09-08 02:21:39 +00:00
copy(_module_target_name) {
sources = invoker.sources
outputs = [ "${root_out_dir}/libs/lib${_module_target_name}.a" ]
}
}
_project_dir = rebase_path(".")
_deps += [ ":${_module_target_name}" ]
if (defined(invoker.deps)) {
_deps += invoker.deps
}
_subsystem_name = ""
if (defined(invoker.subsystem_name)) {
_subsystem_name = invoker.subsystem_name
} else {
2020-09-08 02:21:39 +00:00
_local_path = rebase_path(".")
_args1 = [
"--method_name",
"get_subsystem_name",
"--arguments",
"path=${_local_path}",
2020-09-08 02:21:39 +00:00
]
_subsystem_name = exec_script(rebase_path("$BUILD_DIR_PREFIX/utils.py"),
_args1,
"trim string")
2020-09-08 02:21:39 +00:00
}
target("testsuite_common", target_name) {
2020-09-08 02:21:39 +00:00
suite_name = _suite_name
project_type = _project_type
subsystem_name = _subsystem_name
output_file = _output_file
project_dir = _project_dir
archive_filename = _archive_filename
deps = _deps
}
}
template("hctest_suite") {
_include_dirs = [
2021-03-11 10:41:47 +00:00
"//test/xts/tools/lite/hctest/include",
2020-09-08 02:21:39 +00:00
"//third_party/unity/src",
"//kernel/liteos_m/kal",
2021-03-11 10:41:47 +00:00
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
2020-09-08 02:21:39 +00:00
]
2021-03-11 10:41:47 +00:00
_deps = [ "//test/xts/tools/lite/hctest:hctest" ]
2020-09-08 02:21:39 +00:00
_defines = [ "UNITY_INCLUDE_CONFIG_H" ]
target("testsuite_base", "${target_name}") {
forward_variables_from(invoker, "*")
project_type = "hctest"
if (defined(include_dirs)) {
2020-09-08 02:21:39 +00:00
include_dirs += _include_dirs
} else {
2020-09-08 02:21:39 +00:00
include_dirs = _include_dirs
}
if (defined(deps)) {
2020-09-08 02:21:39 +00:00
deps += _deps
} else {
2020-09-08 02:21:39 +00:00
deps = _deps
}
if (defined(defines)) {
2020-09-08 02:21:39 +00:00
defines += _defines
} else {
2020-09-08 02:21:39 +00:00
defines = _defines
}
}
}
template("ctest_prebuilt_suite") {
assert(defined(invoker.sources),
"sources is required in target ${target_name}")
target("testsuite_base", "${target_name}") {
forward_variables_from(invoker, "*")
project_type = "hctest_prebuilt"
}
}
template("hcpptest_suite") {
target("testsuite_base", "${target_name}") {
forward_variables_from(invoker, "*")
project_type = "hcpptest"
output_extension = "bin"
_include_dirs = [
"//third_party/googletest/googletest/include",
"//third_party/googletest/googletest/src",
2020-09-08 02:21:39 +00:00
]
if (defined(include_dirs)) {
include_dirs += _include_dirs
} else {
include_dirs = _include_dirs
}
2021-03-11 10:41:47 +00:00
_deps = [ "//test/xts/tools/lite/hcpptest:hcpptest_main" ]
2020-09-08 02:21:39 +00:00
if (defined(deps)) {
deps += _deps
} else {
deps = _deps
}
}
}
template("pythontest_suite") {
assert(defined(invoker.script), "script is required in target ${target_name}")
2020-09-08 02:21:39 +00:00
assert(defined(invoker.suite_name),
"suite_name is required in target ${target_name}")
_suite_name = invoker.suite_name
_project_dir = rebase_path(".")
_subsystem_name = ""
if (defined(invoker.subsystem_name)) {
_subsystem_name = invoker.subsystem_name
} else {
2020-09-08 02:21:39 +00:00
_local_path = rebase_path(".")
_args1 = [
"--method_name",
"get_subsystem_name",
"--arguments",
"path=${_local_path}",
2020-09-08 02:21:39 +00:00
]
_subsystem_name = exec_script(rebase_path("$BUILD_DIR_PREFIX/utils.py"),
_args1,
"trim string")
2020-09-08 02:21:39 +00:00
}
_deps = []
if (defined(invoker.deps)) {
_deps = invoker.deps + _deps
}
_outputs_dir = ""
if (defined(invoker.outputs_dir)) {
_outputs_dir = invoker.outputs_dir
}
_output_file = rebase_path("${invoker.script}")
_archive_filename = "${target_name}"
target("testsuite_common", "${target_name}") {
suite_name = _suite_name
project_type = "pythontest"
subsystem_name = _subsystem_name
output_file = _output_file
project_dir = _project_dir
archive_filename = _archive_filename
deps = _deps
outputs_dir = _outputs_dir
}
}
template("test_suite") {
assert(defined(invoker.deps), "deps is required in target ${target_name}")
2020-09-08 02:21:39 +00:00
_output = "${SUITE_OUTPUT_PREFIX}${target_name}.zip"
_suite_path = rebase_path("${SUITE_OUTPUT_PREFIX}${target_name}")
_prebuilts_files = ","
2021-03-19 09:34:16 +00:00
_origin_target_name = target_name
2020-09-08 02:21:39 +00:00
if (defined(invoker.prebuilts_files)) {
_prebuilts_files = invoker.prebuilts_files
}
2021-03-19 09:34:16 +00:00
target("deploy_suite", "${target_name}_xdevice") {
suite_name = _origin_target_name
}
_deps = [ ":${target_name}_xdevice" ]
if (defined(invoker.deps)) {
_deps += invoker.deps
}
2021-03-19 09:34:16 +00:00
if (defined(invoker.version)) {
2021-03-16 14:08:56 +00:00
_version = invoker.version
_out_dir = rebase_path("${_suite_path}/testcases")
_args1 = [
"--method_name",
"record_test_component_info",
"--arguments",
"out_dir=${_out_dir}#version=${_version}",
]
action("${target_name}_generate_module_data") {
script = rebase_path("$BUILD_DIR_PREFIX/utils.py")
deps = _deps
args = _args1
outputs = [ "${SUITE_OUTPUT_PREFIX}/${_origin_target_name}/${SUITE_TESTCASES_NAME}/module_info.json" ]
}
2021-03-16 14:08:56 +00:00
}
2021-03-19 09:34:16 +00:00
2020-09-08 02:21:39 +00:00
_gen_args = [
"archive_suite",
"--suite_path",
_suite_path,
"--testcases_name",
SUITE_TESTCASES_NAME,
"--prebuilts_resource",
_prebuilts_files,
"--build_enabled",
"true",
2020-09-08 02:21:39 +00:00
]
2021-03-19 09:34:16 +00:00
_deps += [ ":${target_name}_generate_module_data" ]
2020-09-08 02:21:39 +00:00
action(target_name) {
script = rebase_path("$BUILD_DIR_PREFIX/suite.py")
deps = _deps
args = _gen_args
outputs = [ _output ]
2020-09-08 02:21:39 +00:00
}
}
template("executable_suite") {
assert(defined(invoker.suite_name),
"suite_name is required in target ${target_name}")
_suite_name = invoker.suite_name
_local_path = rebase_path(".")
_args1 = [
"--method_name",
"get_subsystem_name",
"--arguments",
"path=${_local_path}",
2020-09-08 02:21:39 +00:00
]
_subsystem_name = exec_script(rebase_path("$BUILD_DIR_PREFIX/utils.py"),
_args1,
"trim string")
2020-09-08 02:21:39 +00:00
_extension = ""
if (defined(invoker.output_extension)) {
_extension = ".${invoker.output_extension}"
}
_outputs_dir = ""
if (defined(invoker.outputs_dir)) {
_outputs_dir = "${invoker.outputs_dir}"
2020-09-08 02:21:39 +00:00
}
_module_target_name = "module_${target_name}"
_source_file = rebase_path("${root_out_dir}/bin/${target_name}${_extension}")
_origi_target = target_name
target("executable", "${_module_target_name}") {
forward_variables_from(invoker, "*")
output_name = _origi_target
2020-09-08 02:21:39 +00:00
}
_output_file = rebase_path(
"${SUITE_OUTPUT_PREFIX}${_suite_name}/${SUITE_TESTCASES_NAME}/${_subsystem_name}/${_outputs_dir}")
2020-09-08 02:21:39 +00:00
_args2 = [
"--method_name",
"copy_file",
"--arguments",
"output=${_output_file}#sources=${_source_file}",
2020-09-08 02:21:39 +00:00
]
action(target_name) {
script = rebase_path("$BUILD_DIR_PREFIX/utils.py")
deps = [ ":${_module_target_name}" ]
2020-09-08 02:21:39 +00:00
args = _args2
outputs = [ "${SUITE_OUTPUT_PREFIX}${_suite_name}/${SUITE_TESTCASES_NAME}/${_subsystem_name}/${target_name}${_extension}" ]
2020-09-08 02:21:39 +00:00
}
}
template("open_source_suite") {
assert(defined(invoker.suite_name),
"suite_name is required in target ${target_name}")
assert(defined(invoker.exec_command_path),
"exec_script_path is required in target ${target_name}")
_suite_name = invoker.suite_name
_exec_command_path = invoker.exec_command_path
_exec_sub_dir = invoker.exec_sub_dir
_prebuild_command = invoker.prebuild_command
_output_files = ""
if (defined(invoker.build_args)) {
foreach(target_file, invoker.build_args) {
_output_files =
_output_files +
rebase_path("${_exec_command_path}/${_exec_sub_dir}/${target_file}") +
","
}
} else {
_output_files = rebase_path("${_exec_command_path}")
}
2020-09-08 02:21:39 +00:00
_pre_build_deps = []
if (defined(invoker.deps)) {
_pre_build_deps += invoker.deps
}
target("build_ext_component", "prebuild_${target_name}") {
exec_path = rebase_path("${_exec_command_path}")
command = _prebuild_command
deps = _pre_build_deps
}
2020-09-08 02:21:39 +00:00
_subsystem_name = ""
if (defined(invoker.subsystem_name)) {
_subsystem_name = invoker.subsystem_name
} else {
_local_path = rebase_path(".")
_args1 = [
"--method_name",
"get_subsystem_name",
"--arguments",
"path=${_local_path}",
]
_subsystem_name = exec_script(rebase_path("$BUILD_DIR_PREFIX/utils.py"),
_args1,
"trim string")
}
2020-09-08 02:21:39 +00:00
_archive_filename = "${target_name}"
_project_dir = rebase_path(".")
2020-09-08 02:21:39 +00:00
_build_deps = [ ":prebuild_${target_name}" ]
2020-09-08 02:21:39 +00:00
_outputs_dir = ""
if (defined(invoker.outputs_dir)) {
_outputs_dir = invoker.outputs_dir
}
2020-09-08 02:21:39 +00:00
target("testsuite_common", "${target_name}") {
suite_name = _suite_name
subsystem_name = _subsystem_name
project_type = "open_source_test"
project_dir = _project_dir
output_file = _output_files
archive_filename = _archive_filename
outputs_dir = _outputs_dir
deps = _build_deps
}
2020-09-08 02:21:39 +00:00
}
2021-03-11 10:41:47 +00:00
template("hjsunit_suite") {
assert(defined(invoker.suite_name),
"suite_name is required in target ${target_name}")
assert(defined(invoker.hap_name),
"hap_name is required in target ${target_name}")
_suite_name = invoker.suite_name
_hap_name = invoker.hap_name
_hap_sign = "true"
if (defined(invoker.need_sign)) {
_hap_sign = invoker.need_sign
}
_output_files = ","
_subsystem_name = ""
if (defined(invoker.subsystem_name)) {
_subsystem_name = invoker.subsystem_name
} else {
_local_path = rebase_path(".")
_args1 = [
"--method_name",
"get_subsystem_name",
"--arguments",
"path=${_local_path}",
]
_subsystem_name = exec_script(rebase_path("$BUILD_DIR_PREFIX/utils.py"),
_args1,
"trim string")
}
_archive_filename = "${target_name}"
_project_dir = rebase_path(".")
target("testsuite_common", "${target_name}") {
suite_name = _suite_name
subsystem_name = _subsystem_name
project_type = "hjsunit"
project_dir = _project_dir
output_file = _output_files
archive_filename = _archive_filename
hap_name = _hap_name
hap_sign = _hap_sign
}
}