• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2020 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/lite/config/subsystem/aafwk/path.gni")
15
16template("lite_library") {
17  assert(defined(invoker.target_type), "Library target_type is required.")
18  assert(defined(invoker.sources), "Library sources is required.")
19  target_type = invoker.target_type
20  shared_lib = target_type == "shared_library"
21
22  if (shared_lib && ohos_kernel_type == "liteos_m") {
23    group(target_name) {
24      if (defined(invoker.sources)) {
25        assert(invoker.sources != "")
26      }
27      if (defined(invoker.public_configs)) {
28        assert(invoker.public_configs != "")
29      }
30      if (defined(invoker.public_deps)) {
31        assert(invoker.public_deps != "")
32      }
33      if (defined(invoker.output_name)) {
34        assert(invoker.output_name != "")
35      }
36    }
37  } else {
38    target(target_type, target_name) {
39      forward_variables_from(invoker, "*")
40      cflags = []
41      cflags_cc = []
42      ldflags = []
43      if (defined(invoker.cflags)) {
44        cflags += invoker.cflags
45      }
46      if (defined(invoker.cflags_cc)) {
47        cflags_cc += invoker.cflags_cc
48        ldflags += [ "-lstdc++" ]
49      }
50      if (defined(invoker.ldflags)) {
51        ldflags += invoker.ldflags
52      }
53      shared_lib = target_type == "shared_library"
54      if (shared_lib) {
55        cflags += [ "-fPIC" ]
56        cflags_cc += [ "-fPIC" ]
57      } else if (!shared_lib && ohos_kernel_type != "liteos_m") {
58        cflags += [ "-fPIE" ]
59        cflags_cc += [ "-fPIE" ]
60      }
61    }
62  }
63}
64
65# Defines a component
66#
67# The lite_subsystem template defines all the modules contained in a subsystem
68#
69# Parameters
70#
71#   component_features (required)
72#     [list of scopes] Defines all features in the component.
73template("lite_component") {
74  assert(defined(invoker.features), "Component features is required.")
75
76  if (!defined(invoker.target_type)) {
77    target_type = "group"
78  } else if (invoker.target_type == "static_library") {
79    target_type = "group"
80  } else {
81    target_type = invoker.target_type
82  }
83  assert(target_type != "")
84
85  target(target_type, target_name) {
86    deps = []
87
88    forward_variables_from(invoker, "*")
89
90    # add component deps
91    if (defined(invoker.deps)) {
92      deps += invoker.deps
93    }
94
95    # add component features
96    foreach(feature_label, features) {
97      deps += [ feature_label ]
98    }
99  }
100}
101
102template("build_ext_component") {
103  forward_variables_from(invoker, [ "testonly" ])
104  if (defined(invoker.version)) {
105    print(invoker.version)
106  }
107  action(target_name) {
108    forward_variables_from(invoker,
109                           [
110                             "no_default_deps",
111                             "deps",
112                           ])
113    args = []
114    if (defined(invoker.exec_path)) {
115      args += [ "--path=${invoker.exec_path}" ]
116    }
117    if (defined(invoker.enable)) {
118      args += [ "--enable=${invoker.enable}" ]
119    }
120    if (defined(invoker.prebuilts)) {
121      args += [ "--prebuilts=${invoker.prebuilts}" ]
122    }
123    if (defined(invoker.command)) {
124      args += [ "--command=${invoker.command}" ]
125    }
126
127    # external component build log
128    target_dir = rebase_path("${target_out_dir}/build.log")
129    args += [ "--target_dir=${target_dir}" ]
130
131    # external component error log if compile failed
132    out_dir = rebase_path("${root_out_dir}/error.log")
133    args += [ "--out_dir=${out_dir}" ]
134    script = "//build/lite/build_ext_components.py"
135    outputs = [ "$target_out_dir/${target_name}_build_ext_components.txt" ]
136    if (defined(invoker.outputs)) {
137      outputs += invoker.outputs
138    }
139  }
140}
141
142template("ohos_tools") {
143  target(invoker.target_type, target_name) {
144    forward_variables_from(invoker, "*")
145    output_dir = "$root_out_dir/tools/$target_name"
146    if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
147      configs -= [ "//build/lite/config:ohos" ]
148    } else if (ohos_kernel_type == "liteos_m") {
149      configs -= [ "//build/lite/config:liteos" ]
150    }
151    configs -= [ "//build/lite/config:pie_executable_config" ]
152    configs -= [ "//build/lite/config:static_pie_config" ]
153    configs += [ "//build/lite/config:tools" ]
154  }
155}
156
157template("generate_notice_file") {
158  assert(defined(invoker.module_name), "module_name in required.")
159  assert(defined(invoker.module_source_dir_list),
160         "module_source_dir_list in required.")
161  assert(target_name != "")
162  forward_variables_from(invoker,
163                         [
164                           "module_name",
165                           "module_source_dir_list",
166                         ])
167  gen_script = rebase_path("//build/lite/gen_module_notice_file.py")
168
169  foreach(module_source_dir, module_source_dir_list) {
170    arguments = []
171    arguments = [
172      "--root-out-dir",
173      rebase_path(root_out_dir),
174      "--module-source-dir",
175      rebase_path(module_source_dir),
176      "--module-relative-source-dir",
177      rebase_path(module_source_dir, "//"),
178      "--target-name",
179      module_name,
180    ]
181    ret_msg = ""
182    ret_msg = exec_script(gen_script, arguments, "list lines")
183    if (ret_msg != "") {
184      foreach(msg, ret_msg) {
185        print(msg)
186      }
187    }
188  }
189}
190