diff --git a/common.gypi b/common.gypi index 147cc70fa5d5df..224498b4310ea8 100644 --- a/common.gypi +++ b/common.gypi @@ -38,6 +38,8 @@ ['OS == "win"', { 'os_posix': 0, 'v8_postmortem_support%': 'false', + 'OBJ_DIR': '<(PRODUCT_DIR)/obj', + 'V8_BASE': '<(PRODUCT_DIR)/lib/v8_libbase.lib', }, { 'os_posix': 1, 'v8_postmortem_support%': 'true', @@ -51,8 +53,8 @@ 'OBJ_DIR': '<(PRODUCT_DIR)/obj', 'V8_BASE': '<(PRODUCT_DIR)/obj/deps/v8/src/libv8_base.a', }, { - 'OBJ_DIR': '<(PRODUCT_DIR)/obj.target', - 'V8_BASE': '<(PRODUCT_DIR)/obj.target/deps/v8/src/libv8_base.a', + 'OBJ_DIR%': '<(PRODUCT_DIR)/obj.target', + 'V8_BASE%': '<(PRODUCT_DIR)/obj.target/deps/v8/src/libv8_base.a', }], ], }], diff --git a/node.gyp b/node.gyp index 935b0e7195d3ba..0881a8cc0fd67f 100644 --- a/node.gyp +++ b/node.gyp @@ -145,6 +145,10 @@ 'node_js2c#host', ], + 'includes': [ + 'node.gypi' + ], + 'include_dirs': [ 'src', 'tools/msvs/genfiles', @@ -259,340 +263,6 @@ # Warn when using deprecated V8 APIs. 'V8_DEPRECATION_WARNINGS=1', ], - - - 'conditions': [ - [ 'node_shared=="false"', { - 'msvs_settings': { - 'VCManifestTool': { - 'EmbedManifest': 'true', - 'AdditionalManifestFiles': 'src/res/node.exe.extra.manifest' - } - }, - }, { - 'defines': [ - 'NODE_SHARED_MODE', - ], - 'conditions': [ - [ 'node_module_version!="" and OS!="win"', { - 'product_extension': '<(shlib_suffix)', - }] - ], - }], - [ 'node_enable_d8=="true"', { - 'dependencies': [ 'deps/v8/src/d8.gyp:d8' ], - }], - [ 'node_use_bundled_v8=="true"', { - 'dependencies': [ - 'deps/v8/src/v8.gyp:v8', - 'deps/v8/src/v8.gyp:v8_libplatform' - ], - }], - [ 'node_use_v8_platform=="true"', { - 'defines': [ - 'NODE_USE_V8_PLATFORM=1', - ], - }, { - 'defines': [ - 'NODE_USE_V8_PLATFORM=0', - ], - }], - [ 'node_tag!=""', { - 'defines': [ 'NODE_TAG="<(node_tag)"' ], - }], - [ 'node_v8_options!=""', { - 'defines': [ 'NODE_V8_OPTIONS="<(node_v8_options)"'], - }], - # No node_main.cc for anything except executable - [ 'node_target_type!="executable"', { - 'sources!': [ - 'src/node_main.cc', - ], - }], - [ 'node_release_urlbase!=""', { - 'defines': [ - 'NODE_RELEASE_URLBASE="<(node_release_urlbase)"', - ] - }], - [ 'v8_enable_i18n_support==1', { - 'defines': [ 'NODE_HAVE_I18N_SUPPORT=1' ], - 'dependencies': [ - '<(icu_gyp_path):icui18n', - '<(icu_gyp_path):icuuc', - ], - 'conditions': [ - [ 'icu_small=="true"', { - 'defines': [ 'NODE_HAVE_SMALL_ICU=1' ], - }]], - }], - [ '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' ], - 'dependencies': [ - 'deps/v8/src/third_party/vtune/v8vtune.gyp:v8_vtune' - ], - }], - [ 'v8_inspector=="true"', { - 'defines': [ - 'HAVE_INSPECTOR=1', - ], - 'sources': [ - 'src/inspector_agent.cc', - 'src/inspector_socket.cc', - 'src/inspector_socket_server.cc', - 'src/inspector_agent.h', - 'src/inspector_socket.h', - 'src/inspector_socket_server.h', - ], - 'dependencies': [ - 'deps/v8_inspector/src/inspector/inspector.gyp:standalone_inspector', - 'v8_inspector_compress_protocol_json#host', - ], - 'include_dirs': [ - 'deps/v8_inspector/include', - '<(SHARED_INTERMEDIATE_DIR)/include', # for inspector - '<(SHARED_INTERMEDIATE_DIR)', - ], - }, { - 'defines': [ 'HAVE_INSPECTOR=0' ] - }], - [ 'node_use_openssl=="true"', { - 'defines': [ 'HAVE_OPENSSL=1' ], - 'sources': [ - 'src/node_crypto.cc', - 'src/node_crypto_bio.cc', - 'src/node_crypto_clienthello.cc', - 'src/node_crypto.h', - 'src/node_crypto_bio.h', - 'src/node_crypto_clienthello.h', - 'src/tls_wrap.cc', - 'src/tls_wrap.h' - ], - 'conditions': [ - ['openssl_fips != ""', { - 'defines': [ 'NODE_FIPS_MODE' ], - }], - [ 'node_shared_openssl=="false"', { - 'dependencies': [ - './deps/openssl/openssl.gyp:openssl', - - # For tests - './deps/openssl/openssl.gyp:openssl-cli', - ], - # Do not let unused OpenSSL symbols to slip away - 'conditions': [ - # -force_load or --whole-archive are not applicable for - # the static library - [ 'node_target_type!="static_library"', { - 'xcode_settings': { - 'OTHER_LDFLAGS': [ - '-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)', - ], - }, - 'conditions': [ - ['OS in "linux freebsd" and node_shared=="false"', { - 'ldflags': [ - '-Wl,--whole-archive,' - '<(OBJ_DIR)/deps/openssl/' - '<(OPENSSL_PRODUCT)', - '-Wl,--no-whole-archive', - ], - }], - # openssl.def is based on zlib.def, zlib symbols - # are always exported. - ['use_openssl_def==1', { - 'sources': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'], - }], - ['OS=="win" and use_openssl_def==0', { - 'sources': ['deps/zlib/win32/zlib.def'], - }], - ], - }], - ], - }]] - }, { - 'defines': [ 'HAVE_OPENSSL=0' ] - }], - [ 'node_use_dtrace=="true"', { - 'defines': [ 'HAVE_DTRACE=1' ], - 'dependencies': [ - 'node_dtrace_header', - 'specialize_node_d', - ], - 'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ], - - # - # DTrace is supported on linux, solaris, mac, and bsd. There are - # three object files associated with DTrace support, but they're - # not all used all the time: - # - # node_dtrace.o all configurations - # node_dtrace_ustack.o not supported on mac and linux - # node_dtrace_provider.o All except OS X. "dtrace -G" is not - # used on OS X. - # - # Note that node_dtrace_provider.cc and node_dtrace_ustack.cc do not - # actually exist. They're listed here to trick GYP into linking the - # corresponding object files into the final "node" executable. These - # object files are generated by "dtrace -G" using custom actions - # below, and the GYP-generated Makefiles will properly build them when - # needed. - # - 'sources': [ 'src/node_dtrace.cc' ], - 'conditions': [ - [ 'OS=="linux"', { - 'sources': [ - '<(SHARED_INTERMEDIATE_DIR)/node_dtrace_provider.o' - ], - }], - [ 'OS!="mac" and OS!="linux"', { - 'sources': [ - 'src/node_dtrace_ustack.cc', - 'src/node_dtrace_provider.cc', - ] - } - ] ] - } ], - [ 'node_use_lttng=="true"', { - 'defines': [ 'HAVE_LTTNG=1' ], - 'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ], - 'libraries': [ '-llttng-ust' ], - 'sources': [ - 'src/node_lttng.cc' - ], - } ], - [ 'node_use_etw=="true"', { - 'defines': [ 'HAVE_ETW=1' ], - 'dependencies': [ 'node_etw' ], - 'sources': [ - 'src/node_win32_etw_provider.h', - 'src/node_win32_etw_provider-inl.h', - 'src/node_win32_etw_provider.cc', - 'src/node_dtrace.cc', - 'tools/msvs/genfiles/node_etw_provider.h', - 'tools/msvs/genfiles/node_etw_provider.rc', - ] - } ], - [ 'node_use_perfctr=="true"', { - 'defines': [ 'HAVE_PERFCTR=1' ], - 'dependencies': [ 'node_perfctr' ], - 'sources': [ - 'src/node_win32_perfctr_provider.h', - 'src/node_win32_perfctr_provider.cc', - 'src/node_counters.cc', - 'src/node_counters.h', - 'tools/msvs/genfiles/node_perfctr_provider.rc', - ] - } ], - [ 'node_no_browser_globals=="true"', { - 'defines': [ 'NODE_NO_BROWSER_GLOBALS' ], - } ], - [ 'node_use_bundled_v8=="true" and v8_postmortem_support=="true"', { - 'dependencies': [ 'deps/v8/src/v8.gyp:postmortem-metadata' ], - 'conditions': [ - # -force_load is not applicable for the static library - [ 'node_target_type!="static_library"', { - 'xcode_settings': { - 'OTHER_LDFLAGS': [ - '-Wl,-force_load,<(V8_BASE)', - ], - }, - }], - ], - }], - [ 'node_shared_zlib=="false"', { - 'dependencies': [ 'deps/zlib/zlib.gyp:zlib' ], - }], - - [ 'node_shared_http_parser=="false"', { - 'dependencies': [ 'deps/http_parser/http_parser.gyp:http_parser' ], - }], - - [ 'node_shared_cares=="false"', { - 'dependencies': [ 'deps/cares/cares.gyp:cares' ], - }], - - [ 'node_shared_libuv=="false"', { - 'dependencies': [ 'deps/uv/uv.gyp:libuv' ], - }], - - [ 'OS=="win"', { - 'sources': [ - 'src/backtrace_win32.cc', - 'src/res/node.rc', - ], - 'defines!': [ - 'NODE_PLATFORM="win"', - ], - 'defines': [ - 'FD_SETSIZE=1024', - # we need to use node's preferred "win32" rather than gyp's preferred "win" - 'NODE_PLATFORM="win32"', - '_UNICODE=1', - ], - 'libraries': [ '-lpsapi.lib' ] - }, { # POSIX - 'defines': [ '__POSIX__' ], - 'sources': [ 'src/backtrace_posix.cc' ], - }], - [ 'OS=="mac"', { - # linking Corefoundation is needed since certain OSX debugging tools - # like Instruments require it for some features - 'libraries': [ '-framework CoreFoundation' ], - 'defines!': [ - 'NODE_PLATFORM="mac"', - ], - 'defines': [ - # we need to use node's preferred "darwin" rather than gyp's preferred "mac" - 'NODE_PLATFORM="darwin"', - ], - }], - [ 'OS=="freebsd"', { - 'libraries': [ - '-lutil', - '-lkvm', - ], - }], - [ 'OS=="aix"', { - 'defines': [ - '_LINUX_SOURCE_COMPAT', - ], - }], - [ 'OS=="solaris"', { - 'libraries': [ - '-lkstat', - '-lumem', - ], - 'defines!': [ - 'NODE_PLATFORM="solaris"', - ], - 'defines': [ - # we need to use node's preferred "sunos" - # rather than gyp's preferred "solaris" - 'NODE_PLATFORM="sunos"', - ], - }], - [ '(OS=="freebsd" or OS=="linux") and node_shared=="false" and coverage=="false"', { - 'ldflags': [ '-Wl,-z,noexecstack', - '-Wl,--whole-archive <(V8_BASE)', - '-Wl,--no-whole-archive' ] - }], - [ '(OS=="freebsd" or OS=="linux") and node_shared=="false" and coverage=="true"', { - 'ldflags': [ '-Wl,-z,noexecstack', - '-Wl,--whole-archive <(V8_BASE)', - '-Wl,--no-whole-archive', - '--coverage', - '-g', - '-O0' ], - 'cflags': [ '--coverage', - '-g', - '-O0' ] - }], - [ 'OS=="sunos"', { - 'ldflags': [ '-Wl,-M,/usr/lib/ld/map.noexstk' ], - }], - ], }, { 'target_name': 'mkssldef', @@ -890,12 +560,70 @@ { 'target_name': 'cctest', 'type': 'executable', - 'dependencies': [ 'deps/gtest/gtest.gyp:gtest' ], + + 'dependencies': [ + '<(node_core_target_name)', + 'deps/gtest/gtest.gyp:gtest', + 'node_js2c#host', + 'node_dtrace_header', + 'node_dtrace_ustack', + 'node_dtrace_provider', + ], + + 'variables': { + 'OBJ_PATH': '<(OBJ_DIR)/node/src', + 'OBJ_GEN_PATH': '<(OBJ_DIR)/node/gen', + 'OBJ_TRACING_PATH': '<(OBJ_DIR)/node/src/tracing', + 'OBJ_SUFFIX': 'o', + 'conditions': [ + ['OS=="win"', { + 'OBJ_PATH': '<(OBJ_DIR)/node', + 'OBJ_GEN_PATH': '<(OBJ_DIR)/node', + 'OBJ_TRACING_PATH': '<(OBJ_DIR)/node', + 'OBJ_SUFFIX': 'obj', + }], + ['OS=="aix"', { + 'OBJ_PATH': '<(OBJ_DIR)/node_base/src', + 'OBJ_GEN_PATH': '<(OBJ_DIR)/node_base/gen', + 'OBJ_TRACING_PATH': '<(OBJ_DIR)/node_base/src/tracing', + }], + ], + }, + + 'includes': [ + 'node.gypi' + ], + 'include_dirs': [ 'src', + 'tools/msvs/genfiles', 'deps/v8/include', - '<(SHARED_INTERMEDIATE_DIR)' + 'deps/cares/include', + 'deps/uv/include', + '<(SHARED_INTERMEDIATE_DIR)', # for node_natives.h + ], + + 'libraries': [ + '<(OBJ_GEN_PATH)/node_javascript.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/node_debug_options.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/async-wrap.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/env.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/node.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/node_buffer.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/node_i18n.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/debug-agent.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/util.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/string_bytes.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/string_search.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/stream_base.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/node_constants.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/node_revert.<(OBJ_SUFFIX)', + '<(OBJ_TRACING_PATH)/agent.<(OBJ_SUFFIX)', + '<(OBJ_TRACING_PATH)/node_trace_buffer.<(OBJ_SUFFIX)', + '<(OBJ_TRACING_PATH)/node_trace_writer.<(OBJ_SUFFIX)', + '<(OBJ_TRACING_PATH)/trace_event.<(OBJ_SUFFIX)', ], + 'defines': [ # gtest's ASSERT macros conflict with our own. 'GTEST_DONT_DEFINE_ASSERT_EQ=1', @@ -906,24 +634,19 @@ 'GTEST_DONT_DEFINE_ASSERT_NE=1', 'NODE_WANT_INTERNALS=1', ], + 'sources': [ - 'test/cctest/util.cc', + 'test/cctest/test_environment.cc', + 'test/cctest/test_util.cc', + ], + + 'sources!': [ + 'src/node_main.cc' ], 'conditions': [ ['v8_inspector=="true"', { - 'defines': [ - 'HAVE_INSPECTOR=1', - ], - 'dependencies': [ - 'v8_inspector_compress_protocol_json#host' - ], - 'include_dirs': [ - '<(SHARED_INTERMEDIATE_DIR)' - ], 'sources': [ - 'src/inspector_socket.cc', - 'src/inspector_socket_server.cc', 'test/cctest/test_inspector_socket.cc', 'test/cctest/test_inspector_socket_server.cc' ], @@ -955,12 +678,19 @@ 'deps/v8/src/v8.gyp:v8_libplatform', ], }], - [ 'node_use_bundled_v8=="true"', { - 'dependencies': [ - 'deps/v8/src/v8.gyp:v8', - 'deps/v8/src/v8.gyp:v8_libplatform' + [ 'node_use_dtrace=="true" and OS!="mac" and OS!="linux"', { + 'copies': [{ + 'destination': '<(OBJ_DIR)/cctest/src', + 'files': [ + '<(OBJ_PATH)/node_dtrace_ustack.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/node_dtrace_provider.<(OBJ_SUFFIX)', + '<(OBJ_PATH)/node_dtrace.<(OBJ_SUFFIX)', + ]}, ], }], + ['OS=="solaris"', { + 'ldflags': [ '-I<(SHARED_INTERMEDIATE_DIR)' ] + }], ] } ], # end targets diff --git a/node.gypi b/node.gypi new file mode 100644 index 00000000000000..0c519a487ab86a --- /dev/null +++ b/node.gypi @@ -0,0 +1,333 @@ +{ + 'conditions': [ + [ 'node_shared=="false"', { + 'msvs_settings': { + 'VCManifestTool': { + 'EmbedManifest': 'true', + 'AdditionalManifestFiles': 'src/res/node.exe.extra.manifest' + } + }, + }, { + 'defines': [ + 'NODE_SHARED_MODE', + ], + 'conditions': [ + [ 'node_module_version!="" and OS!="win"', { + 'product_extension': '<(shlib_suffix)', + }] + ], + }], + [ 'node_enable_d8=="true"', { + 'dependencies': [ 'deps/v8/src/d8.gyp:d8' ], + }], + [ 'node_use_bundled_v8=="true"', { + 'dependencies': [ + 'deps/v8/src/v8.gyp:v8', + 'deps/v8/src/v8.gyp:v8_libplatform' + ], + }], + [ 'node_use_v8_platform=="true"', { + 'defines': [ + 'NODE_USE_V8_PLATFORM=1', + ], + }, { + 'defines': [ + 'NODE_USE_V8_PLATFORM=0', + ], + }], + [ 'node_tag!=""', { + 'defines': [ 'NODE_TAG="<(node_tag)"' ], + }], + [ 'node_v8_options!=""', { + 'defines': [ 'NODE_V8_OPTIONS="<(node_v8_options)"'], + }], + # No node_main.cc for anything except executable + [ 'node_target_type!="executable"', { + 'sources!': [ + 'src/node_main.cc', + ], + }], + [ 'node_release_urlbase!=""', { + 'defines': [ + 'NODE_RELEASE_URLBASE="<(node_release_urlbase)"', + ] + }], + [ 'v8_enable_i18n_support==1', { + 'defines': [ 'NODE_HAVE_I18N_SUPPORT=1' ], + 'dependencies': [ + '<(icu_gyp_path):icui18n', + '<(icu_gyp_path):icuuc', + ], + 'conditions': [ + [ 'icu_small=="true"', { + 'defines': [ 'NODE_HAVE_SMALL_ICU=1' ], + }]], + }], + [ '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' ], + 'dependencies': [ + 'deps/v8/src/third_party/vtune/v8vtune.gyp:v8_vtune' + ], + }], + ['v8_inspector=="true"', { + 'defines': [ + 'HAVE_INSPECTOR=1', + ], + 'sources': [ + 'src/inspector_agent.cc', + 'src/inspector_socket.cc', + 'src/inspector_socket_server.cc', + 'src/inspector_agent.h', + 'src/inspector_socket.h', + 'src/inspector_socket_server.h', + ], + 'dependencies': [ + 'v8_inspector_compress_protocol_json#host', + 'deps/v8_inspector/src/inspector/inspector.gyp:standalone_inspector', + ], + 'include_dirs': [ + '<(SHARED_INTERMEDIATE_DIR)/include', # for inspector + '<(SHARED_INTERMEDIATE_DIR)', + ], + }, { + 'defines': [ 'HAVE_INSPECTOR=0' ] + }], + [ 'node_use_openssl=="true"', { + 'defines': [ 'HAVE_OPENSSL=1' ], + 'sources': [ + 'src/node_crypto.cc', + 'src/node_crypto_bio.cc', + 'src/node_crypto_clienthello.cc', + 'src/node_crypto.h', + 'src/node_crypto_bio.h', + 'src/node_crypto_clienthello.h', + 'src/tls_wrap.cc', + 'src/tls_wrap.h' + ], + 'conditions': [ + ['openssl_fips != ""', { + 'defines': [ 'NODE_FIPS_MODE' ], + }], + [ 'node_shared_openssl=="false"', { + 'dependencies': [ + './deps/openssl/openssl.gyp:openssl', + + # For tests + './deps/openssl/openssl.gyp:openssl-cli', + ], + # Do not let unused OpenSSL symbols to slip away + 'conditions': [ + # -force_load or --whole-archive are not applicable for + # the static library + [ 'node_target_type!="static_library"', { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)', + ], + }, + 'conditions': [ + ['OS in "linux freebsd" and node_shared=="false"', { + 'ldflags': [ + '-Wl,--whole-archive,' + '<(OBJ_DIR)/deps/openssl/' + '<(OPENSSL_PRODUCT)', + '-Wl,--no-whole-archive', + ], + }], + # openssl.def is based on zlib.def, zlib symbols + # are always exported. + ['use_openssl_def==1', { + 'sources': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'], + }], + ['OS=="win" and use_openssl_def==0', { + 'sources': ['deps/zlib/win32/zlib.def'], + }], + ], + }], + ], + }]] + }, { + 'defines': [ 'HAVE_OPENSSL=0' ] + }], + [ 'node_use_dtrace=="true"', { + 'defines': [ 'HAVE_DTRACE=1' ], + 'dependencies': [ + 'node_dtrace_header', + 'specialize_node_d', + ], + 'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ], + + # + # DTrace is supported on linux, solaris, mac, and bsd. There are + # three object files associated with DTrace support, but they're + # not all used all the time: + # + # node_dtrace.o all configurations + # node_dtrace_ustack.o not supported on mac and linux + # node_dtrace_provider.o All except OS X. "dtrace -G" is not + # used on OS X. + # + # Note that node_dtrace_provider.cc and node_dtrace_ustack.cc do not + # actually exist. They're listed here to trick GYP into linking the + # corresponding object files into the final "node" executable. These + # object files are generated by "dtrace -G" using custom actions + # below, and the GYP-generated Makefiles will properly build them when + # needed. + # + 'sources': [ 'src/node_dtrace.cc' ], + 'conditions': [ + [ 'OS=="linux"', { + 'sources': [ + '<(SHARED_INTERMEDIATE_DIR)/node_dtrace_provider.o' + ], + }], + [ 'OS!="mac" and OS!="linux"', { + 'sources': [ + 'src/node_dtrace_ustack.cc', + 'src/node_dtrace_provider.cc', + ] + } + ] ] + } ], + [ 'node_use_lttng=="true"', { + 'defines': [ 'HAVE_LTTNG=1' ], + 'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ], + 'libraries': [ '-llttng-ust' ], + 'sources': [ + 'src/node_lttng.cc' + ], + } ], + [ 'node_use_etw=="true"', { + 'defines': [ 'HAVE_ETW=1' ], + 'dependencies': [ 'node_etw' ], + 'sources': [ + 'src/node_win32_etw_provider.h', + 'src/node_win32_etw_provider-inl.h', + 'src/node_win32_etw_provider.cc', + 'src/node_dtrace.cc', + 'tools/msvs/genfiles/node_etw_provider.h', + 'tools/msvs/genfiles/node_etw_provider.rc', + ] + } ], + [ 'node_use_perfctr=="true"', { + 'defines': [ 'HAVE_PERFCTR=1' ], + 'dependencies': [ 'node_perfctr' ], + 'sources': [ + 'src/node_win32_perfctr_provider.h', + 'src/node_win32_perfctr_provider.cc', + 'src/node_counters.cc', + 'src/node_counters.h', + 'tools/msvs/genfiles/node_perfctr_provider.rc', + ] + } ], + [ 'node_no_browser_globals=="true"', { + 'defines': [ 'NODE_NO_BROWSER_GLOBALS' ], + } ], + [ 'node_use_bundled_v8=="true" and v8_postmortem_support=="true"', { + 'dependencies': [ 'deps/v8/src/v8.gyp:postmortem-metadata' ], + 'conditions': [ + # -force_load is not applicable for the static library + [ 'node_target_type!="static_library"', { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-Wl,-force_load,<(V8_BASE)', + ], + }, + }], + ], + }], + [ 'node_shared_zlib=="false"', { + 'dependencies': [ 'deps/zlib/zlib.gyp:zlib' ], + }], + + [ 'node_shared_http_parser=="false"', { + 'dependencies': [ 'deps/http_parser/http_parser.gyp:http_parser' ], + }], + + [ 'node_shared_cares=="false"', { + 'dependencies': [ 'deps/cares/cares.gyp:cares' ], + }], + + [ 'node_shared_libuv=="false"', { + 'dependencies': [ 'deps/uv/uv.gyp:libuv' ], + }], + + [ 'OS=="win"', { + 'sources': [ + 'src/backtrace_win32.cc', + 'src/res/node.rc', + ], + 'defines!': [ + 'NODE_PLATFORM="win"', + ], + 'defines': [ + 'FD_SETSIZE=1024', + # we need to use node's preferred "win32" rather than gyp's preferred "win" + 'NODE_PLATFORM="win32"', + '_UNICODE=1', + ], + 'libraries': [ '-lpsapi.lib' ] + }, { # POSIX + 'defines': [ '__POSIX__' ], + 'sources': [ 'src/backtrace_posix.cc' ], + }], + [ 'OS=="mac"', { + # linking Corefoundation is needed since certain OSX debugging tools + # like Instruments require it for some features + 'libraries': [ '-framework CoreFoundation' ], + 'defines!': [ + 'NODE_PLATFORM="mac"', + ], + 'defines': [ + # we need to use node's preferred "darwin" rather than gyp's preferred "mac" + 'NODE_PLATFORM="darwin"', + ], + }], + [ 'OS=="freebsd"', { + 'libraries': [ + '-lutil', + '-lkvm', + ], + }], + [ 'OS=="aix"', { + 'defines': [ + '_LINUX_SOURCE_COMPAT', + ], + }], + [ 'OS=="solaris"', { + 'libraries': [ + '-lkstat', + '-lumem', + ], + 'defines!': [ + 'NODE_PLATFORM="solaris"', + ], + 'defines': [ + # we need to use node's preferred "sunos" + # rather than gyp's preferred "solaris" + 'NODE_PLATFORM="sunos"', + ], + }], + [ '(OS=="freebsd" or OS=="linux") and node_shared=="false" and coverage=="false"', { + 'ldflags': [ '-Wl,-z,noexecstack', + '-Wl,--whole-archive <(V8_BASE)', + '-Wl,--no-whole-archive' ] + }], + [ '(OS=="freebsd" or OS=="linux") and node_shared=="false" and coverage=="true"', { + 'ldflags': [ '-Wl,-z,noexecstack', + '-Wl,--whole-archive <(V8_BASE)', + '-Wl,--no-whole-archive', + '--coverage', + '-g', + '-O0' ], + 'cflags': [ '--coverage', + '-g', + '-O0' ] + }], + [ 'OS=="sunos"', { + 'ldflags': [ '-Wl,-M,/usr/lib/ld/map.noexstk' ], + }], + ], +} diff --git a/src/debug-agent.cc b/src/debug-agent.cc index 2ce8381fc51462..aef1daa1625b8f 100644 --- a/src/debug-agent.cc +++ b/src/debug-agent.cc @@ -184,6 +184,8 @@ void Agent::WorkerRun() { // Clean-up persistent api_.Reset(); + + env.CleanupHandles(); } isolate->Dispose(); } diff --git a/src/env-inl.h b/src/env-inl.h index 1a17e2947d0597..85847da7aeb508 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -201,28 +201,6 @@ inline Environment::Environment(IsolateData* isolate_data, inline Environment::~Environment() { v8::HandleScope handle_scope(isolate()); - while (HandleCleanup* hc = handle_cleanup_queue_.PopFront()) { - handle_cleanup_waiting_++; - hc->cb_(this, hc->handle_, hc->arg_); - delete hc; - } - - while (handle_cleanup_waiting_ != 0) - uv_run(event_loop(), UV_RUN_ONCE); - - // Closing the destroy_ids_idle_handle_ within the handle cleanup queue - // prevents the async wrap destroy hook from being called. - uv_handle_t* handle = - reinterpret_cast(&destroy_ids_idle_handle_); - handle->data = this; - handle_cleanup_waiting_ = 1; - uv_close(handle, [](uv_handle_t* handle) { - static_cast(handle->data)->FinishHandleCleanup(handle); - }); - - while (handle_cleanup_waiting_ != 0) - uv_run(event_loop(), UV_RUN_ONCE); - context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, nullptr); #define V(PropertyName, TypeName) PropertyName ## _.Reset(); diff --git a/src/env.cc b/src/env.cc index 40f0c9ebd66a07..b44b435d4e3256 100644 --- a/src/env.cc +++ b/src/env.cc @@ -92,6 +92,30 @@ void Environment::Start(int argc, LoadAsyncWrapperInfo(this); } +void Environment::CleanupHandles() { + while (HandleCleanup* hc = handle_cleanup_queue_.PopFront()) { + handle_cleanup_waiting_++; + hc->cb_(this, hc->handle_, hc->arg_); + delete hc; + } + + while (handle_cleanup_waiting_ != 0) + uv_run(event_loop(), UV_RUN_ONCE); + + // Closing the destroy_ids_idle_handle_ within the handle cleanup queue + // prevents the async wrap destroy hook from being called. + uv_handle_t* handle = + reinterpret_cast(&destroy_ids_idle_handle_); + handle->data = this; + handle_cleanup_waiting_ = 1; + uv_close(handle, [](uv_handle_t* handle) { + static_cast(handle->data)->FinishHandleCleanup(handle); + }); + + while (handle_cleanup_waiting_ != 0) + uv_run(event_loop(), UV_RUN_ONCE); +} + void Environment::StartProfilerIdleNotifier() { uv_prepare_start(&idle_prepare_handle_, [](uv_prepare_t* handle) { Environment* env = ContainerOf(&Environment::idle_prepare_handle_, handle); @@ -153,4 +177,15 @@ void Environment::PrintSyncTrace() const { fflush(stderr); } +void Environment::RunAtExitCallbacks() { + for (AtExitCallback at_exit : at_exit_functions_) { + at_exit.cb_(at_exit.arg_); + } + at_exit_functions_.clear(); +} + +void Environment::AtExit(void (*cb)(void* arg), void* arg) { + at_exit_functions_.push_back(AtExitCallback{cb, arg}); +} + } // namespace node diff --git a/src/env.h b/src/env.h index 2e3337c44fe30f..21fff2a5b4c5ac 100644 --- a/src/env.h +++ b/src/env.h @@ -15,6 +15,7 @@ #include "uv.h" #include "v8.h" +#include #include #include @@ -415,6 +416,7 @@ class Environment { const char* const* exec_argv, bool start_profiler_idle_notifier); void AssignToContext(v8::Local context); + void CleanupHandles(); void StartProfilerIdleNotifier(); void StopProfilerIdleNotifier(); @@ -503,6 +505,9 @@ class Environment { inline v8::Local NewInternalFieldObject(); + void AtExit(void (*cb)(void* arg), void* arg); + void RunAtExitCallbacks(); + // Strings and private symbols are shared across shared contexts // The getters simply proxy to the per-isolate primitive. #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) @@ -580,6 +585,14 @@ class Environment { char* http_parser_buffer_; + double* fs_stats_field_array_; + + struct AtExitCallback { + void (*cb_)(void* arg); + void* arg_; + }; + std::list at_exit_functions_; + #define V(PropertyName, TypeName) \ v8::Persistent PropertyName ## _; ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) diff --git a/src/node.cc b/src/node.cc index 3190d371f5ad04..705d0bd1121529 100644 --- a/src/node.cc +++ b/src/node.cc @@ -63,7 +63,6 @@ #include #include -#include #if defined(NODE_HAVE_I18N_SUPPORT) #include @@ -4292,25 +4291,23 @@ void Init(int* argc, } -struct AtExitCallback { - void (*cb_)(void* arg); - void* arg_; -}; +void RunAtExit(Environment* env) { + env->RunAtExitCallbacks(); +} -static std::list at_exit_functions; +static uv_key_t thread_local_env; -// TODO(bnoordhuis) Turn into per-context event. -void RunAtExit(Environment* env) { - for (AtExitCallback at_exit : at_exit_functions) { - at_exit.cb_(at_exit.arg_); - } - at_exit_functions.clear(); + +void AtExit(void (*cb)(void* arg), void* arg) { + auto env = static_cast(uv_key_get(&thread_local_env)); + AtExit(env, cb, arg); } -void AtExit(void (*cb)(void* arg), void* arg) { - at_exit_functions.push_back(AtExitCallback{cb, arg}); +void AtExit(Environment* env, void (*cb)(void* arg), void* arg) { + CHECK_NE(env, nullptr); + env->AtExit(cb, arg); } @@ -4386,6 +4383,8 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, Local context = Context::New(isolate); Context::Scope context_scope(context); Environment env(isolate_data, context); + CHECK_EQ(0, uv_key_create(&thread_local_env)); + uv_key_set(&thread_local_env, &env); env.Start(argc, argv, exec_argc, exec_argv, v8_is_profiling); bool debug_enabled = @@ -4434,6 +4433,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, const int exit_code = EmitExit(&env); RunAtExit(&env); + uv_key_delete(&thread_local_env); WaitForInspectorDisconnect(&env); #if defined(LEAK_SANITIZER) diff --git a/src/node.h b/src/node.h index 1255a4af7f11ce..66b6052198eef2 100644 --- a/src/node.h +++ b/src/node.h @@ -490,6 +490,12 @@ extern "C" NODE_EXTERN void node_module_register(void* mod); */ NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = 0); +/* Registers a callback with the passed-in Environment instance. The callback + * is called after the event loop exits, but before the VM is disposed. + * Callbacks are run in reverse order of registration, i.e. newest first. + */ +NODE_EXTERN void AtExit(Environment* env, void (*cb)(void* arg), void* arg = 0); + } // namespace node #endif // SRC_NODE_H_ diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h new file mode 100644 index 00000000000000..bf155c58945582 --- /dev/null +++ b/test/cctest/node_test_fixture.h @@ -0,0 +1,100 @@ +#ifndef TEST_CCTEST_NODE_TEST_FIXTURE_H_ +#define TEST_CCTEST_NODE_TEST_FIXTURE_H_ + +#include +#include "gtest/gtest.h" +#include "node.h" +#include "env.h" +#include "v8.h" +#include "libplatform/libplatform.h" + +using node::Environment; +using node::IsolateData; +using node::CreateIsolateData; +using node::CreateEnvironment; +using node::AtExit; +using node::RunAtExit; + +class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { + public: + virtual void* Allocate(size_t length) { + return AllocateUninitialized(length); + } + + virtual void* AllocateUninitialized(size_t length) { + return calloc(length, 1); + } + + virtual void Free(void* data, size_t) { + free(data); + } +}; + +struct Argv { + public: + Argv() : Argv({"node", "-p", "process.version"}) {} + + Argv(const std::initializer_list &args) { + nr_args_ = args.size(); + int totalLen = 0; + for (auto it = args.begin(); it != args.end(); ++it) { + totalLen += strlen(*it) + 1; + } + argv_ = static_cast(malloc(nr_args_ * sizeof(char*))); + argv_[0] = static_cast(malloc(totalLen)); + int i = 0; + int offset = 0; + for (auto it = args.begin(); it != args.end(); ++it, ++i) { + int len = strlen(*it) + 1; + snprintf(argv_[0] + offset, len, "%s", *it); + // Skip argv_[0] as it points the correct location already + if (i > 0) { + argv_[i] = argv_[0] + offset; + } + offset += len; + } + } + + ~Argv() { + free(argv_[0]); + free(argv_); + } + + int nr_args() const { + return nr_args_; + } + + char** operator*() const { + return argv_; + } + + private: + char** argv_; + int nr_args_; +}; + +class NodeTestFixture : public ::testing::Test { + protected: + v8::Isolate::CreateParams params_; + ArrayBufferAllocator allocator_; + v8::Isolate* isolate_; + + virtual void SetUp() { + platform_ = v8::platform::CreateDefaultPlatform(); + v8::V8::InitializePlatform(platform_); + v8::V8::Initialize(); + params_.array_buffer_allocator = &allocator_; + isolate_ = v8::Isolate::New(params_); + } + + virtual void TearDown() { + v8::V8::ShutdownPlatform(); + delete platform_; + platform_ = nullptr; + } + + private: + v8::Platform* platform_; +}; + +#endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_ diff --git a/test/cctest/test_environment.cc b/test/cctest/test_environment.cc new file mode 100644 index 00000000000000..79bfbf50b45c03 --- /dev/null +++ b/test/cctest/test_environment.cc @@ -0,0 +1,113 @@ +#include "node.h" +#include "env.h" +#include "v8.h" +#include "libplatform/libplatform.h" + +#include +#include "gtest/gtest.h" +#include "node_test_fixture.h" + +using node::Environment; +using node::IsolateData; +using node::CreateIsolateData; +using node::FreeIsolateData; +using node::CreateEnvironment; +using node::FreeEnvironment; +using node::AtExit; +using node::RunAtExit; + +static bool called_cb_1 = false; +static bool called_cb_2 = false; +static void at_exit_callback1(void* arg); +static void at_exit_callback2(void* arg); +static std::string cb_1_arg; // NOLINT(runtime/string) + +class EnvironmentTest : public NodeTestFixture { + public: + class Env { + public: + Env(const v8::HandleScope& handle_scope, + v8::Isolate* isolate, + const Argv& argv) { + context_ = v8::Context::New(isolate); + CHECK(!context_.IsEmpty()); + isolate_data_ = CreateIsolateData(isolate, uv_default_loop()); + CHECK_NE(nullptr, isolate_data_); + environment_ = CreateEnvironment(isolate_data_, + context_, + 1, *argv, + argv.nr_args(), *argv); + CHECK_NE(nullptr, environment_); + } + + ~Env() { + FreeIsolateData(isolate_data_); + environment_->CleanupHandles(); + FreeEnvironment(environment_); + } + + Environment* operator*() const { + return environment_; + } + + private: + v8::Local context_; + IsolateData* isolate_data_; + Environment* environment_; + }; + + private: + virtual void TearDown() { + NodeTestFixture::TearDown(); + called_cb_1 = false; + called_cb_2 = false; + } +}; + +TEST_F(EnvironmentTest, AtExitWithEnvironment) { + const v8::HandleScope handle_scope(isolate_); + const Argv argv; + Env env {handle_scope, isolate_, argv}; + + AtExit(*env, at_exit_callback1); + RunAtExit(*env); + EXPECT_TRUE(called_cb_1); +} + +TEST_F(EnvironmentTest, AtExitWithArgument) { + const v8::HandleScope handle_scope(isolate_); + const Argv argv; + Env env {handle_scope, isolate_, argv}; + + std::string arg{"some args"}; + AtExit(*env, at_exit_callback1, static_cast(&arg)); + RunAtExit(*env); + EXPECT_EQ(arg, cb_1_arg); +} + +TEST_F(EnvironmentTest, MultipleEnvironmentsPerIsolate) { + const v8::HandleScope handle_scope(isolate_); + const Argv argv; + Env env1 {handle_scope, isolate_, argv}; + Env env2 {handle_scope, isolate_, argv}; + + AtExit(*env1, at_exit_callback1); + AtExit(*env2, at_exit_callback2); + RunAtExit(*env1); + EXPECT_TRUE(called_cb_1); + EXPECT_FALSE(called_cb_2); + + RunAtExit(*env2); + EXPECT_TRUE(called_cb_2); +} + +static void at_exit_callback1(void* arg) { + called_cb_1 = true; + if (arg) { + cb_1_arg = *static_cast(arg); + } +} + +static void at_exit_callback2(void* arg) { + called_cb_2 = true; +} diff --git a/test/cctest/util.cc b/test/cctest/test_util.cc similarity index 99% rename from test/cctest/util.cc rename to test/cctest/test_util.cc index a6ece3c6f4d377..db19d92cbd9c19 100644 --- a/test/cctest/util.cc +++ b/test/cctest/test_util.cc @@ -90,10 +90,6 @@ TEST(UtilTest, ToLower) { EXPECT_EQ('a', ToLower('A')); } -namespace node { - void LowMemoryNotification() {} -} - #define TEST_AND_FREE(expression) \ do { \ auto pointer = expression; \ diff --git a/test/parallel/test-async-wrap-throw-from-callback.js b/test/parallel/test-async-wrap-throw-from-callback.js deleted file mode 100644 index 86abebd7d3a810..00000000000000 --- a/test/parallel/test-async-wrap-throw-from-callback.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -const common = require('../common'); -if (!common.hasCrypto) { - common.skip('missing crypto'); - return; -} - -const async_wrap = process.binding('async_wrap'); -const assert = require('assert'); -const crypto = require('crypto'); -const domain = require('domain'); -const spawn = require('child_process').spawn; -const callbacks = [ 'init', 'pre', 'post', 'destroy' ]; -const toCall = process.argv[2]; -let msgCalled = 0; -let msgReceived = 0; - -function init() { - if (toCall === 'init') - throw new Error('init'); -} -function pre() { - if (toCall === 'pre') - throw new Error('pre'); -} -function post() { - if (toCall === 'post') - throw new Error('post'); -} -function destroy() { - if (toCall === 'destroy') - throw new Error('destroy'); -} - -if (typeof process.argv[2] === 'string') { - async_wrap.setupHooks({ init, pre, post, destroy }); - async_wrap.enable(); - - process.on('uncaughtException', common.mustNotCall()); - - const d = domain.create(); - d.on('error', common.mustNotCall()); - d.run(() => { - // Using randomBytes because timers are not yet supported. - crypto.randomBytes(0, () => { }); - }); - -} else { - - process.on('exit', (code) => { - assert.strictEqual(msgCalled, callbacks.length); - assert.strictEqual(msgCalled, msgReceived); - }); - - callbacks.forEach((item) => { - msgCalled++; - - const child = spawn(process.execPath, [__filename, item]); - let errstring = ''; - - child.stderr.on('data', (data) => { - errstring += data.toString(); - }); - - child.on('close', (code) => { - if (errstring.includes('Error: ' + item)) - msgReceived++; - - assert.strictEqual(code, 1, `${item} closed with code ${code}`); - }); - }); -} diff --git a/test/parallel/test-process-exit-GH-12322.js b/test/parallel/test-process-exit-GH-12322.js new file mode 100644 index 00000000000000..890dfd4df7bff4 --- /dev/null +++ b/test/parallel/test-process-exit-GH-12322.js @@ -0,0 +1,7 @@ +'use strict'; +require('../common'); + +process.on('exit', () => { + setTimeout(process.abort, 0); // Should not run. + for (const start = Date.now(); Date.now() - start < 10; /* Empty. */); +}); diff --git a/tools/gyp/pylib/gyp/generator/make.py b/tools/gyp/pylib/gyp/generator/make.py index 39373b9844e49e..d9adddaa9b5127 100644 --- a/tools/gyp/pylib/gyp/generator/make.py +++ b/tools/gyp/pylib/gyp/generator/make.py @@ -147,7 +147,7 @@ def CalculateGeneratorInputInfo(params): # special "figure out circular dependencies" flags around the entire # input list during linking. quiet_cmd_link = LINK($(TOOLSET)) $@ -cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS) +cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group # We support two kinds of shared objects (.so): # 1) shared_library, which is just bundling together many dependent libraries