1# Copyright 2019 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4# 5# Copy a list of file into a destination directory. Potentially renaming 6# files are they are copied. This also ensures that symlinks are followed 7# during the copy (i.e. the symlinks are never copied, only their content). 8# 9# Variables: 10# dest: Destination directory path. 11# sources: List of source files or directories to copy to dest. 12# renaming_sources: Optional list of source file paths that will be renamed 13# during the copy operation. If provided, renaming_destinations is required. 14# renaming_destinations: Optional list of destination file paths, required 15# when renaming_sources is provided. Both lists should have the same size 16# and matching entries. 17# args: Optional. Additionnal arguments to the copy_ex.py script. 18# 19# The following variables have the usual GN meaning: data, deps, inputs, 20# outputs, testonly, visibility. 21 22import("//build/config/python.gni") 23 24template("copy_ex") { 25 action_with_pydeps(target_name) { 26 forward_variables_from(invoker, 27 [ 28 "data", 29 "deps", 30 "public_deps", 31 "testonly", 32 "visibility", 33 ]) 34 sources = [] 35 if (defined(invoker.sources)) { 36 sources += invoker.sources 37 } 38 outputs = [] 39 if (defined(invoker.outputs)) { 40 outputs += invoker.outputs 41 } 42 if (defined(invoker.inputs)) { 43 inputs = invoker.inputs 44 } 45 46 script = "//build/android/gyp/copy_ex.py" 47 48 args = [ 49 "--dest", 50 rebase_path(invoker.dest, root_build_dir), 51 ] 52 rebased_sources = rebase_path(sources, root_build_dir) 53 args += [ "--files=$rebased_sources" ] 54 55 if (defined(invoker.args)) { 56 args += invoker.args 57 } 58 59 if (defined(invoker.renaming_sources) && 60 defined(invoker.renaming_destinations)) { 61 sources += invoker.renaming_sources 62 renaming_destinations = invoker.renaming_destinations 63 outputs += 64 get_path_info(rebase_path(renaming_destinations, ".", invoker.dest), 65 "abspath") 66 rebased_renaming_sources = 67 rebase_path(invoker.renaming_sources, root_build_dir) 68 args += [ "--renaming-sources=$rebased_renaming_sources" ] 69 args += [ "--renaming-destinations=$renaming_destinations" ] 70 } 71 } 72} 73