asar.gni 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import("npm.gni")
  2. # Run an action with a given working directory. Behaves identically to the
  3. # action() target type, with the exception that it changes directory before
  4. # running the script.
  5. #
  6. # Parameters:
  7. # cwd [required]: Directory to change to before running the script.
  8. template("chdir_action") {
  9. action(target_name) {
  10. forward_variables_from(invoker,
  11. "*",
  12. [
  13. "script",
  14. "args",
  15. ])
  16. assert(defined(cwd), "Need cwd in $target_name")
  17. script = "//electron/build/run-in-dir.py"
  18. if (defined(sources)) {
  19. sources += [ invoker.script ]
  20. } else {
  21. assert(defined(inputs))
  22. inputs += [ invoker.script ]
  23. }
  24. args = [
  25. rebase_path(cwd),
  26. rebase_path(invoker.script),
  27. ]
  28. args += invoker.args
  29. }
  30. }
  31. template("asar") {
  32. assert(defined(invoker.sources),
  33. "Need sources in $target_name listing the JS files.")
  34. assert(defined(invoker.outputs),
  35. "Need asar name (as 1-element array, e.g. \$root_out_dir/foo.asar)")
  36. assert(defined(invoker.root), "Need asar root directory")
  37. asar_root = invoker.root
  38. # js2asar.py expects relative paths to its inputs, so we must run it in a
  39. # working directory in which those relative paths make sense.
  40. chdir_action(target_name) {
  41. sources = invoker.sources
  42. outputs = invoker.outputs
  43. script = "//electron/tools/js2asar.py"
  44. cwd = rebase_path(get_path_info(".", "abspath"))
  45. args = rebase_path(outputs, cwd) + [ asar_root ] + rebase_path(sources, ".")
  46. }
  47. }