# Copyright (c) 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/config/components/ets_frontend/ets2abc_config.gni")
import("//build/ohos.gni")
import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni")

ohos_shared_library("ani_freeInstall") {
  shlib_type = "ani"
  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}/appexecfwk_core/include",
    "${kits_path}/ani/freeInstall",
    "${kits_path}/ani/common",
    "${kits_path}/js/common",
  ]

  sources = []
  if (bundle_framework_free_install) {
    sources += [ "ani_free_install.cpp" ]
  } else {
    sources += [ "ani_free_install_unsupported.cpp" ]
  }

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

  deps = [
    "${base_path}:appexecfwk_base",
    "${common_path}:libappexecfwk_common",
    "${core_path}:appexecfwk_core",
    "${kits_path}/ani/common:bms_ani_common",
    "${kits_path}/js/common:bundle_napi_common",
  ]

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

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

  external_deps = [
    "c_utils:utils",
    "common_event_service:cesfwk_core",
    "common_event_service:cesfwk_innerkits",
    "hilog:libhilog",
    "ipc:ipc_core",
    "libuv:uv",
    "napi:ace_napi",
    "node:node_header_notice",
    "runtime_core:ani",
    "runtime_core:ani_helpers",
    "samgr:samgr_proxy",
  ]

  subsystem_name = "bundlemanager"
  part_name = "bundle_framework"
}

generate_static_abc("bundle_pack_info") {
  base_url = "./ets"
  files = [
    "./ets/bundleManager/BundlePackInfo.ets",
    "./ets/bundleManager/BundlePackInfoInner.ets",
  ]
  is_boot_abc = "True"
  device_dst_file = "/system/framework/bundle_pack_info.abc"
}

ohos_prebuilt_etc("bundle_pack_info_etc") {
  source = "$target_out_dir/bundle_pack_info.abc"
  module_install_dir = "framework"
  subsystem_name = "bundlemanager"
  part_name = "bundle_framework"
  deps = [ ":bundle_pack_info" ]
}

generate_static_abc("dispatch_info") {
  base_url = "./ets"
  files = [
    "./ets/bundleManager/DispatchInfo.ets",
    "./ets/bundleManager/DispatchInfoInner.ets",
  ]
  is_boot_abc = "True"
  device_dst_file = "/system/framework/dispatch_info.abc"
}

ohos_prebuilt_etc("dispatch_info_etc") {
  source = "$target_out_dir/dispatch_info.abc"
  module_install_dir = "framework"
  subsystem_name = "bundlemanager"
  part_name = "bundle_framework"
  deps = [ ":dispatch_info" ]
}

generate_static_abc("freeInstall") {
  base_url = "./ets"
  files = [ "./ets/@ohos.bundle.freeInstall.ets" ]
  is_boot_abc = "True"
  device_dst_file = "/system/framework/freeInstall.abc"
}

ohos_prebuilt_etc("freeInstall_etc") {
  source = "$target_out_dir/freeInstall.abc"
  module_install_dir = "framework"
  subsystem_name = "bundlemanager"
  part_name = "bundle_framework"
  deps = [ ":freeInstall" ]
}