# 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.. import("//build/ohos.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") hdf_fwk_path = "//drivers/hdf_core/framework" template("hdi") { assert(defined(invoker.sources), "sources are must") assert(defined(invoker.language), "language are must") assert(defined(invoker.subsystem_name), "subsystem_name are must") assert(defined(invoker.part_name), "part_name are must") mode = "ipc" if (defined(invoker.mode)) { assert(invoker.mode == "ipc" || invoker.mode == "passthrough", "hdi mode must be ipc or passthrough") mode = invoker.mode } root_package = "ohos.hdi" root_path = rebase_path("//drivers/interface") if (defined(invoker.root)) { package_path_map = string_split(invoker.root, ":") root_package = package_path_map[0] root_path = rebase_path(package_path_map[1]) } root_package_path = "${root_package}:${root_path}" sources_gen_dir = get_path_info("${root_path}/", "gen_dir") get_build_info_args = [ "-m", mode, "-l", invoker.language, "-o", sources_gen_dir, "-r", root_package_path, ] foreach(idl_file, invoker.sources) { get_build_info_args += [ "-f" ] get_build_info_args += [ rebase_path(idl_file) ] } hdi_build_info = exec_script("$hdf_fwk_path/tools/hdi-gen/build_hdi_files_info.py", get_build_info_args, "json") assert(defined(hdi_build_info.include_dirs), "missing include_dirs") assert(defined(hdi_build_info.out_dir), "out_dir") assert(defined(hdi_build_info.version), "missing version") assert(defined(hdi_build_info.sources), "missing sources") assert(defined(hdi_build_info.proxy_sources), "missing proxy_sources") assert(defined(hdi_build_info.stub_sources), "missing stub_sources") idl_headers_config = "$target_name" + "_idl_headers_config" config("$idl_headers_config") { include_dirs = [ "$hdf_uhdf_path/include/hdi", "$hdf_uhdf_path/osal/include", "$hdf_uhdf_path/ipc/include", "$hdf_framework_path/include/utils", ] include_dirs += hdi_build_info.include_dirs } action("hdi_gen") { deps = [ "$hdf_fwk_path/tools/hdi-gen:build_hdi_gen" ] script = "/usr/bin/env" if (defined(ohos_lite)) { script = "//build/lite/run_shell_cmd.py" } idl_sources = invoker.sources inputs = invoker.sources language = "--gen-" + invoker.language outputs = hdi_build_info.sources args = [ rebase_path(get_path_info("$hdf_fwk_path/tools/hdi-gen/", "out_dir") + "/hdi-gen"), "$language", "-d", rebase_path(hdi_build_info.out_dir), ] if (defined(invoker.module_name)) { args += [ "--module-name", invoker.module_name, ] } foreach(idl_file, idl_sources) { args += [ "-c" ] args += [ rebase_path(idl_file) ] } args += [ "-r", root_package_path, ] if (mode == "passthrough") { args += [ "--passthrough" ] } } lib_client = "lib" + target_name + "_proxy" + "_" + hdi_build_info.version ohos_shared_library(lib_client) { if (defined(invoker.sources)) { sources = hdi_build_info.proxy_sources public_configs = [ ":$idl_headers_config" ] deps = [ ":hdi_gen" ] if (is_standard_system) { if (defined(invoker.sequenceable)) { public_deps = invoker.sequenceable } external_deps = [ "c_utils:utils", "hdf_core:libhdi", "hiviewdfx_hilog_native:libhilog", ] if (invoker.language == "c") { external_deps += [ "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", ] } else if (invoker.language == "cpp") { external_deps += [ "ipc:ipc_single" ] } } else { external_deps = [ "hilog:libhilog" ] } install_images = [ system_base_dir ] subsystem_name = invoker.subsystem_name partname_list = string_split(invoker.part_name, "_") if (partname_list[0] == "drivers") { part_name = invoker.part_name } else { part_name = invoker.part_name + "_interface" } } } if (mode == "ipc") { lib_server = "lib" + target_name + "_stub" + "_" + hdi_build_info.version ohos_shared_library(lib_server) { if (defined(invoker.sources)) { sources = hdi_build_info.stub_sources public_configs = [ ":$idl_headers_config" ] deps = [ ":hdi_gen" ] if (is_standard_system) { if (defined(invoker.sequenceable)) { public_deps = invoker.sequenceable } external_deps = [ "c_utils:utils", "hdf_core:libhdi", "hiviewdfx_hilog_native:libhilog", ] if (invoker.language == "c") { external_deps += [ "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", ] } else if (invoker.language == "cpp") { external_deps += [ "ipc:ipc_single" ] } } else { external_deps = [ "hilog:libhilog" ] } install_images = [ chipset_base_dir ] subsystem_name = invoker.subsystem_name part_name = invoker.part_name } } } # generate code and shared library group("$target_name" + "_idl_target") { deps = [ ":$lib_client" ] if (mode == "ipc") { deps += [ ":$lib_server" ] } } # only generate code and provide header file path group("$target_name" + "_idl_headers") { public_configs = [ ":$idl_headers_config" ] deps = [ ":hdi_gen" ] } }