BUILD.gn 4.6 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2020 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/lite/ndk/ndk.gni")

Y
yangming_ha 已提交
15 16
# gn version >= 1714 required.
assert(gn_version >= 1714, "GN version 1714 required, please upgrade!")
Y
yangming_ha 已提交
17

Y
yangming_ha 已提交
18
# write version info.
Y
yangming_ha 已提交
19 20 21 22
version_info = [
  "VERSION=\"$ohos_version\"",
  "BUILD_TIME=\"$ohos_build_datetime\"",
]
Y
yangming_ha 已提交
23 24
write_file("$root_build_dir/etc/version-info", version_info)

C
Caoruihong 已提交
25 26 27 28
group("prebuilts") {
  public_deps = [ "//prebuilts/lite/sysroot" ]
}

M
mamingshuai 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
group("ohos") {
  deps = []
  if (ohos_build_target == "") {
    # Step 1: Read product configuration profile.
    product_cfg = read_file("${product_path}/config.json", "json")

    # Step 2: Loop subsystems configured by product.
    foreach(product_configed_subsystem, product_cfg.subsystems) {
      subsystem_name = product_configed_subsystem.subsystem
      subsystem_info = {
      }

      # Step 3: Read OS subsystems profile.
      subsystem_info =
          read_file("//build/lite/components/${subsystem_name}.json", "json")

      # Step 4: Loop components configured by product.
      foreach(product_configed_component,
              product_configed_subsystem.components) {
        # Step 5: Check whether the component configured by product is exist.
        component_found = false
        foreach(system_component, subsystem_info.components) {
          if (product_configed_component.component ==
              system_component.component) {
            component_found = true
          }
        }
        assert(
            component_found,
            "Component \"${product_configed_component.component}\" not found" +
                ", please check your product configuration.")

        # Step 6: Loop OS components and check validity of product configuration.
        foreach(component, subsystem_info.components) {
          kernel_valid = false
          board_valid = false

          # Step 6.1: Skip component which not configured by product.
          if (component.component == product_configed_component.component) {
            # Step 6.1.1: Loop OS components adapted kernel type.
            foreach(component_adapted_kernel, component.adapted_kernel) {
Y
yangming_ha 已提交
70
              if (component_adapted_kernel == product_cfg.kernel_type &&
71
                  kernel_valid == false) {
M
mamingshuai 已提交
72 73 74 75 76 77
                kernel_valid = true
              }
            }

            assert(
                kernel_valid,
78
                "Invalid component configed, ${subsystem_name}:${product_configed_component.component} " + "not available for kernel: ${product_cfg.kernel_type}!")
M
mamingshuai 已提交
79 80

            # Step 6.1.2: Add valid component for compiling.
Y
yangming_ha 已提交
81 82
            # Skip kernel target for userspace only scenario.
            if (!ohos_build_userspace_only ||
Y
yangming_ha 已提交
83 84
                (ohos_build_userspace_only && subsystem_name != "kernel" &&
                 subsystem_name != "vendor")) {
Y
yangming_ha 已提交
85 86 87
              foreach(component_target, component.targets) {
                deps += [ component_target ]
              }
M
mamingshuai 已提交
88 89 90 91 92
            }
          }
        }
      }
    }
Y
yangming_ha 已提交
93

Y
yangming_ha 已提交
94
    # Skip device target for userspace only scenario.
Y
yangming_ha 已提交
95 96
    if (!ohos_build_userspace_only) {
      # Step 7: Add device and product target by default.
Y
yangming_ha 已提交
97
      deps += [ "${device_path}/../" ]
Y
yangming_ha 已提交
98
    }
M
mamingshuai 已提交
99 100 101 102 103
  } else {
    deps += string_split(ohos_build_target, "&&")
  }
}

Y
yangming_ha 已提交
104 105 106 107 108 109 110 111 112
group("product") {
  deps = []

  # build product, skip build single component scenario.
  if (ohos_build_target == "") {
    deps += [ "${product_path}" ]
  }
}

M
mamingshuai 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
group("ndk") {
  # Add native API targets.
  deps = []
  if (ohos_build_ndk) {
    deps += [ "//build/lite/ndk:ndk" ]
  }
}

if (ohos_build_type == "debug" && product != "") {
  action("gen_testfwk_info") {
    outputs = [ "$root_out_dir/gen_testfwk_info.log" ]
    script = "//build/lite/testfwk/gen_testfwk_info.py"
    archive_dir_name = "test_info"
    args = [
      "--component-info-file",
      rebase_path("${product_path}/config.json"),
      "--output-json-fold",
      rebase_path("${root_out_dir}/${archive_dir_name}/build_configs/"),
      "--output-json-file-name",
      "infos_for_testfwk.json",
      "--output-module-list-files-fold",
      rebase_path("${root_out_dir}/${archive_dir_name}/module_list_files/"),
    ]
  }
}