Wyatt Hepler | e59706b | 2021-03-02 09:00:25 -0800 | [diff] [blame^] | 1 | # Copyright 2021 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("//build_overrides/pigweed.gni") |
| 16 | |
| 17 | # Mirrors a directory structure to the output directory. |
| 18 | # |
| 19 | # This is similar to a GN copy target, with some differences: |
| 20 | # |
| 21 | # - The outputs list is generated by the template based on the source_root and |
| 22 | # directory arguments, rather than using source expansion. |
| 23 | # - The source_root argument can be used to trim prefixes from source files. |
| 24 | # - pw_mirror_tree uses hard links instead of copies for efficiency. |
| 25 | # |
| 26 | # Args: |
| 27 | # |
| 28 | # directory: Output directory for the files. |
| 29 | # sources: List of files to mirror to the output directory. |
| 30 | # source_root: Root path for sources; defaults to ".". |
| 31 | # |
| 32 | template("pw_mirror_tree") { |
| 33 | assert(defined(invoker.sources) && invoker.sources != [], |
| 34 | "At least one source file must be provided in 'sources'") |
| 35 | assert(defined(invoker.directory) && invoker.directory != "", |
| 36 | "The output path must be specified as 'directory'") |
| 37 | |
| 38 | if (defined(invoker.source_root)) { |
| 39 | _root = invoker.source_root |
| 40 | } else { |
| 41 | _root = "." |
| 42 | } |
| 43 | |
| 44 | action(target_name) { |
| 45 | script = "$dir_pw_build/py/pw_build/mirror_tree.py" |
| 46 | |
| 47 | outputs = [] |
| 48 | foreach(path, rebase_path(invoker.sources, _root)) { |
| 49 | outputs += [ "${invoker.directory}/$path" ] |
| 50 | } |
| 51 | |
| 52 | args = [ |
| 53 | "--source-root", |
| 54 | rebase_path(_root), |
| 55 | "--directory", |
| 56 | rebase_path(invoker.directory), |
| 57 | ] + rebase_path(invoker.sources) |
| 58 | |
| 59 | forward_variables_from(invoker, "*", [ "script" ]) |
| 60 | } |
| 61 | } |