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_platformsdk_indirect = false 122 is_passthrough = false 123 is_passthrough_indirect = false 124 is_llndk = false 125 is_chipsetsdk_indirect = false 126 is_chipsetsdk_sp = false 127 is_chipsetsdk_sp_indirect = false 128 129 foreach(tag, filter_include(invoker.innerapi_tags, [ "llndk" ])) { 130 is_llndk = true 131 } 132 foreach(tag, filter_include(invoker.innerapi_tags, [ "chipsetsdk" ])) { 133 is_chipsetsdk = true 134 } 135 foreach(tag, 136 filter_include(invoker.innerapi_tags, [ "chipsetsdk_indirect" ])) { 137 is_chipsetsdk_indirect = true 138 } 139 foreach(tag, filter_include(invoker.innerapi_tags, [ "chipsetsdk_sp" ])) { 140 is_chipsetsdk_sp = true 141 } 142 foreach( 143 tag, 144 filter_include(invoker.innerapi_tags, [ "chipsetsdk_sp_indirect" ])) { 145 is_chipsetsdk_sp_indirect = true 146 } 147 foreach(tag, filter_include(invoker.innerapi_tags, [ "platformsdk" ])) { 148 is_platformsdk = true 149 } 150 foreach(tag, 151 filter_include(invoker.innerapi_tags, [ "platformsdk_indirect" ])) { 152 is_platformsdk_indirect = true 153 } 154 foreach(tag, filter_include(invoker.innerapi_tags, [ "passthrough" ])) { 155 is_passthrough = true 156 } 157 foreach(tag, 158 filter_include(invoker.innerapi_tags, [ "passthrough_indirect" ])) { 159 is_passthrough_indirect = true 160 } 161 162 if (is_chipsetsdk && (is_chipsetsdk_indirect || is_chipsetsdk_sp || is_chipsetsdk_sp_indirect)) { 163 assert(false, "chipsetsdk tags cannot coexist with [chipsetsdk_indirect,chipsetsdk_sp,chipsetsdk_sp_indirect]") 164 } else if (is_chipsetsdk_indirect && (is_chipsetsdk || is_chipsetsdk_sp || is_chipsetsdk_sp_indirect)) { 165 assert(false, "chipsetsdk_indirect tags cannot coexist with [chipsetsdk,chipsetsdk_sp,chipsetsdk_sp_indirect]") 166 } else if (is_chipsetsdk_sp && (is_chipsetsdk || is_chipsetsdk_indirect || is_chipsetsdk_sp_indirect)) { 167 assert(false, "chipsetsdk_sp tags cannot coexist with [chipsetsdk,chipsetsdk_indirect,chipsetsdk_sp_indirect]") 168 } else if (is_chipsetsdk_sp_indirect && (is_chipsetsdk || is_chipsetsdk_sp || is_chipsetsdk_indirect)) { 169 assert(false, "chipsetsdk_sp_indirect tags cannot coexist with [chipsetsdk,chipsetsdk_indirect,chipsetsdk_sp]") 170 } 171 172 if (is_platformsdk) { 173 auto_relative_install_dir = platformsdk_dir 174 } 175 176 if (is_platformsdk_indirect) { 177 auto_relative_install_dir = platformsdk_dir 178 } 179 180 if (is_chipsetsdk) { 181 auto_relative_install_dir = chipset_sdk_dir 182 if (is_platformsdk || is_platformsdk_indirect) { 183 softlink_path = platformsdk_dir 184 } 185 } 186 187 if (is_chipsetsdk_indirect) { 188 auto_relative_install_dir = chipset_sdk_dir 189 if (is_platformsdk || is_platformsdk_indirect) { 190 softlink_path = platformsdk_dir 191 } 192 } 193 194 if (is_chipsetsdk_sp) { 195 auto_relative_install_dir = chipset_sdk_sp_dir 196 if (is_platformsdk || is_platformsdk_indirect) { 197 softlink_path = platformsdk_dir 198 } 199 } 200 201 if (is_chipsetsdk_sp_indirect) { 202 auto_relative_install_dir = chipset_sdk_sp_dir 203 if (is_platformsdk || is_platformsdk_indirect) { 204 softlink_path = platformsdk_dir 205 } 206 } 207 208 if (is_passthrough) { 209 auto_relative_install_dir = passthrough_dir 210 } 211 if (is_passthrough_indirect) { 212 auto_relative_install_dir = passthrough_indirect_dir 213 } 214 215 if (is_llndk) { 216 auto_relative_install_dir = llndk_dir 217 } 218 is_ndk = false 219 foreach(tag, filter_include(invoker.innerapi_tags, [ "ndk" ])) { 220 is_ndk = true 221 } 222 if (is_ndk) { 223 if (is_llndk) { 224 softlink_path = ndk_dir 225 auto_relative_install_dir = llndk_dir 226 } else { 227 auto_relative_install_dir = ndk_dir 228 } 229 } 230 } 231 232 deps_info = [] 233 foreach(dep, invoker.deps) { 234 info = { 235 } 236 info = { 237 target_out_dir = 238 rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir) 239 target_name = get_label_info(dep, "name") 240 } 241 deps_info += [ info ] 242 } 243 module_label = get_label_info(":${target_name}", "label_with_toolchain") 244 target_deps_data = { 245 label = module_label 246 module_deps_info = deps_info 247 type = "shared_library" 248 prebuilt = true 249 stable = invoker.stable 250 toolchain = get_label_info(":${target_name}", "toolchain") 251 source_path = rebase_path(invoker.source, root_build_dir) 252 output_path = rebase_path(_copy_output, root_build_dir) 253 } 254 write_file("${target_out_dir}/${target_name}_deps_data.json", 255 target_deps_data, 256 "json") 257 258 ohos_copy(target_name) { 259 forward_variables_from(invoker, 260 [ 261 "testonly", 262 "visibility", 263 264 "deps", 265 "external_deps", 266 "public_external_deps", 267 "public_configs", 268 "subsystem_name", 269 "part_name", 270 271 # For generate_module_info 272 "install_images", 273 "module_install_dir", 274 "symlink_target_name", 275 "innerapi_tags", 276 "symlink_ext", 277 278 # Open source license related 279 "license_file", 280 "license_as_sources", 281 ]) 282 sources = [ invoker.source ] 283 outputs = [ _copy_output ] 284 module_type = "lib" 285 prebuilt = true 286 install_enable = true 287 enable_strip = false 288 if (defined(invoker.enable_strip) && invoker.enable_strip) { 289 enable_strip = true 290 } 291 292 if (!defined(invoker.copy_linkable_file) && !enable_strip) { 293 copy_linkable_file = true 294 } 295 mini_debug = false 296 if (defined(invoker.mini_debug) && invoker.mini_debug) { 297 mini_debug = true 298 } 299 if (defined(invoker.install_enable)) { 300 install_enable = invoker.install_enable 301 } 302 303 # update relative_install_dir if auto_relative_install_dir defined 304 if (defined(auto_relative_install_dir)) { 305 relative_install_dir = auto_relative_install_dir 306 } 307 if (defined(invoker.relative_install_dir)) { 308 relative_install_dir = invoker.relative_install_dir 309 } 310 311 if (defined(invoker.innerapi_tags)) { 312 if (defined(softlink_path) && softlink_path != "") { 313 softlink_create_path = softlink_path 314 } 315 } 316 if (!defined(public_configs)) { 317 public_configs = [] 318 } 319 public_configs += [ ":${target_name}__config" ] 320 } 321} 322 323template("ohos_prebuilt_static_library") { 324 assert(defined(invoker.source), "source must be defined for ${target_name}.") 325 326 if (defined(invoker.output)) { 327 _copy_output = "${target_out_dir}/${invoker.output}" 328 } else { 329 _copy_output = "${target_out_dir}/${invoker.source}" 330 } 331 config("${target_name}__config") { 332 libs = [ _copy_output ] 333 } 334 ohos_copy(target_name) { 335 forward_variables_from(invoker, 336 [ 337 "testonly", 338 "visibility", 339 "deps", 340 "public_deps", 341 "external_deps", 342 "public_external_deps", 343 "public_configs", 344 "subsystem_name", 345 "part_name", 346 "copy_linkable_file", 347 348 # Open source license related 349 "license_file", 350 "license_as_sources", 351 ]) 352 sources = [ invoker.source ] 353 outputs = [ _copy_output ] 354 bypass_module_info_generation = true 355 if (!defined(public_configs)) { 356 public_configs = [] 357 } 358 public_configs += [ ":${target_name}__config" ] 359 } 360} 361 362template("ohos_prebuilt_etc") { 363 assert(defined(invoker.source), "source must be defined for ${target_name}.") 364 365 if (defined(invoker.output)) { 366 _copy_output = "${target_out_dir}/${invoker.output}" 367 } else { 368 _copy_output = "${target_out_dir}/${invoker.source}" 369 } 370 371 source_path = rebase_path(invoker.source, root_build_dir) 372 module_label = get_label_info(":${target_name}", "label_with_toolchain") 373 target_deps_data = { 374 label = module_label 375 type = "etc" 376 prebuilt = true 377 source_path = source_path 378 output_path = rebase_path(_copy_output, root_build_dir) 379 } 380 write_file("${target_out_dir}/${target_name}_deps_data.json", 381 target_deps_data, 382 "json") 383 384 ohos_copy(target_name) { 385 forward_variables_from(invoker, 386 [ 387 "testonly", 388 "visibility", 389 390 "deps", 391 "external_deps", 392 "public_external_deps", 393 "public_configs", 394 "subsystem_name", 395 "part_name", 396 397 # For generate_module_info 398 "install_images", 399 "module_install_dir", 400 "relative_install_dir", 401 "symlink_target_name", 402 "copy_linkable_file", 403 404 # Open source license related 405 "license_file", 406 "license_as_sources", 407 ]) 408 sources = [ invoker.source ] 409 outputs = [ _copy_output ] 410 module_type = "etc" 411 prebuilt = true 412 install_enable = true 413 if (defined(invoker.install_enable)) { 414 install_enable = invoker.install_enable 415 } 416 if (defined(invoker.symlink_path)) { 417 symlink_path = invoker.symlink_path 418 } 419 } 420} 421 422template("ohos_prebuilt_rust_library") { 423 assert(defined(invoker.source), "source must be defined for ${target_name}.") 424 425 if (defined(invoker.output)) { 426 _copy_output = "${target_out_dir}/${invoker.output}" 427 } else { 428 _copy_output = "${target_out_dir}/${invoker.source}" 429 } 430 config("${target_name}__config") { 431 libs = [ _copy_output ] 432 } 433 434 if (!defined(invoker.deps)) { 435 invoker.deps = [] 436 } 437 438 if (!defined(invoker.stable)) { 439 invoker.stable = false 440 } 441 442 # auto set auto_relative_install_dir by innerapi_tags 443 if (defined(invoker.innerapi_tags)) { 444 is_chipsetsdk = false 445 is_platformsdk = false 446 is_platformsdk_indirect = false 447 is_passthrough = false 448 is_passthrough_indirect = false 449 is_llndk = false 450 is_chipsetsdk_indirect = false 451 is_chipsetsdk_sp = false 452 is_chipsetsdk_sp_indirect = false 453 454 foreach(tag, filter_include(invoker.innerapi_tags, [ "llndk" ])) { 455 is_llndk = true 456 } 457 foreach(tag, filter_include(invoker.innerapi_tags, [ "chipsetsdk" ])) { 458 is_chipsetsdk = true 459 } 460 foreach(tag, 461 filter_include(invoker.innerapi_tags, [ "chipsetsdk_indirect" ])) { 462 is_chipsetsdk_indirect = true 463 } 464 foreach(tag, filter_include(invoker.innerapi_tags, [ "chipsetsdk_sp" ])) { 465 is_chipsetsdk_sp = true 466 } 467 foreach( 468 tag, 469 filter_include(invoker.innerapi_tags, [ "chipsetsdk_sp_indirect" ])) { 470 is_chipsetsdk_sp_indirect = true 471 } 472 foreach(tag, filter_include(invoker.innerapi_tags, [ "platformsdk" ])) { 473 is_platformsdk = true 474 } 475 foreach(tag, 476 filter_include(invoker.innerapi_tags, [ "platformsdk_indirect" ])) { 477 is_platformsdk_indirect = true 478 } 479 foreach(tag, filter_include(invoker.innerapi_tags, [ "passthrough" ])) { 480 is_passthrough = true 481 } 482 foreach(tag, 483 filter_include(invoker.innerapi_tags, [ "passthrough_indirect" ])) { 484 is_passthrough_indirect = true 485 } 486 487 if (is_chipsetsdk && (is_chipsetsdk_indirect || is_chipsetsdk_sp || is_chipsetsdk_sp_indirect)) { 488 assert(false, "chipsetsdk tags cannot coexist with [chipsetsdk_indirect,chipsetsdk_sp,chipsetsdk_sp_indirect]") 489 } else if (is_chipsetsdk_indirect && (is_chipsetsdk || is_chipsetsdk_sp || is_chipsetsdk_sp_indirect)) { 490 assert(false, "chipsetsdk_indirect tags cannot coexist with [chipsetsdk,chipsetsdk_sp,chipsetsdk_sp_indirect]") 491 } else if (is_chipsetsdk_sp && (is_chipsetsdk || is_chipsetsdk_indirect || is_chipsetsdk_sp_indirect)) { 492 assert(false, "chipsetsdk_sp tags cannot coexist with [chipsetsdk,chipsetsdk_indirect,chipsetsdk_sp_indirect]") 493 } else if (is_chipsetsdk_sp_indirect && (is_chipsetsdk || is_chipsetsdk_sp || is_chipsetsdk_indirect)) { 494 assert(false, "chipsetsdk_sp_indirect tags cannot coexist with [chipsetsdk,chipsetsdk_indirect,chipsetsdk_sp]") 495 } 496 497 if (is_platformsdk) { 498 auto_relative_install_dir = platformsdk_dir 499 } 500 501 if (is_platformsdk_indirect) { 502 auto_relative_install_dir = platformsdk_dir 503 } 504 505 if (is_chipsetsdk) { 506 auto_relative_install_dir = chipset_sdk_dir 507 if (is_platformsdk || is_platformsdk_indirect) { 508 softlink_path = platformsdk_dir 509 } 510 } 511 512 if (is_chipsetsdk_indirect) { 513 auto_relative_install_dir = chipset_sdk_dir 514 if (is_platformsdk || is_platformsdk_indirect) { 515 softlink_path = platformsdk_dir 516 } 517 } 518 519 if (is_chipsetsdk_sp) { 520 auto_relative_install_dir = chipset_sdk_sp_dir 521 if (is_platformsdk || is_platformsdk_indirect) { 522 softlink_path = platformsdk_dir 523 } 524 } 525 526 if (is_chipsetsdk_sp_indirect) { 527 auto_relative_install_dir = chipset_sdk_sp_dir 528 if (is_platformsdk || is_platformsdk_indirect) { 529 softlink_path = platformsdk_dir 530 } 531 } 532 533 if (is_passthrough) { 534 auto_relative_install_dir = passthrough_dir 535 } 536 if (is_passthrough_indirect) { 537 auto_relative_install_dir = passthrough_indirect_dir 538 } 539 540 if (is_llndk) { 541 auto_relative_install_dir = llndk_dir 542 } 543 is_ndk = false 544 foreach(tag, filter_include(invoker.innerapi_tags, [ "ndk" ])) { 545 is_ndk = true 546 } 547 if (is_ndk) { 548 if (is_llndk) { 549 softlink_path = ndk_dir 550 auto_relative_install_dir = llndk_dir 551 } else { 552 auto_relative_install_dir = ndk_dir 553 } 554 } 555 } 556 557 deps_info = [] 558 foreach(dep, invoker.deps) { 559 info = { 560 } 561 info = { 562 target_out_dir = 563 rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir) 564 target_name = get_label_info(dep, "name") 565 } 566 deps_info += [ info ] 567 } 568 module_label = get_label_info(":${target_name}", "label_with_toolchain") 569 target_deps_data = { 570 label = module_label 571 module_deps_info = deps_info 572 type = "rust_library" 573 prebuilt = true 574 stable = invoker.stable 575 toolchain = get_label_info(":${target_name}", "toolchain") 576 source_path = rebase_path(invoker.source, root_build_dir) 577 output_path = rebase_path(_copy_output, root_build_dir) 578 } 579 write_file("${target_out_dir}/${target_name}_deps_data.json", 580 target_deps_data, 581 "json") 582 583 ohos_copy(target_name) { 584 forward_variables_from(invoker, 585 [ 586 "testonly", 587 "visibility", 588 "rust_crate_name", 589 "rust_crate_type", 590 "copy_linkable_file", 591 "deps", 592 "external_deps", 593 "public_external_deps", 594 "public_configs", 595 "subsystem_name", 596 "part_name", 597 598 # For generate_module_info 599 "install_images", 600 "module_install_dir", 601 "symlink_target_name", 602 "innerapi_tags", 603 "symlink_ext", 604 605 # Open source license related 606 "license_file", 607 "license_as_sources", 608 ]) 609 sources = [ invoker.source ] 610 outputs = [ _copy_output ] 611 module_type = "lib" 612 prebuilt = true 613 install_enable = true 614 if (!defined(invoker.copy_linkable_file)) { 615 copy_linkable_file = true 616 } 617 if (defined(invoker.install_enable)) { 618 install_enable = invoker.install_enable 619 } 620 621 # update relative_install_dir if auto_relative_install_dir defined 622 if (defined(auto_relative_install_dir)) { 623 relative_install_dir = auto_relative_install_dir 624 } 625 if (defined(invoker.relative_install_dir)) { 626 relative_install_dir = invoker.relative_install_dir 627 } 628 if (defined(invoker.innerapi_tags)) { 629 if (defined(softlink_path) && softlink_path != "") { 630 softlink_create_path = softlink_path 631 } 632 } 633 if (!defined(public_configs)) { 634 public_configs = [] 635 } 636 public_configs += [ ":${target_name}__config" ] 637 } 638} 639