Skip to content
Permalink
Browse files

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: #25293
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
joyeecheung authored and addaleax committed Dec 31, 2018
1 parent 43535f5 commit e9b4d24eda3a53bea1f683dbf7da6d0c304bdfba
Showing with 82 additions and 48 deletions.
  1. +26 −47 src/node.cc
  2. +22 −0 src/node_metadata.cc
  3. +34 −1 src/node_metadata.h
@@ -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<Object> 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(),
@@ -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
@@ -4,9 +4,22 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <string>
#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

0 comments on commit e9b4d24

Please sign in to comment.
You can’t perform that action at this time.