# 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.

print("root_out_dir=$root_out_dir")
print("root_build_dir=$root_build_dir")
print("root_gen_dir=$root_gen_dir")
print("current_toolchain=$current_toolchain")
print("host_toolchain=$host_toolchain")

import("//build/ohos_var.gni")

# gn target defined
if (product_name == "ohos-sdk") {
  group("build_ohos_sdk") {
    deps = [
      "//build/ohos/ndk:ohos_ndk",
      "//build/ohos/sdk:ohos_sdk",
      "//build/ohos/sdk:ohos_sdk_verify",
    ]
  }
} else if (product_name == "arkui-x") {
  group("arkui_targets") {
    deps = [ "//build_plugins/sdk:arkui_cross_sdk" ]
  }
} else {
  group("make_all") {
    deps = [
      ":make_inner_kits",
      ":packages",
    ]
    if (is_standard_system && !is_llvm_build) {
      # Lite system uses different packaging scheme, which is called in hb.
      # So skip images for lite system since it's the mkimage
      # action for standard system.
      deps += [ ":images" ]
    }
  }

  if (!is_llvm_build) {
    if (is_host_product) {
      action("host_images") {
        script = "//build/lite/run_shell_cmd.py"
        outputs = [ "$root_out_dir/packages/phone/images/.host_images.stamp" ]
        args = [
          "mkdir -p packages/phone/images && touch packages/phone/images/.host_images.stamp",
        ]
        deps = [ ":packages" ]
      }
    }

    group("images") {
      if (is_host_product) {
        deps = []
        deps = [ ":host_images" ]
      } else {
        deps = [ "//build/ohos/images:make_images" ]
        if (make_pac_format_image) {
          deps += [ "//device/board/${device_company}/${product_name}:make_pac_format_image" ]
        }
      }
    }
  }

  group("packages") {
    deps = [ "//build/ohos/packages:make_packages" ]
  }

  group("make_inner_kits") {
    deps = [ "$root_build_dir/build_configs:inner_kits" ]
  }

  group("build_all_test_pkg") {
    testonly = true
    deps = []
    if (!is_host_product && !is_llvm_build) {
      deps = [
        "$root_build_dir/build_configs:parts_test",
        "//test/testfwk/developer_test:make_temp_test",
      ]
    }
  }

  group("make_test") {
    testonly = true
    deps = []
    if (!is_host_product) {
      deps = [
        "//build/ohos/packages:build_all_test_pkg",
        "//build/ohos/packages:package_testcase",
        "//build/ohos/packages:package_testcase_mlf",
      ]
    }
    if (!is_host_product && archive_component) {
      deps += [ "//build/ohos/testfwk:archive_testcase" ]
    }
  }
}