blob: b5a1ffc32dc0830c508bec328afdf875c4f18bea [file] [log] [blame]
Alexei Frolovca9cf602019-12-26 13:00:03 -08001# 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
Wyatt Hepler51ded742020-10-19 14:45:27 -070015import("python_action.gni")
Alexei Frolovca9cf602019-12-26 13:00:03 -080016
Alexei Frolov4c0428a2020-06-10 10:46:04 -070017declare_args() {
18 # Whether to build host-side tooling.
19 pw_build_HOST_TOOLS = false
20}
21
22if (pw_build_HOST_TOOLS) {
Alexei Frolovca9cf602019-12-26 13:00:03 -080023 # Defines a Pigweed host tool and installs it into the host_tools directory.
24 #
25 # Args:
Wyatt Hepler8224a642020-07-29 08:55:56 -070026 # tool: The target that outputs the binary tool.
Alexei Frolovca9cf602019-12-26 13:00:03 -080027 # name: Optional name for the installed program. Defaults to the name of
28 # the compiled binary.
29 template("pw_host_tool") {
Wyatt Hepler8224a642020-07-29 08:55:56 -070030 assert(defined(invoker.tool),
31 "pw_host_tool must specify an executable as the tool variable")
Alexei Frolovca9cf602019-12-26 13:00:03 -080032
33 _script_args = [
34 "--src",
Wyatt Hepler8224a642020-07-29 08:55:56 -070035 "<TARGET_FILE(${invoker.tool})>",
Alexei Frolovca9cf602019-12-26 13:00:03 -080036 "--dst",
Michael Spangc8b93902021-05-30 15:53:56 -040037 rebase_path("$root_out_dir/host_tools", root_build_dir),
Alexei Frolovfb277372019-12-26 16:23:46 -080038 "--out-root",
Michael Spangc8b93902021-05-30 15:53:56 -040039 rebase_path(root_out_dir, root_build_dir),
Alexei Frolovca9cf602019-12-26 13:00:03 -080040 ]
41
42 if (defined(invoker.name) && invoker.name != "") {
43 _script_args += [
44 "--name",
45 invoker.name,
46 ]
47 }
48
Wyatt Heplerc8e05a42020-10-19 14:49:39 -070049 pw_python_action(target_name) {
Wyatt Hepler27f69f02020-07-27 09:06:21 -070050 script = "$dir_pw_build/py/pw_build/host_tool.py"
Alexei Frolovca9cf602019-12-26 13:00:03 -080051 args = _script_args
Wyatt Hepler8224a642020-07-29 08:55:56 -070052 deps = [ invoker.tool ]
Alexei Frolovca9cf602019-12-26 13:00:03 -080053 stamp = true
54 }
55 }
56} else {
57 # For builds without host tools, create an empty target.
58 template("pw_host_tool") {
59 not_needed("*")
60 not_needed(invoker, "*")
61
62 group(target_name) {
63 }
64 }
Alexei Frolov4c0428a2020-06-10 10:46:04 -070065} # pw_build_HOST_TOOLS