xref: /aosp_15_r20/external/pigweed/pw_build/host_tool.gni (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2019 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("python_action.gni")
16
17# Defines a Pigweed host tool and installs it into the host_tools directory.
18#
19# Args:
20#   tool: The target that outputs the binary tool.
21#   name: Optional name for the installed program. Defaults to the name of
22#     the compiled binary.
23template("pw_host_tool") {
24  assert(defined(invoker.tool),
25         "pw_host_tool must specify an executable as the tool variable")
26
27  _script_args = [
28    "--src",
29    "<TARGET_FILE(${invoker.tool})>",
30    "--dst",
31    rebase_path("$root_out_dir/host_tools", root_build_dir),
32    "--out-root",
33    rebase_path(root_out_dir, root_build_dir),
34  ]
35
36  if (defined(invoker.name) && invoker.name != "") {
37    _script_args += [
38      "--name",
39      invoker.name,
40    ]
41  }
42
43  pw_python_action(target_name) {
44    script = "$dir_pw_build/py/pw_build/host_tool.py"
45    args = _script_args
46    deps = [ invoker.tool ]
47    python_deps = [ "$dir_pw_cli/py" ]
48    stamp = true
49  }
50}
51