• 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      configs = []
94      forward_variables_from(invoker, "*")
95      if (has_public_config) {
96        included_public_config = false
97        foreach(cfg, public_configs) {
98          what = "label_no_toolchain"
99          if (get_label_info(cfg, what) == get_label_info(":public", what)) {
100            included_public_config = true
101          }
102        }
103        if (!included_public_config) {
104          public_configs += [ ":public" ]
105        }
106      }
107      if (is_lite_system && current_os == "ohos" && !is_mini_system &&
108          !ohos_kernel_is_prebuilt) {
109        configs += [ "$LITEOSTOPDIR:sysroot_flags" ]
110      }
111    }
112  }
113  not_needed([ "auto_config" ])
114}
115
116template("config") {
117  config(target_name) {
118    if (defined(invoker.module_switch) && !invoker.module_switch &&
119        target_name == "public") {
120      not_needed(invoker, "*")
121      forward_variables_from(invoker, [ "configs" ])
122    } else {
123      forward_variables_from(invoker, "*")
124    }
125  }
126}
127
128template("module_group") {
129  assert(defined(invoker.modules), "modules are must")
130  group(target_name) {
131    deps = []
132    foreach(m, invoker.modules) {
133      deps += [ m ]
134    }
135    if (defined(invoker.deps)) {
136      deps += invoker.deps
137    }
138  }
139  config("public") {
140    configs = []
141    foreach(m, invoker.modules) {
142      configs += [ "$m:public" ]
143    }
144    if (defined(invoker.configs)) {
145      configs += invoker.configs
146    }
147  }
148}
149
150set_defaults("kernel_module") {
151  configs = [
152    "$LITEOSTOPDIR:public",
153    "$LITEOSTOPDIR:los_config",
154  ]
155  visibility = [
156    ":*",
157    "$LITEOSTOPDIR:*",
158    "..:*",
159    "../..:*",
160  ]
161}
162