# Copyright (c) 2021 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/clang/clang.gni")
import("//build/ohos.gni")

ohos_prebuilt_shared_library("libclang_rt.asan.so") {
  enable_strip = true
  mini_debug = true
  source = "${runtime_clang_path}/libclang_rt.asan.so"
  deps = [ ":asan_unstripped_copy" ]
  install_images = [
    "system",
    "ramdisk",
    "updater",
  ]
  subsystem_name = "build"
  part_name = "build_framework"
}

ohos_prebuilt_shared_library("libclang_rt.hwasan.so") {
  enable_strip = true
  mini_debug = true
  source = "${runtime_ohos_clang_path}/libclang_rt.hwasan.so"
  install_images = [
    "system",
    "updater",
  ]
  if (use_hwasan) {
    install_images += [ "ramdisk" ]
  }
  subsystem_name = "build"
  part_name = "build_framework"
}

ohos_prebuilt_shared_library("libclang_rt.memgraph.so") {
  enable_strip = true
  mini_debug = true
  source = "${runtime_ohos_clang_path}/libclang_rt.memgraph.so"
  install_images = [
    "system",
    "updater",
  ]
  subsystem_name = "build"
  part_name = "build_framework"
}

ohos_prebuilt_shared_library("libclang_rt.tsan.so") {
  enable_strip = true
  mini_debug = true
  source = "${runtime_ohos_clang_path}/libclang_rt.tsan.so"
  if (is_tsan) {
    deps = [ ":tsan_unstripped_copy" ]
  }

  install_images = [
    "system",
    "ramdisk",
    "updater",
  ]
  subsystem_name = "build"
  part_name = "build_framework"
}

ohos_prebuilt_etc("asan.options") {
  source = "asan.options"
  subsystem_name = "build"
  part_name = "build_framework"
}

ohos_prebuilt_etc("asan.cfg") {
  source = "asan.cfg"
  module_install_dir = "etc/init/"
  subsystem_name = "build"
  part_name = "build_framework"
}

copy("asan_unstripped_copy") {
  sources = [ "${runtime_clang_path}/libclang_rt.asan.so" ]
  outputs = [ root_out_dir + "/lib.unstripped/clang/{{source_file_part}}" ]
}

copy("tsan_unstripped_copy") {
  sources = [ "${runtime_clang_path}/libclang_rt.tsan.so" ]
  outputs = [ root_out_dir + "/lib.unstripped/clang/{{source_file_part}}" ]
}

ohos_prebuilt_etc("tsan.options") {
  source = "tsan.options"
  subsystem_name = "build"
  part_name = "build_framework"
}