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 | |
| 15 | import("python_script.gni") |
| 16 | |
| 17 | if (pw_build_host_tools) { |
| 18 | # Defines a Pigweed host tool and installs it into the host_tools directory. |
| 19 | # |
| 20 | # Args: |
| 21 | # deps: List containing exactly one target which outputs a binary tool. |
| 22 | # name: Optional name for the installed program. Defaults to the name of |
| 23 | # the compiled binary. |
| 24 | template("pw_host_tool") { |
| 25 | assert(defined(invoker.deps), |
| 26 | "pw_host_tool must specify an executable as a dependency") |
| 27 | |
| 28 | num_deps = 0 |
| 29 | foreach(_dep, invoker.deps) { |
| 30 | num_deps += 1 |
| 31 | } |
| 32 | assert(num_deps == 1, "pw_host_tool must have exactly one dependency") |
| 33 | |
| 34 | _host_tools_dir = "$root_out_dir/host_tools" |
| 35 | |
| 36 | # Can't do invoker.deps[0] in GN. |
| 37 | _deps = invoker.deps |
| 38 | _out_target = get_label_info(_deps[0], "target_out_dir") + ":" + |
| 39 | get_label_info(_deps[0], "name") |
| 40 | |
| 41 | _script_args = [ |
| 42 | "--src", |
| 43 | _out_target, |
| 44 | "--dst", |
| 45 | _host_tools_dir, |
Alexei Frolov | fb27737 | 2019-12-26 16:23:46 -0800 | [diff] [blame^] | 46 | "--out-root", |
| 47 | root_out_dir, |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 48 | ] |
| 49 | |
| 50 | if (defined(invoker.name) && invoker.name != "") { |
| 51 | _script_args += [ |
| 52 | "--name", |
| 53 | invoker.name, |
| 54 | ] |
| 55 | } |
| 56 | |
| 57 | pw_python_script(target_name) { |
| 58 | script = "$dir_pw_build/py/host_tool.py" |
| 59 | args = _script_args |
| 60 | deps = _deps |
| 61 | stamp = true |
| 62 | } |
| 63 | } |
| 64 | } else { |
| 65 | # For builds without host tools, create an empty target. |
| 66 | template("pw_host_tool") { |
| 67 | not_needed("*") |
| 68 | not_needed(invoker, "*") |
| 69 | |
| 70 | group(target_name) { |
| 71 | } |
| 72 | } |
| 73 | } # pw_build_host_tools |