15f9996aaSopenharmony_ci# Copyright (c) 2021 Huawei Device Co., Ltd. 25f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 35f9996aaSopenharmony_ci# you may not use this file except in compliance with the License. 45f9996aaSopenharmony_ci# You may obtain a copy of the License at 55f9996aaSopenharmony_ci# 65f9996aaSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 75f9996aaSopenharmony_ci# 85f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 95f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 105f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 115f9996aaSopenharmony_ci# See the License for the specific language governing permissions and 125f9996aaSopenharmony_ci# limitations under the License. 135f9996aaSopenharmony_ci 145f9996aaSopenharmony_ciimport("//build/config/clang/clang.gni") 155f9996aaSopenharmony_ciimport("//build/config/python.gni") 165f9996aaSopenharmony_ciimport("//build/ohos/notice/notice.gni") 175f9996aaSopenharmony_ciimport("//build/templates/common/collect_target.gni") 185f9996aaSopenharmony_ciimport("//build/templates/metadata/module_info.gni") 195f9996aaSopenharmony_ci 205f9996aaSopenharmony_citemplate("ohos_copy") { 215f9996aaSopenharmony_ci assert(defined(invoker.sources), 225f9996aaSopenharmony_ci "sources must be defined for ${target_name}.") 235f9996aaSopenharmony_ci assert(defined(invoker.outputs), 245f9996aaSopenharmony_ci "outputs must be defined for ${target_name}.") 255f9996aaSopenharmony_ci 265f9996aaSopenharmony_ci _is_test_target = defined(invoker.testonly) && invoker.testonly 275f9996aaSopenharmony_ci _is_prebuilt = defined(invoker.prebuilt) && invoker.prebuilt 285f9996aaSopenharmony_ci assert(_is_prebuilt != "") # Mark as used 295f9996aaSopenharmony_ci 305f9996aaSopenharmony_ci # module_info generation is bypassed for prebuilt static library 315f9996aaSopenharmony_ci _bypass_module_info_generation = 325f9996aaSopenharmony_ci defined(invoker.bypass_module_info_generation) && 335f9996aaSopenharmony_ci invoker.bypass_module_info_generation 345f9996aaSopenharmony_ci _main_target_name = target_name 355f9996aaSopenharmony_ci _target_label = 365f9996aaSopenharmony_ci get_label_info(":${_main_target_name}", "label_with_toolchain") 375f9996aaSopenharmony_ci assert(_target_label != "") # Mark as used 385f9996aaSopenharmony_ci 395f9996aaSopenharmony_ci if (defined(invoker.subsystem_name) && defined(invoker.part_name)) { 405f9996aaSopenharmony_ci _subsystem_name = invoker.subsystem_name 415f9996aaSopenharmony_ci _part_name = invoker.part_name 425f9996aaSopenharmony_ci } else if (defined(invoker.part_name)) { 435f9996aaSopenharmony_ci _part_name = invoker.part_name 445f9996aaSopenharmony_ci _part_subsystem_info_file = 455f9996aaSopenharmony_ci "$root_build_dir/build_configs/parts_info/part_subsystem.json" 465f9996aaSopenharmony_ci _arguments = [ 475f9996aaSopenharmony_ci "--part-name", 485f9996aaSopenharmony_ci _part_name, 495f9996aaSopenharmony_ci "--part-subsystem-info-file", 505f9996aaSopenharmony_ci rebase_path(_part_subsystem_info_file, root_build_dir), 515f9996aaSopenharmony_ci ] 525f9996aaSopenharmony_ci get_subsystem_script = "//build/templates/common/get_subsystem_name.py" 535f9996aaSopenharmony_ci _subsystem_name = 545f9996aaSopenharmony_ci exec_script(get_subsystem_script, _arguments, "trim string") 555f9996aaSopenharmony_ci } else if (defined(invoker.subsystem_name)) { 565f9996aaSopenharmony_ci _subsystem_name = invoker.subsystem_name 575f9996aaSopenharmony_ci _part_name = _subsystem_name 585f9996aaSopenharmony_ci } else { 595f9996aaSopenharmony_ci _subsystem_name = "build" 605f9996aaSopenharmony_ci _part_name = "build_framework" 615f9996aaSopenharmony_ci } 625f9996aaSopenharmony_ci assert(_subsystem_name != "") # Mark as used 635f9996aaSopenharmony_ci assert(_part_name != "") # Mark as used 645f9996aaSopenharmony_ci 655f9996aaSopenharmony_ci _deps = [] 665f9996aaSopenharmony_ci if (defined(invoker.deps)) { 675f9996aaSopenharmony_ci _deps += invoker.deps 685f9996aaSopenharmony_ci } 695f9996aaSopenharmony_ci 705f9996aaSopenharmony_ci if (!_is_test_target) { 715f9996aaSopenharmony_ci module_label = get_label_info(":${target_name}", "label_with_toolchain") 725f9996aaSopenharmony_ci _collect_target = "${target_name}__collect" 735f9996aaSopenharmony_ci collect_module_target(_collect_target) { 745f9996aaSopenharmony_ci forward_variables_from(invoker, [ "install_images" ]) 755f9996aaSopenharmony_ci } 765f9996aaSopenharmony_ci _notice_target = "${_main_target_name}__notice" 775f9996aaSopenharmony_ci 785f9996aaSopenharmony_ci # Prebuilt target has some lexing error character 795f9996aaSopenharmony_ci _notice_target = string_replace(_notice_target, "@", "_") 805f9996aaSopenharmony_ci _notice_target = string_replace(_notice_target, "+", "_") 815f9996aaSopenharmony_ci collect_notice(_notice_target) { 825f9996aaSopenharmony_ci forward_variables_from(invoker, 835f9996aaSopenharmony_ci [ 845f9996aaSopenharmony_ci "testonly", 855f9996aaSopenharmony_ci "license_as_sources", 865f9996aaSopenharmony_ci "license_file", 875f9996aaSopenharmony_ci "sources", 885f9996aaSopenharmony_ci ]) 895f9996aaSopenharmony_ci source_list = sources 905f9996aaSopenharmony_ci module_name = _main_target_name 915f9996aaSopenharmony_ci module_source_dir = get_label_info(":${_main_target_name}", "dir") 925f9996aaSopenharmony_ci } 935f9996aaSopenharmony_ci _deps += [ 945f9996aaSopenharmony_ci ":$_notice_target", 955f9996aaSopenharmony_ci ":${_collect_target}", 965f9996aaSopenharmony_ci ] 975f9996aaSopenharmony_ci } 985f9996aaSopenharmony_ci 995f9996aaSopenharmony_ci if (!_bypass_module_info_generation) { 1005f9996aaSopenharmony_ci _module_info_target = "${_main_target_name}_info" 1015f9996aaSopenharmony_ci generate_module_info(_module_info_target) { 1025f9996aaSopenharmony_ci forward_variables_from(invoker, 1035f9996aaSopenharmony_ci [ 1045f9996aaSopenharmony_ci "module_install_dir", 1055f9996aaSopenharmony_ci "relative_install_dir", 1065f9996aaSopenharmony_ci "module_source_dir", 1075f9996aaSopenharmony_ci "module_install_name", 1085f9996aaSopenharmony_ci "module_type", 1095f9996aaSopenharmony_ci "install_enable", 1105f9996aaSopenharmony_ci ]) 1115f9996aaSopenharmony_ci module_name = _main_target_name 1125f9996aaSopenharmony_ci if (!defined(module_type)) { 1135f9996aaSopenharmony_ci module_type = "unknown" 1145f9996aaSopenharmony_ci } 1155f9996aaSopenharmony_ci if (!defined(module_source_dir)) { 1165f9996aaSopenharmony_ci module_source_dir = "${target_out_dir}" 1175f9996aaSopenharmony_ci } 1185f9996aaSopenharmony_ci 1195f9996aaSopenharmony_ci if (_is_prebuilt) { 1205f9996aaSopenharmony_ci _outputs = invoker.outputs 1215f9996aaSopenharmony_ci module_source = string_replace(_outputs[0], "${target_out_dir}/", "", 1) 1225f9996aaSopenharmony_ci } 1235f9996aaSopenharmony_ci prebuilt = _is_prebuilt 1245f9996aaSopenharmony_ci 1255f9996aaSopenharmony_ci if (!defined(install_enable)) { 1265f9996aaSopenharmony_ci install_enable = false 1275f9996aaSopenharmony_ci } 1285f9996aaSopenharmony_ci 1295f9996aaSopenharmony_ci part_name = _part_name 1305f9996aaSopenharmony_ci subsystem_name = _subsystem_name 1315f9996aaSopenharmony_ci 1325f9996aaSopenharmony_ci if (defined(invoker.symlink_path)) { 1335f9996aaSopenharmony_ci symlink_path = invoker.symlink_path 1345f9996aaSopenharmony_ci } 1355f9996aaSopenharmony_ci 1365f9996aaSopenharmony_ci module_install_images = [ "system" ] 1375f9996aaSopenharmony_ci if (defined(invoker.install_images)) { 1385f9996aaSopenharmony_ci module_install_images = [] 1395f9996aaSopenharmony_ci module_install_images += invoker.install_images 1405f9996aaSopenharmony_ci } 1415f9996aaSopenharmony_ci 1425f9996aaSopenharmony_ci if (defined(invoker.symlink_target_name)) { 1435f9996aaSopenharmony_ci symlink_target_name = invoker.symlink_target_name 1445f9996aaSopenharmony_ci } 1455f9996aaSopenharmony_ci 1465f9996aaSopenharmony_ci if (defined(invoker.innerapi_tags)) { 1475f9996aaSopenharmony_ci innerapi_tags = invoker.innerapi_tags 1485f9996aaSopenharmony_ci } 1495f9996aaSopenharmony_ci 1505f9996aaSopenharmony_ci if (defined(invoker.symlink_ext)) { 1515f9996aaSopenharmony_ci symlink_ext = invoker.symlink_ext 1525f9996aaSopenharmony_ci } 1535f9996aaSopenharmony_ci 1545f9996aaSopenharmony_ci notice = "$target_out_dir/$_main_target_name.notice.txt" 1555f9996aaSopenharmony_ci } 1565f9996aaSopenharmony_ci if (!skip_gen_module_info) { 1575f9996aaSopenharmony_ci _deps += [ ":$_module_info_target" ] 1585f9996aaSopenharmony_ci } 1595f9996aaSopenharmony_ci } 1605f9996aaSopenharmony_ci 1615f9996aaSopenharmony_ci if ((defined(invoker.enable_strip) && invoker.enable_strip) || 1625f9996aaSopenharmony_ci (defined(invoker.mini_debug) && invoker.mini_debug)) { 1635f9996aaSopenharmony_ci action_with_pydeps(target_name) { 1645f9996aaSopenharmony_ci forward_variables_from(invoker, 1655f9996aaSopenharmony_ci [ 1665f9996aaSopenharmony_ci "testonly", 1675f9996aaSopenharmony_ci "visibility", 1685f9996aaSopenharmony_ci "external_deps", 1695f9996aaSopenharmony_ci "public_external_deps", 1705f9996aaSopenharmony_ci "public_configs", 1715f9996aaSopenharmony_ci "sources", 1725f9996aaSopenharmony_ci "outputs", 1735f9996aaSopenharmony_ci ]) 1745f9996aaSopenharmony_ci deps = _deps 1755f9996aaSopenharmony_ci script = "//build/templates/common/delete_symbol.py" 1765f9996aaSopenharmony_ci mini_debug = "false" 1775f9996aaSopenharmony_ci if (defined(invoker.mini_debug) && invoker.mini_debug) { 1785f9996aaSopenharmony_ci mini_debug = "true" 1795f9996aaSopenharmony_ci } 1805f9996aaSopenharmony_ci args = [ 1815f9996aaSopenharmony_ci "--strip", 1825f9996aaSopenharmony_ci rebase_path("${clang_base_path}/bin/llvm-strip", root_build_dir), 1835f9996aaSopenharmony_ci "--input", 1845f9996aaSopenharmony_ci rebase_path(sources[0], root_build_dir), 1855f9996aaSopenharmony_ci "--output", 1865f9996aaSopenharmony_ci rebase_path(outputs[0], root_build_dir), 1875f9996aaSopenharmony_ci "--mini-debug", 1885f9996aaSopenharmony_ci mini_debug, 1895f9996aaSopenharmony_ci ] 1905f9996aaSopenharmony_ci 1915f9996aaSopenharmony_ci if (defined(visibility) && visibility != []) { 1925f9996aaSopenharmony_ci visibility += [ "//build/*" ] 1935f9996aaSopenharmony_ci if (defined(build_ext_path)) { 1945f9996aaSopenharmony_ci visibility += [ "${build_ext_path}/*" ] 1955f9996aaSopenharmony_ci } 1965f9996aaSopenharmony_ci } 1975f9996aaSopenharmony_ci 1985f9996aaSopenharmony_ci if (!_bypass_module_info_generation) { 1995f9996aaSopenharmony_ci _install_module_info = { 2005f9996aaSopenharmony_ci module_def = _target_label 2015f9996aaSopenharmony_ci module_info_file = 2025f9996aaSopenharmony_ci rebase_path(get_label_info(_target_label, "target_out_dir"), 2035f9996aaSopenharmony_ci root_build_dir) + 2045f9996aaSopenharmony_ci "/${_main_target_name}_module_info.json" 2055f9996aaSopenharmony_ci subsystem_name = _subsystem_name 2065f9996aaSopenharmony_ci part_name = _part_name 2075f9996aaSopenharmony_ci toolchain = current_toolchain 2085f9996aaSopenharmony_ci toolchain_out_dir = rebase_path(root_out_dir, root_build_dir) 2095f9996aaSopenharmony_ci } 2105f9996aaSopenharmony_ci 2115f9996aaSopenharmony_ci metadata = { 2125f9996aaSopenharmony_ci install_modules = [ _install_module_info ] 2135f9996aaSopenharmony_ci } 2145f9996aaSopenharmony_ci } 2155f9996aaSopenharmony_ci } 2165f9996aaSopenharmony_ci } else { 2175f9996aaSopenharmony_ci copy(target_name) { 2185f9996aaSopenharmony_ci forward_variables_from(invoker, 2195f9996aaSopenharmony_ci [ 2205f9996aaSopenharmony_ci "testonly", 2215f9996aaSopenharmony_ci "visibility", 2225f9996aaSopenharmony_ci "external_deps", 2235f9996aaSopenharmony_ci "public_external_deps", 2245f9996aaSopenharmony_ci "public_configs", 2255f9996aaSopenharmony_ci "sources", 2265f9996aaSopenharmony_ci "outputs", 2275f9996aaSopenharmony_ci ]) 2285f9996aaSopenharmony_ci deps = _deps 2295f9996aaSopenharmony_ci 2305f9996aaSopenharmony_ci if (defined(visibility) && visibility != []) { 2315f9996aaSopenharmony_ci visibility += [ "//build/*" ] 2325f9996aaSopenharmony_ci if (defined(build_ext_path)) { 2335f9996aaSopenharmony_ci visibility += [ "${build_ext_path}/*" ] 2345f9996aaSopenharmony_ci } 2355f9996aaSopenharmony_ci } 2365f9996aaSopenharmony_ci 2375f9996aaSopenharmony_ci if (!_bypass_module_info_generation) { 2385f9996aaSopenharmony_ci _install_module_info = { 2395f9996aaSopenharmony_ci module_def = _target_label 2405f9996aaSopenharmony_ci module_info_file = 2415f9996aaSopenharmony_ci rebase_path(get_label_info(_target_label, "target_out_dir"), 2425f9996aaSopenharmony_ci root_build_dir) + 2435f9996aaSopenharmony_ci "/${_main_target_name}_module_info.json" 2445f9996aaSopenharmony_ci subsystem_name = _subsystem_name 2455f9996aaSopenharmony_ci part_name = _part_name 2465f9996aaSopenharmony_ci toolchain = current_toolchain 2475f9996aaSopenharmony_ci toolchain_out_dir = rebase_path(root_out_dir, root_build_dir) 2485f9996aaSopenharmony_ci } 2495f9996aaSopenharmony_ci 2505f9996aaSopenharmony_ci metadata = { 2515f9996aaSopenharmony_ci install_modules = [ _install_module_info ] 2525f9996aaSopenharmony_ci } 2535f9996aaSopenharmony_ci } 2545f9996aaSopenharmony_ci } 2555f9996aaSopenharmony_ci } 2565f9996aaSopenharmony_ci} 257