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 15import("//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# 32template("pw_mirror_tree") { 33 assert(defined(invoker.sources), "'sources' must be provided") 34 assert(defined(invoker.directory) && invoker.directory != "", 35 "The output path must be specified as 'directory'") 36 37 if (defined(invoker.source_root)) { 38 _root = invoker.source_root 39 } else { 40 _root = "." 41 } 42 43 _deps = [] 44 if (defined(invoker.deps)) { 45 _deps += invoker.deps 46 } 47 48 _public_deps = [] 49 if (defined(invoker.public_deps)) { 50 _public_deps += invoker.public_deps 51 } 52 53 _copy_deps = [] 54 55 foreach(source, invoker.sources) { 56 _stripped_source = rebase_path(source, _root) 57 _subtarget_name = 58 string_replace("${target_name}_${_stripped_source}", "/", ".") 59 60 copy(_subtarget_name) { 61 sources = [ source ] 62 outputs = [ "${invoker.directory}/${_stripped_source}" ] 63 deps = _deps 64 public_deps = _public_deps 65 } 66 _copy_deps += [ ":${_subtarget_name}" ] 67 } 68 69 group(target_name) { 70 public_deps = _copy_deps 71 } 72} 73