1# Copyright (C) 2021-2023 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import("$build_root/templates/cxx/cxx.gni") 15 16template("ohos_prebuilt_executable") { 17 assert(defined(invoker.source), "source must be defined for ${target_name}.") 18 19 if (defined(invoker.output)) { 20 _copy_output = "${target_out_dir}/${invoker.output}" 21 } else { 22 _copy_output = "${target_out_dir}/${invoker.source}" 23 } 24 25 if (!defined(invoker.deps)) { 26 invoker.deps = [] 27 } 28 29 if (!defined(invoker.stable)) { 30 invoker.stable = false 31 } 32 33 deps_info = [] 34 foreach(dep, invoker.deps) { 35 info = { 36 } 37 info = { 38 target_out_dir = 39 rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir) 40 target_name = get_label_info(dep, "name") 41 } 42 deps_info += [ info ] 43 } 44 module_label = get_label_info(":${target_name}", "label_with_toolchain") 45 target_deps_data = { 46 label = module_label 47 module_deps_info = deps_info 48 type = "executable" 49 prebuilt = true 50 stable = invoker.stable 51 toolchain = get_label_info(":${target_name}", "toolchain") 52 source_path = rebase_path(invoker.source, root_build_dir) 53 output_path = rebase_path(_copy_output, root_build_dir) 54 } 55 write_file("${target_out_dir}/${target_name}_deps_data.json", 56 target_deps_data, 57 "json") 58 59 ohos_copy(target_name) { 60 forward_variables_from(invoker, 61 [ 62 "testonly", 63 "visibility", 64 65 "deps", 66 "public_configs", 67 "subsystem_name", 68 "part_name", 69 70 # For generate_module_info 71 "install_images", 72 "module_install_dir", 73 "relative_install_dir", 74 "symlink_target_name", 75 76 # Open source license related 77 "license_file", 78 "license_as_sources", 79 ]) 80 sources = [ invoker.source ] 81 outputs = [ _copy_output ] 82 } 83} 84 85template("ohos_prebuilt_shared_library") { 86 assert(defined(invoker.source), "source must be defined for ${target_name}.") 87 88 if (defined(invoker.output)) { 89 _copy_output = "${target_out_dir}/${invoker.output}" 90 } else { 91 _copy_output = "${target_out_dir}/${invoker.source}" 92 } 93 config("${target_name}__config") { 94 libs = [ _copy_output ] 95 } 96 97 if (!defined(invoker.deps)) { 98 invoker.deps = [] 99 } 100 101 if (!defined(invoker.stable)) { 102 invoker.stable = false 103 } 104 105 deps_info = [] 106 foreach(dep, invoker.deps) { 107 info = { 108 } 109 info = { 110 target_out_dir = 111 rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir) 112 target_name = get_label_info(dep, "name") 113 } 114 deps_info += [ info ] 115 } 116 module_label = get_label_info(":${target_name}", "label_with_toolchain") 117 target_deps_data = { 118 label = module_label 119 module_deps_info = deps_info 120 type = "shared_library" 121 prebuilt = true 122 stable = invoker.stable 123 toolchain = get_label_info(":${target_name}", "toolchain") 124 source_path = rebase_path(invoker.source, root_build_dir) 125 output_path = rebase_path(_copy_output, root_build_dir) 126 } 127 write_file("${target_out_dir}/${target_name}_deps_data.json", 128 target_deps_data, 129 "json") 130 131 ohos_copy(target_name) { 132 forward_variables_from(invoker, 133 [ 134 "testonly", 135 "visibility", 136 137 "deps", 138 "public_configs", 139 "subsystem_name", 140 "part_name", 141 142 # For generate_module_info 143 "install_images", 144 "module_install_dir", 145 "relative_install_dir", 146 "symlink_target_name", 147 148 # Open source license related 149 "license_file", 150 "license_as_sources", 151 ]) 152 sources = [ invoker.source ] 153 outputs = [ _copy_output ] 154 if (!defined(public_configs)) { 155 public_configs = [] 156 } 157 public_configs += [ ":${target_name}__config" ] 158 } 159} 160 161template("ohos_prebuilt_static_library") { 162 assert(defined(invoker.source), "source must be defined for ${target_name}.") 163 164 if (defined(invoker.output)) { 165 _copy_output = "${target_out_dir}/${invoker.output}" 166 } else { 167 _copy_output = "${target_out_dir}/${invoker.source}" 168 } 169 config("${target_name}__config") { 170 libs = [ _copy_output ] 171 } 172 173 ohos_copy(target_name) { 174 forward_variables_from(invoker, 175 [ 176 "testonly", 177 "visibility", 178 179 "deps", 180 "public_configs", 181 "subsystem_name", 182 "part_name", 183 184 # Open source license related 185 "license_file", 186 "license_as_sources", 187 ]) 188 sources = [ invoker.source ] 189 outputs = [ _copy_output ] 190 if (!defined(public_configs)) { 191 public_configs = [] 192 } 193 public_configs += [ ":${target_name}__config" ] 194 } 195} 196 197template("ohos_prebuilt_etc") { 198 assert(defined(invoker.source), "source must be defined for ${target_name}.") 199 200 if (defined(invoker.output)) { 201 _copy_output = "${target_out_dir}/${invoker.output}" 202 } else { 203 _copy_output = "${target_out_dir}/${invoker.source}" 204 } 205 206 module_label = get_label_info(":${target_name}", "label_with_toolchain") 207 target_deps_data = { 208 label = module_label 209 type = "etc" 210 prebuilt = true 211 source_path = rebase_path(invoker.source, root_build_dir) 212 output_path = rebase_path(_copy_output, root_build_dir) 213 } 214 write_file("${target_out_dir}/${target_name}_deps_data.json", 215 target_deps_data, 216 "json") 217 218 ohos_copy(target_name) { 219 forward_variables_from(invoker, 220 [ 221 "testonly", 222 "visibility", 223 224 "deps", 225 "public_configs", 226 "subsystem_name", 227 "part_name", 228 229 # For generate_module_info 230 "install_images", 231 "module_install_dir", 232 "relative_install_dir", 233 "symlink_target_name", 234 235 # Open source license related 236 "license_file", 237 "license_as_sources", 238 ]) 239 sources = [ invoker.source ] 240 outputs = [ _copy_output ] 241 } 242} 243