From 543c1d8b9926fdbe1fc3d852475760f6a091e0f8 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Fri, 12 Oct 2018 18:56:14 -0400 Subject: [PATCH 1/9] tools: tweak js2c.py * remove unused includes * make writing content-stable as to not trigger rebuilding --- tools/js2c.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/js2c.py b/tools/js2c.py index 40f2bc6f48f483..db0500371539d1 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -176,11 +176,8 @@ def ReadMacros(lines): TEMPLATE = """ -#include "node.h" #include "node_javascript.h" -#include "v8.h" -#include "env.h" -#include "env-inl.h" +#include "util.h" namespace node {{ @@ -340,12 +337,19 @@ def JS2C(source, target): initializers.append(INITIALIZER.format(key=key, value=value)) hash_initializers.append(HASH_INITIALIZER.format(key=name, value=hash_value)) - # Emit result - output = open(str(target[0]), "w") - output.write(TEMPLATE.format(definitions=''.join(definitions), - initializers=''.join(initializers), - hash_initializers=''.join(hash_initializers))) - output.close() + content = TEMPLATE.format(definitions=''.join(definitions), + initializers=''.join(initializers), + hash_initializers=''.join(hash_initializers)) + # Emit result if changed + filename = str(target[0]) + old_content = '' + if os.path.isfile(filename): + with open(filename, "r") as fr: + old_content = fr.read() + if old_content == content: + return + with open(filename, "w") as fw: + fw.write(content) def main(): natives = sys.argv[1] From 0a17e279fb4165731188ec9fd3999303681a9795 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Fri, 12 Oct 2018 18:57:45 -0400 Subject: [PATCH 2/9] src: fixup for embedding - reduce dependecy * move `arraysize` to util.h to reduce the need for `node_intrnals.h` * make sure options_parser singletons init in order * deoptimize NodeTraceWriter --- src/env-inl.h | 14 ------ src/env.cc | 10 +++++ src/env.h | 8 ++-- src/node_code_cache.h | 3 +- src/node_internals.h | 13 +----- src/node_javascript.h | 3 +- src/node_options.cc | 13 +++--- src/node_postmortem_metadata.cc | 3 +- src/tracing/agent.cc | 1 - src/tracing/node_trace_writer.h | 5 ++- src/util-inl.h | 76 --------------------------------- src/util.cc | 26 +++++++++++ src/util.h | 70 +++++++++++++++++++++--------- 13 files changed, 109 insertions(+), 136 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index f0a8f2631f2398..55621f8f5a233a 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -330,10 +330,6 @@ inline bool Environment::profiler_idle_notifier_started() const { return profiler_idle_notifier_started_; } -inline v8::Isolate* Environment::isolate() const { - return isolate_; -} - inline Environment* Environment::from_timer_handle(uv_timer_t* handle) { return ContainerOf(&Environment::timer_handle_, handle); } @@ -893,16 +889,6 @@ void Environment::ForEachBaseObject(T&& iterator) { #undef VY #undef VP -#define V(PropertyName, TypeName) \ - inline v8::Local Environment::PropertyName() const { \ - return StrongPersistentToLocal(PropertyName ## _); \ - } \ - inline void Environment::set_ ## PropertyName(v8::Local value) { \ - PropertyName ## _.Reset(isolate(), value); \ - } - ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) -#undef V - } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/env.cc b/src/env.cc index 9983da1e0dd53c..5e3ff4c57fd4ff 100644 --- a/src/env.cc +++ b/src/env.cc @@ -876,4 +876,14 @@ bool BaseObject::IsRootNode() const { return !persistent_handle_.IsWeak(); } +#define V1(PropertyName, TypeName) \ + v8::Local Environment::PropertyName() const { \ + return StrongPersistentToLocal(PropertyName ## _); \ + } \ + void Environment::set_ ## PropertyName(v8::Local value) { \ + PropertyName ## _.Reset(isolate(), value); \ + } + ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V1) +#undef V1 + } // namespace node diff --git a/src/env.h b/src/env.h index a7ea3de82fff8a..620beb6d57cd10 100644 --- a/src/env.h +++ b/src/env.h @@ -629,7 +629,9 @@ class Environment { void StopProfilerIdleNotifier(); inline bool profiler_idle_notifier_started() const; - inline v8::Isolate* isolate() const; + v8::Isolate* isolate() const { + return isolate_; + } inline uv_loop_t* event_loop() const; inline uint32_t watched_providers() const; @@ -813,8 +815,8 @@ class Environment { #undef VP #define V(PropertyName, TypeName) \ - inline v8::Local PropertyName() const; \ - inline void set_ ## PropertyName(v8::Local value); + v8::Local PropertyName() const; \ + void set_ ## PropertyName(v8::Local value); ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) #undef V diff --git a/src/node_code_cache.h b/src/node_code_cache.h index db8012286172a9..d176e23aa577d1 100644 --- a/src/node_code_cache.h +++ b/src/node_code_cache.h @@ -3,7 +3,8 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#include "node_internals.h" +#include "v8.h" +#include "env.h" namespace node { diff --git a/src/node_internals.h b/src/node_internals.h index b3070198529b19..af88da5676db06 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -33,6 +33,8 @@ #include "v8.h" #include "tracing/trace_event.h" #include "node_api.h" +#include "util.h" + #include #include @@ -182,14 +184,6 @@ extern std::shared_ptr per_process_opts; // Forward declaration class Environment; -// If persistent.IsWeak() == false, then do not call persistent.Reset() -// while the returned Local is still in scope, it will destroy the -// reference to the object. -template -inline v8::Local PersistentToLocal( - v8::Isolate* isolate, - const Persistent& persistent); - // Convert a struct sockaddr to a { address: '1.2.3.4', port: 1234 } JS object. // Sets address and port properties on the info object and returns it. // If |info| is omitted, a new object is returned. @@ -231,9 +225,6 @@ bool SafeGetenv(const char* key, std::string* text); std::string GetHumanReadableProcessName(); void GetHumanReadableProcessName(char (*name)[1024]); -template -constexpr size_t arraysize(const T(&)[N]) { return N; } - #ifndef ROUND_UP # define ROUND_UP(a, b) ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a)) #endif diff --git a/src/node_javascript.h b/src/node_javascript.h index 80ef40b4ec414f..3a527a005312a0 100644 --- a/src/node_javascript.h +++ b/src/node_javascript.h @@ -24,7 +24,8 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#include "node_internals.h" +#include "v8.h" +#include "env.h" namespace node { diff --git a/src/node_options.cc b/src/node_options.cc index 4951679994a243..215b9fb4f18138 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -44,6 +44,13 @@ void EnvironmentOptions::CheckOptions(std::vector* errors) { namespace options_parser { +// Make sure dynamic instantiation of singletons is done in the right order. +DebugOptionsParser DebugOptionsParser::instance = {}; +EnvironmentOptionsParser EnvironmentOptionsParser::instance = {}; +PerIsolateOptionsParser PerIsolateOptionsParser::instance = {}; +PerProcessOptionsParser PerProcessOptionsParser::instance = {}; + + // XXX: If you add an option here, please also add it to doc/node.1 and // doc/api/cli.md // TODO(addaleax): Make that unnecessary. @@ -82,8 +89,6 @@ DebugOptionsParser::DebugOptionsParser() { #endif } -DebugOptionsParser DebugOptionsParser::instance; - EnvironmentOptionsParser::EnvironmentOptionsParser() { AddOption("--experimental-modules", "experimental ES Module support and caching modules", @@ -193,7 +198,6 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { &EnvironmentOptions::get_debug_options); } -EnvironmentOptionsParser EnvironmentOptionsParser::instance; PerIsolateOptionsParser::PerIsolateOptionsParser() { AddOption("--track-heap-objects", @@ -216,8 +220,6 @@ PerIsolateOptionsParser::PerIsolateOptionsParser() { &PerIsolateOptions::get_per_env_options); } -PerIsolateOptionsParser PerIsolateOptionsParser::instance; - PerProcessOptionsParser::PerProcessOptionsParser() { AddOption("--title", "the process title to use on startup", @@ -320,7 +322,6 @@ PerProcessOptionsParser::PerProcessOptionsParser() { &PerProcessOptions::get_per_isolate_options); } -PerProcessOptionsParser PerProcessOptionsParser::instance; inline std::string RemoveBrackets(const std::string& host) { if (!host.empty() && host.front() == '[' && host.back() == ']') diff --git a/src/node_postmortem_metadata.cc b/src/node_postmortem_metadata.cc index 93bf5a4dd7d8f4..ba3c8a167db724 100644 --- a/src/node_postmortem_metadata.cc +++ b/src/node_postmortem_metadata.cc @@ -1,7 +1,6 @@ #include "env.h" -#include "base_object-inl.h" #include "handle_wrap.h" -#include "util-inl.h" +#include "util.h" #include "req_wrap.h" #include "v8abbr.h" #include "node_context_data.h" diff --git a/src/tracing/agent.cc b/src/tracing/agent.cc index 103df55da5236e..ceb89b2c4404a3 100644 --- a/src/tracing/agent.cc +++ b/src/tracing/agent.cc @@ -4,7 +4,6 @@ #include "trace_event.h" #include "tracing/node_trace_buffer.h" #include "debug_utils.h" -#include "env-inl.h" namespace node { namespace tracing { diff --git a/src/tracing/node_trace_writer.h b/src/tracing/node_trace_writer.h index 5e5781479c689f..eb560894a419bb 100644 --- a/src/tracing/node_trace_writer.h +++ b/src/tracing/node_trace_writer.h @@ -11,6 +11,8 @@ namespace node { namespace tracing { +constexpr size_t kTracesPerFile = 1 << 19; + using v8::platform::tracing::TraceObject; using v8::platform::tracing::TraceWriter; @@ -23,7 +25,6 @@ class NodeTraceWriter : public AsyncTraceWriter { void AppendTraceEvent(TraceObject* trace_event) override; void Flush(bool blocking) override; - static const int kTracesPerFile = 1 << 19; private: struct WriteRequest { @@ -61,7 +62,7 @@ class NodeTraceWriter : public AsyncTraceWriter { int highest_request_id_completed_ = 0; int total_traces_ = 0; int file_num_ = 0; - const std::string& log_file_pattern_; + std::string log_file_pattern_; std::ostringstream stream_; std::unique_ptr json_trace_writer_; bool exited_ = false; diff --git a/src/util-inl.h b/src/util-inl.h index 0edf77496e9eba..3ae2459fe57e7c 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -141,82 +141,6 @@ typename ListHead::Iterator ListHead::end() const { return Iterator(const_cast*>(&head_)); } -template -constexpr uintptr_t OffsetOf(Inner Outer::*field) { - return reinterpret_cast(&(static_cast(0)->*field)); -} - -template -ContainerOfHelper::ContainerOfHelper(Inner Outer::*field, - Inner* pointer) - : pointer_( - reinterpret_cast( - reinterpret_cast(pointer) - OffsetOf(field))) {} - -template -template -ContainerOfHelper::operator TypeName*() const { - return static_cast(pointer_); -} - -template -constexpr ContainerOfHelper ContainerOf(Inner Outer::*field, - Inner* pointer) { - return ContainerOfHelper(field, pointer); -} - -template -inline v8::Local PersistentToLocal( - v8::Isolate* isolate, - const Persistent& persistent) { - if (persistent.IsWeak()) { - return WeakPersistentToLocal(isolate, persistent); - } else { - return StrongPersistentToLocal(persistent); - } -} - -template -inline v8::Local StrongPersistentToLocal( - const Persistent& persistent) { - return *reinterpret_cast*>( - const_cast*>(&persistent)); -} - -template -inline v8::Local WeakPersistentToLocal( - v8::Isolate* isolate, - const Persistent& persistent) { - return v8::Local::New(isolate, persistent); -} - -inline v8::Local OneByteString(v8::Isolate* isolate, - const char* data, - int length) { - return v8::String::NewFromOneByte(isolate, - reinterpret_cast(data), - v8::NewStringType::kNormal, - length).ToLocalChecked(); -} - -inline v8::Local OneByteString(v8::Isolate* isolate, - const signed char* data, - int length) { - return v8::String::NewFromOneByte(isolate, - reinterpret_cast(data), - v8::NewStringType::kNormal, - length).ToLocalChecked(); -} - -inline v8::Local OneByteString(v8::Isolate* isolate, - const unsigned char* data, - int length) { - return v8::String::NewFromOneByte(isolate, - reinterpret_cast(data), - v8::NewStringType::kNormal, - length).ToLocalChecked(); -} - void SwapBytes16(char* data, size_t nbytes) { CHECK_EQ(nbytes % 2, 0); diff --git a/src/util.cc b/src/util.cc index 9f0b8ebc9d7596..f39e39da26e384 100644 --- a/src/util.cc +++ b/src/util.cc @@ -34,6 +34,32 @@ using v8::Local; using v8::String; using v8::Value; +Local OneByteString(Isolate* isolate, const char* data, int length) { + return String::NewFromOneByte(isolate, + reinterpret_cast(data), + v8::NewStringType::kNormal, + length).ToLocalChecked(); +} + +Local OneByteString(Isolate* isolate, + const signed char* data, + int length) { + return String::NewFromOneByte(isolate, + reinterpret_cast(data), + v8::NewStringType::kNormal, + length).ToLocalChecked(); +} + +Local OneByteString(Isolate* isolate, + const unsigned char* data, + int length) { + return String::NewFromOneByte(isolate, + reinterpret_cast(data), + v8::NewStringType::kNormal, + length).ToLocalChecked(); +} + + template static void MakeUtf8String(Isolate* isolate, Local value, diff --git a/src/util.h b/src/util.h index 68b8fe144bb623..b94b0df449d2df 100644 --- a/src/util.h +++ b/src/util.h @@ -184,13 +184,25 @@ class ListHead { DISALLOW_COPY_AND_ASSIGN(ListHead); }; +template +constexpr uintptr_t OffsetOf(Inner Outer::*field) { + return reinterpret_cast(&(static_cast(0)->*field)); +} + // The helper is for doing safe downcasts from base types to derived types. template class ContainerOfHelper { public: - inline ContainerOfHelper(Inner Outer::*field, Inner* pointer); - template - inline operator TypeName*() const; + ContainerOfHelper(Inner Outer::* field, Inner* pointer) + : pointer_( + reinterpret_cast( + reinterpret_cast(pointer) - OffsetOf(field))) { + } + + template + constexpr operator TypeName*() const { + return static_cast(pointer_); + } private: Outer* const pointer_; }; @@ -199,15 +211,23 @@ class ContainerOfHelper { // the interior pointer to a data member. template constexpr ContainerOfHelper ContainerOf(Inner Outer::*field, - Inner* pointer); + Inner* pointer) { + return ContainerOfHelper(field, pointer); +} // If persistent.IsWeak() == false, then do not call persistent.Reset() // while the returned Local is still in scope, it will destroy the // reference to the object. template -inline v8::Local PersistentToLocal( +v8::Local PersistentToLocal( v8::Isolate* isolate, - const Persistent& persistent); + const Persistent& persistent) { + if (persistent.IsWeak()) { + return WeakPersistentToLocal(isolate, persistent); + } else { + return StrongPersistentToLocal(persistent); + } +} // Unchecked conversion from a non-weak Persistent to Local, // use with care! @@ -215,31 +235,40 @@ inline v8::Local PersistentToLocal( // Do not call persistent.Reset() while the returned Local is still in // scope, it will destroy the reference to the object. template -inline v8::Local StrongPersistentToLocal( - const Persistent& persistent); +constexpr v8::Local StrongPersistentToLocal( + const Persistent& persistent) { + return *reinterpret_cast*>( + const_cast*>(&persistent)); +} template -inline v8::Local WeakPersistentToLocal( +constexpr v8::Local WeakPersistentToLocal( v8::Isolate* isolate, - const Persistent& persistent); + const Persistent& persistent) { + return v8::Local::New(isolate, persistent); +} // Convenience wrapper around v8::String::NewFromOneByte(). -inline v8::Local OneByteString(v8::Isolate* isolate, - const char* data, - int length = -1); +v8::Local OneByteString(v8::Isolate* isolate, + const char* data, + int length = -1); // For the people that compile with -funsigned-char. -inline v8::Local OneByteString(v8::Isolate* isolate, - const signed char* data, - int length = -1); +v8::Local OneByteString(v8::Isolate* isolate, + const signed char* data, + int length = -1); -inline v8::Local OneByteString(v8::Isolate* isolate, - const unsigned char* data, - int length = -1); +v8::Local OneByteString(v8::Isolate* isolate, + const unsigned char* data, + int length = -1); // Used to be a macro, hence the uppercase name. template +#if __cpp_constexpr < 201603 inline v8::Local FIXED_ONE_BYTE_STRING( +#else +constexpr v8::Local FIXED_ONE_BYTE_STRING( +#endif v8::Isolate* isolate, const char(&data)[N]) { return OneByteString(isolate, data, N - 1); @@ -492,6 +521,9 @@ template inline v8::MaybeLocal ToV8Value(v8::Local context, const std::unordered_map& map); +template +constexpr size_t arraysize(const T(&)[N]) { return N; } + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS From cfa64dc801ef64655becae8c6d2d165de0022f65 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Sat, 13 Oct 2018 15:13:06 -0400 Subject: [PATCH 3/9] build: create node_base gyp target --- node.gyp | 479 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 278 insertions(+), 201 deletions(-) diff --git a/node.gyp b/node.gyp index 13c21e33ee88d4..da1e5c42bcdab7 100644 --- a/node.gyp +++ b/node.gyp @@ -248,8 +248,7 @@ 'msvs_disabled_warnings!': [4244], 'conditions': [ - [ 'node_intermediate_lib_type=="static_library" and ' - 'node_shared=="true" and OS=="aix"', { + [ 'node_intermediate_lib_type=="static_library" and node_shared=="true" and OS=="aix"', { # For AIX, shared lib is linked by static lib and .exp. In the # case here, the executable needs to link to shared lib. # Therefore, use 'node_aix_shared' target to generate the @@ -258,26 +257,28 @@ }, { 'dependencies': [ '<(node_lib_target_name)' ], }], - [ 'node_intermediate_lib_type=="static_library" and ' - 'node_shared=="false"', { + [ 'node_intermediate_lib_type=="static_library" and node_shared=="false"', { 'xcode_settings': { 'OTHER_LDFLAGS': [ - '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)' - '<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)', ], }, 'msvs_settings': { 'VCLinkerTool': { + 'ShowProgress': 2, # /VERBOSE:LIB 'AdditionalOptions': [ - '/WHOLEARCHIVE:<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + '/WHOLEARCHIVE:lib<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + '/WHOLEARCHIVE:node_base<(STATIC_LIB_SUFFIX)', ], }, }, 'conditions': [ ['OS!="aix"', { 'ldflags': [ - '-Wl,--whole-archive,<(obj_dir)/<(STATIC_LIB_PREFIX)' - '<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + '-Wl,--whole-archive,' + '<(obj_dir)/<(STATIC_LIB_PREFIX)<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + '<(obj_dir)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)', '-Wl,--no-whole-archive', ], }], @@ -298,18 +299,11 @@ 'OTHER_LDFLAGS': [ '-Wl,-rpath,@loader_path', ], }, }], - [ 'node_intermediate_lib_type=="shared_library" and OS=="win"', { - # On Windows, having the same name for both executable and shared - # lib causes filename collision. Need a different PRODUCT_NAME for - # the executable and rename it back to node.exe later - 'product_name': '<(node_core_target_name)-win', - }], ], }, # node_core_target_name { 'target_name': '<(node_lib_target_name)', 'type': '<(node_intermediate_lib_type)', - 'product_name': '<(node_core_target_name)', 'includes': [ 'node.gypi' ], @@ -320,136 +314,6 @@ ], 'sources': [ - 'src/async_wrap.cc', - 'src/bootstrapper.cc', - 'src/callback_scope.cc', - 'src/cares_wrap.cc', - 'src/connection_wrap.cc', - 'src/connect_wrap.cc', - 'src/debug_utils.cc', - 'src/env.cc', - 'src/exceptions.cc', - 'src/fs_event_wrap.cc', - 'src/handle_wrap.cc', - 'src/heap_utils.cc', - 'src/js_stream.cc', - 'src/module_wrap.cc', - 'src/node.cc', - 'src/node_api.cc', - 'src/node_api.h', - 'src/node_api_types.h', - 'src/node_buffer.cc', - 'src/node_config.cc', - 'src/node_constants.cc', - 'src/node_contextify.cc', - 'src/node_domain.cc', - 'src/node_encoding.cc', - 'src/node_errors.h', - 'src/node_file.cc', - 'src/node_http2.cc', - 'src/node_http_parser.cc', - 'src/node_messaging.cc', - 'src/node_options.cc', - 'src/node_os.cc', - 'src/node_platform.cc', - 'src/node_perf.cc', - 'src/node_postmortem_metadata.cc', - 'src/node_process.cc', - 'src/node_serdes.cc', - 'src/node_trace_events.cc', - 'src/node_types.cc', - 'src/node_url.cc', - 'src/node_util.cc', - 'src/node_v8.cc', - 'src/node_stat_watcher.cc', - 'src/node_watchdog.cc', - 'src/node_worker.cc', - 'src/node_zlib.cc', - 'src/node_i18n.cc', - 'src/pipe_wrap.cc', - 'src/process_wrap.cc', - 'src/sharedarraybuffer_metadata.cc', - 'src/signal_wrap.cc', - 'src/spawn_sync.cc', - 'src/string_bytes.cc', - 'src/string_decoder.cc', - 'src/stream_base.cc', - 'src/stream_pipe.cc', - 'src/stream_wrap.cc', - 'src/tcp_wrap.cc', - 'src/timers.cc', - 'src/tracing/agent.cc', - 'src/tracing/node_trace_buffer.cc', - 'src/tracing/node_trace_writer.cc', - 'src/tracing/trace_event.cc', - 'src/tracing/traced_value.cc', - 'src/tty_wrap.cc', - 'src/udp_wrap.cc', - 'src/util.cc', - 'src/uv.cc', - # headers to make for a more pleasant IDE experience - 'src/aliased_buffer.h', - 'src/async_wrap.h', - 'src/async_wrap-inl.h', - 'src/base_object.h', - 'src/base_object-inl.h', - 'src/connection_wrap.h', - 'src/connect_wrap.h', - 'src/debug_utils.h', - 'src/env.h', - 'src/env-inl.h', - 'src/handle_wrap.h', - 'src/js_stream.h', - 'src/module_wrap.h', - 'src/node.h', - 'src/node_buffer.h', - 'src/node_code_cache.h', - 'src/node_constants.h', - 'src/node_contextify.h', - 'src/node_file.h', - 'src/node_http2.h', - 'src/node_http2_state.h', - 'src/node_internals.h', - 'src/node_javascript.h', - 'src/node_messaging.h', - 'src/node_mutex.h', - 'src/node_options.h', - 'src/node_options-inl.h', - 'src/node_perf.h', - 'src/node_perf_common.h', - 'src/node_persistent.h', - 'src/node_platform.h', - 'src/node_root_certs.h', - 'src/node_version.h', - 'src/node_watchdog.h', - 'src/node_revert.h', - 'src/node_i18n.h', - 'src/node_worker.h', - 'src/memory_tracker.h', - 'src/memory_tracker-inl.h', - 'src/pipe_wrap.h', - 'src/tty_wrap.h', - 'src/tcp_wrap.h', - 'src/udp_wrap.h', - 'src/req_wrap.h', - 'src/req_wrap-inl.h', - 'src/sharedarraybuffer_metadata.h', - 'src/string_bytes.h', - 'src/string_decoder.h', - 'src/string_decoder-inl.h', - 'src/stream_base.h', - 'src/stream_base-inl.h', - 'src/stream_pipe.h', - 'src/stream_wrap.h', - 'src/tracing/agent.h', - 'src/tracing/node_trace_buffer.h', - 'src/tracing/node_trace_writer.h', - 'src/tracing/trace_event.h', - 'src/tracing/traced_value.h', - 'src/util.h', - 'src/util-inl.h', - 'deps/http_parser/http_parser.h', - 'deps/v8/include/v8.h', # javascript files to make for an even more pleasant IDE experience '<@(library_files)', # node.gyp is added to the project by default. @@ -469,11 +333,30 @@ 'NODE_OPENSSL_SYSTEM_CERT_PATH="<(openssl_system_ca_path)"', ], + 'dependencies': [ + 'node_base' + ], # - "C4244: conversion from 'type1' to 'type2', possible loss of data" # Ususaly safe. Disable for `dep`, enable for `src` 'msvs_disabled_warnings!': [4244], 'conditions': [ + [ 'node_intermediate_lib_type=="static_library" and node_shared=="false"', { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)', + ], + }, + 'conditions': [ + ['OS!="aix"', { + 'ldflags': [ + '-Wl,--whole-archive,' + '<(obj_dir)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)' + '-Wl,--no-whole-archive', + ], + }], + ] + }], [ 'node_code_cache_path!=""', { 'sources': [ '<(node_code_cache_path)' ] }, { @@ -489,12 +372,8 @@ ['node_shared=="true" and OS=="aix"', { 'product_name': 'node_base', }], - [ 'v8_enable_inspector==1', { - 'includes' : [ 'src/inspector/node_inspector.gypi' ], - }, { - 'defines': [ 'HAVE_INSPECTOR=0' ] - }], [ 'OS=="win"', { + 'product_name': 'lib<(node_core_target_name)', 'conditions': [ [ 'node_intermediate_lib_type!="static_library"', { 'sources': [ @@ -503,6 +382,8 @@ }], ], 'libraries': [ '-lpsapi.lib' ] + }, { + 'product_name': '<(node_core_target_name)', }], [ 'node_use_etw=="true"', { 'defines': [ 'HAVE_ETW=1' ], @@ -566,27 +447,6 @@ } ] ] } ], - [ 'node_use_openssl=="true"', { - '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' - ], - }], - [ 'node_use_large_pages=="true" and OS=="linux"', { - 'defines': [ 'NODE_ENABLE_LARGE_CODE_PAGES=1' ], - # The current implementation of Large Pages is under Linux. - # Other implementations are possible but not currently supported. - 'sources': [ - 'src/large_pages/node_large_page.cc', - 'src/large_pages/node_large_page.h' - ], - }], [ 'use_openssl_def==1', { # TODO(bnoordhuis) Make all platforms export the same list of symbols. # Teach mkssldef.py to generate linker maps that UNIX linkers understand. @@ -664,6 +524,252 @@ }, ], }, # node_lib_target_name + { + 'target_name': 'node_base', + 'type': 'static_library', + + 'include_dirs': [ + 'src', + 'deps/cares/include', + 'deps/http_parser', + 'deps/icu-small/source/i18n', + 'deps/icu-small/source/common', + 'deps/nghttp2/lib/includes', + 'deps/openssl/openssl/include', + 'deps/uv/include', + 'deps/v8/include', + 'deps/zlib', + '<(SHARED_INTERMEDIATE_DIR)', # for node_natives.h + '<(SHARED_INTERMEDIATE_DIR)/include', # for node_natives.h + '<(SHARED_INTERMEDIATE_DIR)/src', # for node_natives.h + ], + + 'sources': [ + 'src/async_wrap.cc', + 'src/bootstrapper.cc', + 'src/callback_scope.cc', + 'src/cares_wrap.cc', + 'src/connection_wrap.cc', + 'src/connect_wrap.cc', + 'src/debug_utils.cc', + 'src/env.cc', + 'src/exceptions.cc', + 'src/fs_event_wrap.cc', + 'src/handle_wrap.cc', + 'src/heap_utils.cc', + 'src/js_stream.cc', + 'src/module_wrap.cc', + 'src/node.cc', + 'src/node_api.cc', + 'src/node_api.h', + 'src/node_api_types.h', + 'src/node_buffer.cc', + 'src/node_config.cc', + 'src/node_constants.cc', + 'src/node_contextify.cc', + 'src/node_domain.cc', + 'src/node_encoding.cc', + 'src/node_errors.h', + 'src/node_file.cc', + 'src/node_http2.cc', + 'src/node_http_parser.cc', + 'src/node_messaging.cc', + 'src/node_options.cc', + 'src/node_os.cc', + 'src/node_platform.cc', + 'src/node_perf.cc', + 'src/node_postmortem_metadata.cc', + 'src/node_process.cc', + 'src/node_serdes.cc', + 'src/node_trace_events.cc', + 'src/node_types.cc', + 'src/node_url.cc', + 'src/node_util.cc', + 'src/node_v8.cc', + 'src/node_stat_watcher.cc', + 'src/node_watchdog.cc', + 'src/node_worker.cc', + 'src/node_zlib.cc', + 'src/node_i18n.cc', + 'src/pipe_wrap.cc', + 'src/process_wrap.cc', + 'src/sharedarraybuffer_metadata.cc', + 'src/signal_wrap.cc', + 'src/spawn_sync.cc', + 'src/string_bytes.cc', + 'src/string_decoder.cc', + 'src/stream_base.cc', + 'src/stream_pipe.cc', + 'src/stream_wrap.cc', + 'src/tcp_wrap.cc', + 'src/timers.cc', + 'src/tracing/agent.cc', + 'src/tracing/node_trace_buffer.cc', + 'src/tracing/node_trace_writer.cc', + 'src/tracing/trace_event.cc', + 'src/tracing/traced_value.cc', + 'src/tty_wrap.cc', + 'src/udp_wrap.cc', + 'src/util.cc', + 'src/uv.cc', + # headers to make for a more pleasant IDE experience + 'src/aliased_buffer.h', + 'src/async_wrap.h', + 'src/async_wrap-inl.h', + 'src/base_object.h', + 'src/base_object-inl.h', + 'src/connection_wrap.h', + 'src/connect_wrap.h', + 'src/debug_utils.h', + 'src/env.h', + 'src/env-inl.h', + 'src/handle_wrap.h', + 'src/js_stream.h', + 'src/module_wrap.h', + 'src/node.h', + 'src/node_buffer.h', + 'src/node_code_cache.h', + 'src/node_constants.h', + 'src/node_contextify.h', + 'src/node_file.h', + 'src/node_http2.h', + 'src/node_http2_state.h', + 'src/node_internals.h', + 'src/node_javascript.h', + 'src/node_messaging.h', + 'src/node_mutex.h', + 'src/node_options.h', + 'src/node_options-inl.h', + 'src/node_perf.h', + 'src/node_perf_common.h', + 'src/node_persistent.h', + 'src/node_platform.h', + 'src/node_root_certs.h', + 'src/node_version.h', + 'src/node_watchdog.h', + 'src/node_revert.h', + 'src/node_i18n.h', + 'src/node_worker.h', + 'src/memory_tracker.h', + 'src/memory_tracker-inl.h', + 'src/pipe_wrap.h', + 'src/tty_wrap.h', + 'src/tcp_wrap.h', + 'src/udp_wrap.h', + 'src/req_wrap.h', + 'src/req_wrap-inl.h', + 'src/sharedarraybuffer_metadata.h', + 'src/string_bytes.h', + 'src/string_decoder.h', + 'src/string_decoder-inl.h', + 'src/stream_base.h', + 'src/stream_base-inl.h', + 'src/stream_pipe.h', + 'src/stream_wrap.h', + 'src/tracing/agent.h', + 'src/tracing/node_trace_buffer.h', + 'src/tracing/node_trace_writer.h', + 'src/tracing/trace_event.h', + 'src/tracing/traced_value.h', + 'src/util.h', + 'src/util-inl.h', + 'deps/http_parser/http_parser.h', + 'deps/v8/include/v8.h', + ], + + 'variables': { + 'openssl_system_ca_path%': '', + }, + + 'cflags': [ '-Wno-unknown-pragmas', ], + + 'defines': [ + 'NODE_ARCH="<(target_arch)"', + 'NODE_PLATFORM="<(OS)"', + 'NODE_WANT_INTERNALS=1', + # Warn when using deprecated V8 APIs. + 'V8_DEPRECATION_WARNINGS=1', + # 'V8_IMMINENT_DEPRECATION_WARNINGS=1', + 'NODE_OPENSSL_SYSTEM_CERT_PATH="<(openssl_system_ca_path)"', + ], + + # - "C4068: Unknown Pragma + 'msvs_disabled_warnings=': [4068, 4267, 4244, 4251, 4275], + + 'conditions': [ + [ 'v8_enable_inspector==1', { + 'includes' : [ 'src/inspector/node_inspector.gypi' ], + }, { + 'defines': [ 'HAVE_INSPECTOR=0' ] + }], + [ 'node_use_openssl=="true"', { + 'sources': [ + 'src/node_crypto.cc', + 'src/node_crypto.h', + 'src/node_crypto_bio.cc', + 'src/node_crypto_bio.h', + 'src/node_crypto_clienthello.cc', + 'src/node_crypto_clienthello.h', + 'src/tls_wrap.cc', + 'src/tls_wrap.h' + ], + 'defines': [ 'HAVE_OPENSSL=1', ], + }], + [ 'node_use_large_pages=="true" and OS=="linux"', { + 'defines': [ 'NODE_ENABLE_LARGE_CODE_PAGES=1' ], + # The current implementation of Large Pages is under Linux. + # Other implementations are possible but not currently supported. + 'sources': [ + 'src/large_pages/node_large_page.cc', + 'src/large_pages/node_large_page.h' + ], + }], + [ 'v8_enable_i18n_support==1', { + 'defines': [ + 'NODE_HAVE_I18N_SUPPORT=1', + 'UCONFIG_NO_SERVICE=1', + 'U_ENABLE_DYLOAD=0', + 'U_STATIC_IMPLEMENTATION=1', + 'U_HAVE_STD_STRING=1', + 'UCONFIG_NO_BREAK_ITERATION=0', + ], + }], + [ 'icu_small=="true"', { + 'defines': [ 'NODE_HAVE_SMALL_ICU=1' ], + }], + [ 'node_use_v8_platform=="true"', { + 'defines': [ 'NODE_USE_V8_PLATFORM=1', ], + }, { + 'defines': [ 'NODE_USE_V8_PLATFORM=0', ], + }], + [ 'OS=="win"', { + 'dependencies=': [], + '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"', + # Stop from defining macros that conflict with + # std::min() and std::max(). We don't use (much) + # but we still inherit it from uv.h. + 'NOMINMAX', + '_UNICODE=1', + ], + }, { # POSIX + 'defines': [ + '__POSIX__', + '_LARGEFILE_SOURCE', + '_FILE_OFFSET_BITS=64', + ], + }], + [ 'node_shared_nghttp2=="false"', { + 'defines': [ 'NGHTTP2_STATICLIB', ], + }], + [ 'node_shared_http_parser=="false"', { + 'defines': [ 'HTTP_PARSER_STRICT=0', ], + }], + ], + }, # node_base { # generate ETW header and resource files 'target_name': 'node_etw', @@ -822,41 +928,12 @@ } ], ] }, # specialize_node_d - { - # When using shared lib to build executable in Windows, in order to avoid - # filename collision, the executable name is node-win.exe. Need to rename - # it back to node.exe - 'target_name': 'rename_node_bin_win', - 'type': 'none', - 'dependencies': [ - '<(node_core_target_name)', - ], - 'conditions': [ - [ 'OS=="win" and node_intermediate_lib_type=="shared_library"', { - 'actions': [ - { - 'action_name': 'rename_node_bin_win', - 'inputs': [ - '<(PRODUCT_DIR)/<(node_core_target_name)-win.exe' - ], - 'outputs': [ - '<(PRODUCT_DIR)/<(node_core_target_name).exe', - ], - 'action': [ - 'mv', '<@(_inputs)', '<@(_outputs)', - ], - }, - ], - } ], - ] - }, # rename_node_bin_win { 'target_name': 'cctest', 'type': 'executable', 'dependencies': [ '<(node_lib_target_name)', - 'rename_node_bin_win', 'deps/gtest/gtest.gyp:gtest', 'node_dtrace_header', 'node_dtrace_ustack', From 3e230c30a78e6d21453d7e60327592becf1fb312 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Sat, 13 Oct 2018 15:13:43 -0400 Subject: [PATCH 4/9] build,src: add PCH to node_base --- node.gyp | 8 ++++++++ src/node_pch.cc | 1 + src/node_pch.h | 15 +++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 src/node_pch.cc create mode 100644 src/node_pch.h diff --git a/node.gyp b/node.gyp index da1e5c42bcdab7..6c5be4fe67f0f4 100644 --- a/node.gyp +++ b/node.gyp @@ -768,6 +768,14 @@ [ 'node_shared_http_parser=="false"', { 'defines': [ 'HTTP_PARSER_STRICT=0', ], }], + ['node_use_pch=="true"', { + 'msvs_precompiled_header': 'src/node_pch.h', + 'msvs_precompiled_source': 'src/node_pch.cc', + 'sources': [ + '<(_msvs_precompiled_header)', + '<(_msvs_precompiled_source)', + ], + }], ], }, # node_base { diff --git a/src/node_pch.cc b/src/node_pch.cc new file mode 100644 index 00000000000000..2b49436d626c43 --- /dev/null +++ b/src/node_pch.cc @@ -0,0 +1 @@ +#include "node_pch.h" diff --git a/src/node_pch.h b/src/node_pch.h new file mode 100644 index 00000000000000..35d4e03896c3f8 --- /dev/null +++ b/src/node_pch.h @@ -0,0 +1,15 @@ +#pragma once +#define NAPI_EXPERIMENTAL +#include "node.h" +#include "node_internals.h" +#include "aliased_buffer.h" +#include "base_object-inl.h" +#include "env-inl.h" +#include "util-inl.h" +#include "uv.h" +#include "v8.h" + +#include +#include +#include +#include From db60be82eec7a77ff85323a7e08ac6e118f46bad Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Mon, 15 Oct 2018 18:32:11 -0400 Subject: [PATCH 5/9] deps,v8: fix gypfile bug --- deps/v8/gypfiles/toolchain.gypi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deps/v8/gypfiles/toolchain.gypi b/deps/v8/gypfiles/toolchain.gypi index 4860c5b7724e20..fcc0d21985185d 100644 --- a/deps/v8/gypfiles/toolchain.gypi +++ b/deps/v8/gypfiles/toolchain.gypi @@ -1391,6 +1391,8 @@ ], }], ], # conditions + # Temporary refs: https://github.com/nodejs/node/pull/23801 + 'defines!': ['ENABLE_HANDLE_ZAPPING',], }, # Release }, # configurations 'msvs_disabled_warnings': [ From 6643da4d5ccc6a30f920cd5e1f18a4523ce4dfda Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Mon, 15 Oct 2018 18:39:28 -0400 Subject: [PATCH 6/9] build: better deafults for V8 --- common.gypi | 3 +++ node.gyp | 13 ++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/common.gypi b/common.gypi index 0ba7c8e816746a..4df42a23e8db53 100644 --- a/common.gypi +++ b/common.gypi @@ -30,6 +30,9 @@ 'openssl_no_asm%': 0, 'openssl_fips%': '', + # Default to -O0 for debug builds. + 'v8_optimized_debug%': 1, + # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. 'v8_embedder_string': '-node.9', diff --git a/node.gyp b/node.gyp index 6c5be4fe67f0f4..c0268570591344 100644 --- a/node.gyp +++ b/node.gyp @@ -244,19 +244,10 @@ ], # - "C4244: conversion from 'type1' to 'type2', possible loss of data" - # Ususaly safe. Disable for `dep`, enable for `src` + # Disabled for `/deps/`, so re-enable for `/src/`. 'msvs_disabled_warnings!': [4244], - + 'dependencies': [ '<(node_lib_target_name)' ], 'conditions': [ - [ 'node_intermediate_lib_type=="static_library" and node_shared=="true" and OS=="aix"', { - # For AIX, shared lib is linked by static lib and .exp. In the - # case here, the executable needs to link to shared lib. - # Therefore, use 'node_aix_shared' target to generate the - # shared lib and then executable. - 'dependencies': [ 'node_aix_shared' ], - }, { - 'dependencies': [ '<(node_lib_target_name)' ], - }], [ 'node_intermediate_lib_type=="static_library" and node_shared=="false"', { 'xcode_settings': { 'OTHER_LDFLAGS': [ From 5dbf8d8437c981e80e1e73525acd941e02afda82 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Sun, 28 Oct 2018 18:14:42 -0400 Subject: [PATCH 7/9] build,src,inspector: break includes cycle --- src/inspector/node_inspector.gypi | 83 ++++++++++++------------- src/inspector/node_protocol_config.json | 12 ++-- src/inspector/node_string.cc | 2 +- src/inspector/tracing_agent.h | 2 +- src/inspector/worker_agent.h | 2 +- src/inspector_agent.cc | 2 +- src/inspector_socket_server.cc | 3 +- src/tracing/agent.cc | 2 + src/tracing/agent.h | 1 - 9 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/inspector/node_inspector.gypi b/src/inspector/node_inspector.gypi index aea4de894fbe99..3d0f8f7afd6e74 100644 --- a/src/inspector/node_inspector.gypi +++ b/src/inspector/node_inspector.gypi @@ -1,15 +1,16 @@ { 'variables': { 'protocol_tool_path': '../../tools/inspector_protocol', - 'node_inspector_path': '../../src/inspector', + 'node_inspector_path': './', + 'node_inspector_generated_path': '<(SHARED_INTERMEDIATE_DIR)/node_inspector', 'node_inspector_generated_sources': [ - '<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Forward.h', - '<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Protocol.cpp', - '<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Protocol.h', - '<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeWorker.cpp', - '<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeWorker.h', - '<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeTracing.cpp', - '<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeTracing.h', + '<(node_inspector_generated_path)/protocol/Forward.h', + '<(node_inspector_generated_path)/protocol/Protocol.cpp', + '<(node_inspector_generated_path)/protocol/Protocol.h', + '<(node_inspector_generated_path)/protocol/NodeWorker.cpp', + '<(node_inspector_generated_path)/protocol/NodeWorker.h', + '<(node_inspector_generated_path)/protocol/NodeTracing.cpp', + '<(node_inspector_generated_path)/protocol/NodeTracing.h', ], 'node_protocol_files': [ '<(protocol_tool_path)/lib/Allocator_h.template', @@ -41,48 +42,46 @@ 'HAVE_INSPECTOR=1', ], 'sources': [ - '../../src/inspector_agent.cc', - '../../src/inspector_io.cc', - '../../src/inspector_agent.h', - '../../src/inspector_io.h', - '../../src/inspector_js_api.cc', - '../../src/inspector_socket.cc', - '../../src/inspector_socket.h', - '../../src/inspector_socket_server.cc', - '../../src/inspector_socket_server.h', - '../../src/inspector/main_thread_interface.cc', - '../../src/inspector/main_thread_interface.h', - '../../src/inspector/node_string.cc', - '../../src/inspector/node_string.h', - '../../src/inspector/tracing_agent.cc', - '../../src/inspector/tracing_agent.h', - '../../src/inspector/worker_agent.cc', - '../../src/inspector/worker_agent.h', - '../../src/inspector/worker_inspector.cc', - '../../src/inspector/worker_inspector.h', + '../inspector_agent.cc', + '../inspector_io.cc', + '../inspector_agent.h', + '../inspector_io.h', + '../inspector_js_api.cc', + '../inspector_socket.cc', + '../inspector_socket.h', + '../inspector_socket_server.cc', + '../inspector_socket_server.h', + 'main_thread_interface.cc', + 'main_thread_interface.h', + 'node_string.cc', + 'node_string.h', + 'tracing_agent.cc', + 'tracing_agent.h', + 'worker_agent.cc', + 'worker_agent.h', + 'worker_inspector.cc', + 'worker_inspector.h', ], 'include_dirs': [ - '<(SHARED_INTERMEDIATE_DIR)/include', # for inspector - '<(SHARED_INTERMEDIATE_DIR)', - '<(SHARED_INTERMEDIATE_DIR)/src', # for inspector + '<(node_inspector_generated_path)', ], 'copies': [ { 'files': [ '<(node_inspector_path)/node_protocol_config.json', - '<(node_inspector_path)/node_protocol.pdl' + '<(node_inspector_path)/node_protocol.pdl', ], - 'destination': '<(SHARED_INTERMEDIATE_DIR)', + 'destination': '<(node_inspector_generated_path)', } ], 'actions': [ { 'action_name': 'convert_node_protocol_to_json', 'inputs': [ - '<(SHARED_INTERMEDIATE_DIR)/node_protocol.pdl', + '<(node_inspector_generated_path)/node_protocol.pdl', ], 'outputs': [ - '<(SHARED_INTERMEDIATE_DIR)/node_protocol.json', + '<(node_inspector_generated_path)/node_protocol.json', ], 'action': [ 'python', @@ -95,8 +94,8 @@ 'action_name': 'node_protocol_generated_sources', 'process_outputs_as_sources': 0, 'inputs': [ - '<(SHARED_INTERMEDIATE_DIR)/node_protocol_config.json', - '<(SHARED_INTERMEDIATE_DIR)/node_protocol.json', + '<(node_inspector_generated_path)/node_protocol_config.json', + '<(node_inspector_generated_path)/node_protocol.json', '<@(node_protocol_files)', ], 'outputs': [ @@ -107,8 +106,8 @@ 'python', 'tools/inspector_protocol/CodeGenerator.py', '--jinja_dir', '<@(protocol_tool_path)/..', - '--output_base', '<(SHARED_INTERMEDIATE_DIR)/src/', - '--config', '<(SHARED_INTERMEDIATE_DIR)/node_protocol_config.json', + '--output_base', '<(node_inspector_generated_path)', + '--config', '<(node_inspector_generated_path)/node_protocol_config.json', ], 'message': 'Generating node protocol sources from protocol json', }, @@ -116,10 +115,10 @@ 'action_name': 'concatenate_protocols', 'inputs': [ '../../deps/v8/src/inspector/js_protocol.json', - '<(SHARED_INTERMEDIATE_DIR)/node_protocol.json', + '<(node_inspector_generated_path)/node_protocol.json', ], 'outputs': [ - '<(SHARED_INTERMEDIATE_DIR)/concatenated_protocol.json', + '<(node_inspector_generated_path)/concatenated_protocol.json', ], 'action': [ 'python', @@ -132,10 +131,10 @@ 'action_name': 'v8_inspector_compress_protocol_json', 'process_outputs_as_sources': 0, 'inputs': [ - '<(SHARED_INTERMEDIATE_DIR)/concatenated_protocol.json', + '<(node_inspector_generated_path)/concatenated_protocol.json', ], 'outputs': [ - '<(SHARED_INTERMEDIATE_DIR)/v8_inspector_protocol_json.h', + '<(node_inspector_generated_path)/concatenated_protocol/v8_inspector_protocol_json.h', ], 'process_outputs_as_sources': 1, 'action': [ diff --git a/src/inspector/node_protocol_config.json b/src/inspector/node_protocol_config.json index 4ef37856068093..4965a131d4a88a 100644 --- a/src/inspector/node_protocol_config.json +++ b/src/inspector/node_protocol_config.json @@ -1,13 +1,13 @@ { "protocol": { "path": "node_protocol.json", - "package": "src/node/inspector/protocol", - "output": "node/inspector/protocol", + "package": "protocol", + "output": "protocol", "namespace": ["node", "inspector", "protocol"] }, "exported": { - "package": "include/inspector", - "output": "../../include/inspector", + "package": "include", + "output": "include", "string_header": "v8-inspector.h", "string_in": "StringView", "string_out": "std::unique_ptr", @@ -15,8 +15,8 @@ "export_macro": "V8_EXPORT" }, "lib": { - "package": "src/node/inspector/protocol", - "output": "node/inspector/protocol", + "package": "protocol", + "output": "protocol", "string_header": "inspector/node_string.h" } } diff --git a/src/inspector/node_string.cc b/src/inspector/node_string.cc index cb9e90c20e807a..2c8cd5e4a09eec 100644 --- a/src/inspector/node_string.cc +++ b/src/inspector/node_string.cc @@ -1,5 +1,5 @@ #include "node_string.h" -#include "node/inspector/protocol/Protocol.h" +#include "protocol/Protocol.h" #include diff --git a/src/inspector/tracing_agent.h b/src/inspector/tracing_agent.h index 029fce7c191b42..4d0bbc6f1254f9 100644 --- a/src/inspector/tracing_agent.h +++ b/src/inspector/tracing_agent.h @@ -1,7 +1,7 @@ #ifndef SRC_INSPECTOR_TRACING_AGENT_H_ #define SRC_INSPECTOR_TRACING_AGENT_H_ -#include "node/inspector/protocol/NodeTracing.h" +#include "protocol/NodeTracing.h" #include "tracing/agent.h" #include "v8.h" diff --git a/src/inspector/worker_agent.h b/src/inspector/worker_agent.h index 402c7194163967..51c9098cbf2fa3 100644 --- a/src/inspector/worker_agent.h +++ b/src/inspector/worker_agent.h @@ -1,7 +1,7 @@ #ifndef SRC_INSPECTOR_WORKER_AGENT_H_ #define SRC_INSPECTOR_WORKER_AGENT_H_ -#include "node/inspector/protocol/NodeWorker.h" +#include "protocol/NodeWorker.h" #include "v8.h" diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index ebb7b7d5bc3e72..a729c559208c79 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -6,7 +6,7 @@ #include "inspector/tracing_agent.h" #include "inspector/worker_agent.h" #include "inspector/worker_inspector.h" -#include "node/inspector/protocol/Protocol.h" +#include "protocol/Protocol.h" #include "node_internals.h" #include "node_url.h" #include "v8-inspector.h" diff --git a/src/inspector_socket_server.cc b/src/inspector_socket_server.cc index 1621b408b43274..60a0c3e7b93522 100644 --- a/src/inspector_socket_server.cc +++ b/src/inspector_socket_server.cc @@ -20,7 +20,8 @@ std::string FormatWsAddress(const std::string& host, int port, namespace { static const uint8_t PROTOCOL_JSON[] = { - #include "v8_inspector_protocol_json.h" // NOLINT(build/include_order) + // NOLINT(build/include_order) + #include "concatenated_protocol/v8_inspector_protocol_json.h" }; void Escape(std::string* string) { diff --git a/src/tracing/agent.cc b/src/tracing/agent.cc index ceb89b2c4404a3..2301dd799a1d00 100644 --- a/src/tracing/agent.cc +++ b/src/tracing/agent.cc @@ -4,6 +4,8 @@ #include "trace_event.h" #include "tracing/node_trace_buffer.h" #include "debug_utils.h" +#include "util-inl.h" + namespace node { namespace tracing { diff --git a/src/tracing/agent.h b/src/tracing/agent.h index db5e2a6bfd049f..73010f9dcfb903 100644 --- a/src/tracing/agent.h +++ b/src/tracing/agent.h @@ -4,7 +4,6 @@ #include "libplatform/v8-tracing.h" #include "uv.h" #include "v8.h" -#include "util.h" #include "node_mutex.h" #include From b22cc31db3e9cfd9b47ab9d588f2c13b7e6411d1 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Sun, 28 Oct 2018 21:57:36 -0400 Subject: [PATCH 8/9] build: refacor dtrace & etw build --- common.gypi | 2 +- dtrace.gypi | 166 ++++++++++++++++++++ node.gyp | 384 ++++++++++----------------------------------- src/node_dtrace.cc | 2 +- 4 files changed, 247 insertions(+), 307 deletions(-) create mode 100644 dtrace.gypi diff --git a/common.gypi b/common.gypi index 4df42a23e8db53..c99da96a9bfb5f 100644 --- a/common.gypi +++ b/common.gypi @@ -242,7 +242,7 @@ }, { 'msvs_settings': { 'VCCLCompilerTool': { - 'WholeProgramOptimization': 'false' + 'WholeProgramOptimization': 'false' # /GL- }, 'VCLinkerTool': { 'LinkIncremental': 2 # enable incremental linking diff --git a/dtrace.gypi b/dtrace.gypi new file mode 100644 index 00000000000000..d50479a38044a3 --- /dev/null +++ b/dtrace.gypi @@ -0,0 +1,166 @@ +{ + 'conditions': [ + [ 'node_use_dtrace=="true"', { + 'defines': [ 'HAVE_DTRACE=1' ], + '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_header/node_dtrace_provider.o' + ], + }], + [ 'OS!="mac" and OS!="linux"', { + 'sources': [ + 'src/node_dtrace_ustack.cc', + 'src/node_dtrace_provider.cc', + ], + }], + ], + }], + [ 'node_use_dtrace=="true" and OS!="linux"', { + 'actions': [ + { + 'action_name': 'node_dtrace_header', + 'inputs': [ 'src/node_provider.d' ], + 'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/node_dtrace_header/node_provider.h' ], + 'action': [ 'dtrace', '-h', '-xnolibs', '-s', '<@(_inputs)', + '-o', '<@(_outputs)' ] + } + ] + } ], + [ 'node_use_dtrace=="true" and OS=="linux"', { + 'actions': [ + { + 'action_name': 'node_dtrace_header', + 'inputs': [ 'src/node_provider.d' ], + 'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/node_dtrace_header/node_provider.h' ], + 'action': [ 'dtrace', '-h', '-s', '<@(_inputs)', '-o', '<@(_outputs)' ] + }, + ], + }], + [ 'node_use_dtrace=="true" and OS!="mac" and OS!="linux"', { + 'actions': [ + { + 'action_name': 'node_dtrace_provider_o', + 'inputs': [ + '<(obj_dir)/node_base/src/node_dtrace.o', + ], + 'outputs': [ + '<(obj_dir)/node_base/src/node_dtrace_provider.o' + ], + 'action': [ + 'dtrace', + '-G', '-xnolibs', + '-s', 'src/node_provider.d', + '<@(_inputs)', + '-o', '<@(_outputs)', + ] + } + ] + }], + [ 'node_use_dtrace=="true" and OS=="linux"', { + 'actions': [ + { + 'action_name': 'node_dtrace_provider_o', + 'inputs': [ 'src/node_provider.d' ], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/node_dtrace_header/node_dtrace_provider.o' + ], + 'action': [ + 'dtrace', '-C', '-G', '-s', '<@(_inputs)', '-o', '<@(_outputs)' + ], + }, + ], + }], + [ 'node_use_dtrace=="true" and OS!="mac" and OS!="linux"', { + 'actions': [ + { + 'action_name': 'node_dtrace_ustack_constants', + 'inputs': [ + '<(v8_base)' + ], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/node_dtrace_header/v8constants.h' + ], + 'action': [ + 'tools/genv8constants.py', + '<@(_outputs)', + '<@(_inputs)' + ] + }, + { + 'action_name': 'node_dtrace_ustack', + 'inputs': [ + 'src/v8ustack.d', + '<(SHARED_INTERMEDIATE_DIR)/node_dtrace_header/v8constants.h' + ], + 'outputs': [ + '<(obj_dir)/<(node_lib_target_name)/src/node_dtrace_ustack.o' + ], + 'conditions': [ + [ 'target_arch=="ia32" or target_arch=="arm"', { + 'action': [ + 'dtrace', + '-32', + '-I<(SHARED_INTERMEDIATE_DIR)/node_dtrace_header', + '-Isrc', + '-C', '-G', + '-s', 'src/v8ustack.d', + '-o', '<@(_outputs)', + ], + }], + [ 'target_arch=="x64"', { + 'action': [ + 'dtrace', + '-64', + '-I<(SHARED_INTERMEDIATE_DIR)/node_dtrace_header', + '-Isrc', + '-C', '-G', + '-s', 'src/v8ustack.d', + '-o', '<@(_outputs)', + ], + }], + ], + }, + ], + }], + [ 'node_use_dtrace=="true"', { + 'actions': [ + { + 'action_name': 'specialize_node_d', + 'inputs': [ + 'src/node.d' + ], + 'outputs': [ + '<(PRODUCT_DIR)/node.d', + ], + 'action': [ + 'tools/specialize_node_d.py', + '<@(_outputs)', + '<@(_inputs)', + '<@(OS)', + '<@(target_arch)', + ], + }, + ], + }], + ] +} diff --git a/node.gyp b/node.gyp index c0268570591344..d61c8912898b18 100644 --- a/node.gyp +++ b/node.gyp @@ -233,7 +233,7 @@ 'target_name': '<(node_core_target_name)', 'type': 'executable', 'sources': [ - 'src/node_main.cc' + 'src/node_main.cc', ], 'includes': [ 'node.gypi' @@ -333,11 +333,6 @@ 'conditions': [ [ 'node_intermediate_lib_type=="static_library" and node_shared=="false"', { - 'xcode_settings': { - 'OTHER_LDFLAGS': [ - '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)', - ], - }, 'conditions': [ ['OS!="aix"', { 'ldflags': [ @@ -360,9 +355,6 @@ '@rpath/lib<(node_core_target_name).<(shlib_suffix)' }, }], - ['node_shared=="true" and OS=="aix"', { - 'product_name': 'node_base', - }], [ 'OS=="win"', { 'product_name': 'lib<(node_core_target_name)', 'conditions': [ @@ -376,68 +368,6 @@ }, { 'product_name': '<(node_core_target_name)', }], - [ 'node_use_etw=="true"', { - 'defines': [ 'HAVE_ETW=1' ], - 'dependencies': [ 'node_etw' ], - 'include_dirs': [ - 'src', - 'tools/msvs/genfiles', - '<(SHARED_INTERMEDIATE_DIR)' # for node_natives.h - ], - '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', - ], - 'conditions': [ - ['node_intermediate_lib_type != "static_library"', { - 'sources': [ - 'tools/msvs/genfiles/node_etw_provider.rc', - ], - }], - ], - }], - [ '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', - ] - } - ] ] - } ], [ 'use_openssl_def==1', { # TODO(bnoordhuis) Make all platforms export the same list of symbols. # Teach mkssldef.py to generate linker maps that UNIX linkers understand. @@ -483,42 +413,41 @@ }, ], }], - ], - 'actions': [ - { - 'action_name': 'node_js2c', - 'process_outputs_as_sources': 1, - 'inputs': [ - '<@(library_files)', - 'config.gypi', - 'tools/check_macros.py' - ], - 'outputs': [ - '<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc', - ], + [ 'OS=="aix" and node_shared=="true"', { + 'variables': {'real_os_name': ' Date: Tue, 30 Oct 2018 12:05:23 -0400 Subject: [PATCH 9/9] dontland! windows workaround --- vcbuild.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcbuild.bat b/vcbuild.bat index 1e31440cc29857..a07ba28e4dbbf1 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -61,7 +61,7 @@ set doc= :next-arg if "%1"=="" goto args-done if /i "%1"=="debug" set config=Debug&goto arg-ok -if /i "%1"=="release" set config=Release&set ltcg=1&set "pch="&goto arg-ok +if /i "%1"=="release" set config=Release&goto arg-ok if /i "%1"=="clean" set target=Clean&goto arg-ok if /i "%1"=="ia32" set target_arch=x86&goto arg-ok if /i "%1"=="x86" set target_arch=x86&goto arg-ok