summaryrefslogtreecommitdiff
path: root/src/mongo/util/version.cpp.in
blob: abe9c6315b6c30663eb7df9edd8e04ef987bdfef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// @file version.cpp

/*    Copyright 2009 10gen Inc.
 *
 *    This program is free software: you can redistribute it and/or  modify
 *    it under the terms of the GNU Affero General Public License, version 3,
 *    as published by the Free Software Foundation.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    As a special exception, the copyright holders give permission to link the
 *    code of portions of this program with the OpenSSL library under certain
 *    conditions as described in each individual source file and distribute
 *    linked combinations including the program with the OpenSSL library. You
 *    must comply with the GNU Affero General Public License in all respects
 *    for all of the code used other than as permitted herein. If you modify
 *    file(s) with this exception, you may extend this exception to your
 *    version of the file(s), but you are not obligated to do so. If you do not
 *    wish to do so, delete this exception statement from your version. If you
 *    delete this exception statement from all source files in the program,
 *    then also delete it in the license file.
 */

#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kControl

#include "mongo/platform/basic.h"

#include <initializer_list>
#include <boost/version.hpp>
#include <sstream>
#include <string>

#include "mongo/base/parse_number.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/config.h"
#include "mongo/db/jsobj.h"
#include "mongo/util/debug_util.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/version.h"

#ifdef MONGO_CONFIG_SSL
#include <openssl/crypto.h>
#endif

#include <pcrecpp.h>
#include <cstdlib>

namespace mongo {

using std::string;
using std::stringstream;

const char versionString[] = "@mongo_version@";
const char* gitVersion() {
    return "@mongo_git_hash@";
}
const char* compiledJSEngine() {
    return "@buildinfo_js_engine@";
}
const char* allocator() {
    return "@buildinfo_allocator@";
}

const int kMongoVersionMajor = @mongo_version_major@;
const int kMongoVersionMinor = @mongo_version_minor@;
const int kMongoVersionPatch = @mongo_version_patch@;
const int kMongoVersionExtra = @mongo_version_extra@;
const char kMongoVersionExtraStr[] = "@mongo_version_extra_str@";

using BuildInfoTuple = std::tuple<std::string, std::string, bool, bool>;
const std::vector<BuildInfoTuple> kBuildEnvironment = @buildinfo_environment_data@;

std::vector<std::string> compiledModules() {
    const std::vector<string> modules_list = @buildinfo_modules@;
    return modules_list;
}

bool isSameMajorVersion(const char* version) {
    int major = -1, minor = -1;
    pcrecpp::RE ver_regex("^(\\d+)\\.(\\d+)\\.");
    ver_regex.PartialMatch(version, &major, &minor);

    if (major == -1 || minor == -1)
        return false;
    return (major == kMongoVersionMajor && minor == kMongoVersionMinor);
}

string mongodVersion() {
    stringstream ss;
    ss << "db version v" << versionString;
    return ss.str();
}

const std::string openSSLVersion(const std::string& prefix, const std::string& suffix) {
#ifndef MONGO_CONFIG_SSL
    return "";
#else
    return prefix + SSLeay_version(SSLEAY_VERSION) + suffix;
#endif
}

#if defined(_WIN32)
const char* targetMinOS() {
#if (NTDDI_VERSION >= NTDDI_WIN7)
    return "Windows 7/Windows Server 2008 R2";
#elif(NTDDI_VERSION >= NTDDI_VISTA)
    return "Windows Vista/Windows Server 2008";
#else
#error This targeted Windows version is not supported
#endif  // NTDDI_VERSION
}

void printTargetMinOS() {
    log() << "targetMinOS: " << targetMinOS();
}
#endif  // _WIN32

void printBuildInfo() {
    log() << "git version: " << gitVersion();

#ifdef MONGO_CONFIG_SSL
    log() << openSSLVersion("OpenSSL version: ");
#endif

    log() << "allocator: " << allocator();

    stringstream ss;
    ss << "modules: ";
    auto modules_list = compiledModules();
    if (modules_list.size() == 0) {
        ss << "none";
    } else {
        for (const auto& m : modules_list) {
            ss << m << " ";
        }
    }
    log() << ss.str();

    log() << "build environment:";
    for (auto&& envDataEntry : kBuildEnvironment) {
        if (std::get<3>(envDataEntry)) {
            auto val = std::get<1>(envDataEntry);
            if (val.length() == 0)
                continue;
            log() << "    " << std::get<0>(envDataEntry) << ": " << std::get<1>(envDataEntry);
        }
    }
}

void appendBuildInfo(BSONObjBuilder& result) {
    result << "version" << versionString << "gitVersion" << gitVersion()
#if defined(_WIN32)
           << "targetMinOS" << targetMinOS()
#endif
           << "modules" << compiledModules()
           << "allocator" << allocator() << "javascriptEngine" << compiledJSEngine() << "sysInfo"
           << "deprecated";

    BSONArrayBuilder versionArray(result.subarrayStart("versionArray"));
    versionArray << kMongoVersionMajor << kMongoVersionMinor << kMongoVersionPatch
                 << kMongoVersionExtra;
    versionArray.done();

    BSONObjBuilder opensslInfo(result.subobjStart("openssl"));
#ifdef MONGO_CONFIG_SSL
    opensslInfo << "running" << openSSLVersion() << "compiled" << OPENSSL_VERSION_TEXT;
#else
    opensslInfo << "running"
                << "disabled"
                << "compiled"
                << "disabled";
#endif
    opensslInfo.done();

    BSONObjBuilder buildvarsInfo(result.subobjStart("buildEnvironment"));
    for (auto&& envDataEntry : kBuildEnvironment) {
        if (std::get<2>(envDataEntry)) {
            buildvarsInfo << std::get<0>(envDataEntry) << std::get<1>(envDataEntry);
        }
    }
    buildvarsInfo.done();

    result << "bits" << (int)sizeof(void*) * 8;
    result.appendBool("debug", kDebugBuild);
    result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize);
}
}