# Copyright (c) 2021-2022 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("//ark/ts2abc/ts2panda/ts2abc_config.gni")
import("//build/ohos.gni")
import("//foundation/aafwk/standard/aafwk.gni")

ts2abc_gen_abc("gen_delegator_mgmt_abc") {
  src_js = rebase_path(
          "native/ability_delegator/src/runner_runtime/delegator_mgmt.js")
  dst_file = rebase_path(target_out_dir + "/delegator_mgmt.abc")
  in_puts = [ "native/ability_delegator/src/runner_runtime/delegator_mgmt.js" ]
  out_puts = [ target_out_dir + "/delegator_mgmt.abc" ]
  extra_args = [ "--module" ]
}

gen_js_obj("delegator_mgmt_js") {
  input = "native/ability_delegator/src/runner_runtime/delegator_mgmt.js"
  output = target_out_dir + "/delegator_mgmt.o"
}

gen_js_obj("delegator_mgmt_abc") {
  input = get_label_info(":gen_delegator_mgmt_abc", "target_out_dir") +
          "/delegator_mgmt.abc"
  output = target_out_dir + "/delegator_mgmt_abc.o"
  dep = ":gen_delegator_mgmt_abc"
}

config("appkit_config") {
  defines = [
    "AMS_LOG_TAG = \"AppkitNative\"",
    "AMS_LOG_DOMAIN = 0xD001150",
  ]
  if (target_cpu == "arm64") {
    defines += [ "_ARM64_" ]
  }

  include_dirs = [
    "${aafwk_path}/frameworks/kits/ability/native/include",
    "//third_party/json/include",
  ]
}

config("appkit_public_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "${ability_base_innerapi_path}/configuration/include",
    "native/ability_delegator/include",
    "${global_path}/resource_management/interfaces/inner_api/include",
  ]

  if (ability_runtime_graphics) {
    include_dirs += [
      "${global_path}/i18n/frameworks/intl/include",
      "//third_party/icu/icu4c/source/common",
    ]

    defines = [ "SUPPORT_GRAPHICS" ]
  }
}

# build so
ohos_shared_library("appkit_native") {
  cflags_cc = []
  include_dirs = [
    "native",
    "native/ability_runtime/app",
    "native/ability_runtime/context",
    "native/app/include",
    "native/app/include/task",
    "${aafwk_path}/services/common/include",
    "${aafwk_path}/frameworks/kits/ability/native/include",
    "${aafwk_path}/services/abilitymgr/include",
    "${aafwk_path}/interfaces/kits/napi/aafwk/inner/napi_common",
  ]

  configs = [ ":appkit_config" ]

  public_configs = [ ":appkit_public_config" ]

  sources = [
    "native/ability_runtime/app/ability_stage.cpp",
    "native/ability_runtime/app/js_ability_stage.cpp",
    "native/ability_runtime/app/js_ability_stage_context.cpp",
    "native/app/src/ability_manager.cpp",
    "native/app/src/ability_record_mgr.cpp",
    "native/app/src/app_loader.cpp",
    "native/app/src/application_context.cpp",
    "native/app/src/application_env.cpp",
    "native/app/src/application_env_impl.cpp",
    "native/app/src/application_impl.cpp",
    "native/app/src/context_container.cpp",
    "native/app/src/context_deal.cpp",
    "native/app/src/hdc_register.cpp",
    "native/app/src/main_thread.cpp",
    "native/app/src/ohos_application.cpp",
    "native/app/src/sys_mgr_client.cpp",
    "native/app/src/watchdog.cpp",
  ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  deps = [
    ":appkit_delegator",
    "${aafwk_path}/frameworks/kits/appkit:app_context",
    "${innerkits_path}/uri_permission:uri_permission_mgr",
  ]

  public_deps =
      [ "${global_path}/resource_management/frameworks/resmgr:global_resmgr" ]
  external_deps = [
    "ability_base:configuration",
    "ability_base:want",
    "ability_base:zuri",
    "ability_runtime:ability_manager",
    "ability_runtime:abilitykit_native",
    "ability_runtime:app_manager",
    "ability_runtime:runtime",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "common_event_service:cesfwk_innerkits",
    "eventhandler:libeventhandler",
    "faultloggerd:lib_dfx_dump_catcher",
    "faultloggerd:libfaultloggerd",
    "hisysevent_native:libhisysevent",
    "hitrace_native:hitrace_meter",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
    "napi:ace_napi",
    "samgr_standard:samgr_proxy",
    "utils_base:utils",
  ]

  if (os_account_part_enabled) {
    cflags_cc += [ "-DOS_ACCOUNT_PART_ENABLED" ]
    external_deps += [ "os_account:os_account_innerkits" ]
  }

  if (ability_runtime_graphics) {
    deps += [
      "${multimodalinput_path}/frameworks/proxy:libmmi-client",
      "//third_party/icu/icu4c:shared_icuuc",
    ]
    public_deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ]
  }
  part_name = "ability_runtime"
}

# build so
ohos_shared_library("app_context") {
  cflags_cc = []
  include_dirs = [
    "native/ability_runtime/context",
    "native/app/include",
  ]

  configs = [ ":appkit_config" ]

  public_configs = [ ":appkit_public_config" ]

  sources = [
    "native/ability_runtime/context/ability_lifecycle_callback.cpp",
    "native/ability_runtime/context/application_context.cpp",
    "native/ability_runtime/context/context_impl.cpp",
    "native/ability_runtime/context/js_application_context_utils.cpp",
    "native/ability_runtime/context/js_context_utils.cpp",
    "native/ability_runtime/context/js_hap_module_info_utils.cpp",
    "native/ability_runtime/context/js_resource_manager_utils.cpp",
    "native/app/src/sys_mgr_client.cpp",
  ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  deps = [
    # "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native",
    "//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility",
  ]

  public_deps =
      [ "${global_path}/resource_management/frameworks/resmgr:global_resmgr" ]

  external_deps = [
    "ability_base:configuration",
    "ability_base:want",
    "ability_base:zuri",
    "ability_runtime:ability_manager",
    "ability_runtime:app_manager",
    "ability_runtime:runtime",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "eventhandler:libeventhandler",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
    "napi:ace_napi",
    "resource_management:resmgr_napi_core",
    "samgr_standard:samgr_proxy",
    "utils_base:utils",
  ]

  if (os_account_part_enabled) {
    cflags_cc += [ "-DOS_ACCOUNT_PART_ENABLED" ]
    external_deps += [ "os_account:os_account_innerkits" ]
    public_deps += [ "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits" ]
  }

  if (ability_runtime_graphics) {
    deps += [
      "${multimodalinput_path}/frameworks/proxy:libmmi-client",
      "//third_party/icu/icu4c:shared_icuuc",
    ]
    public_deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ]
  }
  part_name = "ability_runtime"
}

# build so
ohos_shared_library("appkit_delegator") {
  include_dirs = [
    "native",
    "native/ability_runtime/app",
    "native/ability_runtime/context",
    "native/ability_delegator/include",
    "${aafwk_path}/services/common/include",
    "${aafwk_path}/frameworks/kits/ability/native/include",
  ]

  configs = [ ":appkit_config" ]

  public_configs = [ ":appkit_public_config" ]

  sources = [
    "${aafwk_path}/tools/aa/src/shell_command_result.cpp",
    "${aafwk_path}/tools/aa/src/test_observer_proxy.cpp",
    "native/ability_delegator/src/ability_delegator.cpp",
    "native/ability_delegator/src/ability_delegator_args.cpp",
    "native/ability_delegator/src/ability_delegator_registry.cpp",
    "native/ability_delegator/src/delegator_thread.cpp",
    "native/ability_delegator/src/iability_monitor.cpp",
    "native/ability_delegator/src/runner_runtime/js_test_runner.cpp",
    "native/ability_delegator/src/shell_cmd_result.cpp",
    "native/ability_delegator/src/test_runner.cpp",
  ]

  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }

  deps = [
    ":delegator_mgmt_abc",
    ":delegator_mgmt_js",
    "${aafwk_path}/frameworks/kits/appkit:app_context",
  ]

  external_deps = [
    "ability_base:want",
    "ability_runtime:ability_manager",
    "ability_runtime:app_manager",
    "ability_runtime:runtime",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "eventhandler:libeventhandler",
    "hitrace_native:hitrace_meter",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
    "samgr_standard:samgr_proxy",
    "utils_base:utils",
  ]

  public_deps = [ "//foundation/arkui/napi:ace_napi" ]

  if (ability_runtime_graphics) {
    deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
  }
  part_name = "ability_runtime"
}
