15f9996aaSopenharmony_ci# Copyright (c) 2020 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/lite/config/subsystem/aafwk/path.gni") 155f9996aaSopenharmony_ci 165f9996aaSopenharmony_citemplate("lite_library") { 175f9996aaSopenharmony_ci assert(defined(invoker.target_type), "Library target_type is required.") 185f9996aaSopenharmony_ci assert(defined(invoker.sources), "Library sources is required.") 195f9996aaSopenharmony_ci target_type = invoker.target_type 205f9996aaSopenharmony_ci shared_lib = target_type == "shared_library" 215f9996aaSopenharmony_ci 225f9996aaSopenharmony_ci if (shared_lib && 235f9996aaSopenharmony_ci (ohos_kernel_type == "liteos_m" || ohos_kernel_type == "uniproton")) { 245f9996aaSopenharmony_ci group(target_name) { 255f9996aaSopenharmony_ci if (defined(invoker.sources)) { 265f9996aaSopenharmony_ci assert(invoker.sources != "") 275f9996aaSopenharmony_ci } 285f9996aaSopenharmony_ci if (defined(invoker.public_configs)) { 295f9996aaSopenharmony_ci assert(invoker.public_configs != "") 305f9996aaSopenharmony_ci } 315f9996aaSopenharmony_ci if (defined(invoker.public_deps)) { 325f9996aaSopenharmony_ci assert(invoker.public_deps != "") 335f9996aaSopenharmony_ci } 345f9996aaSopenharmony_ci if (defined(invoker.output_name)) { 355f9996aaSopenharmony_ci assert(invoker.output_name != "") 365f9996aaSopenharmony_ci } 375f9996aaSopenharmony_ci } 385f9996aaSopenharmony_ci } else { 395f9996aaSopenharmony_ci target(target_type, target_name) { 405f9996aaSopenharmony_ci forward_variables_from(invoker, "*", [ "remove_configs" ]) 415f9996aaSopenharmony_ci cflags = [] 425f9996aaSopenharmony_ci cflags_cc = [] 435f9996aaSopenharmony_ci ldflags = [] 445f9996aaSopenharmony_ci if (defined(invoker.cflags)) { 455f9996aaSopenharmony_ci cflags += invoker.cflags 465f9996aaSopenharmony_ci } 475f9996aaSopenharmony_ci if (defined(invoker.cflags_cc)) { 485f9996aaSopenharmony_ci cflags_cc += invoker.cflags_cc 495f9996aaSopenharmony_ci ldflags += [ "-lstdc++" ] 505f9996aaSopenharmony_ci } 515f9996aaSopenharmony_ci if (defined(invoker.ldflags)) { 525f9996aaSopenharmony_ci ldflags += invoker.ldflags 535f9996aaSopenharmony_ci } 545f9996aaSopenharmony_ci if (defined(invoker.remove_configs)) { 555f9996aaSopenharmony_ci configs -= invoker.remove_configs 565f9996aaSopenharmony_ci } 575f9996aaSopenharmony_ci shared_lib = target_type == "shared_library" 585f9996aaSopenharmony_ci if (shared_lib) { 595f9996aaSopenharmony_ci cflags += [ "-fPIC" ] 605f9996aaSopenharmony_ci cflags_cc += [ "-fPIC" ] 615f9996aaSopenharmony_ci } else if (!shared_lib && (ohos_kernel_type != "liteos_m" && 625f9996aaSopenharmony_ci ohos_kernel_type != "uniproton")) { 635f9996aaSopenharmony_ci cflags += [ "-fPIE" ] 645f9996aaSopenharmony_ci cflags_cc += [ "-fPIE" ] 655f9996aaSopenharmony_ci } 665f9996aaSopenharmony_ci } 675f9996aaSopenharmony_ci } 685f9996aaSopenharmony_ci} 695f9996aaSopenharmony_ci 705f9996aaSopenharmony_ci# Defines a component 715f9996aaSopenharmony_ci# 725f9996aaSopenharmony_ci# The lite_component template defines all the modules contained in a subsystem 735f9996aaSopenharmony_ci# 745f9996aaSopenharmony_ci# Parameters 755f9996aaSopenharmony_ci# 765f9996aaSopenharmony_ci# features (required) 775f9996aaSopenharmony_ci# [list of scopes] Defines all features in the component. 785f9996aaSopenharmony_citemplate("lite_component") { 795f9996aaSopenharmony_ci assert(defined(invoker.features), "Component features is required.") 805f9996aaSopenharmony_ci 815f9996aaSopenharmony_ci if (!defined(invoker.target_type)) { 825f9996aaSopenharmony_ci target_type = "group" 835f9996aaSopenharmony_ci } else if (invoker.target_type == "static_library") { 845f9996aaSopenharmony_ci target_type = "group" 855f9996aaSopenharmony_ci } else { 865f9996aaSopenharmony_ci target_type = invoker.target_type 875f9996aaSopenharmony_ci } 885f9996aaSopenharmony_ci assert(target_type != "") 895f9996aaSopenharmony_ci 905f9996aaSopenharmony_ci target(target_type, target_name) { 915f9996aaSopenharmony_ci deps = [] 925f9996aaSopenharmony_ci 935f9996aaSopenharmony_ci forward_variables_from(invoker, "*") 945f9996aaSopenharmony_ci 955f9996aaSopenharmony_ci # add component deps 965f9996aaSopenharmony_ci if (defined(invoker.deps)) { 975f9996aaSopenharmony_ci deps += invoker.deps 985f9996aaSopenharmony_ci } 995f9996aaSopenharmony_ci 1005f9996aaSopenharmony_ci # add component features 1015f9996aaSopenharmony_ci foreach(feature_label, features) { 1025f9996aaSopenharmony_ci deps += [ feature_label ] 1035f9996aaSopenharmony_ci } 1045f9996aaSopenharmony_ci } 1055f9996aaSopenharmony_ci} 1065f9996aaSopenharmony_ci 1075f9996aaSopenharmony_citemplate("build_ext_component") { 1085f9996aaSopenharmony_ci forward_variables_from(invoker, [ "testonly" ]) 1095f9996aaSopenharmony_ci if (defined(invoker.version)) { 1105f9996aaSopenharmony_ci print(invoker.version) 1115f9996aaSopenharmony_ci } 1125f9996aaSopenharmony_ci action(target_name) { 1135f9996aaSopenharmony_ci forward_variables_from(invoker, 1145f9996aaSopenharmony_ci [ 1155f9996aaSopenharmony_ci "no_default_deps", 1165f9996aaSopenharmony_ci "deps", 1175f9996aaSopenharmony_ci ]) 1185f9996aaSopenharmony_ci args = [] 1195f9996aaSopenharmony_ci if (defined(invoker.exec_path)) { 1205f9996aaSopenharmony_ci args += [ "--path=${invoker.exec_path}" ] 1215f9996aaSopenharmony_ci } 1225f9996aaSopenharmony_ci if (defined(invoker.enable)) { 1235f9996aaSopenharmony_ci args += [ "--enable=${invoker.enable}" ] 1245f9996aaSopenharmony_ci } 1255f9996aaSopenharmony_ci if (defined(invoker.prebuilts)) { 1265f9996aaSopenharmony_ci args += [ "--prebuilts=${invoker.prebuilts}" ] 1275f9996aaSopenharmony_ci } 1285f9996aaSopenharmony_ci if (defined(invoker.command)) { 1295f9996aaSopenharmony_ci args += [ "--command=${invoker.command}" ] 1305f9996aaSopenharmony_ci } 1315f9996aaSopenharmony_ci 1325f9996aaSopenharmony_ci # external component build log 1335f9996aaSopenharmony_ci target_dir = rebase_path("${target_out_dir}/build.log") 1345f9996aaSopenharmony_ci args += [ "--target_dir=${target_dir}" ] 1355f9996aaSopenharmony_ci 1365f9996aaSopenharmony_ci # external component error log if compile failed 1375f9996aaSopenharmony_ci out_dir = rebase_path("${root_out_dir}/error.log") 1385f9996aaSopenharmony_ci args += [ "--out_dir=${out_dir}" ] 1395f9996aaSopenharmony_ci script = "//build/lite/build_ext_components.py" 1405f9996aaSopenharmony_ci outputs = [ "$target_out_dir/${target_name}_build_ext_components.txt" ] 1415f9996aaSopenharmony_ci if (defined(invoker.outputs)) { 1425f9996aaSopenharmony_ci outputs += invoker.outputs 1435f9996aaSopenharmony_ci } 1445f9996aaSopenharmony_ci } 1455f9996aaSopenharmony_ci} 1465f9996aaSopenharmony_ci 1475f9996aaSopenharmony_citemplate("ohos_tools") { 1485f9996aaSopenharmony_ci target(invoker.target_type, target_name) { 1495f9996aaSopenharmony_ci forward_variables_from(invoker, "*") 1505f9996aaSopenharmony_ci output_dir = "$root_out_dir/tools/$target_name" 1515f9996aaSopenharmony_ci if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") { 1525f9996aaSopenharmony_ci configs -= [ "//build/lite/config:ohos" ] 1535f9996aaSopenharmony_ci } else if (ohos_kernel_type == "liteos_m") { 1545f9996aaSopenharmony_ci configs -= [ "//build/lite/config:liteos" ] 1555f9996aaSopenharmony_ci } 1565f9996aaSopenharmony_ci configs -= [ "//build/lite/config:pie_executable_config" ] 1575f9996aaSopenharmony_ci configs -= [ "//build/lite/config:static_pie_config" ] 1585f9996aaSopenharmony_ci configs += [ "//build/lite/config:tools" ] 1595f9996aaSopenharmony_ci } 1605f9996aaSopenharmony_ci} 1615f9996aaSopenharmony_ci 1625f9996aaSopenharmony_citemplate("generate_notice_file") { 1635f9996aaSopenharmony_ci assert(defined(invoker.module_name), "module_name in required.") 1645f9996aaSopenharmony_ci assert(defined(invoker.module_source_dir_list), 1655f9996aaSopenharmony_ci "module_source_dir_list in required.") 1665f9996aaSopenharmony_ci assert(target_name != "") 1675f9996aaSopenharmony_ci forward_variables_from(invoker, 1685f9996aaSopenharmony_ci [ 1695f9996aaSopenharmony_ci "module_name", 1705f9996aaSopenharmony_ci "module_source_dir_list", 1715f9996aaSopenharmony_ci ]) 1725f9996aaSopenharmony_ci gen_script = rebase_path("//build/lite/gen_module_notice_file.py") 1735f9996aaSopenharmony_ci 1745f9996aaSopenharmony_ci foreach(module_source_dir, module_source_dir_list) { 1755f9996aaSopenharmony_ci arguments = [] 1765f9996aaSopenharmony_ci arguments = [ 1775f9996aaSopenharmony_ci "--root-out-dir", 1785f9996aaSopenharmony_ci rebase_path(root_out_dir), 1795f9996aaSopenharmony_ci "--module-source-dir", 1805f9996aaSopenharmony_ci rebase_path(module_source_dir), 1815f9996aaSopenharmony_ci "--module-relative-source-dir", 1825f9996aaSopenharmony_ci rebase_path(module_source_dir, "//"), 1835f9996aaSopenharmony_ci "--target-name", 1845f9996aaSopenharmony_ci module_name, 1855f9996aaSopenharmony_ci ] 1865f9996aaSopenharmony_ci ret_msg = "" 1875f9996aaSopenharmony_ci ret_msg = exec_script(gen_script, arguments, "list lines") 1885f9996aaSopenharmony_ci if (ret_msg != "") { 1895f9996aaSopenharmony_ci foreach(msg, ret_msg) { 1905f9996aaSopenharmony_ci print(msg) 1915f9996aaSopenharmony_ci } 1925f9996aaSopenharmony_ci } 1935f9996aaSopenharmony_ci } 1945f9996aaSopenharmony_ci} 195