• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2024 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16template("hc_gen") {
17  assert(defined(invoker.sources), "sources are must")
18  if (defined(invoker.outputs)) {
19    foreach(o, invoker.outputs) {
20      if (o == string_replace(o, "{{", "")) {
21        specified_output_name = true
22      }
23    }
24  }
25  if (defined(specified_output_name) && specified_output_name) {
26    target_type = "action"
27  } else {
28    target_type = "action_foreach"
29  }
30
31  # get all hcs file by sources
32  hcs_inputs = exec_script("//build/config/components/hc_gen/hcs_build_info.py",
33                           rebase_path(invoker.sources),
34                           "list lines")
35
36  target(target_type, target_name) {
37    external_deps = [ "hdf_core:hc_gen" ]
38    script = "/usr/bin/env"
39    if (defined(ohos_lite)) {
40      script = "//build/lite/run_shell_cmd.py"
41    }
42    inputs = hcs_inputs
43    sources = invoker.sources
44    if (defined(invoker.hc_gen_hex) && invoker.hc_gen_hex) {
45      hc_flags = [
46        "-b",
47        "-i",
48        "-a",
49      ]
50      output_suffix = "_hex.c"
51      output_suffix2 = ".hcb"
52    } else if (defined(invoker.hc_gen_c) && invoker.hc_gen_c) {
53      hc_flags = [ "-t" ]
54      output_suffix = ".c"
55      output_suffix2 = ".h"
56    } else if (defined(invoker.hc_gen_macro) && invoker.hc_gen_macro) {
57      hc_flags = [ "-m" ]
58      output_suffix = ".h"
59    } else if (defined(invoker.hc_gen_start_cfg) && invoker.hc_gen_start_cfg) {
60      hc_flags = [ "-s" ]
61      output_suffix = ".cfg"
62    } else {
63      hc_flags = []
64      output_suffix = ".hcb"
65    }
66
67    if (defined(invoker.outputs)) {
68      outputs = invoker.outputs
69    } else {
70      outputs = [ "$target_gen_dir/{{source_name_part}}$output_suffix" ]
71    }
72    if (defined(output_suffix2)) {
73      outputs += [ string_replace(outputs[0], output_suffix, output_suffix2) ]
74    }
75    if (target_type == "action") {
76      src = rebase_path(sources[0], root_build_dir)
77    } else {
78      src = "{{source}}"
79    }
80
81    hc_gen_path =
82        rebase_path(get_label_info("hdf_core:hc_gen", "target_out_dir"))
83    if (ohos_indep_compiler_enable) {
84      hc_gen_path += "/libs"
85    }
86    args = [ hc_gen_path + "/hc-gen" ]
87    args += hc_flags
88    args += [
89      "-o",
90      rebase_path(string_replace(outputs[0], output_suffix, "")),
91      src,
92    ]
93  }
94}
95
96template("hc_gen_c") {
97  hc_gen_c = true
98  hc_gen(target_name) {
99    forward_variables_from(invoker, "*")
100  }
101}
102
103template("hc_gen_hex") {
104  hc_gen_hex = true
105  hc_gen(target_name) {
106    forward_variables_from(invoker, "*")
107  }
108}
109
110template("hc_gen_macro") {
111  hc_gen_macro = true
112  hc_gen(target_name) {
113    forward_variables_from(invoker, "*")
114  }
115}
116
117template("hc_gen_start_cfg") {
118  hc_gen_start_cfg = true
119  hc_gen(target_name) {
120    forward_variables_from(invoker, "*")
121  }
122}
123