• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2025 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/config/components/ets_frontend/ets2abc_config.gni")
15
16template("link_abc_files") {
17  assert(defined(invoker.targets), "Must specify 'targets'")
18  assert(defined(invoker.output_name), "Must specify 'output_name'")
19
20  action(target_name) {
21    forward_variables_from(invoker,
22                           [
23                             "deps",
24                             "testonly",
25                             "visibility",
26                           ])
27
28    if (!defined(deps)) {
29      deps = []
30    }
31
32    # Add all target dependencies
33    foreach(target, invoker.targets) {
34      deps += [ target ]
35    }
36
37    # Determine output directory
38    if (defined(invoker.output_dir)) {
39      output_dir = invoker.output_dir
40    } else {
41      output_dir = get_label_info(":$target_name", "target_out_dir")
42    }
43
44    # Set output file
45    output_file = "$output_dir/${invoker.output_name}.abc"
46    outputs = [ output_file ]
47
48    # Collect input .abc files
49    input_files = []
50    foreach(target, invoker.targets) {
51      target_out_dir = get_label_info(target, "target_out_dir")
52      target_name = get_label_info(target, "name")
53    #   target_label = get_label_info(target, "label_no_toolchain")
54      component_name = string_replace(target_name, "_", ".")
55      input_files += [ "$target_out_dir/${component_name}" ]
56    }
57
58    # Script that will be executed
59    script = "./run_binary.py"
60
61    # Build arguments for the link command
62    args = [
63      rebase_path("${static_linker_build_path}"),
64      "--output",
65      rebase_path(output_file, root_build_dir),
66      "--",
67    ]
68
69    # Add all input files to the arguments
70    foreach(input_file, input_files) {
71      args += [ rebase_path(input_file, root_build_dir) ]
72    }
73  }
74}