GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_metadata.cc Lines: 41 41 100.0 %
Date: 2022-12-31 04:22:30 Branches: 2 4 50.0 %

Line Branch Exec Source
1
#include "node_metadata.h"
2
#include "acorn_version.h"
3
#include "ares.h"
4
#include "brotli/encode.h"
5
#include "llhttp.h"
6
#include "nghttp2/nghttp2ver.h"
7
#include "node.h"
8
#include "undici_version.h"
9
#include "util.h"
10
#include "uv.h"
11
#include "uvwasi.h"
12
#include "v8.h"
13
#include "zlib.h"
14
15
#if HAVE_OPENSSL
16
#include <openssl/opensslv.h>
17
#if NODE_OPENSSL_HAS_QUIC
18
#include <openssl/quic.h>
19
#endif
20
#endif  // HAVE_OPENSSL
21
22
#ifdef OPENSSL_INFO_QUIC
23
#include <ngtcp2/version.h>
24
#include <nghttp3/version.h>
25
#endif
26
27
#ifdef NODE_HAVE_I18N_SUPPORT
28
#include <unicode/timezone.h>
29
#include <unicode/ulocdata.h>
30
#include <unicode/uvernum.h>
31
#include <unicode/uversion.h>
32
#endif  // NODE_HAVE_I18N_SUPPORT
33
34
namespace node {
35
36
namespace per_process {
37
Metadata metadata;
38
}
39
40
#if HAVE_OPENSSL
41
static constexpr size_t search(const char* s, char c, size_t n = 0) {
42
  return *s == c ? n : search(s + 1, c, n + 1);
43
}
44
45
5788
static inline std::string GetOpenSSLVersion() {
46
  // sample openssl version string format
47
  // for reference: "OpenSSL 1.1.0i 14 Aug 2018"
48
5788
  constexpr size_t start = search(OPENSSL_VERSION_TEXT, ' ') + 1;
49
5788
  constexpr size_t len = search(&OPENSSL_VERSION_TEXT[start], ' ');
50
5788
  return std::string(OPENSSL_VERSION_TEXT, start, len);
51
}
52
#endif  // HAVE_OPENSSL
53
54
#ifdef NODE_HAVE_I18N_SUPPORT
55
5737
void Metadata::Versions::InitializeIntlVersions() {
56
5737
  UErrorCode status = U_ZERO_ERROR;
57
58
5737
  const char* tz_version = icu::TimeZone::getTZDataVersion(status);
59
5737
  if (U_SUCCESS(status)) {
60
5737
    tz = tz_version;
61
  }
62
63
  char buf[U_MAX_VERSION_STRING_LENGTH];
64
  UVersionInfo versionArray;
65
5737
  ulocdata_getCLDRVersion(versionArray, &status);
66
5737
  if (U_SUCCESS(status)) {
67
5737
    u_versionToString(versionArray, buf);
68
5737
    cldr = buf;
69
  }
70
5737
}
71
#endif  // NODE_HAVE_I18N_SUPPORT
72
73
5788
Metadata::Versions::Versions() {
74
5788
  node = NODE_VERSION_STRING;
75
5788
  v8 = v8::V8::GetVersion();
76
5788
  uv = uv_version_string();
77
5788
  zlib = ZLIB_VERSION;
78
5788
  ares = ARES_VERSION_STR;
79
5788
  modules = NODE_STRINGIFY(NODE_MODULE_VERSION);
80
5788
  nghttp2 = NGHTTP2_VERSION;
81
5788
  napi = NODE_STRINGIFY(NAPI_VERSION);
82
  llhttp =
83
      NODE_STRINGIFY(LLHTTP_VERSION_MAJOR)
84
      "."
85
      NODE_STRINGIFY(LLHTTP_VERSION_MINOR)
86
      "."
87
5788
      NODE_STRINGIFY(LLHTTP_VERSION_PATCH);
88
89
  brotli =
90
11576
    std::to_string(BrotliEncoderVersion() >> 24) +
91
11576
    "." +
92
23152
    std::to_string((BrotliEncoderVersion() & 0xFFF000) >> 12) +
93
11576
    "." +
94
17364
    std::to_string(BrotliEncoderVersion() & 0xFFF);
95
#ifndef NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH
96
5788
  undici = UNDICI_VERSION;
97
#endif
98
5788
  acorn = ACORN_VERSION;
99
100
5788
  uvwasi = UVWASI_VERSION_STRING;
101
102
#if HAVE_OPENSSL
103
5788
  openssl = GetOpenSSLVersion();
104
#endif
105
106
#ifdef NODE_HAVE_I18N_SUPPORT
107
5788
  icu = U_ICU_VERSION;
108
5788
  unicode = U_UNICODE_VERSION;
109
#endif  // NODE_HAVE_I18N_SUPPORT
110
111
#ifdef OPENSSL_INFO_QUIC
112
5788
  ngtcp2 = NGTCP2_VERSION;
113
5788
  nghttp3 = NGHTTP3_VERSION;
114
#endif
115
5788
}
116
117
5788
Metadata::Release::Release() : name(NODE_RELEASE) {
118
#if NODE_VERSION_IS_LTS
119
  lts = NODE_VERSION_LTS_CODENAME;
120
#endif  // NODE_VERSION_IS_LTS
121
122
#ifdef NODE_HAS_RELEASE_URLS
123
#define NODE_RELEASE_URLPFX NODE_RELEASE_URLBASE "v" NODE_VERSION_STRING "/"
124
#define NODE_RELEASE_URLFPFX NODE_RELEASE_URLPFX "node-v" NODE_VERSION_STRING
125
126
  source_url = NODE_RELEASE_URLFPFX ".tar.gz";
127
  headers_url = NODE_RELEASE_URLFPFX "-headers.tar.gz";
128
#ifdef _WIN32
129
  lib_url = strcmp(NODE_ARCH, "ia32") ? NODE_RELEASE_URLPFX "win-" NODE_ARCH
130
                                                           "/node.lib"
131
                                     : NODE_RELEASE_URLPFX "win-x86/node.lib";
132
#endif  // _WIN32
133
134
#endif  // NODE_HAS_RELEASE_URLS
135
5788
}
136
137
5788
Metadata::Metadata() : arch(NODE_ARCH), platform(NODE_PLATFORM) {}
138
139
}  // namespace node