Browse Source

fix: generate valid config.gypi (#31989)

* fix: generate valid config.gypi

* chore: update patches

Co-authored-by: Cheng Zhao <[email protected]>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
trop[bot] 3 years ago
parent
commit
b07b268fd0

+ 6 - 0
BUILD.gn

@@ -183,6 +183,12 @@ action("electron_js2c") {
          rebase_path(sources, root_build_dir)
 }
 
+action("generate_config_gypi") {
+  outputs = [ "$root_gen_dir/config.gypi" ]
+  script = "script/generate-config-gypi.py"
+  args = rebase_path(outputs) + [ target_cpu ]
+}
+
 target_gen_default_app_js = "$target_gen_dir/js/default_app"
 
 typescript_build("default_app_js") {

+ 0 - 1
patches/node/.patches

@@ -6,7 +6,6 @@ feat_initialize_asar_support.patch
 expose_get_builtin_module_function.patch
 build_add_gn_build_files.patch
 fix_add_default_values_for_enable_lto_and_build_v8_with_gn_in.patch
-feat_add_new_built_with_electron_variable_to_config_gypi.patch
 feat_add_flags_for_low-level_hooks_and_exceptions.patch
 fix_expose_tracing_agent_and_use_tracing_tracingcontroller_instead.patch
 pass_all_globals_through_require.patch

+ 6 - 31
patches/node/build_add_gn_build_files.patch

@@ -7,10 +7,10 @@ This adds GN build files for Node, so we don't have to build with GYP.
 
 diff --git a/BUILD.gn b/BUILD.gn
 new file mode 100644
-index 0000000000000000000000000000000000000000..446119163d1f7bad577cb0b7b217ecf24b994526
+index 0000000000000000000000000000000000000000..f267a14ffd12828417e441c09ca3a673236dfd34
 --- /dev/null
 +++ b/BUILD.gn
-@@ -0,0 +1,360 @@
+@@ -0,0 +1,352 @@
 +import("//electron/build/asar.gni")
 +import("//v8/gni/v8.gni")
 +
@@ -75,20 +75,12 @@ index 0000000000000000000000000000000000000000..446119163d1f7bad577cb0b7b217ecf2
 +  ]
 +}
 +
-+action("generate_config_gypi") {
-+  outputs = [
-+    "$target_gen_dir/config.gypi",
-+  ]
-+  script = "tools/generate_config_gypi.py"
-+  args = rebase_path(outputs, root_build_dir)
-+}
-+
 +chdir_action("node_js2c") {
 +  deps = [
-+    ":generate_config_gypi",
++    "//electron:generate_config_gypi",
 +    ":node_js2c_inputs",
 +  ]
-+  config_gypi = [ "$target_gen_dir/config.gypi" ]
++  config_gypi = [ "$root_gen_dir/config.gypi" ]
 +  inputs = library_files + config_gypi
 +  outputs = [
 +    "$target_gen_dir/node_javascript.cc",
@@ -319,10 +311,10 @@ index 0000000000000000000000000000000000000000..446119163d1f7bad577cb0b7b217ecf2
 +
 +copy("node_gypi_headers") {
 +  deps = [
-+    ":generate_config_gypi",
++    "//electron:generate_config_gypi",
 +  ]
 +  sources = [
-+    "$target_gen_dir/config.gypi",
++    "$root_gen_dir/config.gypi",
 +    "common.gypi",
 +  ]
 +  outputs = [
@@ -1647,23 +1639,6 @@ index 0f72abc0bf0302e1f535f71803f5aa063424f8b9..c6a76e408312d8fcfc48490827273319
  
  // The NAPI_VERSION provided by this version of the runtime. This is the version
  // which the Node binary being built supports.
-diff --git a/tools/generate_config_gypi.py b/tools/generate_config_gypi.py
-new file mode 100644
-index 0000000000000000000000000000000000000000..01f62d4ae6e3b9d539444e3dff069f0011353caa
---- /dev/null
-+++ b/tools/generate_config_gypi.py
-@@ -0,0 +1,11 @@
-+# TODO: assess which if any of the config variables are important to include in
-+# the js2c'd config.gypi.
-+import sys
-+
-+def main(args):
-+  out = args[0]
-+  with open(out, 'w') as f:
-+    f.write("{'variables':{}}\n")
-+
-+if __name__ == '__main__':
-+  main(sys.argv[1:])
 diff --git a/tools/generate_gn_filenames_json.py b/tools/generate_gn_filenames_json.py
 new file mode 100755
 index 0000000000000000000000000000000000000000..e5fd79da5323e7039730fd8cca66caae8c84e903

+ 0 - 21
patches/node/feat_add_new_built_with_electron_variable_to_config_gypi.patch

@@ -1,21 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Shelley Vohr <[email protected]>
-Date: Tue, 2 Oct 2018 11:39:58 -0700
-Subject: feat: add new built_with_electron variable to config.gypi
-
-This allows 3rd-party native modules to know whether they're being built
-against Electron.
-
-diff --git a/tools/generate_config_gypi.py b/tools/generate_config_gypi.py
-index 01f62d4ae6e3b9d539444e3dff069f0011353caa..d8b279f590c115108d5dca879747de7b0c9f1934 100644
---- a/tools/generate_config_gypi.py
-+++ b/tools/generate_config_gypi.py
-@@ -5,7 +5,7 @@ import sys
- def main(args):
-   out = args[0]
-   with open(out, 'w') as f:
--    f.write("{'variables':{}}\n")
-+    f.write("{'variables':{'built_with_electron': 1}}\n")
- 
- if __name__ == '__main__':
-   main(sys.argv[1:])

+ 65 - 0
script/generate-config-gypi.py

@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+import ast
+import os
+import pprint
+import re
+import subprocess
+import sys
+
+ELECTRON_DIR = os.path.abspath(os.path.join(__file__, '..', '..'))
+NODE_DIR = os.path.join(ELECTRON_DIR, '..', 'third_party', 'electron_node')
+
+def run_node_configure(target_cpu):
+  configure = os.path.join(NODE_DIR, 'configure.py')
+  args = ['--dest-cpu', target_cpu]
+  # Enabled in Chromium's V8.
+  if target_cpu == 'arm64' or target_cpu == 'x64':
+    args += ['--experimental-enable-pointer-compression']
+  # Work around "No acceptable ASM compiler found" error on some Windows
+  # machines, it breaks nothing since Electron does not use OpenSSL.
+  if sys.platform == 'win32':
+    args += ['--openssl-no-asm']
+  subprocess.check_call([sys.executable, configure] + args)
+
+def read_node_config_gypi():
+  config_gypi = os.path.join(NODE_DIR, 'config.gypi')
+  with open(config_gypi, 'r') as f:
+    content = f.read()
+    return ast.literal_eval(content)
+
+def read_electron_args():
+  all_gn = os.path.join(ELECTRON_DIR, 'build', 'args', 'all.gn')
+  args = {}
+  with open(all_gn, 'r') as f:
+    for line in f:
+      if line.startswith('#'):
+        continue
+      m = re.match('([\w_]+) = (.+)', line)
+      if m == None:
+        continue
+      args[m.group(1)] = m.group(2)
+  return args
+
+def main(target_file, target_cpu):
+  run_node_configure(target_cpu)
+  config = read_node_config_gypi()
+  args = read_electron_args()
+
+  # Remove the generated config.gypi to make the parallel/test-process-config
+  # test pass.
+  os.remove(os.path.join(NODE_DIR, 'config.gypi'))
+
+  v = config['variables']
+  # Electron specific variables:
+  v['built_with_electron'] = 1
+  v['node_module_version'] = int(args['node_module_version'])
+  # Used by certain versions of node-gyp.
+  v['build_v8_with_gn'] = 'false'
+
+  with open(target_file, 'w+') as f:
+    f.write(pprint.pformat(config, indent=2))
+
+if __name__ == '__main__':
+  sys.exit(main(*sys.argv[1:]))