1# Copyright 2015 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# Creates a symlink. 6# Args: 7# source: Path to link to. 8# output: Where to create the symlink. 9template("symlink") { 10 action(target_name) { 11 forward_variables_from(invoker, 12 [ 13 "data_deps", 14 "deps", 15 "testonly", 16 "visibility", 17 ]) 18 outputs = [ invoker.output ] 19 script = "//build/symlink.py" 20 args = [ 21 "-f", 22 rebase_path(invoker.source, get_path_info(invoker.output, "dir")), 23 rebase_path(invoker.output, root_build_dir), 24 ] 25 if (defined(invoker.touch) && invoker.touch) { 26 args += [ "--touch=" + rebase_path(invoker.source, root_build_dir) ] 27 } 28 } 29} 30 31# Creates a symlink from root_build_dir/target_name to |binary_label|. This rule 32# is meant to be used within if (current_toolchain == default_toolchain) blocks 33# and point to targets in the non-default toolchain. 34# Note that for executables, using a copy (as opposed to a symlink) does not 35# work when is_component_build=true, since dependent libraries are found via 36# relative location. 37# 38# Args: 39# binary_label: Target that builds the file to symlink to. e.g.: 40# ":$target_name($host_toolchain)". 41# binary_output_name: The output_name set by the binary_label target 42# (if applicable). 43# output_name: Where to create the symlink 44# (default="$root_out_dir/$binary_output_name"). 45# 46# Example: 47# if (current_toolchain == host_toolchain) { 48# executable("foo") { ... } 49# } else if (current_toolchain == default_toolchain) { 50# binary_symlink("foo") { 51# binary_label = ":foo($host_toolchain)" 52# } 53# } 54template("binary_symlink") { 55 symlink(target_name) { 56 forward_variables_from(invoker, 57 [ 58 "output", 59 "testonly", 60 "visibility", 61 ]) 62 deps = [ invoker.binary_label ] 63 data_deps = [ invoker.binary_label ] 64 if (defined(invoker.data_deps)) { 65 data_deps += invoker.data_deps 66 } 67 68 _out_dir = get_label_info(invoker.binary_label, "root_out_dir") 69 if (defined(invoker.binary_output_name)) { 70 _name = invoker.binary_output_name 71 } else { 72 _name = get_label_info(invoker.binary_label, "name") 73 } 74 source = "$_out_dir/$_name" 75 76 _output_name = _name 77 if (defined(invoker.output_name)) { 78 _output_name = invoker.output_name 79 } 80 output = "$root_out_dir/$_output_name" 81 } 82} 83