• 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                             "external_deps",
67                             "public_external_deps",
68                             "public_configs",
69                             "subsystem_name",
70                             "part_name",
71
72                             # For generate_module_info
73                             "install_images",
74                             "module_install_dir",
75                             "relative_install_dir",
76                             "symlink_target_name",
77
78                             # Open source license related
79                             "license_file",
80                             "license_as_sources",
81                           ])
82    sources = [ invoker.source ]
83    outputs = [ _copy_output ]
84    module_type = "bin"
85    prebuilt = true
86    install_enable = false
87    enable_strip = false
88    if (defined(invoker.enable_strip) && invoker.enable_strip) {
89      enable_strip = true
90    }
91    if (defined(invoker.install_enable)) {
92      install_enable = invoker.install_enable
93    }
94  }
95}
96
97template("ohos_prebuilt_shared_library") {
98  assert(defined(invoker.source), "source must be defined for ${target_name}.")
99
100  if (defined(invoker.output)) {
101    _copy_output = "${target_out_dir}/${invoker.output}"
102  } else {
103    _copy_output = "${target_out_dir}/${invoker.source}"
104  }
105  config("${target_name}__config") {
106    libs = [ _copy_output ]
107  }
108
109  if (!defined(invoker.deps)) {
110    invoker.deps = []
111  }
112
113  if (!defined(invoker.stable)) {
114    invoker.stable = false
115  }
116
117  # auto set auto_relative_install_dir by innerapi_tags
118  if (defined(invoker.innerapi_tags)) {
119    is_chipsetsdk = false
120    is_platformsdk = false
121    is_passthrough = false
122    foreach(tag, filter_include(invoker.innerapi_tags, [ "chipsetsdk*" ])) {
123      is_chipsetsdk = true
124    }
125    foreach(tag, filter_include(invoker.innerapi_tags, [ "platformsdk*" ])) {
126      is_platformsdk = true
127    }
128    foreach(tag, filter_include(invoker.innerapi_tags, [ "passthrough*" ])) {
129      is_passthrough = true
130    }
131
132    if (is_chipsetsdk && is_platformsdk) {
133      auto_relative_install_dir = "chipset-pub-sdk"
134    } else if (is_chipsetsdk) {
135      auto_relative_install_dir = "chipset-sdk"
136    } else if (is_platformsdk) {
137      auto_relative_install_dir = "platformsdk"
138    }
139    if (is_passthrough) {
140      auto_relative_install_dir = chipset_passthrough_dir
141    }
142
143    is_ndk = false
144    foreach(tag, filter_include(invoker.innerapi_tags, [ "ndk" ])) {
145      is_ndk = true
146    }
147    if (is_ndk) {
148      auto_relative_install_dir = "ndk"
149    }
150  }
151
152  deps_info = []
153  foreach(dep, invoker.deps) {
154    info = {
155    }
156    info = {
157      target_out_dir =
158          rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir)
159      target_name = get_label_info(dep, "name")
160    }
161    deps_info += [ info ]
162  }
163  module_label = get_label_info(":${target_name}", "label_with_toolchain")
164  target_deps_data = {
165    label = module_label
166    module_deps_info = deps_info
167    type = "shared_library"
168    prebuilt = true
169    stable = invoker.stable
170    toolchain = get_label_info(":${target_name}", "toolchain")
171    source_path = rebase_path(invoker.source, root_build_dir)
172    output_path = rebase_path(_copy_output, root_build_dir)
173  }
174  write_file("${target_out_dir}/${target_name}_deps_data.json",
175             target_deps_data,
176             "json")
177
178  ohos_copy(target_name) {
179    forward_variables_from(invoker,
180                           [
181                             "testonly",
182                             "visibility",
183
184                             "deps",
185                             "external_deps",
186                             "public_external_deps",
187                             "public_configs",
188                             "subsystem_name",
189                             "part_name",
190
191                             # For generate_module_info
192                             "install_images",
193                             "module_install_dir",
194                             "symlink_target_name",
195                             "innerapi_tags",
196                             "symlink_ext",
197
198                             # Open source license related
199                             "license_file",
200                             "license_as_sources",
201                           ])
202    sources = [ invoker.source ]
203    outputs = [ _copy_output ]
204    module_type = "lib"
205    prebuilt = true
206    install_enable = true
207    enable_strip = false
208    if (defined(invoker.enable_strip) && invoker.enable_strip) {
209      enable_strip = true
210    }
211
212    if (!defined(invoker.copy_linkable_file) && !enable_strip) {
213      copy_linkable_file = true
214    }
215    mini_debug = false
216    if (defined(invoker.mini_debug) && invoker.mini_debug) {
217      mini_debug = true
218    }
219    if (defined(invoker.install_enable)) {
220      install_enable = invoker.install_enable
221    }
222
223    # update relative_install_dir if auto_relative_install_dir defined
224    if (defined(auto_relative_install_dir)) {
225      relative_install_dir = auto_relative_install_dir
226    }
227    if (defined(invoker.relative_install_dir)) {
228      relative_install_dir = invoker.relative_install_dir
229    }
230    if (!defined(public_configs)) {
231      public_configs = []
232    }
233    public_configs += [ ":${target_name}__config" ]
234  }
235}
236
237template("ohos_prebuilt_static_library") {
238  assert(defined(invoker.source), "source must be defined for ${target_name}.")
239
240  if (defined(invoker.output)) {
241    _copy_output = "${target_out_dir}/${invoker.output}"
242  } else {
243    _copy_output = "${target_out_dir}/${invoker.source}"
244  }
245  config("${target_name}__config") {
246    libs = [ _copy_output ]
247  }
248  ohos_copy(target_name) {
249    forward_variables_from(invoker,
250                           [
251                             "testonly",
252                             "visibility",
253
254                             "deps",
255                             "external_deps",
256                             "public_external_deps",
257                             "public_configs",
258                             "subsystem_name",
259                             "part_name",
260                             "copy_linkable_file",
261
262                             # Open source license related
263                             "license_file",
264                             "license_as_sources",
265                           ])
266    sources = [ invoker.source ]
267    outputs = [ _copy_output ]
268    bypass_module_info_generation = true
269    if (!defined(public_configs)) {
270      public_configs = []
271    }
272    public_configs += [ ":${target_name}__config" ]
273  }
274}
275
276template("ohos_prebuilt_etc") {
277  assert(defined(invoker.source), "source must be defined for ${target_name}.")
278
279  if (defined(invoker.output)) {
280    _copy_output = "${target_out_dir}/${invoker.output}"
281  } else {
282    _copy_output = "${target_out_dir}/${invoker.source}"
283  }
284
285  source_path = rebase_path(invoker.source, root_build_dir)
286  module_label = get_label_info(":${target_name}", "label_with_toolchain")
287  target_deps_data = {
288    label = module_label
289    type = "etc"
290    prebuilt = true
291    source_path = source_path
292    output_path = rebase_path(_copy_output, root_build_dir)
293  }
294  write_file("${target_out_dir}/${target_name}_deps_data.json",
295             target_deps_data,
296             "json")
297
298  ohos_copy(target_name) {
299    forward_variables_from(invoker,
300                           [
301                             "testonly",
302                             "visibility",
303
304                             "deps",
305                             "external_deps",
306                             "public_external_deps",
307                             "public_configs",
308                             "subsystem_name",
309                             "part_name",
310
311                             # For generate_module_info
312                             "install_images",
313                             "module_install_dir",
314                             "relative_install_dir",
315                             "symlink_target_name",
316                             "copy_linkable_file",
317
318                             # Open source license related
319                             "license_file",
320                             "license_as_sources",
321                           ])
322    sources = [ invoker.source ]
323    outputs = [ _copy_output ]
324    module_type = "etc"
325    prebuilt = true
326    install_enable = true
327    if (defined(invoker.install_enable)) {
328      install_enable = invoker.install_enable
329    }
330    if (defined(invoker.symlink_path)) {
331      symlink_path = invoker.symlink_path
332    }
333  }
334}
335
336template("ohos_prebuilt_rust_library") {
337  assert(defined(invoker.source), "source must be defined for ${target_name}.")
338
339  if (defined(invoker.output)) {
340    _copy_output = "${target_out_dir}/${invoker.output}"
341  } else {
342    _copy_output = "${target_out_dir}/${invoker.source}"
343  }
344  config("${target_name}__config") {
345    libs = [ _copy_output ]
346  }
347
348  if (!defined(invoker.deps)) {
349    invoker.deps = []
350  }
351
352  if (!defined(invoker.stable)) {
353    invoker.stable = false
354  }
355
356  # auto set auto_relative_install_dir by innerapi_tags
357  if (defined(invoker.innerapi_tags)) {
358    is_chipsetsdk = false
359    is_platformsdk = false
360    is_passthrough = false
361    foreach(tag, filter_include(invoker.innerapi_tags, [ "chipsetsdk*" ])) {
362      is_chipsetsdk = true
363    }
364    foreach(tag, filter_include(invoker.innerapi_tags, [ "platformsdk*" ])) {
365      is_platformsdk = true
366    }
367    foreach(tag, filter_include(invoker.innerapi_tags, [ "passthrough*" ])) {
368      is_passthrough = true
369    }
370
371    if (is_chipsetsdk && is_platformsdk) {
372      auto_relative_install_dir = "chipset-pub-sdk"
373    } else if (is_chipsetsdk) {
374      auto_relative_install_dir = "chipset-sdk"
375    } else if (is_platformsdk) {
376      auto_relative_install_dir = "platformsdk"
377    }
378    if (is_passthrough) {
379      auto_relative_install_dir = chipset_passthrough_dir
380    }
381
382    is_ndk = false
383    foreach(tag, filter_include(invoker.innerapi_tags, [ "ndk" ])) {
384      is_ndk = true
385    }
386    if (is_ndk) {
387      auto_relative_install_dir = "ndk"
388    }
389  }
390
391  deps_info = []
392  foreach(dep, invoker.deps) {
393    info = {
394    }
395    info = {
396      target_out_dir =
397          rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir)
398      target_name = get_label_info(dep, "name")
399    }
400    deps_info += [ info ]
401  }
402  module_label = get_label_info(":${target_name}", "label_with_toolchain")
403  target_deps_data = {
404    label = module_label
405    module_deps_info = deps_info
406    type = "rust_library"
407    prebuilt = true
408    stable = invoker.stable
409    toolchain = get_label_info(":${target_name}", "toolchain")
410    source_path = rebase_path(invoker.source, root_build_dir)
411    output_path = rebase_path(_copy_output, root_build_dir)
412  }
413  write_file("${target_out_dir}/${target_name}_deps_data.json",
414             target_deps_data,
415             "json")
416
417  ohos_copy(target_name) {
418    forward_variables_from(invoker,
419                           [
420                             "testonly",
421                             "visibility",
422                             "rust_crate_name",
423                             "rust_crate_type",
424                             "copy_linkable_file",
425                             "deps",
426                             "external_deps",
427                             "public_external_deps",
428                             "public_configs",
429                             "subsystem_name",
430                             "part_name",
431
432                             # For generate_module_info
433                             "install_images",
434                             "module_install_dir",
435                             "symlink_target_name",
436                             "innerapi_tags",
437                             "symlink_ext",
438
439                             # Open source license related
440                             "license_file",
441                             "license_as_sources",
442                           ])
443    sources = [ invoker.source ]
444    outputs = [ _copy_output ]
445    module_type = "lib"
446    prebuilt = true
447    install_enable = true
448    if (!defined(invoker.copy_linkable_file)) {
449      copy_linkable_file = true
450    }
451    if (defined(invoker.install_enable)) {
452      install_enable = invoker.install_enable
453    }
454
455    # update relative_install_dir if auto_relative_install_dir defined
456    if (defined(auto_relative_install_dir)) {
457      relative_install_dir = auto_relative_install_dir
458    }
459    if (defined(invoker.relative_install_dir)) {
460      relative_install_dir = invoker.relative_install_dir
461    }
462    if (!defined(public_configs)) {
463      public_configs = []
464    }
465    public_configs += [ ":${target_name}__config" ]
466  }
467}
468