Coverage Report

Created: 2025-12-30 08:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/node/src/node_metadata.cc
Line
Count
Source
1
#include "node_metadata.h"
2
#include "acorn_version.h"
3
#include "ada.h"
4
#include "amaro_version.h"
5
#include "ares.h"
6
#include "brotli/encode.h"
7
#include "cjs_module_lexer_version.h"
8
#include "llhttp.h"
9
#include "nbytes.h"
10
#include "nghttp2/nghttp2ver.h"
11
#include "node.h"
12
#include "simdjson.h"
13
#include "simdutf.h"
14
#if HAVE_SQLITE
15
#include "quic/guard.h"
16
#include "sqlite3.h"
17
#endif  // HAVE_SQLITE
18
#include "undici_version.h"
19
#include "util.h"
20
#include "uv.h"
21
#include "uvwasi.h"
22
#include "v8.h"
23
#include "zstd.h"
24
25
#ifdef NODE_BUNDLED_ZLIB
26
#include "zlib_version.h"
27
#else
28
#include <zlib.h>
29
#endif  // NODE_BUNDLED_ZLIB
30
31
#if HAVE_OPENSSL
32
#include <openssl/crypto.h>
33
#include "ncrypto.h"
34
#ifndef OPENSSL_NO_QUIC
35
#include <openssl/quic.h>
36
#endif
37
#endif  // HAVE_OPENSSL
38
39
#ifndef OPENSSL_NO_QUIC
40
#include <ngtcp2/version.h>
41
#include <nghttp3/version.h>
42
#endif
43
44
#ifdef NODE_HAVE_I18N_SUPPORT
45
#include <unicode/timezone.h>
46
#include <unicode/ulocdata.h>
47
#include <unicode/uvernum.h>
48
#include <unicode/uversion.h>
49
#endif  // NODE_HAVE_I18N_SUPPORT
50
51
namespace node {
52
53
namespace per_process {
54
Metadata metadata;
55
}
56
57
#if HAVE_OPENSSL
58
1.00k
static constexpr size_t search(const char* s, char c, size_t n = 0) {
59
1.00k
  return *s == '\0' ? n : (*s == c ? n : search(s + 1, c, n + 1));
60
1.00k
}
61
62
72
static inline std::string GetOpenSSLVersion() {
63
  // sample openssl version string format
64
  // for reference: "OpenSSL 1.1.0i 14 Aug 2018"
65
72
  const char* version = OpenSSL_version(OPENSSL_VERSION);
66
72
  const size_t first_space = search(version, ' ');
67
68
  // When Node.js is linked to an alternative library implementing the
69
  // OpenSSL API e.g. BoringSSL, the version string may not match the
70
  //  expected pattern. In this case just return “0.0.0” as placeholder.
71
72
  if (version[first_space] == '\0') {
72
0
    return "0.0.0";
73
0
  }
74
75
72
  const size_t start = first_space + 1;
76
72
  const size_t len = search(&version[start], ' ');
77
72
  return std::string(version, start, len);
78
72
}
79
#endif  // HAVE_OPENSSL
80
81
#ifdef NODE_HAVE_I18N_SUPPORT
82
35
void Metadata::Versions::InitializeIntlVersions() {
83
35
  UErrorCode status = U_ZERO_ERROR;
84
85
35
  const char* tz_version = icu::TimeZone::getTZDataVersion(status);
86
35
  if (U_SUCCESS(status)) {
87
35
    tz = tz_version;
88
35
  }
89
90
35
  char buf[U_MAX_VERSION_STRING_LENGTH];
91
35
  UVersionInfo versionArray;
92
35
  ulocdata_getCLDRVersion(versionArray, &status);
93
35
  if (U_SUCCESS(status)) {
94
35
    u_versionToString(versionArray, buf);
95
35
    cldr = buf;
96
35
  }
97
35
}
98
#endif  // NODE_HAVE_I18N_SUPPORT
99
100
72
Metadata::Versions::Versions() {
101
72
  node = NODE_VERSION_STRING;
102
72
  v8 = v8::V8::GetVersion();
103
72
  uv = uv_version_string();
104
72
#ifdef NODE_BUNDLED_ZLIB
105
72
  zlib = ZLIB_VERSION;
106
#else
107
  zlib = zlibVersion();
108
#endif  // NODE_BUNDLED_ZLIB
109
72
  ares = ARES_VERSION_STR;
110
72
  modules = NODE_STRINGIFY(NODE_MODULE_VERSION);
111
72
  nghttp2 = NGHTTP2_VERSION;
112
72
  napi = NODE_STRINGIFY(NODE_API_SUPPORTED_VERSION_MAX);
113
72
  llhttp =
114
72
      NODE_STRINGIFY(LLHTTP_VERSION_MAJOR)
115
72
      "."
116
72
      NODE_STRINGIFY(LLHTTP_VERSION_MINOR)
117
72
      "."
118
72
      NODE_STRINGIFY(LLHTTP_VERSION_PATCH);
119
120
72
  brotli =
121
72
    std::to_string(BrotliEncoderVersion() >> 24) +
122
72
    "." +
123
72
    std::to_string((BrotliEncoderVersion() & 0xFFF000) >> 12) +
124
72
    "." +
125
72
    std::to_string(BrotliEncoderVersion() & 0xFFF);
126
72
#ifndef NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH
127
72
  undici = UNDICI_VERSION;
128
72
#endif
129
130
72
  acorn = ACORN_VERSION;
131
72
  cjs_module_lexer = CJS_MODULE_LEXER_VERSION;
132
72
  uvwasi = UVWASI_VERSION_STRING;
133
72
  zstd = ZSTD_VERSION_STRING;
134
135
72
#ifndef NODE_SHARED_BUILTIN_AMARO_DIST_INDEX_PATH
136
72
#if HAVE_AMARO
137
72
  amaro = AMARO_VERSION;
138
72
#endif
139
72
#endif
140
141
72
#if HAVE_OPENSSL
142
72
  openssl = GetOpenSSLVersion();
143
72
  ncrypto = NCRYPTO_VERSION;
144
72
#endif
145
146
72
#ifdef NODE_HAVE_I18N_SUPPORT
147
72
  icu = U_ICU_VERSION;
148
72
  unicode = U_UNICODE_VERSION;
149
72
#endif  // NODE_HAVE_I18N_SUPPORT
150
151
72
#ifndef OPENSSL_NO_QUIC
152
72
  ngtcp2 = NGTCP2_VERSION;
153
72
  nghttp3 = NGHTTP3_VERSION;
154
72
#endif
155
156
72
  simdjson = SIMDJSON_VERSION;
157
72
  simdutf = SIMDUTF_VERSION;
158
72
#if HAVE_SQLITE
159
72
  sqlite = SQLITE_VERSION;
160
72
#endif  // HAVE_SQLITE
161
72
  ada = ADA_VERSION;
162
72
  nbytes = NBYTES_VERSION;
163
72
}
164
165
std::array<std::pair<std::string_view, std::string_view>,
166
           NODE_VERSIONS_KEY_COUNT>
167
70
Metadata::Versions::pairs() const {
168
70
  std::array<std::pair<std::string_view, std::string_view>,
169
70
             NODE_VERSIONS_KEY_COUNT>
170
70
      versions_array;
171
70
  auto slot = versions_array.begin();
172
173
70
#define V(key)                                                                 \
174
2.03k
  do {                                                                         \
175
2.03k
    *slot++ = std::pair<std::string_view, std::string_view>(                   \
176
2.03k
        #key, per_process::metadata.versions.key);                             \
177
2.03k
  } while (0);
178
2.03k
  NODE_VERSIONS_KEYS(V)
179
70
#undef V
180
181
70
  std::ranges::sort(versions_array,
182
10.5k
                    [](auto& a, auto& b) { return a.first < b.first; });
183
184
70
  return versions_array;
185
70
}
186
187
72
Metadata::Release::Release() : name(NODE_RELEASE) {
188
#if NODE_VERSION_IS_LTS
189
  lts = NODE_VERSION_LTS_CODENAME;
190
#endif  // NODE_VERSION_IS_LTS
191
192
#ifdef NODE_HAS_RELEASE_URLS
193
#define NODE_RELEASE_URLPFX NODE_RELEASE_URLBASE "v" NODE_VERSION_STRING "/"
194
#define NODE_RELEASE_URLFPFX NODE_RELEASE_URLPFX "node-v" NODE_VERSION_STRING
195
196
  source_url = NODE_RELEASE_URLFPFX ".tar.gz";
197
  headers_url = NODE_RELEASE_URLFPFX "-headers.tar.gz";
198
#ifdef _WIN32
199
  lib_url = NODE_RELEASE_URLPFX "win-" NODE_ARCH "/node.lib";
200
#endif  // _WIN32
201
202
#endif  // NODE_HAS_RELEASE_URLS
203
72
}
204
205
72
Metadata::Metadata() : arch(NODE_ARCH), platform(NODE_PLATFORM) {}
206
207
}  // namespace node