compile_plist.gni 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright 2021 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. # Template to merge multiple plist files and perform variable substitutions.
  5. #
  6. # Arguments
  7. #
  8. # plist_templates:
  9. # string array, paths to plist files which will be used for the bundle.
  10. #
  11. # format:
  12. # string, the format to `plutil -convert` the plist to when
  13. # generating the output.
  14. #
  15. # substitutions:
  16. # string array, 'key=value' pairs used to replace ${key} by value
  17. # when generating the output plist file.
  18. #
  19. # output_name:
  20. # string, name of the generated plist file.
  21. template("compile_plist") {
  22. assert(defined(invoker.plist_templates),
  23. "A list of template plist files must be specified for $target_name")
  24. assert(defined(invoker.format),
  25. "The plist format must be specified for $target_name")
  26. assert(defined(invoker.substitutions),
  27. "A list of key=value pairs must be specified for $target_name")
  28. assert(defined(invoker.output_name),
  29. "The name of the output file must be specified for $target_name")
  30. _output_name = invoker.output_name
  31. _merged_name = get_path_info(_output_name, "dir") + "/" +
  32. get_path_info(_output_name, "name") + "_merged." +
  33. get_path_info(_output_name, "extension")
  34. _merge_target = target_name + "_merge"
  35. action(_merge_target) {
  36. forward_variables_from(invoker,
  37. [
  38. "deps",
  39. "testonly",
  40. ])
  41. script = "//build/apple/plist_util.py"
  42. sources = invoker.plist_templates
  43. outputs = [ _merged_name ]
  44. args = [
  45. "merge",
  46. "-f=" + invoker.format,
  47. "-o=" + rebase_path(_merged_name, root_build_dir),
  48. ] + rebase_path(invoker.plist_templates, root_build_dir)
  49. }
  50. action(target_name) {
  51. forward_variables_from(invoker,
  52. [
  53. "testonly",
  54. "visibility",
  55. ])
  56. script = "//build/apple/plist_util.py"
  57. sources = [ _merged_name ]
  58. outputs = [ _output_name ]
  59. args = [
  60. "substitute",
  61. "-f=" + invoker.format,
  62. "-o=" + rebase_path(_output_name, root_build_dir),
  63. "-t=" + rebase_path(_merged_name, root_build_dir),
  64. ]
  65. foreach(_substitution, invoker.substitutions) {
  66. args += [ "-s=$_substitution" ]
  67. }
  68. deps = [ ":$_merge_target" ]
  69. }
  70. }