diff --git a/src/node.cc b/src/node.cc index be8f0d0df95560..52167a85909d7f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -170,8 +170,10 @@ class NodeTraceStateObserver : TRACE_EVENT_METADATA1("__metadata", "process_name", "name", TRACE_STR_COPY(name_buffer)); } - TRACE_EVENT_METADATA1("__metadata", "version", - "node", NODE_VERSION_STRING); + TRACE_EVENT_METADATA1("__metadata", + "version", + "node", + per_process::metadata.versions.node.c_str()); TRACE_EVENT_METADATA1("__metadata", "thread_name", "name", "JavaScriptMainThread"); @@ -186,13 +188,15 @@ class NodeTraceStateObserver : trace_process->EndDictionary(); - trace_process->SetString("arch", NODE_ARCH); - trace_process->SetString("platform", NODE_PLATFORM); + trace_process->SetString("arch", per_process::metadata.arch.c_str()); + trace_process->SetString("platform", + per_process::metadata.platform.c_str()); trace_process->BeginDictionary("release"); - trace_process->SetString("name", NODE_RELEASE); + trace_process->SetString("name", + per_process::metadata.release.name.c_str()); #if NODE_VERSION_IS_LTS - trace_process->SetString("lts", NODE_VERSION_LTS_CODENAME); + trace_process->SetString("lts", per_process::metadata.release.lts.c_str()); #endif trace_process->EndDictionary(); TRACE_EVENT_METADATA1("__metadata", "node", @@ -888,54 +892,29 @@ void SetupProcessObject(Environment* env, #undef V // process.arch - READONLY_PROPERTY(process, "arch", OneByteString(env->isolate(), NODE_ARCH)); + READONLY_STRING_PROPERTY(process, "arch", per_process::metadata.arch); // process.platform - READONLY_PROPERTY(process, - "platform", - OneByteString(env->isolate(), NODE_PLATFORM)); + READONLY_STRING_PROPERTY(process, "platform", per_process::metadata.platform); // process.release Local release = Object::New(env->isolate()); READONLY_PROPERTY(process, "release", release); - READONLY_PROPERTY(release, "name", - OneByteString(env->isolate(), NODE_RELEASE)); - + READONLY_STRING_PROPERTY(release, "name", per_process::metadata.release.name); #if NODE_VERSION_IS_LTS - READONLY_PROPERTY(release, "lts", - OneByteString(env->isolate(), NODE_VERSION_LTS_CODENAME)); -#endif - -// if this is a release build and no explicit base has been set -// substitute the standard release download URL -#ifndef NODE_RELEASE_URLBASE -# if NODE_VERSION_IS_RELEASE -# define NODE_RELEASE_URLBASE "https://nodejs.org/download/release/" -# endif -#endif - -#if defined(NODE_RELEASE_URLBASE) -# define NODE_RELEASE_URLPFX NODE_RELEASE_URLBASE "v" NODE_VERSION_STRING "/" -# define NODE_RELEASE_URLFPFX NODE_RELEASE_URLPFX "node-v" NODE_VERSION_STRING - - READONLY_PROPERTY(release, - "sourceUrl", - OneByteString(env->isolate(), - NODE_RELEASE_URLFPFX ".tar.gz")); - READONLY_PROPERTY(release, - "headersUrl", - OneByteString(env->isolate(), - NODE_RELEASE_URLFPFX "-headers.tar.gz")); -# ifdef _WIN32 - READONLY_PROPERTY(release, - "libUrl", - OneByteString(env->isolate(), - strcmp(NODE_ARCH, "ia32") ? NODE_RELEASE_URLPFX "win-" - NODE_ARCH "/node.lib" - : NODE_RELEASE_URLPFX - "win-x86/node.lib")); -# endif -#endif + READONLY_STRING_PROPERTY(release, "lts", per_process::metadata.release.lts); +#endif // NODE_VERSION_IS_LTS + +#ifdef NODE_HAS_RELEASE_URLS + READONLY_STRING_PROPERTY( + release, "sourceUrl", per_process::metadata.release.source_url); + READONLY_STRING_PROPERTY( + release, "headersUrl", per_process::metadata.release.headers_url); +#ifdef _WIN32 + READONLY_STRING_PROPERTY( + release, "libUrl", per_process::metadata.release.lib_url); +#endif // _WIN32 +#endif // NODE_HAS_RELEASE_URLS // process.argv process->Set(env->context(), diff --git a/src/node_metadata.cc b/src/node_metadata.cc index ff8d408f5bdc68..7eda9e84cdf463 100644 --- a/src/node_metadata.cc +++ b/src/node_metadata.cc @@ -82,4 +82,26 @@ Metadata::Versions::Versions() { #endif // NODE_HAVE_I18N_SUPPORT } +Metadata::Release::Release() : name(NODE_RELEASE) { +#if NODE_VERSION_IS_LTS + lts = NODE_VERSION_LTS_CODENAME; +#endif // NODE_VERSION_IS_LTS + +#ifdef NODE_HAS_RELEASE_URLS +#define NODE_RELEASE_URLPFX NODE_RELEASE_URLBASE "v" NODE_VERSION_STRING "/" +#define NODE_RELEASE_URLFPFX NODE_RELEASE_URLPFX "node-v" NODE_VERSION_STRING + + source_url = NODE_RELEASE_URLFPFX ".tar.gz"; + headers_url = NODE_RELEASE_URLFPFX "-headers.tar.gz"; +#ifdef _WIN32 + lib_url = strcmp(NODE_ARCH, "ia32") ? NODE_RELEASE_URLPFX "win-" NODE_ARCH + "/node.lib" + : NODE_RELEASE_URLPFX "win-x86/node.lib"; +#endif // _WIN32 + +#endif // NODE_HAS_RELEASE_URLS +} + +Metadata::Metadata() : arch(NODE_ARCH), platform(NODE_PLATFORM) {} + } // namespace node diff --git a/src/node_metadata.h b/src/node_metadata.h index 3c3a430dd73584..42002b7dc3d484 100644 --- a/src/node_metadata.h +++ b/src/node_metadata.h @@ -4,9 +4,22 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include +#include "node_version.h" namespace node { +// if this is a release build and no explicit base has been set +// substitute the standard release download URL +#ifndef NODE_RELEASE_URLBASE +#if NODE_VERSION_IS_RELEASE +#define NODE_RELEASE_URLBASE "https://nodejs.org/download/release/" +#endif // NODE_VERSION_IS_RELEASE +#endif // NODE_RELEASE_URLBASE + +#if defined(NODE_RELEASE_URLBASE) +#define NODE_HAS_RELEASE_URLS +#endif + #define NODE_VERSIONS_KEYS_BASE(V) \ V(node) \ V(v8) \ @@ -42,7 +55,7 @@ namespace node { class Metadata { public: - Metadata() = default; + Metadata(); Metadata(Metadata&) = delete; Metadata(Metadata&&) = delete; Metadata operator=(Metadata&) = delete; @@ -62,7 +75,27 @@ class Metadata { #undef V }; + struct Release { + Release(); + + std::string name; +#if NODE_VERSION_IS_LTS + std::string lts; +#endif // NODE_VERSION_IS_LTS + +#ifdef NODE_HAS_RELEASE_URLS + std::string source_url; + std::string headers_url; +#ifdef _WIN32 + std::string lib_url; +#endif // _WIN32 +#endif // NODE_HAS_RELEASE_URLS + }; + Versions versions; + const Release release; + const std::string arch; + const std::string platform; }; // Per-process global