Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: move arch, platform and release into node_metadata.cc #25293

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 26 additions & 47 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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",
Expand Down Expand Up @@ -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<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
Local<Array> arguments = Array::New(env->isolate(), args.size());
Expand Down
22 changes: 22 additions & 0 deletions src/node_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -42,7 +55,7 @@ namespace node {

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