• 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("$root_out_dir/config.gni")
31
32LITEOSTOPDIR = "//kernel/liteos_a"
33LITEOSTHIRDPARTY = "//third_party"
34HDFTOPDIR = "//drivers/hdf_core/adapter/khdf/liteos"
35HIVIEWDFX_HILOG_LITE_DIR = "//base/hiviewdfx/hilog_lite"
36DRIVERS_LITEOS_DIR = "//drivers/liteos"
37THIRDPARTY_BOUNDS_CHECKING_FUNCTION_DIR =
38    "//third_party/bounds_checking_function"
39THIRDPARTY_FATFS_DIR = "//third_party/FatFs"
40THIRDPARTY_NUTTX_DIR = "//third_party/NuttX"
41THIRDPARTY_MUSL_DIR = "//third_party/musl"
42THIRDPARTY_TOYBOX_DIR = "//third_party/toybox"
43THIRDPARTY_MKSH_DIR = "//third_party/mksh"
44THIRDPARTY_FREEBSD_DIR = "//third_party/FreeBSD"
45THIRDPARTY_OPTIMIZED_ROUTINES_DIR = "//third_party/optimized-routines"
46THIRDPARTY_GOOGLETEST_DIR = "//third_party/googletest"
47KERNEL_LINUX_DIR = "//kernel/linux/linux-5.10"
48
49ARCH = ""
50if (defined(LOSCFG_ARCH_ARM_AARCH32)) {
51  ARCH = "arm"
52} else if (defined(LOSCFG_ARCH_ARM_AARCH64)) {
53  ARCH = "aarch64"
54}
55
56template("kernel_module") {
57  build_gn = rebase_path("BUILD.gn")
58  cmd = "grep -c '^\s*\(kernel_module\|hdf_driver\)\s*(\s*\S*\s*)\s*{\s*\$' $build_gn"
59  modules_count = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
60  if (modules_count == 1) {
61    auto_config = true
62  }
63
64  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"
65  has_public_config =
66      exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
67  if (!has_public_config && defined(auto_config)) {
68    config("public") {
69      configs = []
70    }
71  }
72
73  current_dir_name = get_path_info(rebase_path("."), "file")
74  if (target_name != current_dir_name) {
75    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"
76    has_current_dir_group =
77        exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
78    if (!has_current_dir_group && defined(auto_config)) {
79      module_name = target_name
80      group(current_dir_name) {
81        public_deps = [ ":$module_name" ]
82      }
83    }
84  }
85
86  if (defined(invoker.module_switch) && !invoker.module_switch) {
87    group(target_name) {
88      not_needed(invoker, "*")
89    }
90  } else {
91    source_set(target_name) {
92      public_configs = []
93      forward_variables_from(invoker, "*")
94      if (has_public_config) {
95        included_public_config = false
96        foreach(cfg, public_configs) {
97          what = "label_no_toolchain"
98          if (get_label_info(cfg, what) == get_label_info(":public", what)) {
99            included_public_config = true
100          }
101        }
102        if (!included_public_config) {
103          public_configs += [ ":public" ]
104        }
105      }
106    }
107  }
108  not_needed([ "auto_config" ])
109}
110
111template("config") {
112  config(target_name) {
113    if (defined(invoker.module_switch) && !invoker.module_switch &&
114        target_name == "public") {
115      not_needed(invoker, "*")
116      forward_variables_from(invoker, [ "configs" ])
117    } else {
118      forward_variables_from(invoker, "*")
119    }
120  }
121}
122
123template("module_group") {
124  assert(defined(invoker.modules), "modules are must")
125  group(target_name) {
126    deps = []
127    foreach(m, invoker.modules) {
128      deps += [ m ]
129    }
130    if (defined(invoker.deps)) {
131      deps += invoker.deps
132    }
133  }
134  config("public") {
135    configs = []
136    foreach(m, invoker.modules) {
137      configs += [ "$m:public" ]
138    }
139    if (defined(invoker.configs)) {
140      configs += invoker.configs
141    }
142  }
143}
144
145set_defaults("kernel_module") {
146  configs = [
147    "$LITEOSTOPDIR:public",
148    "$LITEOSTOPDIR:los_config",
149  ]
150  visibility = [
151    ":*",
152    "$LITEOSTOPDIR:*",
153    "..:*",
154    "../..:*",
155  ]
156}
157