From 3f68d0e468564991ae1abfef9f9f349bf94d99e5 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Sat, 26 Mar 2016 20:17:55 -0400 Subject: [PATCH 1/9] build: configure --shared/--no-v8-platform Add configure flag for building shared library that could be used to embed node.js in some application (like Electron). This commit is esentially a merged and refined version of: * atom/node@289649a919d557182ff951589fc9859778206e4c * atom/node@f76669ffdcb8613133dc9c3764fb21c10207582e * atom/node@0828dfa193038209b7b337ba5479c3373f7cf87f --- common.gypi | 3 +++ configure | 14 +++++++++++ node.gyp | 68 +++++++++++++++++++++++++++++++++++++++++------------ src/node.cc | 50 ++++++++++++++++++++++++++++++++------- src/node.h | 14 +++++++---- 5 files changed, 122 insertions(+), 27 deletions(-) diff --git a/common.gypi b/common.gypi index 8da603d00f618e..6591bf5dd85fb8 100644 --- a/common.gypi +++ b/common.gypi @@ -11,6 +11,9 @@ 'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way 'python%': 'python', + 'node_shared%': 'false', + 'node_no_v8_platform%': 'false', + 'node_tag%': '', 'uv_library%': 'static_library', diff --git a/configure b/configure index d622a6f0625a18..01a930e88157cc 100755 --- a/configure +++ b/configure @@ -420,6 +420,18 @@ parser.add_option('--without-inspector', dest='without_inspector', help='disable experimental V8 inspector support') +parser.add_option('--shared', + action='store_true', + dest='shared', + help='compile shared library for embedding node in another project. ' + + '(This mode is not officially supported for regular applications)') + +parser.add_option('--no-v8-platform', + action='store_true', + dest='no_v8_platform', + help='do not initialize v8 platform during node.js startup. ' + + '(This mode is not officially supported for regular applications)') + (options, args) = parser.parse_args() # Expand ~ in the install prefix now, it gets written to multiple files. @@ -810,6 +822,8 @@ def configure_node(o): o['variables']['node_target_type'] = 'static_library' o['variables']['node_no_browser_globals'] = b(options.no_browser_globals) + o['variables']['node_shared'] = b(options.shared) + o['variables']['node_no_v8_platform'] = b(options.no_v8_platform) if options.linked_module: o['variables']['library_files'] = options.linked_module diff --git a/node.gyp b/node.gyp index c3f591351d52ce..5763e599d2832b 100644 --- a/node.gyp +++ b/node.gyp @@ -6,6 +6,8 @@ 'node_use_etw%': 'false', 'node_use_perfctr%': 'false', 'node_no_browser_globals%': 'false', + 'node_no_v8_platform%': 'false', + 'node_shared%': 'false', 'node_shared_zlib%': 'false', 'node_shared_http_parser%': 'false', 'node_shared_cares%': 'false', @@ -14,7 +16,6 @@ 'node_shared_openssl%': 'false', 'node_v8_options%': '', 'node_enable_v8_vtunejit%': 'false', - 'node_target_type%': 'executable', 'node_core_target_name%': 'node', 'library_files': [ 'lib/internal/bootstrap_node.js', @@ -100,6 +101,13 @@ 'deps/v8/tools/SourceMap.js', 'deps/v8/tools/tickprocessor-driver.js', ], + 'conditions': [ + [ 'node_shared=="true"', { + 'node_target_type%': 'shared_library', + }, { + 'node_target_type%': 'executable', + }], + ], }, 'targets': [ @@ -109,8 +117,6 @@ 'dependencies': [ 'node_js2c#host', - 'deps/v8/tools/gyp/v8.gyp:v8', - 'deps/v8/tools/gyp/v8.gyp:v8_libplatform' ], 'include_dirs': [ @@ -118,7 +124,6 @@ 'tools/msvs/genfiles', 'deps/uv/src/ares', '<(SHARED_INTERMEDIATE_DIR)', # for node_natives.h - 'deps/v8' # include/v8_platform.h ], 'sources': [ @@ -217,6 +222,36 @@ 'conditions': [ + [ 'node_shared=="false"', { + 'dependencies': [ + 'deps/v8/tools/gyp/v8.gyp:v8', + ], + 'msvs_settings': { + 'VCManifestTool': { + 'EmbedManifest': 'true', + 'AdditionalManifestFiles': 'src/res/node.exe.extra.manifest' + } + }, + }, { + 'defines': [ + 'NODE_SHARED_MODE', + ], + 'libraries': [ + '-lv8', + ], + }], + [ 'node_no_v8_platform=="false"', { + 'include_dirs': [ + 'deps/v8', # include/v8_platform.h + ], + 'dependencies': [ + 'deps/v8/tools/gyp/v8.gyp:v8_libplatform', + ], + }, { + 'defines': [ + 'NODE_NO_V8_PLATFORM', + ], + }], [ 'node_tag!=""', { 'defines': [ 'NODE_TAG="<(node_tag)"' ], }], @@ -245,7 +280,8 @@ 'defines': [ 'NODE_HAVE_SMALL_ICU=1' ], }]], }], - [ 'node_enable_v8_vtunejit=="true" and (target_arch=="x64" or \ + [ 'node_no_bundled_v8=="false" and \ + node_enable_v8_vtunejit=="true" and (target_arch=="x64" or \ target_arch=="ia32" or target_arch=="x32")', { 'defines': [ 'NODE_ENABLE_VTUNE_PROFILING' ], 'dependencies': [ @@ -395,7 +431,7 @@ [ 'node_no_browser_globals=="true"', { 'defines': [ 'NODE_NO_BROWSER_GLOBALS' ], } ], - [ 'v8_postmortem_support=="true"', { + [ 'node_no_bundled_v8=="false" and v8_postmortem_support=="true"', { 'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:postmortem-metadata' ], 'conditions': [ # -force_load is not applicable for the static library @@ -487,12 +523,6 @@ 'ldflags': [ '-Wl,-M,/usr/lib/ld/map.noexstk' ], }], ], - 'msvs_settings': { - 'VCManifestTool': { - 'EmbedManifest': 'true', - 'AdditionalManifestFiles': 'src/res/node.exe.extra.manifest' - } - }, }, # generate ETW header and resource files { @@ -718,8 +748,6 @@ 'deps/http_parser/http_parser.gyp:http_parser', 'deps/gtest/gtest.gyp:gtest', 'deps/uv/uv.gyp:libuv', - 'deps/v8/tools/gyp/v8.gyp:v8', - 'deps/v8/tools/gyp/v8.gyp:v8_libplatform' ], 'include_dirs': [ 'src', @@ -750,7 +778,17 @@ 'src/inspector_socket.cc', 'test/cctest/test_inspector_socket.cc' ] - }] + }], + [ 'node_shared=="false"', { + 'dependencies': [ + 'deps/v8/tools/gyp/v8.gyp:v8', + ], + }], + [ 'node_no_v8_platform=="false"', { + 'dependencies': [ + 'deps/v8/tools/gyp/v8.gyp:v8_libplatform', + ], + }], ] } ], # end targets diff --git a/src/node.cc b/src/node.cc index b6fa4606f5fae0..8a99f44ac8bf6d 100644 --- a/src/node.cc +++ b/src/node.cc @@ -39,7 +39,9 @@ #include "string_bytes.h" #include "util.h" #include "uv.h" +#ifndef NODE_NO_V8_PLATFORM #include "libplatform/libplatform.h" +#endif // NODE_NO_V8_PLATFORM #include "v8-debug.h" #include "v8-profiler.h" #include "zlib.h" @@ -183,7 +185,41 @@ static uv_async_t dispatch_debug_messages_async; static Mutex node_isolate_mutex; static v8::Isolate* node_isolate; -static v8::Platform* default_platform; + +static struct { +#ifdef NODE_NO_V8_PLATFORM + void Initialize(int thread_pool_size) {} + void PumpMessageLoop(Isolate* isolate) {} + void Dispose() {} +#if HAVE_INSPECTOR + void StartInspector(Environment *env, int port, bool wait) { + env->ThrowError("Node compiled with NODE_NO_V8_PLATFORM"); + } +#endif // HAVE_INSPECTOR +#else // !NODE_NO_V8_PLATFORM + void Initialize(int thread_pool_size) { + platform = v8::platform::CreateDefaultPlatform(thread_pool_size); + V8::InitializePlatform(platform); + } + + void PumpMessageLoop(Isolate* isolate) { + v8::platform::PumpMessageLoop(platform, isolate); + } + + void Dispose() { + delete platform; + platform = nullptr; + } + +#if HAVE_INSPECTOR + void StartInspector(Environment *env, int port, bool wait) { + env->inspector_agent()->Start(platform, port, wait); + } +#endif // HAVE_INSPECTOR + + static v8::Platform* platform; +#endif // !NODE_NO_V8_PLATFORM +} v8_platform; #ifdef __POSIX__ static uv_sem_t debug_semaphore; @@ -3652,7 +3688,7 @@ static void StartDebug(Environment* env, bool wait) { CHECK(!debugger_running); #if HAVE_INSPECTOR if (use_inspector) { - env->inspector_agent()->Start(default_platform, inspector_port, wait); + v8_platform.StartInspector(env, inspector_port, wait); debugger_running = true; } else { #endif @@ -4299,11 +4335,11 @@ static void StartNodeInstance(void* arg) { SealHandleScope seal(isolate); bool more; do { - v8::platform::PumpMessageLoop(default_platform, isolate); + v8_platform.PumpMessageLoop(isolate); more = uv_run(env.event_loop(), UV_RUN_ONCE); if (more == false) { - v8::platform::PumpMessageLoop(default_platform, isolate); + v8_platform.PumpMessageLoop(isolate); EmitBeforeExit(&env); // Emit `beforeExit` if the loop became alive either after emitting @@ -4364,8 +4400,7 @@ int Start(int argc, char** argv) { V8::SetEntropySource(crypto::EntropySource); #endif - default_platform = v8::platform::CreateDefaultPlatform(v8_thread_pool_size); - V8::InitializePlatform(default_platform); + v8_platform.Initialize(v8_thread_pool_size); V8::Initialize(); int exit_code = 1; @@ -4382,8 +4417,7 @@ int Start(int argc, char** argv) { } V8::Dispose(); - delete default_platform; - default_platform = nullptr; + v8_platform.Dispose(); delete[] exec_argv; exec_argv = nullptr; diff --git a/src/node.h b/src/node.h index 0347dc10cbcdbb..873551fa338a97 100644 --- a/src/node.h +++ b/src/node.h @@ -411,17 +411,23 @@ extern "C" NODE_EXTERN void node_module_register(void* mod); # define NODE_MODULE_EXPORT __attribute__((visibility("default"))) #endif +#ifdef NODE_SHARED_MODE +# define NODE_CTOR_PREFIX +#else +# define NODE_CTOR_PREFIX static +#endif + #if defined(_MSC_VER) #pragma section(".CRT$XCU", read) #define NODE_C_CTOR(fn) \ - static void __cdecl fn(void); \ + NODE_CTOR_PREFIX void __cdecl fn(void); \ __declspec(dllexport, allocate(".CRT$XCU")) \ void (__cdecl*fn ## _)(void) = fn; \ - static void __cdecl fn(void) + NODE_CTOR_PREFIX void __cdecl fn(void) #else #define NODE_C_CTOR(fn) \ - static void fn(void) __attribute__((constructor)); \ - static void fn(void) + NODE_CTOR_PREFIX void fn(void) __attribute__((constructor)); \ + NODE_CTOR_PREFIX void fn(void) #endif #define NODE_MODULE_X(modname, regfunc, priv, flags) \ From eeeeeaf1d88860d6584faac22aa655f0f09a443c Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Tue, 10 May 2016 14:41:27 -0400 Subject: [PATCH 2/9] build: additions/fixes for shared library support Added --no-bundled-v8 flag to separate header inclusion matters from --no-v8-platform. Compiling with ./configure --shared and make install should now work out of the box for Linux. Conflicts: src/node.cc --- common.gypi | 4 ++++ configure | 7 +++++++ node.gyp | 21 ++++++++++++--------- src/node.cc | 4 ++-- tools/install.py | 13 +++++++++++-- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/common.gypi b/common.gypi index 6591bf5dd85fb8..b3ce75c009252b 100644 --- a/common.gypi +++ b/common.gypi @@ -13,6 +13,7 @@ 'node_shared%': 'false', 'node_no_v8_platform%': 'false', + 'node_no_bundled_v8%': 'false', 'node_tag%': '', 'uv_library%': 'static_library', @@ -293,6 +294,9 @@ ], 'ldflags!': [ '-rdynamic' ], }], + [ 'node_shared=="true"', { + 'cflags': [ '-fPIC' ], + }], ], }], [ 'OS=="android"', { diff --git a/configure b/configure index 01a930e88157cc..36619d030b6525 100755 --- a/configure +++ b/configure @@ -432,6 +432,12 @@ parser.add_option('--no-v8-platform', help='do not initialize v8 platform during node.js startup. ' + '(This mode is not officially supported for regular applications)') +parser.add_option('--no-bundled-v8', + action='store_true', + dest='no_bundled_v8', + help='do not use V8 includes from the bundled deps folder. ' + + '(This mode is not officially supported for regular applications)') + (options, args) = parser.parse_args() # Expand ~ in the install prefix now, it gets written to multiple files. @@ -824,6 +830,7 @@ def configure_node(o): o['variables']['node_no_browser_globals'] = b(options.no_browser_globals) o['variables']['node_shared'] = b(options.shared) o['variables']['node_no_v8_platform'] = b(options.no_v8_platform) + o['variables']['node_no_bundled_v8'] = b(options.no_bundled_v8) if options.linked_module: o['variables']['library_files'] = options.linked_module diff --git a/node.gyp b/node.gyp index 5763e599d2832b..fda50bb6c5fca2 100644 --- a/node.gyp +++ b/node.gyp @@ -7,6 +7,7 @@ 'node_use_perfctr%': 'false', 'node_no_browser_globals%': 'false', 'node_no_v8_platform%': 'false', + 'node_no_bundled_v8%': 'false', 'node_shared%': 'false', 'node_shared_zlib%': 'false', 'node_shared_http_parser%': 'false', @@ -223,9 +224,6 @@ 'conditions': [ [ 'node_shared=="false"', { - 'dependencies': [ - 'deps/v8/tools/gyp/v8.gyp:v8', - ], 'msvs_settings': { 'VCManifestTool': { 'EmbedManifest': 'true', @@ -236,16 +234,15 @@ 'defines': [ 'NODE_SHARED_MODE', ], - 'libraries': [ - '-lv8', - ], }], - [ 'node_no_v8_platform=="false"', { + [ 'node_no_bundled_v8=="false"', { 'include_dirs': [ 'deps/v8', # include/v8_platform.h ], + 'dependencies': [ - 'deps/v8/tools/gyp/v8.gyp:v8_libplatform', + 'deps/v8/tools/gyp/v8.gyp:v8', + 'deps/v8/tools/gyp/v8.gyp:v8_libplatform' ], }, { 'defines': [ @@ -515,7 +512,7 @@ ], }], [ 'OS=="freebsd" or OS=="linux"', { - 'ldflags': [ '-Wl,-z,noexecstack', + 'ldflags': [ '-Wl,-z,noexecstack,--allow-multiple-definition', '-Wl,--whole-archive <(V8_BASE)', '-Wl,--no-whole-archive' ] }], @@ -789,6 +786,12 @@ 'deps/v8/tools/gyp/v8.gyp:v8_libplatform', ], }], + [ 'node_no_bundled_v8=="false"', { + 'dependencies': [ + 'deps/v8/tools/gyp/v8.gyp:v8', + 'deps/v8/tools/gyp/v8.gyp:v8_libplatform' + ], + }], ] } ], # end targets diff --git a/src/node.cc b/src/node.cc index 8a99f44ac8bf6d..10e99d5b364764 100644 --- a/src/node.cc +++ b/src/node.cc @@ -186,7 +186,7 @@ static uv_async_t dispatch_debug_messages_async; static Mutex node_isolate_mutex; static v8::Isolate* node_isolate; -static struct { +static struct v8_plat { #ifdef NODE_NO_V8_PLATFORM void Initialize(int thread_pool_size) {} void PumpMessageLoop(Isolate* isolate) {} @@ -217,7 +217,7 @@ static struct { } #endif // HAVE_INSPECTOR - static v8::Platform* platform; + v8::Platform* platform; #endif // !NODE_NO_V8_PLATFORM } v8_platform; diff --git a/tools/install.py b/tools/install.py index f3fa4fe898157b..1624747a526e62 100755 --- a/tools/install.py +++ b/tools/install.py @@ -108,8 +108,17 @@ def subdir_files(path, dest, action): def files(action): is_windows = sys.platform == 'win32' - exeext = '.exe' if is_windows else '' - action(['out/Release/node' + exeext], 'bin/node' + exeext) + if 'false' == variables.get('node_shared') and is_windows: + output_file += '.exe' + else: + if is_windows: + output_file += '.dll' + else: + # GYP will output to lib.target, this is hardcoded in its source, + # see the _InstallableTargetInstallPath function. + output_file = 'lib.target/lib' + output_file + '.so' + + action(['out/Release/' + output_file], 'bin/' + output_file) if 'true' == variables.get('node_use_dtrace'): action(['out/Release/node.d'], 'lib/dtrace/node.d') From 6d027f6cac45e5d58c1e055fcca871e88f4a2967 Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Tue, 31 May 2016 14:41:55 -0400 Subject: [PATCH 3/9] WIP: Add soname & fix make install --- common.gypi | 1 + configure | 7 +++++++ node.gyp | 6 ++++++ tools/getmoduleversion.py | 19 +++++++++++++++++++ tools/install.py | 8 ++++++-- 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tools/getmoduleversion.py diff --git a/common.gypi b/common.gypi index b3ce75c009252b..948ffc9183976b 100644 --- a/common.gypi +++ b/common.gypi @@ -14,6 +14,7 @@ 'node_shared%': 'false', 'node_no_v8_platform%': 'false', 'node_no_bundled_v8%': 'false', + 'node_module_ver%': '', 'node_tag%': '', 'uv_library%': 'static_library', diff --git a/configure b/configure index 36619d030b6525..9571f0ab7acb1d 100755 --- a/configure +++ b/configure @@ -24,6 +24,10 @@ from gyp.common import GetFlavor sys.path.insert(0, os.path.join(root_dir, 'tools', 'configure.d')) import nodedownload +# imports in tools/ +sys.path.insert(0, os.path.join(root_dir, 'tools', )) +import getmoduleversion + # parse our options parser = optparse.OptionParser() @@ -831,6 +835,9 @@ def configure_node(o): o['variables']['node_shared'] = b(options.shared) o['variables']['node_no_v8_platform'] = b(options.no_v8_platform) o['variables']['node_no_bundled_v8'] = b(options.no_bundled_v8) + + if flavor == 'linux' and options.shared: + o['variables']['node_module_ver'] = getmoduleversion.get_version() if options.linked_module: o['variables']['library_files'] = options.linked_module diff --git a/node.gyp b/node.gyp index fda50bb6c5fca2..88c4c89cc68865 100644 --- a/node.gyp +++ b/node.gyp @@ -9,6 +9,7 @@ 'node_no_v8_platform%': 'false', 'node_no_bundled_v8%': 'false', 'node_shared%': 'false', + 'node_module_ver%': '', 'node_shared_zlib%': 'false', 'node_shared_http_parser%': 'false', 'node_shared_cares%': 'false', @@ -234,6 +235,11 @@ 'defines': [ 'NODE_SHARED_MODE', ], + 'conditions': [ + [ 'node_module_ver!=""', { + 'product_extension': 'so.<(node_module_ver)', + }] + ], }], [ 'node_no_bundled_v8=="false"', { 'include_dirs': [ diff --git a/tools/getmoduleversion.py b/tools/getmoduleversion.py new file mode 100644 index 00000000000000..bf6ca4822f9bbf --- /dev/null +++ b/tools/getmoduleversion.py @@ -0,0 +1,19 @@ +import os,re + +def get_version(): + node_version_h = os.path.join(os.path.dirname(__file__), '..', 'src', + 'node_version.h') + + f = open(node_version_h) + + regex = '#define NODE_MODULE_VERSION [0-9]+' + + for line in f: + if re.match(regex, line): + major = line.split()[2] + return major + + raise Exception("Could not find pattern matching '%s'" % regex) + +if __name__ == "__main__": + print get_version() diff --git a/tools/install.py b/tools/install.py index 1624747a526e62..5fcd064f78db7e 100755 --- a/tools/install.py +++ b/tools/install.py @@ -6,6 +6,7 @@ import re import shutil import sys +from getmoduleversion import get_version # set at init time node_prefix = '/usr/local' # PREFIX variable from Makefile @@ -107,6 +108,8 @@ def subdir_files(path, dest, action): def files(action): is_windows = sys.platform == 'win32' + output_file = 'node' + output_prefix = 'out/Release/' if 'false' == variables.get('node_shared') and is_windows: output_file += '.exe' @@ -116,9 +119,10 @@ def files(action): else: # GYP will output to lib.target, this is hardcoded in its source, # see the _InstallableTargetInstallPath function. - output_file = 'lib.target/lib' + output_file + '.so' + output_prefix += 'lib.target/' + output_file = 'lib' + output_file + '.so.' + get_version() - action(['out/Release/' + output_file], 'bin/' + output_file) + action([output_prefix + output_file], 'bin/' + output_file) if 'true' == variables.get('node_use_dtrace'): action(['out/Release/node.d'], 'lib/dtrace/node.d') From 66fd9d42457950451ca1a4c65be53b3376733c48 Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Thu, 2 Jun 2016 15:51:20 -0400 Subject: [PATCH 4/9] WIP: Fixes from review * Spacing for Python code * Remove unneeded GYP dependencies --- node.gyp | 5 ----- tools/getmoduleversion.py | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/node.gyp b/node.gyp index 88c4c89cc68865..3b750a6a412f1c 100644 --- a/node.gyp +++ b/node.gyp @@ -782,11 +782,6 @@ 'test/cctest/test_inspector_socket.cc' ] }], - [ 'node_shared=="false"', { - 'dependencies': [ - 'deps/v8/tools/gyp/v8.gyp:v8', - ], - }], [ 'node_no_v8_platform=="false"', { 'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:v8_libplatform', diff --git a/tools/getmoduleversion.py b/tools/getmoduleversion.py index bf6ca4822f9bbf..c2af0594e2b037 100644 --- a/tools/getmoduleversion.py +++ b/tools/getmoduleversion.py @@ -2,7 +2,7 @@ def get_version(): node_version_h = os.path.join(os.path.dirname(__file__), '..', 'src', - 'node_version.h') + 'node_version.h') f = open(node_version_h) From f9d4754bf828a452f7ede5608493b607f64d7acd Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Tue, 14 Jun 2016 10:43:27 -0400 Subject: [PATCH 5/9] WIP: Remove trailing comma --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 9571f0ab7acb1d..f2110b5f425455 100755 --- a/configure +++ b/configure @@ -25,7 +25,7 @@ sys.path.insert(0, os.path.join(root_dir, 'tools', 'configure.d')) import nodedownload # imports in tools/ -sys.path.insert(0, os.path.join(root_dir, 'tools', )) +sys.path.insert(0, os.path.join(root_dir, 'tools')) import getmoduleversion # parse our options From 8f418f5b5053853d9f51b34f17acbf9e52108e59 Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Fri, 24 Jun 2016 18:00:11 -0400 Subject: [PATCH 6/9] WIP: More review fixes --- common.gypi | 4 ++-- configure | 6 ++++-- node.gyp | 20 ++++++++++---------- src/node.cc | 16 ++++++++-------- tools/getmoduleversion.py | 11 +++++++---- tools/getnodeversion.py | 11 +++++++---- 6 files changed, 38 insertions(+), 30 deletions(-) diff --git a/common.gypi b/common.gypi index 948ffc9183976b..d4dbfa7df1448c 100644 --- a/common.gypi +++ b/common.gypi @@ -12,8 +12,8 @@ 'python%': 'python', 'node_shared%': 'false', - 'node_no_v8_platform%': 'false', - 'node_no_bundled_v8%': 'false', + 'node_use_v8_platform%': 'true', + 'node_use_bundled_v8%': 'true', 'node_module_ver%': '', 'node_tag%': '', diff --git a/configure b/configure index f2110b5f425455..2e3ffecd1911d6 100755 --- a/configure +++ b/configure @@ -433,12 +433,14 @@ parser.add_option('--shared', parser.add_option('--no-v8-platform', action='store_true', dest='no_v8_platform', + default=False, help='do not initialize v8 platform during node.js startup. ' + '(This mode is not officially supported for regular applications)') parser.add_option('--no-bundled-v8', action='store_true', dest='no_bundled_v8', + default=False, help='do not use V8 includes from the bundled deps folder. ' + '(This mode is not officially supported for regular applications)') @@ -833,8 +835,8 @@ def configure_node(o): o['variables']['node_no_browser_globals'] = b(options.no_browser_globals) o['variables']['node_shared'] = b(options.shared) - o['variables']['node_no_v8_platform'] = b(options.no_v8_platform) - o['variables']['node_no_bundled_v8'] = b(options.no_bundled_v8) + o['variables']['node_use_v8_platform'] = b(not options.no_v8_platform) + o['variables']['node_use_bundled_v8'] = b(not options.no_bundled_v8) if flavor == 'linux' and options.shared: o['variables']['node_module_ver'] = getmoduleversion.get_version() diff --git a/node.gyp b/node.gyp index 3b750a6a412f1c..37fa951b990ac4 100644 --- a/node.gyp +++ b/node.gyp @@ -6,8 +6,8 @@ 'node_use_etw%': 'false', 'node_use_perfctr%': 'false', 'node_no_browser_globals%': 'false', - 'node_no_v8_platform%': 'false', - 'node_no_bundled_v8%': 'false', + 'node_use_v8_platform%': 'true', + 'node_use_bundled_v8%': 'true', 'node_shared%': 'false', 'node_module_ver%': '', 'node_shared_zlib%': 'false', @@ -241,7 +241,7 @@ }] ], }], - [ 'node_no_bundled_v8=="false"', { + [ 'node_use_bundled_v8=="true"', { 'include_dirs': [ 'deps/v8', # include/v8_platform.h ], @@ -283,7 +283,7 @@ 'defines': [ 'NODE_HAVE_SMALL_ICU=1' ], }]], }], - [ 'node_no_bundled_v8=="false" and \ + [ 'node_use_bundled_v8=="true" and \ node_enable_v8_vtunejit=="true" and (target_arch=="x64" or \ target_arch=="ia32" or target_arch=="x32")', { 'defines': [ 'NODE_ENABLE_VTUNE_PROFILING' ], @@ -347,7 +347,7 @@ ], }, 'conditions': [ - ['OS in "linux freebsd"', { + ['OS in "linux freebsd"' and 'node_shared=="false"', { 'ldflags': [ '-Wl,--whole-archive <(PRODUCT_DIR)/<(OPENSSL_PRODUCT)', '-Wl,--no-whole-archive', @@ -434,7 +434,7 @@ [ 'node_no_browser_globals=="true"', { 'defines': [ 'NODE_NO_BROWSER_GLOBALS' ], } ], - [ 'node_no_bundled_v8=="false" and v8_postmortem_support=="true"', { + [ 'node_use_bundled_v8=="true" and v8_postmortem_support=="true"', { 'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:postmortem-metadata' ], 'conditions': [ # -force_load is not applicable for the static library @@ -517,8 +517,8 @@ 'NODE_PLATFORM="sunos"', ], }], - [ 'OS=="freebsd" or OS=="linux"', { - 'ldflags': [ '-Wl,-z,noexecstack,--allow-multiple-definition', + [ '(OS=="freebsd" or OS=="linux") and node_shared=="false"', { + 'ldflags': [ '-Wl,-z,noexecstack', '-Wl,--whole-archive <(V8_BASE)', '-Wl,--no-whole-archive' ] }], @@ -782,12 +782,12 @@ 'test/cctest/test_inspector_socket.cc' ] }], - [ 'node_no_v8_platform=="false"', { + [ 'node_use_v8_platform=="true"', { 'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:v8_libplatform', ], }], - [ 'node_no_bundled_v8=="false"', { + [ 'node_use_bundled_v8=="true"', { 'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:v8', 'deps/v8/tools/gyp/v8.gyp:v8_libplatform' diff --git a/src/node.cc b/src/node.cc index 10e99d5b364764..eb549ef8b3aa81 100644 --- a/src/node.cc +++ b/src/node.cc @@ -186,7 +186,7 @@ static uv_async_t dispatch_debug_messages_async; static Mutex node_isolate_mutex; static v8::Isolate* node_isolate; -static struct v8_plat { +static struct { #ifdef NODE_NO_V8_PLATFORM void Initialize(int thread_pool_size) {} void PumpMessageLoop(Isolate* isolate) {} @@ -198,26 +198,26 @@ static struct v8_plat { #endif // HAVE_INSPECTOR #else // !NODE_NO_V8_PLATFORM void Initialize(int thread_pool_size) { - platform = v8::platform::CreateDefaultPlatform(thread_pool_size); - V8::InitializePlatform(platform); + platform_ = v8::platform::CreateDefaultPlatform(thread_pool_size); + V8::InitializePlatform(platform_); } void PumpMessageLoop(Isolate* isolate) { - v8::platform::PumpMessageLoop(platform, isolate); + v8::platform::PumpMessageLoop(platform_, isolate); } void Dispose() { - delete platform; - platform = nullptr; + delete platform_; + platform_ = nullptr; } #if HAVE_INSPECTOR void StartInspector(Environment *env, int port, bool wait) { - env->inspector_agent()->Start(platform, port, wait); + env->inspector_agent()->Start(platform_, port, wait); } #endif // HAVE_INSPECTOR - v8::Platform* platform; + v8::Platform* platform_; #endif // !NODE_NO_V8_PLATFORM } v8_platform; diff --git a/tools/getmoduleversion.py b/tools/getmoduleversion.py index c2af0594e2b037..83e0c91673c822 100644 --- a/tools/getmoduleversion.py +++ b/tools/getmoduleversion.py @@ -1,19 +1,22 @@ import os,re def get_version(): - node_version_h = os.path.join(os.path.dirname(__file__), '..', 'src', + node_version_h = os.path.join( + os.path.dirname(__file__), + '..', + 'src', 'node_version.h') f = open(node_version_h) - regex = '#define NODE_MODULE_VERSION [0-9]+' + regex = '^#define NODE_MODULE_VERSION [0-9]+' for line in f: if re.match(regex, line): major = line.split()[2] return major - raise Exception("Could not find pattern matching '%s'" % regex) + raise Exception('Could not find pattern matching %s' % regex) -if __name__ == "__main__": +if __name__ == '__main__': print get_version() diff --git a/tools/getnodeversion.py b/tools/getnodeversion.py index 766e4f60dc07ad..f76c2aeb851d73 100644 --- a/tools/getnodeversion.py +++ b/tools/getnodeversion.py @@ -1,16 +1,19 @@ import os,re -node_version_h = os.path.join(os.path.dirname(__file__), '..', 'src', +node_version_h = os.path.join( + os.path.dirname(__file__), + '..', + 'src', 'node_version.h') f = open(node_version_h) for line in f: - if re.match('#define NODE_MAJOR_VERSION', line): + if re.match('^#define NODE_MAJOR_VERSION', line): major = line.split()[2] - if re.match('#define NODE_MINOR_VERSION', line): + if re.match('^#define NODE_MINOR_VERSION', line): minor = line.split()[2] - if re.match('#define NODE_PATCH_VERSION', line): + if re.match('^#define NODE_PATCH_VERSION', line): patch = line.split()[2] print '%(major)s.%(minor)s.%(patch)s'% locals() From 38acb907ddb7bfe30207e4b7ea0af992b6bce26d Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Mon, 27 Jun 2016 17:41:46 -0400 Subject: [PATCH 7/9] WIP: Review Fixes --- common.gypi | 2 +- configure | 16 +++++++--------- node.gyp | 15 ++++++++++----- src/node.cc | 6 +++--- tools/getmoduleversion.py | 6 ++++-- tools/getnodeversion.py | 3 ++- tools/install.py | 5 +++-- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/common.gypi b/common.gypi index d4dbfa7df1448c..a892c2d6e38f5b 100644 --- a/common.gypi +++ b/common.gypi @@ -14,7 +14,7 @@ 'node_shared%': 'false', 'node_use_v8_platform%': 'true', 'node_use_bundled_v8%': 'true', - 'node_module_ver%': '', + 'node_module_version%': '', 'node_tag%': '', 'uv_library%': 'static_library', diff --git a/configure b/configure index 2e3ffecd1911d6..9d4e04527136da 100755 --- a/configure +++ b/configure @@ -430,16 +430,16 @@ parser.add_option('--shared', help='compile shared library for embedding node in another project. ' + '(This mode is not officially supported for regular applications)') -parser.add_option('--no-v8-platform', +parser.add_option('--without-v8-platform', action='store_true', - dest='no_v8_platform', + dest='without_v8_platform', default=False, help='do not initialize v8 platform during node.js startup. ' + '(This mode is not officially supported for regular applications)') -parser.add_option('--no-bundled-v8', +parser.add_option('--without-bundled-v8', action='store_true', - dest='no_bundled_v8', + dest='without_bundled_v8', default=False, help='do not use V8 includes from the bundled deps folder. ' + '(This mode is not officially supported for regular applications)') @@ -835,11 +835,9 @@ def configure_node(o): o['variables']['node_no_browser_globals'] = b(options.no_browser_globals) o['variables']['node_shared'] = b(options.shared) - o['variables']['node_use_v8_platform'] = b(not options.no_v8_platform) - o['variables']['node_use_bundled_v8'] = b(not options.no_bundled_v8) - - if flavor == 'linux' and options.shared: - o['variables']['node_module_ver'] = getmoduleversion.get_version() + o['variables']['node_use_v8_platform'] = b(not options.without_v8_platform) + o['variables']['node_use_bundled_v8'] = b(not options.without_bundled_v8) + o['variables']['node_module_version'] = getmoduleversion.get_version() if options.linked_module: o['variables']['library_files'] = options.linked_module diff --git a/node.gyp b/node.gyp index 37fa951b990ac4..acb5a458cae74d 100644 --- a/node.gyp +++ b/node.gyp @@ -9,7 +9,7 @@ 'node_use_v8_platform%': 'true', 'node_use_bundled_v8%': 'true', 'node_shared%': 'false', - 'node_module_ver%': '', + 'node_module_version%': '', 'node_shared_zlib%': 'false', 'node_shared_http_parser%': 'false', 'node_shared_cares%': 'false', @@ -236,8 +236,8 @@ 'NODE_SHARED_MODE', ], 'conditions': [ - [ 'node_module_ver!=""', { - 'product_extension': 'so.<(node_module_ver)', + [ 'node_module_version!=""', { + 'product_extension': 'so.<(node_module_version)', }] ], }], @@ -250,9 +250,14 @@ 'deps/v8/tools/gyp/v8.gyp:v8', 'deps/v8/tools/gyp/v8.gyp:v8_libplatform' ], + }], + [ 'node_use_v8_platform=="true"', { + 'defines': [ + 'NODE_NO_V8_PLATFORM=0', + ], }, { 'defines': [ - 'NODE_NO_V8_PLATFORM', + 'NODE_NO_V8_PLATFORM=1', ], }], [ 'node_tag!=""', { @@ -347,7 +352,7 @@ ], }, 'conditions': [ - ['OS in "linux freebsd"' and 'node_shared=="false"', { + ['OS in "linux freebsd" and node_shared=="false"', { 'ldflags': [ '-Wl,--whole-archive <(PRODUCT_DIR)/<(OPENSSL_PRODUCT)', '-Wl,--no-whole-archive', diff --git a/src/node.cc b/src/node.cc index eb549ef8b3aa81..089d99d699eb35 100644 --- a/src/node.cc +++ b/src/node.cc @@ -39,9 +39,9 @@ #include "string_bytes.h" #include "util.h" #include "uv.h" -#ifndef NODE_NO_V8_PLATFORM +#if !NODE_NO_V8_PLATFORM #include "libplatform/libplatform.h" -#endif // NODE_NO_V8_PLATFORM +#endif // !NODE_NO_V8_PLATFORM #include "v8-debug.h" #include "v8-profiler.h" #include "zlib.h" @@ -187,7 +187,7 @@ static Mutex node_isolate_mutex; static v8::Isolate* node_isolate; static struct { -#ifdef NODE_NO_V8_PLATFORM +#if NODE_NO_V8_PLATFORM void Initialize(int thread_pool_size) {} void PumpMessageLoop(Isolate* isolate) {} void Dispose() {} diff --git a/tools/getmoduleversion.py b/tools/getmoduleversion.py index 83e0c91673c822..fb86ba1fa923dd 100644 --- a/tools/getmoduleversion.py +++ b/tools/getmoduleversion.py @@ -1,4 +1,6 @@ -import os,re +from __future__ import print_function +import os +import re def get_version(): node_version_h = os.path.join( @@ -19,4 +21,4 @@ def get_version(): raise Exception('Could not find pattern matching %s' % regex) if __name__ == '__main__': - print get_version() + print(get_version()) diff --git a/tools/getnodeversion.py b/tools/getnodeversion.py index f76c2aeb851d73..f2032cccefe936 100644 --- a/tools/getnodeversion.py +++ b/tools/getnodeversion.py @@ -1,4 +1,5 @@ -import os,re +import os +import re node_version_h = os.path.join( os.path.dirname(__file__), diff --git a/tools/install.py b/tools/install.py index 5fcd064f78db7e..a3986c5033904d 100755 --- a/tools/install.py +++ b/tools/install.py @@ -111,8 +111,9 @@ def files(action): output_file = 'node' output_prefix = 'out/Release/' - if 'false' == variables.get('node_shared') and is_windows: - output_file += '.exe' + if 'false' == variables.get('node_shared'): + if is_windows: + output_file += '.exe' else: if is_windows: output_file += '.dll' From eeb315bbeff544b44369f36b5c731d3878af37c6 Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Tue, 28 Jun 2016 12:37:15 -0400 Subject: [PATCH 8/9] WIP: Added test & inverted logic --- configure | 2 +- node.gyp | 4 ++-- src/node.cc | 27 ++++++++++++++------------- test/parallel/test-module-version.js | 10 ++++++++++ 4 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 test/parallel/test-module-version.js diff --git a/configure b/configure index 9d4e04527136da..879c12b496017f 100755 --- a/configure +++ b/configure @@ -837,7 +837,7 @@ def configure_node(o): o['variables']['node_shared'] = b(options.shared) o['variables']['node_use_v8_platform'] = b(not options.without_v8_platform) o['variables']['node_use_bundled_v8'] = b(not options.without_bundled_v8) - o['variables']['node_module_version'] = getmoduleversion.get_version() + o['variables']['node_module_version'] = int(getmoduleversion.get_version()) if options.linked_module: o['variables']['library_files'] = options.linked_module diff --git a/node.gyp b/node.gyp index acb5a458cae74d..c14f57e94a02f3 100644 --- a/node.gyp +++ b/node.gyp @@ -253,11 +253,11 @@ }], [ 'node_use_v8_platform=="true"', { 'defines': [ - 'NODE_NO_V8_PLATFORM=0', + 'NODE_USE_V8_PLATFORM=1', ], }, { 'defines': [ - 'NODE_NO_V8_PLATFORM=1', + 'NODE_USE_V8_PLATFORM=0', ], }], [ 'node_tag!=""', { diff --git a/src/node.cc b/src/node.cc index 089d99d699eb35..c7dacafacfd7fe 100644 --- a/src/node.cc +++ b/src/node.cc @@ -39,9 +39,9 @@ #include "string_bytes.h" #include "util.h" #include "uv.h" -#if !NODE_NO_V8_PLATFORM +#if NODE_USE_V8_PLATFORM #include "libplatform/libplatform.h" -#endif // !NODE_NO_V8_PLATFORM +#endif // NODE_USE_V8_PLATFORM #include "v8-debug.h" #include "v8-profiler.h" #include "zlib.h" @@ -187,16 +187,7 @@ static Mutex node_isolate_mutex; static v8::Isolate* node_isolate; static struct { -#if NODE_NO_V8_PLATFORM - void Initialize(int thread_pool_size) {} - void PumpMessageLoop(Isolate* isolate) {} - void Dispose() {} -#if HAVE_INSPECTOR - void StartInspector(Environment *env, int port, bool wait) { - env->ThrowError("Node compiled with NODE_NO_V8_PLATFORM"); - } -#endif // HAVE_INSPECTOR -#else // !NODE_NO_V8_PLATFORM +#if NODE_USE_V8_PLATFORM void Initialize(int thread_pool_size) { platform_ = v8::platform::CreateDefaultPlatform(thread_pool_size); V8::InitializePlatform(platform_); @@ -218,7 +209,17 @@ static struct { #endif // HAVE_INSPECTOR v8::Platform* platform_; -#endif // !NODE_NO_V8_PLATFORM +#else // !NODE_USE_V8_PLATFORM + void Initialize(int thread_pool_size) {} + void PumpMessageLoop(Isolate* isolate) {} + void Dispose() {} +#if HAVE_INSPECTOR + void StartInspector(Environment *env, int port, bool wait) { + env->ThrowError("Node compiled with NODE_NO_V8_PLATFORM"); + } +#endif // HAVE_INSPECTOR + +#endif // !NODE_USE_V8_PLATFORM } v8_platform; #ifdef __POSIX__ diff --git a/test/parallel/test-module-version.js b/test/parallel/test-module-version.js new file mode 100644 index 00000000000000..7f96e8bb60f0ac --- /dev/null +++ b/test/parallel/test-module-version.js @@ -0,0 +1,10 @@ +'use strict'; +require('../common'); +var assert = require('assert'); + +// check for existence +assert(process.config.variables.hasOwnProperty('node_module_version')); + +// ensure that `node_module_version` is an Integer > 0 +assert(Number.isInteger(process.config.variables.node_module_version)); +assert(process.config.variables.node_module_version > 0); From 53c7adc030b93087cdd19d82e7ff80bbf3af1af0 Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Tue, 28 Jun 2016 14:38:36 -0400 Subject: [PATCH 9/9] WIP: Update error string --- src/node.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index c7dacafacfd7fe..cc15ac272aaa00 100644 --- a/src/node.cc +++ b/src/node.cc @@ -215,7 +215,7 @@ static struct { void Dispose() {} #if HAVE_INSPECTOR void StartInspector(Environment *env, int port, bool wait) { - env->ThrowError("Node compiled with NODE_NO_V8_PLATFORM"); + env->ThrowError("Node compiled with NODE_USE_V8_PLATFORM=0"); } #endif // HAVE_INSPECTOR