Skip to content

Commit 2c1d1e6

Browse files
targosCommit bot
authored andcommitted
[build] Introduce an embedder version string
Sometimes, the embedder might want to merge a fix to an abandoned branch or to a supported branch but the fix is not relevant to Chromium. This adds a new version string that the embedder can set on compile time and that will be appended to the official V8 version. The separator must be provided in the string. For instance, to have a full version string like "5.5.372.37.custom.1", the embedder must set V8_EMBEDDER_STRING to ".custom.1". Related Node.js issue: nodejs/node#9754 BUG=v8:5740 R=machenbach@chromium.org,hablich@chromium.com,ofrobots@google.com CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_rel_ng Review-Url: https://codereview.chromium.org/2619213002 Cr-Original-Commit-Position: refs/heads/master@{#42175} Committed: https://chromium.googlesource.com/v8/v8/+/fc86d4329b253bf21c1dd85469f1ef4b6e5ba01a Review-Url: https://codereview.chromium.org/2619213002 Cr-Commit-Position: refs/heads/master@{#42582}
1 parent 72e8a97 commit 2c1d1e6

8 files changed

Lines changed: 77 additions & 41 deletions

File tree

BUILD.gn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ declare_args() {
2929
# Enable compiler warnings when using V8_DEPRECATED apis.
3030
v8_deprecation_warnings = false
3131

32+
# Allow the embedder to add a custom suffix to the version string.
33+
v8_embedder_string = ""
34+
3235
# Enable compiler warnings when using V8_DEPRECATE_SOON apis.
3336
v8_imminent_deprecation_warnings = ""
3437

@@ -189,6 +192,10 @@ config("features") {
189192

190193
defines = []
191194

195+
if (v8_embedder_string != "") {
196+
defines += [ "V8_EMBEDDER_STRING=\"$v8_embedder_string\"" ]
197+
}
198+
192199
if (v8_enable_disassembler) {
193200
defines += [ "ENABLE_DISASSEMBLER" ]
194201
}

gypfiles/features.gypi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
# Enable compiler warnings when using V8_DEPRECATE_SOON apis.
6565
'v8_imminent_deprecation_warnings%': 0,
6666

67+
# Allow the embedder to add a custom suffix to the version string.
68+
'v8_embedder_string%': '',
69+
6770
# Set to 1 to enable DCHECKs in release builds.
6871
'dcheck_always_on%': 0,
6972

@@ -105,6 +108,9 @@
105108
['v8_use_snapshot=="true" and v8_use_external_startup_data==1', {
106109
'defines': ['V8_USE_EXTERNAL_STARTUP_DATA',],
107110
}],
111+
['v8_embedder_string!=""', {
112+
'defines': ['V8_EMBEDDER_STRING="<(v8_embedder_string)"',],
113+
}],
108114
['dcheck_always_on!=0', {
109115
'defines': ['DEBUG',],
110116
}],

include/v8-version-string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define V8_VERSION_STRING \
2424
V8_S(V8_MAJOR_VERSION) \
2525
"." V8_S(V8_MINOR_VERSION) "." V8_S(V8_BUILD_NUMBER) "." V8_S( \
26-
V8_PATCH_LEVEL) V8_CANDIDATE_STRING
26+
V8_PATCH_LEVEL) V8_EMBEDDER_STRING V8_CANDIDATE_STRING
2727
#else
2828
#define V8_VERSION_STRING \
2929
V8_S(V8_MAJOR_VERSION) \

include/v8-version.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#define V8_BUILD_NUMBER 0
1414
#define V8_PATCH_LEVEL 0
1515

16+
#ifndef V8_EMBEDDER_STRING
17+
#define V8_EMBEDDER_STRING ""
18+
#endif // V8_EMBEDDER_STRING
19+
1620
// Use 1 for candidates and 0 otherwise.
1721
// (Boolean macro values are not supported by all preprocessors.)
1822
#define V8_IS_CANDIDATE_VERSION 1

src/log-utils.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,16 @@ void Log::Initialize(const char* log_file_name) {
5555

5656
if (output_handle_ != nullptr) {
5757
Log::MessageBuilder msg(this);
58-
msg.Append("v8-version,%d,%d,%d,%d,%d", Version::GetMajor(),
59-
Version::GetMinor(), Version::GetBuild(), Version::GetPatch(),
60-
Version::IsCandidate());
58+
if (strlen(Version::GetEmbedder()) == 0) {
59+
msg.Append("v8-version,%d,%d,%d,%d,%d", Version::GetMajor(),
60+
Version::GetMinor(), Version::GetBuild(),
61+
Version::GetPatch(), Version::IsCandidate());
62+
} else {
63+
msg.Append("v8-version,%d,%d,%d,%d,%s,%d", Version::GetMajor(),
64+
Version::GetMinor(), Version::GetBuild(),
65+
Version::GetPatch(), Version::GetEmbedder(),
66+
Version::IsCandidate());
67+
}
6168
msg.WriteToLogFile();
6269
}
6370
}

src/version.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ int Version::major_ = V8_MAJOR_VERSION;
2020
int Version::minor_ = V8_MINOR_VERSION;
2121
int Version::build_ = V8_BUILD_NUMBER;
2222
int Version::patch_ = V8_PATCH_LEVEL;
23+
const char* Version::embedder_ = V8_EMBEDDER_STRING;
2324
bool Version::candidate_ = (V8_IS_CANDIDATE_VERSION != 0);
2425
const char* Version::soname_ = SONAME;
2526
const char* Version::version_string_ = V8_VERSION_STRING;
@@ -33,9 +34,8 @@ void Version::GetString(Vector<char> str) {
3334
const char* is_simulator = "";
3435
#endif // USE_SIMULATOR
3536
if (GetPatch() > 0) {
36-
SNPrintF(str, "%d.%d.%d.%d%s%s",
37-
GetMajor(), GetMinor(), GetBuild(), GetPatch(), candidate,
38-
is_simulator);
37+
SNPrintF(str, "%d.%d.%d.%d%s%s%s", GetMajor(), GetMinor(), GetBuild(),
38+
GetPatch(), GetEmbedder(), candidate, is_simulator);
3939
} else {
4040
SNPrintF(str, "%d.%d.%d%s%s",
4141
GetMajor(), GetMinor(), GetBuild(), candidate,
@@ -50,8 +50,8 @@ void Version::GetSONAME(Vector<char> str) {
5050
// Generate generic SONAME if no specific SONAME is defined.
5151
const char* candidate = IsCandidate() ? "-candidate" : "";
5252
if (GetPatch() > 0) {
53-
SNPrintF(str, "libv8-%d.%d.%d.%d%s.so",
54-
GetMajor(), GetMinor(), GetBuild(), GetPatch(), candidate);
53+
SNPrintF(str, "libv8-%d.%d.%d.%d%s%s.so", GetMajor(), GetMinor(),
54+
GetBuild(), GetPatch(), GetEmbedder(), candidate);
5555
} else {
5656
SNPrintF(str, "libv8-%d.%d.%d%s.so",
5757
GetMajor(), GetMinor(), GetBuild(), candidate);

src/version.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Version {
1818
static int GetMinor() { return minor_; }
1919
static int GetBuild() { return build_; }
2020
static int GetPatch() { return patch_; }
21+
static const char* GetEmbedder() { return embedder_; }
2122
static bool IsCandidate() { return candidate_; }
2223
static uint32_t Hash() {
2324
return static_cast<uint32_t>(
@@ -38,13 +39,15 @@ class Version {
3839
static int minor_;
3940
static int build_;
4041
static int patch_;
42+
static const char* embedder_;
4143
static bool candidate_;
4244
static const char* soname_;
4345
static const char* version_string_;
4446

4547
// In test-version.cc.
4648
friend void SetVersion(int major, int minor, int build, int patch,
47-
bool candidate, const char* soname);
49+
const char* embedder, bool candidate,
50+
const char* soname);
4851
};
4952

5053
} // namespace internal

test/cctest/test-version.cc

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,35 @@ namespace v8 {
3737
namespace internal {
3838

3939
void SetVersion(int major, int minor, int build, int patch,
40-
bool candidate, const char* soname) {
40+
const char* embedder, bool candidate, const char* soname) {
4141
Version::major_ = major;
4242
Version::minor_ = minor;
4343
Version::build_ = build;
4444
Version::patch_ = patch;
45+
Version::embedder_ = embedder;
4546
Version::candidate_ = candidate;
4647
Version::soname_ = soname;
4748
}
4849

4950
} // namespace internal
5051
} // namespace v8
5152

52-
53-
static void CheckVersion(int major, int minor, int build,
54-
int patch, bool candidate,
53+
static void CheckVersion(int major, int minor, int build, int patch,
54+
const char* embedder, bool candidate,
5555
const char* expected_version_string,
5656
const char* expected_generic_soname) {
5757
static v8::internal::EmbeddedVector<char, 128> version_str;
5858
static v8::internal::EmbeddedVector<char, 128> soname_str;
59-
6059
// Test version without specific SONAME.
61-
SetVersion(major, minor, build, patch, candidate, "");
60+
SetVersion(major, minor, build, patch, embedder, candidate, "");
6261
Version::GetString(version_str);
6362
CHECK_EQ(0, strcmp(expected_version_string, version_str.start()));
6463
Version::GetSONAME(soname_str);
6564
CHECK_EQ(0, strcmp(expected_generic_soname, soname_str.start()));
6665

6766
// Test version with specific SONAME.
6867
const char* soname = "libv8.so.1";
69-
SetVersion(major, minor, build, patch, candidate, soname);
68+
SetVersion(major, minor, build, patch, embedder, candidate, soname);
7069
Version::GetString(version_str);
7170
CHECK_EQ(0, strcmp(expected_version_string, version_str.start()));
7271
Version::GetSONAME(soname_str);
@@ -76,30 +75,40 @@ static void CheckVersion(int major, int minor, int build,
7675

7776
TEST(VersionString) {
7877
#ifdef USE_SIMULATOR
79-
CheckVersion(0, 0, 0, 0, false, "0.0.0 SIMULATOR", "libv8-0.0.0.so");
80-
CheckVersion(0, 0, 0, 0, true,
81-
"0.0.0 (candidate) SIMULATOR", "libv8-0.0.0-candidate.so");
82-
CheckVersion(1, 0, 0, 0, false, "1.0.0 SIMULATOR", "libv8-1.0.0.so");
83-
CheckVersion(1, 0, 0, 0, true,
84-
"1.0.0 (candidate) SIMULATOR", "libv8-1.0.0-candidate.so");
85-
CheckVersion(1, 0, 0, 1, false, "1.0.0.1 SIMULATOR", "libv8-1.0.0.1.so");
86-
CheckVersion(1, 0, 0, 1, true,
87-
"1.0.0.1 (candidate) SIMULATOR", "libv8-1.0.0.1-candidate.so");
88-
CheckVersion(2, 5, 10, 7, false, "2.5.10.7 SIMULATOR", "libv8-2.5.10.7.so");
89-
CheckVersion(2, 5, 10, 7, true,
90-
"2.5.10.7 (candidate) SIMULATOR", "libv8-2.5.10.7-candidate.so");
78+
CheckVersion(0, 0, 0, 0, "", false, "0.0.0 SIMULATOR", "libv8-0.0.0.so");
79+
CheckVersion(0, 0, 0, 0, "", true, "0.0.0 (candidate) SIMULATOR",
80+
"libv8-0.0.0-candidate.so");
81+
CheckVersion(1, 0, 0, 0, "", false, "1.0.0 SIMULATOR", "libv8-1.0.0.so");
82+
CheckVersion(1, 0, 0, 0, "", true, "1.0.0 (candidate) SIMULATOR",
83+
"libv8-1.0.0-candidate.so");
84+
CheckVersion(1, 0, 0, 1, "", false, "1.0.0.1 SIMULATOR", "libv8-1.0.0.1.so");
85+
CheckVersion(1, 0, 0, 1, "", true, "1.0.0.1 (candidate) SIMULATOR",
86+
"libv8-1.0.0.1-candidate.so");
87+
CheckVersion(2, 5, 10, 7, "", false, "2.5.10.7 SIMULATOR",
88+
"libv8-2.5.10.7.so");
89+
CheckVersion(2, 5, 10, 7, "", true, "2.5.10.7 (candidate) SIMULATOR",
90+
"libv8-2.5.10.7-candidate.so");
91+
CheckVersion(2, 5, 10, 7, ".emb.1", false, "2.5.10.7.emb.1 SIMULATOR",
92+
"libv8-2.5.10.7.emb.1.so");
93+
CheckVersion(2, 5, 10, 7, ".emb.1", true,
94+
"2.5.10.7.emb.1 (candidate) SIMULATOR",
95+
"libv8-2.5.10.7.emb.1-candidate.so");
9196
#else
92-
CheckVersion(0, 0, 0, 0, false, "0.0.0", "libv8-0.0.0.so");
93-
CheckVersion(0, 0, 0, 0, true,
94-
"0.0.0 (candidate)", "libv8-0.0.0-candidate.so");
95-
CheckVersion(1, 0, 0, 0, false, "1.0.0", "libv8-1.0.0.so");
96-
CheckVersion(1, 0, 0, 0, true,
97-
"1.0.0 (candidate)", "libv8-1.0.0-candidate.so");
98-
CheckVersion(1, 0, 0, 1, false, "1.0.0.1", "libv8-1.0.0.1.so");
99-
CheckVersion(1, 0, 0, 1, true,
100-
"1.0.0.1 (candidate)", "libv8-1.0.0.1-candidate.so");
101-
CheckVersion(2, 5, 10, 7, false, "2.5.10.7", "libv8-2.5.10.7.so");
102-
CheckVersion(2, 5, 10, 7, true,
103-
"2.5.10.7 (candidate)", "libv8-2.5.10.7-candidate.so");
97+
CheckVersion(0, 0, 0, 0, "", false, "0.0.0", "libv8-0.0.0.so");
98+
CheckVersion(0, 0, 0, 0, "", true, "0.0.0 (candidate)",
99+
"libv8-0.0.0-candidate.so");
100+
CheckVersion(1, 0, 0, 0, "", false, "1.0.0", "libv8-1.0.0.so");
101+
CheckVersion(1, 0, 0, 0, "", true, "1.0.0 (candidate)",
102+
"libv8-1.0.0-candidate.so");
103+
CheckVersion(1, 0, 0, 1, "", false, "1.0.0.1", "libv8-1.0.0.1.so");
104+
CheckVersion(1, 0, 0, 1, "", true, "1.0.0.1 (candidate)",
105+
"libv8-1.0.0.1-candidate.so");
106+
CheckVersion(2, 5, 10, 7, "", false, "2.5.10.7", "libv8-2.5.10.7.so");
107+
CheckVersion(2, 5, 10, 7, "", true, "2.5.10.7 (candidate)",
108+
"libv8-2.5.10.7-candidate.so");
109+
CheckVersion(2, 5, 10, 7, ".emb.1", false, "2.5.10.7.emb.1",
110+
"libv8-2.5.10.7.emb.1.so");
111+
CheckVersion(2, 5, 10, 7, ".emb.1", true, "2.5.10.7.emb.1 (candidate)",
112+
"libv8-2.5.10.7.emb.1-candidate.so");
104113
#endif
105114
}

0 commit comments

Comments
 (0)