• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 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/templates/common/copy.gni")
15
16template("ohos_prebuilt_executable") {
17  assert(defined(invoker.source), "source must be defined for ${target_name}.")
18
19  if (defined(invoker.output)) {
20    _copy_output = "${target_out_dir}/${invoker.output}"
21  } else {
22    _copy_output = "${target_out_dir}/${invoker.source}"
23  }
24
25  if (!defined(invoker.deps)) {
26    invoker.deps = []
27  }
28
29  if (!defined(invoker.stable)) {
30    invoker.stable = false
31  }
32
33  deps_info = []
34  foreach(dep, invoker.deps) {
35    info = {
36    }
37    info = {
38      target_out_dir =
39          rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir)
40      target_name = get_label_info(dep, "name")
41    }
42    deps_info += [ info ]
43  }
44  module_label = get_label_info(":${target_name}", "label_with_toolchain")
45  target_deps_data = {
46    label = module_label
47    module_deps_info = deps_info
48    type = "executable"
49    prebuilt = true
50    stable = invoker.stable
51    toolchain = get_label_info(":${target_name}", "toolchain")
52    source_path = rebase_path(invoker.source, root_build_dir)
53    output_path = rebase_path(_copy_output, root_build_dir)
54  }
55  write_file("${target_out_dir}/${target_name}_deps_data.json",
56             target_deps_data,
57             "json")
58
59  ohos_copy(target_name) {
60    forward_variables_from(invoker,
61                           [
62                             "testonly",
63                             "visibility",
64
65                             "deps",
66                             "public_configs",
67                             "subsystem_name",
68                             "part_name",
69
70                             # For generate_module_info
71                             "install_images",
72                             "module_install_dir",
73                             "relative_install_dir",
74                             "symlink_target_name",
75
76                             # Open source license related
77                             "license_file",
78                             "license_as_sources",
79                           ])
80    sources = [ invoker.source ]
81    outputs = [ _copy_output ]
82    module_type = "bin"
83    prebuilt = true
84    install_enable = false
85    enable_strip = false
86    if (defined(invoker.enable_strip) && invoker.enable_strip) {
87      enable_strip = true
88    }
89    if (defined(invoker.install_enable)) {
90      install_enable = invoker.install_enable
91    }
92  }
93}
94
95template("ohos_prebuilt_shared_library") {
96  assert(defined(invoker.source), "source must be defined for ${target_name}.")
97
98  if (defined(invoker.output)) {
99    _copy_output = "${target_out_dir}/${invoker.output}"
100  } else {
101    _copy_output = "${target_out_dir}/${invoker.source}"
102  }
103  config("${target_name}__config") {
104    libs = [ _copy_output ]
105  }
106
107  if (!defined(invoker.deps)) {
108    invoker.deps = []
109  }
110
111  if (!defined(invoker.stable)) {
112    invoker.stable = false
113  }
114
115  # auto set auto_relative_install_dir by innerapi_tags
116  if (defined(invoker.innerapi_tags)) {
117    is_chipsetsdk = false
118    is_platformsdk = false
119    is_passthrough = false
120    foreach(tag, filter_include(invoker.innerapi_tags, [ "chipsetsdk*" ])) {
121      is_chipsetsdk = true
122    }
123    foreach(tag, filter_include(invoker.innerapi_tags, [ "platformsdk*" ])) {
124      is_platformsdk = true
125    }
126    foreach(tag, filter_include(invoker.innerapi_tags, [ "passthrough*" ])) {
127      is_passthrough = true
128    }
129
130    if (is_chipsetsdk && is_platformsdk) {
131      auto_relative_install_dir = "chipset-pub-sdk"
132    } else if (is_chipsetsdk) {
133      auto_relative_install_dir = "chipset-sdk"
134    } else if (is_platformsdk) {
135      auto_relative_install_dir = "platformsdk"
136    }
137    if (is_passthrough) {
138      auto_relative_install_dir = chipset_passthrough_dir
139    }
140
141    is_ndk = false
142    foreach(tag, filter_include(invoker.innerapi_tags, [ "ndk" ])) {
143      is_ndk = true
144    }
145    if (is_ndk) {
146      auto_relative_install_dir = "ndk"
147    }
148  }
149
150  deps_info = []
151  foreach(dep, invoker.deps) {
152    info = {
153    }
154    info = {
155      target_out_dir =
156          rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir)
157      target_name = get_label_info(dep, "name")
158    }
159    deps_info += [ info ]
160  }
161  module_label = get_label_info(":${target_name}", "label_with_toolchain")
162  target_deps_data = {
163    label = module_label
164    module_deps_info = deps_info
165    type = "shared_library"
166    prebuilt = true
167    stable = invoker.stable
168    toolchain = get_label_info(":${target_name}", "toolchain")
169    source_path = rebase_path(invoker.source, root_build_dir)
170    output_path = rebase_path(_copy_output, root_build_dir)
171  }
172  write_file("${target_out_dir}/${target_name}_deps_data.json",
173             target_deps_data,
174             "json")
175
176  ohos_copy(target_name) {
177    forward_variables_from(invoker,
178                           [
179                             "testonly",
180                             "visibility",
181                             "public_external_deps",
182                             "deps",
183                             "public_configs",
184                             "subsystem_name",
185                             "part_name",
186
187                             # For generate_module_info
188                             "install_images",
189                             "module_install_dir",
190                             "symlink_target_name",
191                             "innerapi_tags",
192
193                             # Open source license related
194                             "license_file",
195                             "license_as_sources",
196                           ])
197    sources = [ invoker.source ]
198    outputs = [ _copy_output ]
199    module_type = "lib"
200    prebuilt = true
201    install_enable = true
202    enable_strip = false
203    if (defined(invoker.enable_strip) && invoker.enable_strip) {
204      enable_strip = true
205    }
206    if (defined(invoker.install_enable)) {
207      install_enable = invoker.install_enable
208    }
209
210    # update relative_install_dir if auto_relative_install_dir defined
211    if (defined(auto_relative_install_dir)) {
212      relative_install_dir = auto_relative_install_dir
213    }
214    if (defined(invoker.relative_install_dir)) {
215      relative_install_dir = invoker.relative_install_dir
216    }
217    if (!defined(public_configs)) {
218      public_configs = []
219    }
220    public_configs += [ ":${target_name}__config" ]
221  }
222}
223
224template("ohos_prebuilt_static_library") {
225  assert(defined(invoker.source), "source must be defined for ${target_name}.")
226
227  if (defined(invoker.output)) {
228    _copy_output = "${target_out_dir}/${invoker.output}"
229  } else {
230    _copy_output = "${target_out_dir}/${invoker.source}"
231  }
232  config("${target_name}__config") {
233    libs = [ _copy_output ]
234  }
235  ohos_copy(target_name) {
236    forward_variables_from(invoker,
237                           [
238                             "testonly",
239                             "visibility",
240
241                             "deps",
242                             "public_external_deps",
243                             "public_configs",
244                             "subsystem_name",
245                             "part_name",
246
247                             # Open source license related
248                             "license_file",
249                             "license_as_sources",
250                           ])
251    sources = [ invoker.source ]
252    outputs = [ _copy_output ]
253    bypass_module_info_generation = true
254    if (!defined(public_configs)) {
255      public_configs = []
256    }
257    public_configs += [ ":${target_name}__config" ]
258  }
259}
260
261template("ohos_prebuilt_etc") {
262  assert(defined(invoker.source), "source must be defined for ${target_name}.")
263
264  if (defined(invoker.output)) {
265    _copy_output = "${target_out_dir}/${invoker.output}"
266  } else {
267    _copy_output = "${target_out_dir}/${invoker.source}"
268  }
269
270  module_label = get_label_info(":${target_name}", "label_with_toolchain")
271  target_deps_data = {
272    label = module_label
273    type = "etc"
274    prebuilt = true
275    source_path = rebase_path(invoker.source, root_build_dir)
276    output_path = rebase_path(_copy_output, root_build_dir)
277  }
278  write_file("${target_out_dir}/${target_name}_deps_data.json",
279             target_deps_data,
280             "json")
281
282  ohos_copy(target_name) {
283    forward_variables_from(invoker,
284                           [
285                             "testonly",
286                             "visibility",
287
288                             "deps",
289                             "public_configs",
290                             "subsystem_name",
291                             "part_name",
292
293                             # For generate_module_info
294                             "install_images",
295                             "module_install_dir",
296                             "relative_install_dir",
297                             "symlink_target_name",
298
299                             # Open source license related
300                             "license_file",
301                             "license_as_sources",
302                           ])
303    sources = [ invoker.source ]
304    outputs = [ _copy_output ]
305    module_type = "etc"
306    prebuilt = true
307    install_enable = true
308    if (defined(invoker.install_enable)) {
309      install_enable = invoker.install_enable
310    }
311  }
312}
313