diff --git a/BUILD.gn b/BUILD.gn index 8d8000dc28..959c811dad 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -137,7 +137,12 @@ action("atom_js2c") { rebase_path(sources, root_build_dir) } -asar("js2asar") { +target_gen_electron_js = "$target_gen_dir/js/electron" +target_gen_default_app_js = "$target_gen_dir/js/default_app" + +# TODO(MarshallOfSound) +# This copy will be replaced by a call to tsc in the future +copy("lib_js") { sources = filenames.js_sources if (enable_desktop_capturer) { sources += [ @@ -156,18 +161,50 @@ asar("js2asar") { "lib/browser/api/views/text-field.js", ] } + + outputs = [ + "$target_gen_electron_js/{{source}}", + ] +} + +asar("electron_asar") { + deps = [ + ":lib_js", + ] + + root = "$target_gen_electron_js/electron/lib" + sources = get_target_outputs(":lib_js") outputs = [ "$root_out_dir/resources/electron.asar", ] - root = "lib" } -asar("app2asar") { +copy("default_app_js") { sources = filenames.default_app_sources + outputs = [ + "$target_gen_default_app_js/{{source}}", + ] +} + +copy("default_app_octicon_deps") { + sources = filenames.default_app_octicon_sources + outputs = [ + "$target_gen_default_app_js/electron/default_app/octicon/{{source_file_part}}", + ] +} + +asar("default_app_asar") { + deps = [ + ":default_app_js", + ":default_app_octicon_deps", + ] + + root = "$target_gen_default_app_js/electron/default_app" + sources = get_target_outputs(":default_app_js") + + get_target_outputs(":default_app_octicon_deps") outputs = [ "$root_out_dir/resources/default_app.asar", ] - root = "default_app" } grit("resources") { @@ -712,9 +749,9 @@ if (is_mac) { bundle_data("electron_app_resources") { public_deps = [ - ":app2asar", + ":default_app_asar", ":electron_app_strings_bundle_data", - ":js2asar", + ":electron_asar", ] sources = [ "$root_out_dir/resources/default_app.asar", @@ -760,10 +797,10 @@ if (is_mac) { sources = filenames.app_sources include_dirs = [ "." ] deps = [ - ":app2asar", + ":default_app_asar", ":electron_app_manifest", + ":electron_asar", ":electron_lib", - ":js2asar", ":packed_resources", "//content:sandbox_helper_win", "//ui/strings", diff --git a/build/asar.gni b/build/asar.gni index 110a1d8928..4df8ea34dd 100644 --- a/build/asar.gni +++ b/build/asar.gni @@ -1,5 +1,6 @@ -import("npm.gni") +import("node.gni") +# TODO(MarshallOfSound): Move to electron/node, this is the only place it is used now # Run an action with a given working directory. Behaves identically to the # action() target type, with the exception that it changes directory before # running the script. @@ -32,19 +33,28 @@ template("chdir_action") { template("asar") { assert(defined(invoker.sources), - "Need sources in $target_name listing the JS files.") + "Need sources in $target_name listing the source files") assert(defined(invoker.outputs), "Need asar name (as 1-element array, e.g. \$root_out_dir/foo.asar)") - assert(defined(invoker.root), "Need asar root directory") - asar_root = invoker.root + assert(defined(invoker.root), "Need the base dir for generating the ASAR") - # js2asar.py expects relative paths to its inputs, so we must run it in a - # working directory in which those relative paths make sense. - chdir_action(target_name) { - sources = invoker.sources - outputs = invoker.outputs - script = "//electron/tools/js2asar.py" - cwd = rebase_path(get_path_info(".", "abspath")) - args = rebase_path(outputs, cwd) + [ asar_root ] + rebase_path(sources, ".") + node_action(target_name) { + forward_variables_from(invoker, + "*", + [ + "script", + "args", + ]) + + script = "//electron/script/gn-asar.js" + args = [ + "--base", + rebase_path(root), + "--files", + ] + rebase_path(sources) + + [ + "--out", + rebase_path(outputs[0]), + ] } } diff --git a/build/node.gni b/build/node.gni new file mode 100644 index 0000000000..a65f718e63 --- /dev/null +++ b/build/node.gni @@ -0,0 +1,21 @@ +template("node_action") { + assert(defined(invoker.script), "Need script path to run") + assert(defined(invoker.args), "Need script argumets") + + action(target_name) { + forward_variables_from(invoker, + [ + "deps", + "public_deps", + "sources", + "inputs", + "outputs", + ]) + if (!defined(inputs)) { + inputs = [] + } + inputs += [ invoker.script ] + script = "//electron/build/run-node.py" + args = [ rebase_path(invoker.script) ] + invoker.args + } +} diff --git a/build/run-node.py b/build/run-node.py new file mode 100644 index 0000000000..0e0c30d671 --- /dev/null +++ b/build/run-node.py @@ -0,0 +1,14 @@ +import os +import subprocess +import sys + + +SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__)) + +def main(): + # Proxy all args to node script + script = os.path.join(SOURCE_ROOT, sys.argv[1]) + subprocess.check_call(['node', script] + [str(x) for x in sys.argv[2:]]) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/default_app/index.html b/default_app/index.html index c2a796291d..cba87e5eef 100644 --- a/default_app/index.html +++ b/default_app/index.html @@ -4,7 +4,7 @@