Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: port js2c.py to C++ #46997

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,7 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
test/fixtures/*.c \
test/js-native-api/*/*.cc \
test/node-api/*/*.cc \
tools/js2c.cc \
tools/icu/*.cc \
tools/icu/*.h \
tools/code_cache/*.cc \
Expand Down
1 change: 1 addition & 0 deletions deps/simdutf/simdutf.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'targets': [
{
'target_name': 'simdutf',
'toolsets': ['host', 'target'],
'type': 'static_library',
'include_dirs': ['.'],
'direct_dependent_settings': {
Expand Down
1 change: 1 addition & 0 deletions deps/uv/uv.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
'targets': [
{
'target_name': 'libuv',
'toolsets': ['host', 'target'],
'type': '<(uv_library)',
'include_dirs': [
'include',
Expand Down
44 changes: 36 additions & 8 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'node_lib_target_name%': 'libnode',
'node_intermediate_lib_type%': 'static_library',
'node_builtin_modules_path%': '',
# We list the deps/ files out instead of globbing them in js2c.py since we
# We list the deps/ files out instead of globbing them in js2c.cc since we
# only include a subset of all the files under these directories.
# The lengths of their file names combined should not exceed the
# Windows command length limit or there would be an error.
Expand Down Expand Up @@ -362,6 +362,7 @@
'src/quic/transportparams.h',
],
'node_mksnapshot_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)node_mksnapshot<(EXECUTABLE_SUFFIX)',
'node_js2c_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)node_js2c<(EXECUTABLE_SUFFIX)',
'conditions': [
['GENERATOR == "ninja"', {
'node_text_start_object_path': 'src/large_pages/node_text_start.node_text_start.o'
Expand Down Expand Up @@ -770,6 +771,7 @@
'deps/uvwasi/uvwasi.gyp:uvwasi',
'deps/simdutf/simdutf.gyp:simdutf',
'deps/ada/ada.gyp:ada',
'node_js2c#host',
],

'sources': [
Expand Down Expand Up @@ -925,8 +927,7 @@
'action_name': 'node_js2c',
'process_outputs_as_sources': 1,
'inputs': [
# Put the code first so it's a dependency and can be used for invocation.
'tools/js2c.py',
'<(node_js2c_exec)',
'<@(library_files)',
'<@(deps_files)',
'config.gypi'
Expand All @@ -935,12 +936,9 @@
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
],
'action': [
'<(python)',
'tools/js2c.py',
'--directory',
'lib',
'--target',
'<(node_js2c_exec)',
'<@(_outputs)',
'lib',
'config.gypi',
'<@(deps_files)',
],
Expand Down Expand Up @@ -1175,6 +1173,36 @@
}],
]
}, # overlapped-checker
{
'target_name': 'node_js2c',
'type': 'executable',
'toolsets': ['host'],
'dependencies': [
'deps/simdutf/simdutf.gyp:simdutf#host',
],
'include_dirs': [
'tools'
],
'sources': [
'tools/js2c.cc',
'tools/executable_wrapper.h'
],
'conditions': [
[ 'node_shared_libuv=="false"', {
'dependencies': [ 'deps/uv/uv.gyp:libuv#host' ],
}],
[ 'debug_node=="true"', {
'cflags!': [ '-O3' ],
'cflags': [ '-g', '-O0' ],
'defines': [ 'DEBUG' ],
'xcode_settings': {
'OTHER_CFLAGS': [
'-g', '-O0'
],
},
}],
]
},
{
'target_name': 'node_mksnapshot',
'type': 'executable',
Expand Down
14 changes: 0 additions & 14 deletions test/tools/test_js2c.py

This file was deleted.

55 changes: 55 additions & 0 deletions tools/executable_wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef TOOLS_EXECUTABLE_WRAPPER_H_
#define TOOLS_EXECUTABLE_WRAPPER_H_

// TODO(joyeecheung): reuse this in mksnapshot.
#include "uv.h"
#ifdef _WIN32
#include <windows.h>
#endif

namespace node {
#ifdef _WIN32
using argv_type = wchar_t*;
#define NODE_MAIN int wmain

void FixupMain(int argc, argv_type raw_argv[], char*** argv) {
// Convert argv to UTF8.
*argv = new char*[argc + 1];
for (int i = 0; i < argc; i++) {
// Compute the size of the required buffer
DWORD size = WideCharToMultiByte(
CP_UTF8, 0, raw_argv[i], -1, nullptr, 0, nullptr, nullptr);
if (size == 0) {
// This should never happen.
fprintf(stderr, "Could not convert arguments to utf8.");
exit(1);
}
// Do the actual conversion
(*argv)[i] = new char[size];
DWORD result = WideCharToMultiByte(
CP_UTF8, 0, raw_argv[i], -1, (*argv)[i], size, nullptr, nullptr);
if (result == 0) {
// This should never happen.
fprintf(stderr, "Could not convert arguments to utf8.");
exit(1);
}
}
(*argv)[argc] = nullptr;
}
#else

using argv_type = char*;
#define NODE_MAIN int main

void FixupMain(int argc, argv_type raw_argv[], char*** argv) {
*argv = uv_setup_args(argc, raw_argv);
// Disable stdio buffering, it interacts poorly with printf()
// calls elsewhere in the program (e.g., any logging from V8.)
setvbuf(stdout, nullptr, _IONBF, 0);
setvbuf(stderr, nullptr, _IONBF, 0);
}
#endif

} // namespace node

#endif // TOOLS_EXECUTABLE_WRAPPER_H_
Loading