generate_wrapper.gni 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright 2019 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. # Wraps a target and any of its arguments to an executable script.
  5. #
  6. # Many executable targets have build-time-constant arguments. This
  7. # template allows those to be wrapped into a single, user- or bot-friendly
  8. # script at build time.
  9. #
  10. # Paths to be wrapped should be relative to root_build_dir and should be
  11. # wrapped in "@WrappedPath(...)"; see Example below.
  12. #
  13. # Variables:
  14. # generator_script: Path to the script to use to perform the wrapping.
  15. # Defaults to //build/util/generate_wrapper.py. Generally should only
  16. # be set by other templates.
  17. # wrapper_script: Output path.
  18. # executable: Path to the executable to wrap. Can be a script or a
  19. # build product. Paths can be relative to the containing gn file
  20. # or source-absolute.
  21. # executable_args: List of arguments to write into the wrapper.
  22. #
  23. # Example wrapping a checked-in script:
  24. # generate_wrapper("sample_wrapper") {
  25. # executable = "//for/bar/sample.py"
  26. # wrapper_script = "$root_build_dir/bin/run_sample"
  27. #
  28. # _sample_argument_path = "//sample/$target_cpu/lib/sample_lib.so"
  29. # _rebased_sample_argument_path = rebase_path(
  30. # _sample_argument_path,
  31. # root_build_dir)
  32. # executable_args = [
  33. # "--sample-lib", "@WrappedPath(${_rebased_sample_argument_path})",
  34. # ]
  35. # }
  36. #
  37. # Example wrapping a build product:
  38. # generate_wrapper("sample_wrapper") {
  39. # executable = "$root_build_dir/sample_build_product"
  40. # wrapper_script = "$root_build_dir/bin/run_sample_build_product"
  41. # }
  42. template("generate_wrapper") {
  43. _generator_script = "//build/util/generate_wrapper.py"
  44. if (defined(invoker.generator_script)) {
  45. _generator_script = invoker.generator_script
  46. }
  47. _executable_to_wrap = invoker.executable
  48. _wrapper_script = invoker.wrapper_script
  49. if (is_win) {
  50. _wrapper_script += ".bat"
  51. }
  52. if (defined(invoker.executable_args)) {
  53. _wrapped_arguments = invoker.executable_args
  54. } else {
  55. _wrapped_arguments = []
  56. }
  57. action(target_name) {
  58. forward_variables_from(invoker,
  59. TESTONLY_AND_VISIBILITY + [
  60. "assert_no_deps",
  61. "data",
  62. "data_deps",
  63. "deps",
  64. "public_deps",
  65. "sources",
  66. ])
  67. script = _generator_script
  68. if (!defined(data)) {
  69. data = []
  70. }
  71. data += [
  72. _wrapper_script,
  73. "//.vpython3",
  74. ]
  75. outputs = [ _wrapper_script ]
  76. _rebased_executable_to_wrap =
  77. rebase_path(_executable_to_wrap, root_build_dir)
  78. _rebased_wrapper_script = rebase_path(_wrapper_script, root_build_dir)
  79. if (is_win) {
  80. _script_language = "batch"
  81. } else {
  82. _script_language = "bash"
  83. }
  84. args = [
  85. "--executable",
  86. "@WrappedPath(${_rebased_executable_to_wrap})",
  87. "--wrapper-script",
  88. _rebased_wrapper_script,
  89. "--output-directory",
  90. rebase_path(root_build_dir, root_build_dir),
  91. "--script-language",
  92. _script_language,
  93. ]
  94. args += [ "--" ]
  95. args += _wrapped_arguments
  96. if (defined(invoker.write_runtime_deps)) {
  97. write_runtime_deps = invoker.write_runtime_deps
  98. }
  99. }
  100. }