Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 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 | |
Wyatt Hepler | 51ded74 | 2020-10-19 14:45:27 -0700 | [diff] [blame] | 15 | import("python_action.gni") |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 16 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 17 | declare_args() { |
| 18 | # Whether to build host-side tooling. |
| 19 | pw_build_HOST_TOOLS = false |
| 20 | } |
| 21 | |
| 22 | if (pw_build_HOST_TOOLS) { |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 23 | # Defines a Pigweed host tool and installs it into the host_tools directory. |
| 24 | # |
| 25 | # Args: |
Wyatt Hepler | 8224a64 | 2020-07-29 08:55:56 -0700 | [diff] [blame] | 26 | # tool: The target that outputs the binary tool. |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 27 | # name: Optional name for the installed program. Defaults to the name of |
| 28 | # the compiled binary. |
| 29 | template("pw_host_tool") { |
Wyatt Hepler | 8224a64 | 2020-07-29 08:55:56 -0700 | [diff] [blame] | 30 | assert(defined(invoker.tool), |
| 31 | "pw_host_tool must specify an executable as the tool variable") |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 32 | |
| 33 | _script_args = [ |
| 34 | "--src", |
Wyatt Hepler | 8224a64 | 2020-07-29 08:55:56 -0700 | [diff] [blame] | 35 | "<TARGET_FILE(${invoker.tool})>", |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 36 | "--dst", |
Michael Spang | c8b9390 | 2021-05-30 15:53:56 -0400 | [diff] [blame] | 37 | rebase_path("$root_out_dir/host_tools", root_build_dir), |
Alexei Frolov | fb27737 | 2019-12-26 16:23:46 -0800 | [diff] [blame] | 38 | "--out-root", |
Michael Spang | c8b9390 | 2021-05-30 15:53:56 -0400 | [diff] [blame] | 39 | rebase_path(root_out_dir, root_build_dir), |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 40 | ] |
| 41 | |
| 42 | if (defined(invoker.name) && invoker.name != "") { |
| 43 | _script_args += [ |
| 44 | "--name", |
| 45 | invoker.name, |
| 46 | ] |
| 47 | } |
| 48 | |
Wyatt Hepler | c8e05a4 | 2020-10-19 14:49:39 -0700 | [diff] [blame] | 49 | pw_python_action(target_name) { |
Wyatt Hepler | 27f69f0 | 2020-07-27 09:06:21 -0700 | [diff] [blame] | 50 | script = "$dir_pw_build/py/pw_build/host_tool.py" |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 51 | args = _script_args |
Wyatt Hepler | 8224a64 | 2020-07-29 08:55:56 -0700 | [diff] [blame] | 52 | deps = [ invoker.tool ] |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 53 | 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 Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 65 | } # pw_build_HOST_TOOLS |