• 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"
35
36ARCH = ""
37if (defined(LOSCFG_ARCH_ARM_AARCH32)) {
38  ARCH = "arm"
39} else if (defined(LOSCFG_ARCH_ARM_AARCH64)) {
40  ARCH = "aarch64"
41}
42
43template("kernel_module") {
44  build_gn = rebase_path("BUILD.gn")
45  cmd = "grep -c '^\s*\(kernel_module\|hdf_driver\)\s*(\s*\S*\s*)\s*{\s*\$' $build_gn"
46  modules_count = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
47  if (modules_count == 1) {
48    auto_config = true
49  }
50
51  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"
52  has_public_config =
53      exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
54  if (!has_public_config && defined(auto_config)) {
55    config("public") {
56      configs = []
57    }
58  }
59
60  current_dir_name = get_path_info(rebase_path("."), "file")
61  if (target_name != current_dir_name) {
62    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"
63    has_current_dir_group =
64        exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
65    if (!has_current_dir_group && defined(auto_config)) {
66      module_name = target_name
67      group(current_dir_name) {
68        public_deps = [ ":$module_name" ]
69      }
70    }
71  }
72
73  if (defined(invoker.module_switch) && !invoker.module_switch) {
74    group(target_name) {
75      not_needed(invoker, "*")
76    }
77  } else {
78    source_set(target_name) {
79      public_configs = []
80      forward_variables_from(invoker, "*")
81      if (has_public_config) {
82        included_public_config = false
83        foreach(cfg, public_configs) {
84          what = "label_no_toolchain"
85          if (get_label_info(cfg, what) == get_label_info(":public", what)) {
86            included_public_config = true
87          }
88        }
89        if (!included_public_config) {
90          public_configs += [ ":public" ]
91        }
92      }
93    }
94  }
95  not_needed([ "auto_config" ])
96}
97
98template("config") {
99  config(target_name) {
100    if (defined(invoker.module_switch) && !invoker.module_switch &&
101        target_name == "public") {
102      not_needed(invoker, "*")
103      forward_variables_from(invoker, [ "configs" ])
104    } else {
105      forward_variables_from(invoker, "*")
106    }
107  }
108}
109
110template("module_group") {
111  assert(defined(invoker.modules), "modules are must")
112  group(target_name) {
113    deps = []
114    foreach(m, invoker.modules) {
115      deps += [ m ]
116    }
117    if (defined(invoker.deps)) {
118      deps += invoker.deps
119    }
120  }
121  config("public") {
122    configs = []
123    foreach(m, invoker.modules) {
124      configs += [ "$m:public" ]
125    }
126    if (defined(invoker.configs)) {
127      configs += invoker.configs
128    }
129  }
130}
131
132set_defaults("kernel_module") {
133  configs = [
134    "$LITEOSTOPDIR:public",
135    "$LITEOSTOPDIR:los_config",
136  ]
137  visibility = [
138    "$LITEOSTOPDIR:*",
139    ":*",
140    "..:*",
141    "../..:*",
142  ]
143}
144