refactor: move node ofs script to electron (#44425)

* refactor: move node ofs script to electron

* chore: remove empty file
This commit is contained in:
Shelley Vohr 2024-10-29 13:22:26 +01:00 committed by GitHub
parent f7ead785cd
commit 39b24aed92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 56 additions and 54 deletions

View file

@ -1534,7 +1534,7 @@ copy("node_gypi_headers") {
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"
script = "script/node/generate_node_version_header.py"
args = rebase_path(inputs) + rebase_path(outputs)
if (node_module_version != "") {
args += [ "$node_module_version" ]

View file

@ -11,7 +11,7 @@ really in 20/21. We have to wait until 22 is released to be able to
build with upstream GN files.
diff --git a/BUILD.gn b/BUILD.gn
index 1ed186b597eece7c34cb69c8e1e20870555a040d..2ce1e8a7dcca2ba153d387d11970c72b5f43c167 100644
index 1ed186b597eece7c34cb69c8e1e20870555a040d..e36168f0a051ca2fa2fc024aadcf5375b860105e 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1,14 +1,406 @@
@ -113,7 +113,7 @@ index 1ed186b597eece7c34cb69c8e1e20870555a040d..2ce1e8a7dcca2ba153d387d11970c72b
+}
+
+action("node_js2c_original_fs") {
+ script = "tools/generate_original_fs.py"
+ script = "//electron/script/node/generate_original_fs.py"
+ inputs = fs_files
+ outputs = []
+ foreach(file, fs_files + original_fs_files) {
@ -2384,30 +2384,6 @@ index 0000000000000000000000000000000000000000..37c16859003e61636fe2f1a4040b1e90
+ f.write(FILENAMES_JSON_HEADER)
+ f.write(json.dumps(out, sort_keys=True, indent=2, separators=(',', ': ')))
+ f.write('\n')
diff --git a/tools/generate_original_fs.py b/tools/generate_original_fs.py
new file mode 100644
index 0000000000000000000000000000000000000000..5259e6a7a1fd6b21df69dc461dee67d95800c2c8
--- /dev/null
+++ b/tools/generate_original_fs.py
@@ -0,0 +1,18 @@
+import os
+import sys
+
+node_root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+out_dir = sys.argv[1]
+fs_files = sys.argv[2:]
+
+for fs_file in fs_files:
+ with open(os.path.join(node_root_dir, fs_file), 'r') as f:
+ contents = f.read()
+ original_fs_file = fs_file.replace('internal/fs/', 'internal/original-fs/').replace('lib/fs.js', 'lib/original-fs.js').replace('lib/fs/', 'lib/original-fs/')
+
+ with open(os.path.join(out_dir, fs_file), 'w') as original_f:
+ original_f.write(contents)
+
+ with open(os.path.join(out_dir, original_fs_file), 'w') as transformed_f:
+ transformed_contents = contents.replace('internal/fs/', 'internal/original-fs/').replace('require(\'fs', 'require(\'original-fs')
+ transformed_f.write(transformed_contents)
diff --git a/tools/install.py b/tools/install.py
index b132c7bf26c02886a7ab341a1973bf449744ba0f..757e3e60a7be01fac55c5fbb010dbbae00b1bfca 100755
--- a/tools/install.py

View file

@ -1,27 +0,0 @@
#!/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', encoding='utf-8') as in_file, \
open(out_file, 'w', encoding='utf-8') 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)

View file

@ -0,0 +1,25 @@
#!/usr/bin/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', encoding='utf-8') as in_file:
with open(out_file, 'w', encoding='utf-8') 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('NMV must differ from current value in Node.js')
out_file.writelines(new_contents)

View file

@ -0,0 +1,28 @@
#!/usr/bin/python3
import os
import sys
NODE_ROOT_DIR = "../../third_party/electron_node"
out_dir = sys.argv[1]
fs_files = sys.argv[2:]
for fs_file in fs_files:
with open(os.path.join(NODE_ROOT_DIR, fs_file), 'r',
encoding='utf-8') as f:
contents = f.read()
original_fs_file = fs_file.replace('internal/fs/',
'internal/original-fs/').replace('lib/fs.js',
'lib/original-fs.js').replace('lib/fs/',
'lib/original-fs/')
with open(os.path.join(out_dir, fs_file), 'w', encoding='utf-8'
) as original_f:
original_f.write(contents)
with open(os.path.join(out_dir, original_fs_file), 'w',
encoding='utf-8') as transformed_f:
transformed_contents = contents.replace('internal/fs/',
'internal/original-fs/').replace('require(\'fs',
'require(\'original-fs')
transformed_f.write(transformed_contents)