symlink.gni 2.5 KB

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