1# Copyright (c) 2021 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/templates/common/copy.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 "external_deps", 67 "public_external_deps", 68 "public_configs", 69 "subsystem_name", 70 "part_name", 71 72 # For generate_module_info 73 "install_images", 74 "module_install_dir", 75 "relative_install_dir", 76 "symlink_target_name", 77 78 # Open source license related 79 "license_file", 80 "license_as_sources", 81 ]) 82 sources = [ invoker.source ] 83 outputs = [ _copy_output ] 84 module_type = "bin" 85 prebuilt = true 86 install_enable = false 87 enable_strip = false 88 if (defined(invoker.enable_strip) && invoker.enable_strip) { 89 enable_strip = true 90 } 91 if (defined(invoker.install_enable)) { 92 install_enable = invoker.install_enable 93 } 94 } 95} 96 97template("ohos_prebuilt_shared_library") { 98 assert(defined(invoker.source), "source must be defined for ${target_name}.") 99 100 if (defined(invoker.output)) { 101 _copy_output = "${target_out_dir}/${invoker.output}" 102 } else { 103 _copy_output = "${target_out_dir}/${invoker.source}" 104 } 105 config("${target_name}__config") { 106 libs = [ _copy_output ] 107 } 108 109 if (!defined(invoker.deps)) { 110 invoker.deps = [] 111 } 112 113 if (!defined(invoker.stable)) { 114 invoker.stable = false 115 } 116 117 # auto set auto_relative_install_dir by innerapi_tags 118 if (defined(invoker.innerapi_tags)) { 119 is_chipsetsdk = false 120 is_platformsdk = false 121 is_passthrough = false 122 foreach(tag, filter_include(invoker.innerapi_tags, [ "chipsetsdk*" ])) { 123 is_chipsetsdk = true 124 } 125 foreach(tag, filter_include(invoker.innerapi_tags, [ "platformsdk*" ])) { 126 is_platformsdk = true 127 } 128 foreach(tag, filter_include(invoker.innerapi_tags, [ "passthrough*" ])) { 129 is_passthrough = true 130 } 131 132 if (is_chipsetsdk && is_platformsdk) { 133 auto_relative_install_dir = "chipset-pub-sdk" 134 } else if (is_chipsetsdk) { 135 auto_relative_install_dir = "chipset-sdk" 136 } else if (is_platformsdk) { 137 auto_relative_install_dir = "platformsdk" 138 } 139 if (is_passthrough) { 140 auto_relative_install_dir = chipset_passthrough_dir 141 } 142 143 is_ndk = false 144 foreach(tag, filter_include(invoker.innerapi_tags, [ "ndk" ])) { 145 is_ndk = true 146 } 147 if (is_ndk) { 148 auto_relative_install_dir = "ndk" 149 } 150 } 151 152 deps_info = [] 153 foreach(dep, invoker.deps) { 154 info = { 155 } 156 info = { 157 target_out_dir = 158 rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir) 159 target_name = get_label_info(dep, "name") 160 } 161 deps_info += [ info ] 162 } 163 module_label = get_label_info(":${target_name}", "label_with_toolchain") 164 target_deps_data = { 165 label = module_label 166 module_deps_info = deps_info 167 type = "shared_library" 168 prebuilt = true 169 stable = invoker.stable 170 toolchain = get_label_info(":${target_name}", "toolchain") 171 source_path = rebase_path(invoker.source, root_build_dir) 172 output_path = rebase_path(_copy_output, root_build_dir) 173 } 174 write_file("${target_out_dir}/${target_name}_deps_data.json", 175 target_deps_data, 176 "json") 177 178 ohos_copy(target_name) { 179 forward_variables_from(invoker, 180 [ 181 "testonly", 182 "visibility", 183 184 "deps", 185 "external_deps", 186 "public_external_deps", 187 "public_configs", 188 "subsystem_name", 189 "part_name", 190 191 # For generate_module_info 192 "install_images", 193 "module_install_dir", 194 "symlink_target_name", 195 "innerapi_tags", 196 "symlink_ext", 197 198 # Open source license related 199 "license_file", 200 "license_as_sources", 201 ]) 202 sources = [ invoker.source ] 203 outputs = [ _copy_output ] 204 module_type = "lib" 205 prebuilt = true 206 install_enable = true 207 enable_strip = false 208 if (defined(invoker.enable_strip) && invoker.enable_strip) { 209 enable_strip = true 210 } 211 mini_debug = false 212 if (defined(invoker.mini_debug) && invoker.mini_debug) { 213 mini_debug = true 214 } 215 if (defined(invoker.install_enable)) { 216 install_enable = invoker.install_enable 217 } 218 219 # update relative_install_dir if auto_relative_install_dir defined 220 if (defined(auto_relative_install_dir)) { 221 relative_install_dir = auto_relative_install_dir 222 } 223 if (defined(invoker.relative_install_dir)) { 224 relative_install_dir = invoker.relative_install_dir 225 } 226 if (!defined(public_configs)) { 227 public_configs = [] 228 } 229 public_configs += [ ":${target_name}__config" ] 230 } 231} 232 233template("ohos_prebuilt_static_library") { 234 assert(defined(invoker.source), "source must be defined for ${target_name}.") 235 236 if (defined(invoker.output)) { 237 _copy_output = "${target_out_dir}/${invoker.output}" 238 } else { 239 _copy_output = "${target_out_dir}/${invoker.source}" 240 } 241 config("${target_name}__config") { 242 libs = [ _copy_output ] 243 } 244 ohos_copy(target_name) { 245 forward_variables_from(invoker, 246 [ 247 "testonly", 248 "visibility", 249 250 "deps", 251 "external_deps", 252 "public_external_deps", 253 "public_configs", 254 "subsystem_name", 255 "part_name", 256 257 # Open source license related 258 "license_file", 259 "license_as_sources", 260 ]) 261 sources = [ invoker.source ] 262 outputs = [ _copy_output ] 263 bypass_module_info_generation = true 264 if (!defined(public_configs)) { 265 public_configs = [] 266 } 267 public_configs += [ ":${target_name}__config" ] 268 } 269} 270 271template("ohos_prebuilt_etc") { 272 assert(defined(invoker.source), "source must be defined for ${target_name}.") 273 274 if (defined(invoker.output)) { 275 _copy_output = "${target_out_dir}/${invoker.output}" 276 } else { 277 _copy_output = "${target_out_dir}/${invoker.source}" 278 } 279 280 source_path = rebase_path(invoker.source, root_build_dir) 281 module_label = get_label_info(":${target_name}", "label_with_toolchain") 282 target_deps_data = { 283 label = module_label 284 type = "etc" 285 prebuilt = true 286 source_path = source_path 287 output_path = rebase_path(_copy_output, root_build_dir) 288 } 289 write_file("${target_out_dir}/${target_name}_deps_data.json", 290 target_deps_data, 291 "json") 292 293 ohos_copy(target_name) { 294 forward_variables_from(invoker, 295 [ 296 "testonly", 297 "visibility", 298 299 "deps", 300 "external_deps", 301 "public_external_deps", 302 "public_configs", 303 "subsystem_name", 304 "part_name", 305 306 # For generate_module_info 307 "install_images", 308 "module_install_dir", 309 "relative_install_dir", 310 "symlink_target_name", 311 312 # Open source license related 313 "license_file", 314 "license_as_sources", 315 ]) 316 sources = [ invoker.source ] 317 outputs = [ _copy_output ] 318 module_type = "etc" 319 prebuilt = true 320 install_enable = true 321 if (defined(invoker.install_enable)) { 322 install_enable = invoker.install_enable 323 } 324 if (defined(invoker.symlink_path)) { 325 symlink_path = invoker.symlink_path 326 } 327 } 328} 329