From bfa58df7c97a7d2e191a5d7ac5ea1891e95f9907 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 22 Aug 2023 18:13:49 +0900 Subject: [PATCH] chore: move node headers generation to electron (#39589) --- .circleci/config/base.yml | 4 +- BUILD.gn | 68 +++++++++ appveyor-woa.yml | 4 +- appveyor.yml | 4 +- docs/development/build-instructions-gn.md | 2 +- docs/development/testing.md | 2 +- patches/node/build_add_gn_build_files.patch | 147 ++------------------ script/generate_node_version_header.py | 26 ++++ script/tar.py | 12 ++ 9 files changed, 123 insertions(+), 146 deletions(-) create mode 100755 script/generate_node_version_header.py create mode 100644 script/tar.py diff --git a/.circleci/config/base.yml b/.circleci/config/base.yml index 18a316cda1b0..a4e476ccbc3f 100644 --- a/.circleci/config/base.yml +++ b/.circleci/config/base.yml @@ -645,7 +645,7 @@ step-nodejs-headers-build: &step-nodejs-headers-build name: Build Node.js headers command: | cd src - ninja -C out/Default third_party/electron_node:headers + ninja -C out/Default electron:node_headers step-electron-publish: &step-electron-publish run: @@ -1072,7 +1072,7 @@ commands: build-type: << parameters.build-type >> - *step-maybe-electron-dist-strip - step-electron-dist-build: - additional-targets: shell_browser_ui_unittests third_party/electron_node:headers third_party/electron_node:overlapped-checker electron:hunspell_dictionaries_zip + additional-targets: shell_browser_ui_unittests electron:node_headers third_party/electron_node:overlapped-checker electron:hunspell_dictionaries_zip - *step-show-goma-stats diff --git a/BUILD.gn b/BUILD.gn index 2577ec5e0abb..7c1cdff21a4c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -9,6 +9,7 @@ import("//pdf/features.gni") import("//ppapi/buildflags/buildflags.gni") import("//printing/buildflags/buildflags.gni") import("//testing/test.gni") +import("//third_party/electron_node/node.gni") import("//third_party/ffmpeg/ffmpeg_options.gni") import("//tools/generate_library_loader/generate_library_loader.gni") import("//tools/grit/grit_rule.gni") @@ -1567,3 +1568,70 @@ action("libcxx_objects_zip") { group("electron") { public_deps = [ ":electron_app" ] } + +##### node_headers + +node_dir = "../third_party/electron_node" +node_files = read_file("$node_dir/filenames.json", "json") +node_headers_dir = "$root_gen_dir/node_headers" + +header_group_index = 0 +header_groups = [] +foreach(header_group, node_files.headers) { + copy("node_headers_${header_group_index}") { + sources = rebase_path(header_group.files, ".", node_dir) + outputs = + [ "$node_headers_dir/${header_group.dest_dir}/{{source_file_part}}" ] + } + header_groups += [ ":node_headers_${header_group_index}" ] + header_group_index += 1 +} + +copy("zlib_headers") { + sources = [ + "$node_dir/deps/zlib/zconf.h", + "$node_dir/deps/zlib/zlib.h", + ] + outputs = [ "$node_headers_dir/include/node/{{source_file_part}}" ] +} + +copy("node_gypi_headers") { + deps = [ ":generate_config_gypi" ] + sources = [ + "$node_dir/common.gypi", + "$root_gen_dir/config.gypi", + ] + outputs = [ "$node_headers_dir/include/node/{{source_file_part}}" ] +} + +action("node_version_header") { + inputs = [ "$node_dir/src/node_version.h" ] + outputs = [ "$node_headers_dir/include/node/node_version.h" ] + script = "script/generate_node_version_header.py" + args = rebase_path(inputs) + rebase_path(outputs) + if (node_module_version != "") { + args += [ "$node_module_version" ] + } +} + +action("tar_node_headers") { + deps = [ ":copy_node_headers" ] + outputs = [ "$root_gen_dir/node_headers.tar.gz" ] + script = "script/tar.py" + args = [ + rebase_path("$root_gen_dir/node_headers"), + rebase_path(outputs[0]), + ] +} + +group("copy_node_headers") { + public_deps = header_groups + [ + ":node_gypi_headers", + ":node_version_header", + ":zlib_headers", + ] +} + +group("node_headers") { + public_deps = [ ":tar_node_headers" ] +} diff --git a/appveyor-woa.yml b/appveyor-woa.yml index 68daad4cf4ff..bceebd1fb7e7 100644 --- a/appveyor-woa.yml +++ b/appveyor-woa.yml @@ -167,7 +167,7 @@ for: - cd ..\.. - ninja -C out/Default electron:hunspell_dictionaries_zip - ninja -C out/Default electron:electron_chromedriver_zip - - ninja -C out/Default third_party/electron_node:headers + - ninja -C out/Default electron:node_headers - python %LOCAL_GOMA_DIR%\goma_ctl.py stat - ps: >- Get-CimInstance -Namespace root\cimv2 -Class Win32_product | Select vendor, description, @{l='install_location';e='InstallLocation'}, @{l='install_date';e='InstallDate'}, @{l='install_date_2';e='InstallDate2'}, caption, version, name, @{l='sku_number';e='SKUNumber'} | ConvertTo-Json | Out-File -Encoding utf8 -FilePath .\installed_software.json @@ -319,4 +319,4 @@ for: on_finish: # Uncomment these lines to enable RDP # - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) - - if exist electron\electron.log ( appveyor-retry appveyor PushArtifact electron\electron.log ) \ No newline at end of file + - if exist electron\electron.log ( appveyor-retry appveyor PushArtifact electron\electron.log ) diff --git a/appveyor.yml b/appveyor.yml index f9f17eae6649..0830ae40312a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -165,7 +165,7 @@ for: - cd ..\.. - ninja -C out/Default electron:hunspell_dictionaries_zip - ninja -C out/Default electron:electron_chromedriver_zip - - ninja -C out/Default third_party/electron_node:headers + - ninja -C out/Default electron:node_headers - python %LOCAL_GOMA_DIR%\goma_ctl.py stat - ps: >- Get-CimInstance -Namespace root\cimv2 -Class Win32_product | Select vendor, description, @{l='install_location';e='InstallLocation'}, @{l='install_date';e='InstallDate'}, @{l='install_date_2';e='InstallDate2'}, caption, version, name, @{l='sku_number';e='SKUNumber'} | ConvertTo-Json | Out-File -Encoding utf8 -FilePath .\installed_software.json @@ -319,4 +319,4 @@ for: on_finish: # Uncomment these lines to enable RDP # - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) - - if exist electron\electron.log ( appveyor-retry appveyor PushArtifact electron\electron.log ) \ No newline at end of file + - if exist electron\electron.log ( appveyor-retry appveyor PushArtifact electron\electron.log ) diff --git a/docs/development/build-instructions-gn.md b/docs/development/build-instructions-gn.md index 4532a71ea68e..acf7cf048ac4 100644 --- a/docs/development/build-instructions-gn.md +++ b/docs/development/build-instructions-gn.md @@ -225,7 +225,7 @@ generate build headers for the modules to compile against, run the following under `src/` directory. ```sh -$ ninja -C out/Testing third_party/electron_node:headers +$ ninja -C out/Testing electron:node_headers ``` You can now [run the tests](testing.md#unit-tests). diff --git a/docs/development/testing.md b/docs/development/testing.md index f29738f6c727..cce8ea5eab46 100644 --- a/docs/development/testing.md +++ b/docs/development/testing.md @@ -66,7 +66,7 @@ the Node.js source tree. 2. Node headers have to be compiled for your configuration. ```powershell - ninja -C out\Testing third_party\electron_node:headers + ninja -C out\Testing electron:node_headers ``` 3. The electron.lib has to be copied as node.lib. diff --git a/patches/node/build_add_gn_build_files.patch b/patches/node/build_add_gn_build_files.patch index 7cd86fd3735f..90d428a52602 100644 --- a/patches/node/build_add_gn_build_files.patch +++ b/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..a3e4599c21f2faa92a0dca47b1e0b4e836bb475d +index 0000000000000000000000000000000000000000..e2b19b7500b4710e3a55e08f662d989c18272b70 --- /dev/null +++ b/BUILD.gn -@@ -0,0 +1,443 @@ +@@ -0,0 +1,358 @@ +import("//v8/gni/v8.gni") +import("node.gni") + @@ -51,9 +51,6 @@ index 0000000000000000000000000000000000000000..a3e4599c21f2faa92a0dca47b1e0b4e8 + # default to https://nodejs.org/download/release/') + node_release_urlbase = "" + -+ # Allows embedders to override the NODE_MODULE_VERSION define -+ node_module_version = "" -+ + # Allows downstream packagers (eg. Linux distributions) to build Electron against system shared libraries. + use_system_cares = false + use_system_nghttp2 = false @@ -372,88 +369,6 @@ index 0000000000000000000000000000000000000000..a3e4599c21f2faa92a0dca47b1e0b4e8 + cflags_cc += [ "-Wno-sign-compare" ] + } +} -+ -+##### node_headers -+ -+node_headers_dir = "$root_gen_dir/node_headers" -+ -+header_group_index = 0 -+header_groups = [] -+foreach(header_group, node_files.headers) { -+ copy("node_headers_${header_group_index}") { -+ sources = header_group.files -+ outputs = [ -+ "$node_headers_dir/${header_group.dest_dir}/{{source_file_part}}", -+ ] -+ } -+ header_groups += [ ":node_headers_${header_group_index}" ] -+ header_group_index += 1 -+} -+ -+copy("zlib_headers") { -+ sources = [ -+ "deps/zlib/zconf.h", -+ "deps/zlib/zlib.h", -+ ] -+ outputs = [ -+ "$node_headers_dir/include/node/{{source_file_part}}", -+ ] -+} -+ -+copy("node_gypi_headers") { -+ deps = [ -+ "//electron:generate_config_gypi", -+ ] -+ sources = [ -+ "$root_gen_dir/config.gypi", -+ "common.gypi", -+ ] -+ outputs = [ -+ "$node_headers_dir/include/node/{{source_file_part}}", -+ ] -+} -+ -+action("node_version_header") { -+ inputs = [ -+ "src/node_version.h", -+ ] -+ outputs = [ -+ "$node_headers_dir/include/node/node_version.h", -+ ] -+ script = "tools/generate_node_version_header.py" -+ args = [ rebase_path("src/node_version.h"), rebase_path(outputs[0]) ] -+ if (node_module_version != "") { -+ args += [ "$node_module_version" ] -+ } -+} -+ -+action("tar_headers") { -+ deps = [ -+ ":copy_headers", -+ ] -+ outputs = [ -+ "$root_gen_dir/node_headers.tar.gz", -+ ] -+ script = "tools/tar.py" -+ args = [ -+ rebase_path("$root_gen_dir/node_headers"), -+ rebase_path(outputs[0]), -+ ] -+} -+ -+group("copy_headers") { -+ public_deps = header_groups + [ -+ ":zlib_headers", -+ ":node_gypi_headers", -+ ":node_version_header", -+ ] -+} -+ -+group("headers") { -+ public_deps = [ -+ ":tar_headers", -+ ] -+} diff --git a/deps/ada/BUILD.gn b/deps/ada/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a564653c3f05608d59fed5aa071d63b81f4e0e42 @@ -1932,10 +1847,15 @@ index 0000000000000000000000000000000000000000..7d86765bf229275ba55d37a452ef2483 +} diff --git a/node.gni b/node.gni new file mode 100644 -index 0000000000000000000000000000000000000000..9b1a4048a4a64c36d88de0bbe1a548c906aaa22c +index 0000000000000000000000000000000000000000..345327e89d71585c558fabcf11970d7c5363cd3a --- /dev/null +++ b/node.gni -@@ -0,0 +1,29 @@ +@@ -0,0 +1,34 @@ ++declare_args() { ++ # Allows embedders to override the NODE_MODULE_VERSION define ++ node_module_version = "" ++} ++ +# 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. @@ -2286,37 +2206,6 @@ index 0000000000000000000000000000000000000000..616dc0c61ed4ea1bf2fb9e4768ba2ec5 + f.write(FILENAMES_JSON_HEADER) + f.write(json.dumps(out, sort_keys=True, indent=2, separators=(',', ': '))) + f.write('\n') -diff --git a/tools/generate_node_version_header.py b/tools/generate_node_version_header.py -new file mode 100755 -index 0000000000000000000000000000000000000000..2a92eccfa582df361f2a889c0d9b32c1059baa7d ---- /dev/null -+++ b/tools/generate_node_version_header.py -@@ -0,0 +1,25 @@ -+#!/usr/bin/env python3 -+import re -+import sys -+ -+node_version_file = sys.argv[1] -+out_file = sys.argv[2] -+NMV = None -+if len(sys.argv) > 3: -+ NMV = sys.argv[3] -+ -+with open(node_version_file, 'r') as in_file, open(out_file, 'w') as out_file: -+ changed = False -+ contents = in_file.read() -+ new_contents = re.sub( -+ r'^#define NODE_MODULE_VERSION [0-9]+$', -+ '#define NODE_MODULE_VERSION ' + NMV, -+ contents, -+ flags=re.MULTILINE) -+ -+ changed = contents != new_contents -+ -+ if not changed and NMV is not None: -+ raise Exception("Did not modify the NMV from nodes value, this value MUST differ from node") -+ -+ out_file.writelines(new_contents) diff --git a/tools/install.py b/tools/install.py index f13f2ecd662a5fb985839b394b45319c091b56d4..21bc48324946d52ed2b1c9eec35c1fcd4c536570 100755 --- a/tools/install.py @@ -2477,21 +2366,3 @@ index 54c7dfce3631001e108570b19d34966edafd624f..077bba1572f05f1aa16553894703b12a return os.path.splitext(filename)[0] -diff --git a/tools/tar.py b/tools/tar.py -new file mode 100644 -index 0000000000000000000000000000000000000000..eb697be25779db62c829aac45a509804e9fff331 ---- /dev/null -+++ b/tools/tar.py -@@ -0,0 +1,12 @@ -+import os -+import sys -+import tarfile -+ -+source = sys.argv[1] -+target = sys.argv[2] -+ -+os.chdir(os.path.dirname(source)) -+ -+tarball = tarfile.open(name=os.path.basename(target), mode='w:gz') -+tarball.add(os.path.relpath(source)) -+tarball.close() diff --git a/script/generate_node_version_header.py b/script/generate_node_version_header.py new file mode 100755 index 000000000000..60f1e54720d0 --- /dev/null +++ b/script/generate_node_version_header.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import re +import sys + +node_version_file = sys.argv[1] +out_file = sys.argv[2] +NMV = None +if len(sys.argv) > 3: + NMV = sys.argv[3] + +with open(node_version_file, 'r') as in_file, open(out_file, 'w') as out_file: + changed = False + contents = in_file.read() + new_contents = re.sub( + r'^#define NODE_MODULE_VERSION [0-9]+$', + '#define NODE_MODULE_VERSION ' + NMV, + contents, + flags=re.MULTILINE) + + changed = contents != new_contents + + if not changed and NMV is not None: + raise Exception("Did not modify the NMV from nodes value, this value MUST " + "differ from node") + + out_file.writelines(new_contents) diff --git a/script/tar.py b/script/tar.py new file mode 100644 index 000000000000..eb697be25779 --- /dev/null +++ b/script/tar.py @@ -0,0 +1,12 @@ +import os +import sys +import tarfile + +source = sys.argv[1] +target = sys.argv[2] + +os.chdir(os.path.dirname(source)) + +tarball = tarfile.open(name=os.path.basename(target), mode='w:gz') +tarball.add(os.path.relpath(source)) +tarball.close()