From b00647b114f7f7f36b37acb6217025ba1bd378c2 Mon Sep 17 00:00:00 2001 From: Andy Schwerin Date: Thu, 19 Dec 2013 19:13:11 -0500 Subject: SERVER-12156 Split version.h/cpp into version and version_reporting. --- src/mongo/SConscript | 13 +++- src/mongo/db/db.cpp | 2 +- src/mongo/db/dbcommands_generic.cpp | 2 +- src/mongo/db/dbwebserver.cpp | 2 +- src/mongo/db/log_process_details.cpp | 1 + src/mongo/db/mongod_options.cpp | 1 + src/mongo/dbtests/framework.cpp | 2 +- src/mongo/dbtests/perftests.cpp | 1 + src/mongo/s/version_mongos.cpp | 1 + src/mongo/shell/shell_utils.cpp | 2 +- src/mongo/util/version.cpp | 93 ++++------------------------- src/mongo/util/version.h | 18 +----- src/mongo/util/version_reporting.cpp | 111 +++++++++++++++++++++++++++++++++++ src/mongo/util/version_reporting.h | 56 ++++++++++++++++++ 14 files changed, 200 insertions(+), 105 deletions(-) create mode 100644 src/mongo/util/version_reporting.cpp create mode 100644 src/mongo/util/version_reporting.h diff --git a/src/mongo/SConscript b/src/mongo/SConscript index fad019887d6..9c91e09e1a7 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -260,8 +260,16 @@ env.Library('lasterror', [ 'foundation', ]) +env.Library('version', + [ + 'buildinfo.cpp', + 'util/version.cpp' + ], + LIBDEPS=[ + 'bson', + '$BUILD_DIR/mongo/base/base' + ]) commonFiles = [ "pch.cpp", - "buildinfo.cpp", "db/catalog/ondisk/namespace.cpp", "shell/mongo.cpp", "util/intrusive_counter.cpp", @@ -276,7 +284,7 @@ commonFiles = [ "pch.cpp", "util/histogram.cpp", "util/text_startuptest.cpp", "util/stack_introspect.cpp", - "util/version.cpp", + "util/version_reporting.cpp", ] extraCommonLibdeps = [] @@ -345,6 +353,7 @@ env.Library('mongocommon', commonFiles, 'stringutils', 'synchronization', 'util/concurrency/thread_name', + 'version', '$BUILD_DIR/third_party/shim_pcrecpp', '$BUILD_DIR/third_party/murmurhash3/murmurhash3', '$BUILD_DIR/third_party/shim_boost', diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 272db7d801e..55db6189235 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -87,7 +87,7 @@ #include "mongo/util/stacktrace.h" #include "mongo/util/startup_test.h" #include "mongo/util/text.h" -#include "mongo/util/version.h" +#include "mongo/util/version_reporting.h" #if !defined(_WIN32) # include diff --git a/src/mongo/db/dbcommands_generic.cpp b/src/mongo/db/dbcommands_generic.cpp index 393511049a5..977fc7cc49b 100644 --- a/src/mongo/db/dbcommands_generic.cpp +++ b/src/mongo/db/dbcommands_generic.cpp @@ -59,7 +59,7 @@ #include "mongo/util/md5.hpp" #include "mongo/util/processinfo.h" #include "mongo/util/ramlog.h" -#include "mongo/util/version.h" +#include "mongo/util/version_reporting.h" namespace mongo { diff --git a/src/mongo/db/dbwebserver.cpp b/src/mongo/db/dbwebserver.cpp index 14163ce8de5..57a7d505e15 100644 --- a/src/mongo/db/dbwebserver.cpp +++ b/src/mongo/db/dbwebserver.cpp @@ -56,7 +56,7 @@ #include "mongo/util/net/miniwebserver.h" #include "mongo/util/ramlog.h" #include "mongo/util/version.h" - +#include "mongo/util/version_reporting.h" namespace mongo { diff --git a/src/mongo/db/log_process_details.cpp b/src/mongo/db/log_process_details.cpp index 54643ec72b0..a851444f5cd 100644 --- a/src/mongo/db/log_process_details.cpp +++ b/src/mongo/db/log_process_details.cpp @@ -38,6 +38,7 @@ #include "mongo/util/net/ssl_manager.h" #include "mongo/util/processinfo.h" #include "mongo/util/version.h" +#include "mongo/util/version_reporting.h" namespace mongo { diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index 3881d383bfb..d4a11d5ec62 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -44,6 +44,7 @@ #include "mongo/util/net/ssl_options.h" #include "mongo/util/options_parser/startup_options.h" #include "mongo/util/version.h" +#include "mongo/util/version_reporting.h" namespace mongo { diff --git a/src/mongo/dbtests/framework.cpp b/src/mongo/dbtests/framework.cpp index 69cabdf589a..53c9f868369 100644 --- a/src/mongo/dbtests/framework.cpp +++ b/src/mongo/dbtests/framework.cpp @@ -47,7 +47,7 @@ #include "mongo/util/background.h" #include "mongo/util/concurrency/mutex.h" #include "mongo/util/file_allocator.h" -#include "mongo/util/version.h" +#include "mongo/util/version_reporting.h" namespace moe = mongo::optionenvironment; diff --git a/src/mongo/dbtests/perftests.cpp b/src/mongo/dbtests/perftests.cpp index 725274cb961..d97851f3aad 100644 --- a/src/mongo/dbtests/perftests.cpp +++ b/src/mongo/dbtests/perftests.cpp @@ -55,6 +55,7 @@ #include "mongo/util/fail_point.h" #include "mongo/util/timer.h" #include "mongo/util/version.h" +#include "mongo/util/version_reporting.h" #if (__cplusplus >= 201103L) #include diff --git a/src/mongo/s/version_mongos.cpp b/src/mongo/s/version_mongos.cpp index e23c8cfd92a..4fafaa0de6b 100644 --- a/src/mongo/s/version_mongos.cpp +++ b/src/mongo/s/version_mongos.cpp @@ -37,6 +37,7 @@ #include "mongo/util/log.h" #include "mongo/util/net/sock.h" #include "mongo/util/version.h" +#include "mongo/util/version_reporting.h" namespace mongo { diff --git a/src/mongo/shell/shell_utils.cpp b/src/mongo/shell/shell_utils.cpp index 69abe910d42..3091eec7971 100644 --- a/src/mongo/shell/shell_utils.cpp +++ b/src/mongo/shell/shell_utils.cpp @@ -27,7 +27,7 @@ #include "mongo/shell/shell_utils_launcher.h" #include "mongo/util/processinfo.h" #include "mongo/util/text.h" -#include "mongo/util/version.h" +#include "mongo/util/version_reporting.h" namespace mongo { diff --git a/src/mongo/util/version.cpp b/src/mongo/util/version.cpp index 6c5f15be206..50ba5cc3fa1 100644 --- a/src/mongo/util/version.cpp +++ b/src/mongo/util/version.cpp @@ -15,25 +15,12 @@ * limitations under the License. */ +#include "mongo/platform/basic.h" -#include -#include -#include -#include -#include -#include +#include "mongo/util/version.h" #include "mongo/base/parse_number.h" #include "mongo/db/jsobj.h" -#include "mongo/db/pdfile_version.h" -#include "mongo/db/storage_options.h" -#include "mongo/util/file.h" -#include "mongo/util/net/ssl_manager.h" -#include "mongo/util/processinfo.h" -#include "mongo/util/ramlog.h" -#include "mongo/util/stringutils.h" -#include "mongo/util/version.h" - namespace mongo { @@ -111,27 +98,16 @@ namespace mongo { } #ifndef _SCONS - // only works in scons + // + // The following implementations are provided for use when buildinfo.cpp is not autogenerated. + // + const char * gitVersion() { return "not-scons"; } const char * compiledJSEngine() { return ""; } const char * allocator() { return ""; } const char * loaderFlags() { return ""; } const char * compilerFlags() { return ""; } -#endif - - void printGitVersion() { log() << "git version: " << gitVersion() << endl; } - const std::string openSSLVersion(const std::string &prefix, const std::string &suffix) { - return getSSLVersion(prefix, suffix); - } - - void printOpenSSLVersion() { -#ifdef MONGO_SSL - log() << openSSLVersion("OpenSSL version: ") << endl; -#endif - } - -#ifndef _SCONS #if defined(_WIN32) string sysInfo() { stringstream ss; @@ -140,61 +116,14 @@ namespace mongo { ss << " boostver:" << BOOST_VERSION; #if( !defined(_MT) ) #error _MT is not defined -#endif +#endif // !defined(_MT) ss << (sizeof(char *) == 8 ? " 64bit" : " 32bit"); return ss.str(); } -#else +#else // defined(_WIN32) string sysInfo() { return ""; } -#endif -#endif - -#if defined(_WIN32) - std::string targetMinOS() { - stringstream ss; -#if (NTDDI_VERSION >= 0x06010000) - ss << "Windows 7/Windows Server 2008 R2"; -#elif (NTDDI_VERSION >= 0x05020200) - ss << "Windows Server 2003 SP2"; -#elif (NTDDI_VERSION >= 0x05010300) - ss << "Windows XP SP3"; -#else -#error This targetted Windows version is not supported -#endif // NTDDI_VERSION - return ss.str(); - } +#endif // defined(_WIN32) +#endif // !defined(_SCONS) - void printTargetMinOS() { - log() << "targetMinOS: " << targetMinOS(); - } -#endif // _WIN32 - - void printSysInfo() { - log() << "build info: " << sysInfo() << endl; - } - - void printAllocator() { - log() << "allocator: " << allocator() << endl; - } - - void appendBuildInfo(BSONObjBuilder& result) { - result << "version" << versionString - << "gitVersion" << gitVersion() -#if defined(_WIN32) - << "targetMinOS" << targetMinOS() -#endif - << "OpenSSLVersion" << openSSLVersion() - << "sysInfo" << sysInfo() - << "loaderFlags" << loaderFlags() - << "compilerFlags" << compilerFlags() - << "allocator" << allocator() - << "versionArray" << versionArray - << "javascriptEngine" << compiledJSEngine() -/*TODO: add this back once the module system is in place -- maybe once we do something like serverstatus with callbacks*/ -// << "interpreterVersion" << globalScriptEngine->getInterpreterVersionString() - << "bits" << ( sizeof( int* ) == 4 ? 32 : 64 ); - result.appendBool( "debug" , debug ); - result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize); - } -} +} // namespace mongo diff --git a/src/mongo/util/version.h b/src/mongo/util/version.h index dcdb12c44d6..24a465285e5 100644 --- a/src/mongo/util/version.h +++ b/src/mongo/util/version.h @@ -31,8 +31,7 @@ #include -#include "mongo/base/string_data.h" -#include "mongo/bson/bsonobjbuilder.h" +#include "mongo/bson/bsonobj.h" namespace mongo { struct BSONArray; @@ -44,29 +43,16 @@ namespace mongo { // Convert a version string into a numeric array BSONArray toVersionArray(const char* version); - + // Checks whether another version is the same major version as us bool isSameMajorVersion(const char* version); - void appendBuildInfo(BSONObjBuilder& result); - const char * gitVersion(); const char * compiledJSEngine(); const char * allocator(); const char * loaderFlags(); const char * compilerFlags(); - - void printGitVersion(); - - const std::string openSSLVersion(const std::string &prefix = "", const std::string &suffix = ""); - void printOpenSSLVersion(); - std::string sysInfo(); - void printSysInfo(); - void printTargetMinOS(); - void printAllocator(); - - void show_warnings(); } // namespace mongo diff --git a/src/mongo/util/version_reporting.cpp b/src/mongo/util/version_reporting.cpp new file mode 100644 index 00000000000..32994231a40 --- /dev/null +++ b/src/mongo/util/version_reporting.cpp @@ -0,0 +1,111 @@ +// @file version.cpp + +/* Copyright 2009 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/util/version_reporting.h" + +#include +#include + +#include "mongo/bson/bsonobjbuilder.h" +#include "mongo/db/jsobj.h" +#include "mongo/util/net/ssl_manager.h" +#include "mongo/util/version.h" + + +namespace mongo { + + void printGitVersion() { log() << "git version: " << gitVersion() << endl; } + + const std::string openSSLVersion(const std::string &prefix, const std::string &suffix) { + return getSSLVersion(prefix, suffix); + } + + void printOpenSSLVersion() { +#ifdef MONGO_SSL + log() << openSSLVersion("OpenSSL version: ") << endl; +#endif + } + +#ifndef _SCONS +#if defined(_WIN32) + string sysInfo() { + stringstream ss; + ss << "not-scons win"; + ss << " mscver:" << _MSC_FULL_VER << " built:" << __DATE__; + ss << " boostver:" << BOOST_VERSION; +#if( !defined(_MT) ) +#error _MT is not defined +#endif + ss << (sizeof(char *) == 8 ? " 64bit" : " 32bit"); + return ss.str(); + } +#else + string sysInfo() { return ""; } + +#endif +#endif + +#if defined(_WIN32) + std::string targetMinOS() { + stringstream ss; +#if (NTDDI_VERSION >= 0x06010000) + ss << "Windows 7/Windows Server 2008 R2"; +#elif (NTDDI_VERSION >= 0x05020200) + ss << "Windows Server 2003 SP2"; +#elif (NTDDI_VERSION >= 0x05010300) + ss << "Windows XP SP3"; +#else +#error This targetted Windows version is not supported +#endif // NTDDI_VERSION + return ss.str(); + } + + void printTargetMinOS() { + log() << "targetMinOS: " << targetMinOS(); + } +#endif // _WIN32 + + void printSysInfo() { + log() << "build info: " << sysInfo() << endl; + } + + void printAllocator() { + log() << "allocator: " << allocator() << endl; + } + + void appendBuildInfo(BSONObjBuilder& result) { + result << "version" << versionString + << "gitVersion" << gitVersion() +#if defined(_WIN32) + << "targetMinOS" << targetMinOS() +#endif + << "OpenSSLVersion" << openSSLVersion() + << "sysInfo" << sysInfo() + << "loaderFlags" << loaderFlags() + << "compilerFlags" << compilerFlags() + << "allocator" << allocator() + << "versionArray" << versionArray + << "javascriptEngine" << compiledJSEngine() +/*TODO: add this back once the module system is in place -- maybe once we do something like serverstatus with callbacks*/ +// << "interpreterVersion" << globalScriptEngine->getInterpreterVersionString() + << "bits" << ( sizeof( int* ) == 4 ? 32 : 64 ); + result.appendBool( "debug" , debug ); + result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize); + } +} diff --git a/src/mongo/util/version_reporting.h b/src/mongo/util/version_reporting.h new file mode 100644 index 00000000000..278a2ec0e69 --- /dev/null +++ b/src/mongo/util/version_reporting.h @@ -0,0 +1,56 @@ +/** +* Copyright (C) 2012 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 . +* +* 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. +*/ + +#pragma once + +#include + +namespace mongo { + class BSONObjBuilder; + + void appendBuildInfo(BSONObjBuilder& result); + + const char * gitVersion(); + const char * compiledJSEngine(); + const char * allocator(); + const char * loaderFlags(); + const char * compilerFlags(); + + void printGitVersion(); + + const std::string openSSLVersion(const std::string &prefix = "", const std::string &suffix = ""); + void printOpenSSLVersion(); + + std::string sysInfo(); + void printSysInfo(); + void printTargetMinOS(); + void printAllocator(); + + void show_warnings(); + +} // namespace mongo -- cgit v1.2.1