asar.gni 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. template("node_action") {
  2. assert(defined(invoker.script), "Need script path to run")
  3. assert(defined(invoker.args), "Need script arguments")
  4. action(target_name) {
  5. forward_variables_from(invoker,
  6. [
  7. "deps",
  8. "public_deps",
  9. "sources",
  10. "inputs",
  11. "outputs",
  12. ])
  13. if (!defined(inputs)) {
  14. inputs = []
  15. }
  16. inputs += [ invoker.script ]
  17. script = "//electron/build/run-node.py"
  18. args = [ rebase_path(invoker.script) ] + invoker.args
  19. }
  20. }
  21. template("asar") {
  22. assert(defined(invoker.sources),
  23. "Need sources in $target_name listing the source files")
  24. assert(defined(invoker.outputs),
  25. "Need asar name (as 1-element array, e.g. \$root_out_dir/foo.asar)")
  26. assert(defined(invoker.root), "Need the base dir for generating the ASAR")
  27. node_action(target_name) {
  28. forward_variables_from(invoker,
  29. "*",
  30. [
  31. "script",
  32. "args",
  33. ])
  34. script = "//electron/script/gn-asar.js"
  35. args = [
  36. "--base",
  37. rebase_path(root),
  38. "--files",
  39. ] + rebase_path(sources) +
  40. [
  41. "--out",
  42. rebase_path(outputs[0]),
  43. ]
  44. }
  45. node_action(target_name + "_header_hash") {
  46. invoker_out = invoker.outputs
  47. deps = [ ":" + invoker.target_name ]
  48. sources = invoker.outputs
  49. script = "//electron/script/gn-asar-hash.js"
  50. outputs = [ "$target_gen_dir/asar_hashes/$target_name.hash" ]
  51. args = [
  52. rebase_path(invoker_out[0]),
  53. rebase_path(outputs[0]),
  54. ]
  55. }
  56. }
  57. template("asar_hashed_info_plist") {
  58. node_action(target_name) {
  59. assert(defined(invoker.plist_file),
  60. "Need plist_file to add hashed assets to")
  61. assert(defined(invoker.keys), "Need keys to replace with asset hash")
  62. assert(defined(invoker.hash_targets), "Need hash_targets to read hash from")
  63. deps = invoker.hash_targets
  64. script = "//electron/script/gn-plist-but-with-hashes.js"
  65. inputs = [ invoker.plist_file ]
  66. outputs = [ "$target_gen_dir/hashed_plists/$target_name.plist" ]
  67. hash_files = []
  68. foreach(hash_target, invoker.hash_targets) {
  69. hash_files += get_target_outputs(hash_target)
  70. }
  71. args = [
  72. rebase_path(invoker.plist_file),
  73. rebase_path(outputs[0]),
  74. ] + invoker.keys + rebase_path(hash_files)
  75. }
  76. }