Skip to content

Commit

Permalink
src: move arch, platform and release into node_metadata.cc
Browse files Browse the repository at this point in the history
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 Jan 14, 2019
1 parent 43535f5 commit e9b4d24
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 48 deletions.
73 changes: 26 additions & 47 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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",
Expand Down Expand Up @@ -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(),
Expand Down
22 changes: 22 additions & 0 deletions src/node_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 34 additions & 1 deletion src/node_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -43,7 +56,7 @@ namespace node {

class Metadata {
public:
Metadata() = default;
Metadata();
Metadata(Metadata&) = delete;
Metadata(Metadata&&) = delete;
Metadata operator=(Metadata&) = delete;
Expand All @@ -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
Expand Down

0 comments on commit e9b4d24

Please sign in to comment.