• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
2# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without modification,
5# are permitted provided that the following conditions are met:
6#
7# 1. Redistributions of source code must retain the above copyright notice, this list of
8#    conditions and the following disclaimer.
9#
10# 2. Redistributions in binary form must reproduce the above copyright notice, this list
11#    of conditions and the following disclaimer in the documentation and/or other materials
12#    provided with the distribution.
13#
14# 3. Neither the name of the copyright holder nor the names of its contributors may be used
15#    to endorse or promote products derived from this software without specific prior written
16#    permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30import("//build/lite/config/component/lite_component.gni")
31
32LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
33
34liteos_config_file = "${ohos_build_type}.config"
35
36liteos_config_file =
37    rebase_path(liteos_config_file, "", "$product_path/kernel_configs")
38print("liteos_config_file:", liteos_config_file)
39
40exec_script("//build/lite/run_shell_cmd.py",
41            [ "env" + " CONFIG_=LOSCFG_" + " KCONFIG_CONFIG_HEADER='y=true'" +
42                  " KCONFIG_CONFIG=$liteos_config_file" +
43                  " BOARD_COMPANY=$device_company" +
44                  " DEVICE_PATH=$device_path" + " srctree=" + rebase_path(".") +
45                  " genconfig" + " --header-path $LITEOS_MENUCONFIG_H" +
46                  " --file-list kconfig_files.txt" +
47                  " --env-list kconfig_env.txt" + " --config-out config.gni" ],
48            "",
49            [ liteos_config_file ])
50
51import("$root_out_dir/config.gni")
52
53LITEOSTOPDIR = "//kernel/liteos_m"
54LITEOSTHIRDPARTY = "//third_party"
55HDFTOPDIR = "//drivers/adapter/khdf/liteos_m"
56
57ARCH = ""
58if (defined(LOSCFG_ARCH_ARM_AARCH32)) {
59  ARCH = "arm"
60} else if (defined(LOSCFG_ARCH_ARM_AARCH64)) {
61  ARCH = "aarch64"
62} else if (defined(LOSCFG_ARCH_RISCV32)) {
63  ARCH = "rv32imac"
64} else if (defined(LOSCFG_ARCH_CSKY)) {
65  ARCH = "csky"
66} else if (defined(LOSCFG_ARCH_XTENSA)) {
67  ARCH = "xtensa"
68}
69
70template("kernel_module") {
71  build_gn = rebase_path("BUILD.gn")
72  cmd = "grep -c '^\s*\(kernel_module\|hdf_driver\)\s*(\s*\S*\s*)\s*{\s*\$' $build_gn"
73  modules_count = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
74  if (modules_count == 1) {
75    auto_config = true
76  }
77
78  cmd = "if grep -q '^\s*\(config\s*(\s*\"public\"\s*)\|module_group\s*(\s*\"\S*\"\s*)\)\s*{\s*\$' $build_gn; then echo true; else echo false; fi"
79  has_public_config =
80      exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
81  if (!has_public_config && defined(auto_config)) {
82    config("public") {
83      configs = []
84    }
85  }
86
87  current_dir_name = get_path_info(rebase_path("."), "file")
88  if (target_name != current_dir_name) {
89    cmd = "if grep -q '^\s*\(module_group\|group\)\s*(\s*\"$current_dir_name\"\s*)\s*{\s*\$' $build_gn; then echo true; else echo false; fi"
90    has_current_dir_group =
91        exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
92    if (!has_current_dir_group && defined(auto_config)) {
93      module_name = target_name
94      group(current_dir_name) {
95        public_deps = [ ":$module_name" ]
96      }
97    }
98  }
99
100  if (defined(invoker.module_switch) && !invoker.module_switch) {
101    group(target_name) {
102      not_needed(invoker, "*")
103    }
104  } else {
105    source_set(target_name) {
106      public_configs = []
107      forward_variables_from(invoker, "*", [ "configs" ])
108      configs += invoker.configs
109      if (has_public_config) {
110        included_public_config = false
111        foreach(cfg, public_configs) {
112          what = "label_no_toolchain"
113          if (get_label_info(cfg, what) == get_label_info(":public", what)) {
114            included_public_config = true
115          }
116        }
117        if (!included_public_config) {
118          public_configs += [ ":public" ]
119        }
120      }
121    }
122  }
123  not_needed([ "auto_config" ])
124}
125
126template("config") {
127  config(target_name) {
128    if (defined(invoker.module_switch) && !invoker.module_switch &&
129        target_name == "public") {
130      not_needed(invoker, "*")
131      forward_variables_from(invoker, [ "configs" ])
132    } else {
133      forward_variables_from(invoker, "*")
134    }
135  }
136}
137
138template("module_group") {
139  assert(defined(invoker.modules), "modules are must")
140  group(target_name) {
141    deps = []
142    foreach(m, invoker.modules) {
143      deps += [ m ]
144    }
145    if (defined(invoker.deps)) {
146      deps += invoker.deps
147    }
148  }
149  config("public") {
150    configs = []
151    foreach(m, invoker.modules) {
152      configs += [ "$m:public" ]
153    }
154    if (defined(invoker.configs)) {
155      configs += invoker.configs
156    }
157  }
158}
159
160set_defaults("kernel_module") {
161  configs = [
162    "$LITEOSTOPDIR:public",
163    "$LITEOSTOPDIR:los_config",
164  ]
165  visibility = [
166    "$LITEOSTOPDIR:*",
167    ":*",
168    "..:*",
169    "../..:*",
170  ]
171}
172