From 6c0162149bc96de44e7596ebb8c668e46256279d Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 31 Dec 2018 17:57:39 +0800 Subject: [PATCH] src: move arch, platform and release into node_metadata.cc Move definitions of more metadata into node_metadata{.h, .cc} so the data can be reused and easily inspected in C++. PR-URL: https://github.com/nodejs/node/pull/25293 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- src/node.cc | 73 ++++++++++++++++---------------------------- src/node_metadata.cc | 22 +++++++++++++ src/node_metadata.h | 35 ++++++++++++++++++++- 3 files changed, 82 insertions(+), 48 deletions(-) diff --git a/src/node.cc b/src/node.cc index cec333bd82c01c..0b496da4a273bc 100644 --- a/src/node.cc +++ b/src/node.cc @@ -168,8 +168,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"); @@ -184,13 +186,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", @@ -839,54 +843,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 3bfed6d4b57ea2..602115ad4f2590 100644 --- a/src/node_metadata.cc +++ b/src/node_metadata.cc @@ -90,4 +90,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 ef93c7b7e41707..c6f379f085de03 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) \ @@ -43,7 +56,7 @@ namespace node { class Metadata { public: - Metadata() = default; + Metadata(); Metadata(Metadata&) = delete; Metadata(Metadata&&) = delete; Metadata operator=(Metadata&) = delete; @@ -63,7 +76,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