asar.gni 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import("node.gni")
  2. # TODO(MarshallOfSound): Move to electron/node, this is the only place it is used now
  3. # Run an action with a given working directory. Behaves identically to the
  4. # action() target type, with the exception that it changes directory before
  5. # running the script.
  6. #
  7. # Parameters:
  8. # cwd [required]: Directory to change to before running the script.
  9. template("chdir_action") {
  10. action(target_name) {
  11. forward_variables_from(invoker,
  12. "*",
  13. [
  14. "script",
  15. "args",
  16. ])
  17. assert(defined(cwd), "Need cwd in $target_name")
  18. script = "//electron/build/run-in-dir.py"
  19. if (defined(sources)) {
  20. sources += [ invoker.script ]
  21. } else {
  22. assert(defined(inputs))
  23. inputs += [ invoker.script ]
  24. }
  25. args = [
  26. rebase_path(cwd),
  27. rebase_path(invoker.script),
  28. ]
  29. args += invoker.args
  30. }
  31. }
  32. template("asar") {
  33. assert(defined(invoker.sources),
  34. "Need sources in $target_name listing the source files")
  35. assert(defined(invoker.outputs),
  36. "Need asar name (as 1-element array, e.g. \$root_out_dir/foo.asar)")
  37. assert(defined(invoker.root), "Need the base dir for generating the ASAR")
  38. node_action(target_name) {
  39. forward_variables_from(invoker,
  40. "*",
  41. [
  42. "script",
  43. "args",
  44. ])
  45. script = "//electron/script/gn-asar.js"
  46. args = [
  47. "--base",
  48. rebase_path(root),
  49. "--files",
  50. ] + rebase_path(sources) +
  51. [
  52. "--out",
  53. rebase_path(outputs[0]),
  54. ]
  55. }
  56. node_action(target_name + "_header_hash") {
  57. invoker_out = invoker.outputs
  58. deps = [ ":" + invoker.target_name ]
  59. sources = invoker.outputs
  60. script = "//electron/script/gn-asar-hash.js"
  61. outputs = [ "$target_gen_dir/asar_hashes/$target_name.hash" ]
  62. args = [
  63. rebase_path(invoker_out[0]),
  64. rebase_path(outputs[0]),
  65. ]
  66. }
  67. }
  68. template("asar_hashed_info_plist") {
  69. node_action(target_name) {
  70. assert(defined(invoker.plist_file),
  71. "Need plist_file to add hashed assets to")
  72. assert(defined(invoker.keys), "Need keys to replace with asset hash")
  73. assert(defined(invoker.hash_targets), "Need hash_targets to read hash from")
  74. deps = invoker.hash_targets
  75. script = "//electron/script/gn-plist-but-with-hashes.js"
  76. inputs = [ invoker.plist_file ]
  77. outputs = [ "$target_gen_dir/hashed_plists/$target_name.plist" ]
  78. hash_files = []
  79. foreach(hash_target, invoker.hash_targets) {
  80. hash_files += get_target_outputs(hash_target)
  81. }
  82. args = [
  83. rebase_path(invoker.plist_file),
  84. rebase_path(outputs[0]),
  85. ] + invoker.keys + rebase_path(hash_files)
  86. }
  87. }