# Copyright (c) 2023-2025 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("../../../../appexecfwk.gni")

ohos_shared_library("bundle_res_common") {
  branch_protector_ret = "pac_ret"

  sanitize = {
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
    integer_overflow = true
    ubsan = true
  }

  include_dirs = [ "${kits_path}/js/common" ]
  sources = [ "resource_helper.cpp" ]

  cflags = [
    "-Os",
    "-fstack-protector-strong",
  ]

  cflags_cc = [
    "-Os",
    "-fstack-protector-strong",
  ]

  deps = [
    "${base_path}:appexecfwk_base",
    "${common_path}:libappexecfwk_common",
    "${core_path}:appexecfwk_core",
    "../common:bundle_napi_common",
  ]

  defines = [
    "APP_LOG_TAG = \"BMS\"",
    "LOG_DOMAIN = 0xD001120",
  ]

  external_deps = [
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_core",
    "libuv:uv",
    "napi:ace_napi",
    "node:node_header_notice",
    "runtime_core:ani",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  subsystem_name = "bundlemanager"
  part_name = "bundle_framework"
}

ohos_shared_library("bundleresourcemanager") {
  branch_protector_ret = "pac_ret"

  sanitize = {
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
    integer_overflow = true
    ubsan = true
  }

  include_dirs = [
    "${inner_api_path}/bundlemgr_resource/include",
    "${kits_path}/js/common",
    "${kits_path}/js/resource_comm",
  ]
  defines = [
    "APP_LOG_TAG = \"BMS\"",
    "LOG_DOMAIN = 0xD001120",
  ]
  sources = [ "native_module.cpp" ]

  deps = [
    ":bundle_res_common",
    "${base_path}:appexecfwk_base",
    "${common_path}:libappexecfwk_common",
    "${core_path}:appexecfwk_core",
    "../common:bundle_napi_common",
  ]

  cflags = [
    "-Os",
    "-fstack-protector-strong",
  ]

  cflags_cc = [
    "-Os",
    "-fstack-protector-strong",
  ]

  external_deps = [
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_core",
    "libuv:uv",
    "napi:ace_napi",
    "node:node_header_notice",
    "samgr:samgr_proxy",
  ]

  defines = []

  if (bundle_framework_bundle_resource) {
    defines += [ "BUNDLE_FRAMEWORK_BUNDLE_RESOURCE" ]
    sources += [
      "bundle_resource.cpp",
      "bundle_resource_drawable_utils.cpp",
    ]
    if (bundle_framework_graphics) {
      defines += [ "BUNDLE_FRAMEWORK_GRAPHICS" ]
      external_deps += [
        "ace_engine:drawable_descriptor",
        "image_framework:image_native",
        "resource_management:global_resmgr",
      ]
    }
  } else {
    sources += [ "bundle_resource_unsupported.cpp" ]
  }

  relative_install_dir = "module/bundle"
  subsystem_name = "bundlemanager"
  part_name = "bundle_framework"
}