From cafcb3f238fdbd33b34a76b56d5cd350c1379d3c Mon Sep 17 00:00:00 2001 From: sjunges Date: Wed, 8 Oct 2014 01:05:37 +0200 Subject: [PATCH] version info extended and moved to cpp, added options flag (although unclear what exactly should be displayed then) Former-commit-id: 3c82455d24bcdaf13c590c0c1f9a273e0078780b --- CMakeLists.txt | 15 +++--- src/settings/SettingsManager.cpp | 6 +++ src/settings/SettingsManager.h | 5 ++ src/settings/modules/GeneralSettings.cpp | 6 +++ src/settings/modules/GeneralSettings.h | 9 ++++ src/utility/cli.h | 22 ++++---- src/utility/storm-version.h | 66 ++++++++++++++++++++++++ storm-version.cpp.in | 28 ++++++++++ storm-version.h.in | 12 ----- 9 files changed, 140 insertions(+), 29 deletions(-) create mode 100644 src/utility/storm-version.h create mode 100644 storm-version.cpp.in delete mode 100644 storm-version.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 80d5d806f..e42817b3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,7 +93,7 @@ message(STATUS "StoRM - CMAKE_BUILD_TYPE (ENV): $ENV{CMAKE_BUILD_TYPE}") set(CONVERSIONHELPER_TARGET "${PROJECT_SOURCE_DIR}/src/utility/ConversionHelper.cpp") if(CMAKE_COMPILER_IS_GNUCC) - message(STATUS "StoRM - Using Compiler Configuration: GCC") + set(STORM_COMPILED_BY "GCC") # Set standard flags for GCC set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic -DBOOST_RESULT_OF_USE_TR1") @@ -109,7 +109,7 @@ if(CMAKE_COMPILER_IS_GNUCC) # Set the no-strict-aliasing target for GCC set_source_files_properties(${CONVERSIONHELPER_TARGET} PROPERTIES COMPILE_FLAGS " -fno-strict-aliasing ") elseif(MSVC) - message(STATUS "StoRM - Using Compiler Configuration: MSVC") + set(STORM_COMPILED_BY "MSVC") # required for GMM to compile, ugly error directive in their code add_definitions(/D_SCL_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS) # required as the PRCTL Parser bloats object files (COFF) beyond their maximum size (see http://msdn.microsoft.com/en-us/library/8578y171(v=vs.110).aspx) @@ -128,7 +128,7 @@ elseif(MSVC) # MSVC does not do strict-aliasing, so no option needed else(CLANG) - message(STATUS "StoRM - Using Compiler Configuration: Clang (LLVM)") + set(STORM_COMPILED_BY "Clang (LLVM)") # As CLANG is not set as a variable, we need to set it in case we have not matched another compiler. set (CLANG ON) # Set standard flags for clang @@ -159,6 +159,8 @@ else(CLANG) set_source_files_properties(${CONVERSIONHELPER_TARGET} PROPERTIES COMPILE_FLAGS " -fno-strict-aliasing ") endif() +message(STATUS "StoRM - Using Compiler Configuration: ${STORM_COMPILED_BY}") + ############################################################# ## ## CMake-generated Config File for StoRM @@ -219,8 +221,8 @@ configure_file ( # Configure a header file to pass the storm version to the source code configure_file ( - "${PROJECT_SOURCE_DIR}/storm-version.h.in" - "${PROJECT_BINARY_DIR}/include/storm-version.h" + "${PROJECT_SOURCE_DIR}/storm-version.cpp.in" + "${PROJECT_SOURCE_DIR}/src/utility/storm-version.cpp" ) # Add the binary dir include directory for storm-config.h @@ -266,6 +268,7 @@ file(GLOB_RECURSE STORM_PERFORMANCE_TEST_FILES ${STORM_CPP_TESTS_BASE_PATH}/perf # Additional include files like the storm-config.h file(GLOB_RECURSE STORM_BUILD_HEADERS ${PROJECT_BINARY_DIR}/include/*.h) + # Group the headers and sources source_group(main FILES ${STORM_MAIN_FILE}) source_group(adapters FILES ${STORM_ADAPTERS_FILES}) @@ -275,7 +278,7 @@ source_group(properties\\csl FILES ${STORM_PROPERTIES_CSL_FILES}) source_group(properties\\ltl FILES ${STORM_PROPERTIES_LTL_FILES}) source_group(properties\\prctl FILES ${STORM_PROPERTIES_PRCTL_FILES}) source_group(properties\\actions FILES ${STORM_PROPERTIES_ACTIONS_FILES}) -source_group(generated FILES ${STORM_BUILD_HEADERS}) +source_group(generated FILES ${STORM_BUILD_HEADERS} ${STORM_BUILD_SOURCES}) source_group(modelchecker FILES ${STORM_MODELCHECKER_FILES}) source_group(counterexamples FILES ${STORM_COUNTEREXAMPLES_FILES}) source_group(models FILES ${STORM_MODELS_FILES}) diff --git a/src/settings/SettingsManager.cpp b/src/settings/SettingsManager.cpp index 26fb6070d..5c311c602 100644 --- a/src/settings/SettingsManager.cpp +++ b/src/settings/SettingsManager.cpp @@ -11,6 +11,7 @@ #include "src/exceptions/IllegalFunctionCallException.h" #include "src/exceptions/OptionParserException.h" +#include "src/utility/storm-version.h" namespace storm { namespace settings { @@ -229,6 +230,11 @@ namespace storm { STORM_PRINT(std::endl); } + void SettingsManager::printVersion() const { + STORM_PRINT(storm::utility::StormVersion::shortVersionString()); + STORM_PRINT(std::endl); + } + uint_fast64_t SettingsManager::getPrintLengthOfLongestOption() const { uint_fast64_t length = 0; for (auto const& moduleName : this->moduleNames) { diff --git a/src/settings/SettingsManager.h b/src/settings/SettingsManager.h index 41383f336..3daa43beb 100644 --- a/src/settings/SettingsManager.h +++ b/src/settings/SettingsManager.h @@ -91,6 +91,11 @@ namespace storm { */ void printHelpForModule(std::string const& moduleName, uint_fast64_t maxLength = 30) const; + /*! + * This function prints the version string to the command line. + */ + void printVersion() const; + /*! * Retrieves the only existing instance of a settings manager. * diff --git a/src/settings/modules/GeneralSettings.cpp b/src/settings/modules/GeneralSettings.cpp index 585bcfdfb..e310a68c8 100644 --- a/src/settings/modules/GeneralSettings.cpp +++ b/src/settings/modules/GeneralSettings.cpp @@ -11,6 +11,7 @@ namespace storm { const std::string GeneralSettings::moduleName = "general"; const std::string GeneralSettings::helpOptionName = "help"; const std::string GeneralSettings::helpOptionShortName = "h"; + const std::string GeneralSettings::versionOptionName = "version"; const std::string GeneralSettings::verboseOptionName = "verbose"; const std::string GeneralSettings::verboseOptionShortName = "v"; const std::string GeneralSettings::precisionOptionName = "precision"; @@ -46,6 +47,7 @@ namespace storm { GeneralSettings::GeneralSettings(storm::settings::SettingsManager& settingsManager) : ModuleSettings(settingsManager, moduleName) { this->addOption(storm::settings::OptionBuilder(moduleName, helpOptionName, false, "Shows all available options, arguments and descriptions.").setShortName(helpOptionShortName) .addArgument(storm::settings::ArgumentBuilder::createStringArgument("hint", "A regular expression to show help for all matching entities or 'all' for the complete help.").setDefaultValueString("all").build()).build()); + this->addOption(storm::settings::OptionBuilder(moduleName, versionOptionName, false, "Prints the version information.").build()); this->addOption(storm::settings::OptionBuilder(moduleName, verboseOptionName, false, "Enables more verbose output.").setShortName(verboseOptionShortName).build()); this->addOption(storm::settings::OptionBuilder(moduleName, precisionOptionName, false, "The internally used precision.").setShortName(precisionOptionShortName) .addArgument(storm::settings::ArgumentBuilder::createDoubleArgument("value", "The precision to use.").setDefaultValueDouble(1e-06).addValidationFunctionDouble(storm::settings::ArgumentValidators::doubleRangeValidatorExcluding(0.0, 1.0)).build()).build()); @@ -98,6 +100,10 @@ namespace storm { return this->getOption(helpOptionName).getHasOptionBeenSet(); } + bool GeneralSettings::isVersionSet() const { + return this->getOption(versionOptionName).getHasOptionBeenSet(); + } + std::string GeneralSettings::getHelpModuleName() const { return this->getOption(helpOptionName).getArgumentByName("hint").getValueAsString(); } diff --git a/src/settings/modules/GeneralSettings.h b/src/settings/modules/GeneralSettings.h index 75f48d8f1..912053083 100644 --- a/src/settings/modules/GeneralSettings.h +++ b/src/settings/modules/GeneralSettings.h @@ -32,6 +32,14 @@ namespace storm { */ bool isHelpSet() const; + /*! + * Retrieves whether the version option was set. + * + * @return True if the version option was set. + */ + bool isVersionSet() const; + + /*! * Retrieves the name of the module for which to show the help or "all" to indicate that the full help * needs to be shown. @@ -323,6 +331,7 @@ namespace storm { // Define the string names of the options as constants. static const std::string helpOptionName; static const std::string helpOptionShortName; + static const std::string versionOptionName; static const std::string verboseOptionName; static const std::string verboseOptionShortName; static const std::string precisionOptionName; diff --git a/src/utility/cli.h b/src/utility/cli.h index 4ceb64a95..ebd8a9bc7 100644 --- a/src/utility/cli.h +++ b/src/utility/cli.h @@ -29,6 +29,7 @@ log4cplus::Logger logger; // Headers that provide auxiliary functionality. +#include "src/utility/storm-version.h" #include "src/utility/OsDetection.h" #include "src/settings/SettingsManager.h" @@ -49,6 +50,7 @@ log4cplus::Logger logger; // Headers related to exception handling. #include "src/exceptions/InvalidSettingsException.h" +#include "src/exceptions/InvalidTypeException.h" namespace storm { namespace utility { @@ -108,17 +110,9 @@ namespace storm { void printHeader(const int argc, const char* argv[]) { std::cout << "StoRM" << std::endl; std::cout << "-----" << std::endl << std::endl; - - std::cout << "Version: " << STORM_CPP_VERSION_MAJOR << "." << STORM_CPP_VERSION_MINOR << "." << STORM_CPP_VERSION_PATCH; - if (STORM_CPP_VERSION_COMMITS_AHEAD != 0) { - std::cout << " (+" << STORM_CPP_VERSION_COMMITS_AHEAD << " commits)"; - } - std::cout << " build from revision " << STORM_CPP_VERSION_HASH; - if (STORM_CPP_VERSION_DIRTY == 1) { - std::cout << " (DIRTY)"; - } - std::cout << "." << std::endl; - + + + std::cout << storm::utility::StormVersion::longVersionString() << std::endl; #ifdef STORM_HAVE_INTELTBB std::cout << "Linked with Intel Threading Building Blocks v" << TBB_VERSION_MAJOR << "." << TBB_VERSION_MINOR << " (Interface version " << TBB_INTERFACE_VERSION << ")." << std::endl; #endif @@ -208,6 +202,12 @@ namespace storm { storm::settings::manager().printHelp(storm::settings::generalSettings().getHelpModuleName()); return false; } + + if (storm::settings::generalSettings().isVersionSet()) { + storm::settings::manager().printVersion(); + return false; + } + if (storm::settings::generalSettings().isVerboseSet()) { logger.getAppender("mainConsoleAppender")->setThreshold(log4cplus::INFO_LOG_LEVEL); diff --git a/src/utility/storm-version.h b/src/utility/storm-version.h new file mode 100644 index 000000000..12a92f142 --- /dev/null +++ b/src/utility/storm-version.h @@ -0,0 +1,66 @@ +/** + * @file: storm-version.h + * @author: Sebastian Junges + * + * @since October 7, 2014 + */ + +#pragma once +#include +#include + +namespace storm +{ + namespace utility { + struct StormVersion + { + /// The major version of StoRM + const static unsigned versionMajor; + /// The minor version of StoRM + const static unsigned versionMinor; + /// The patch version of StoRM + const static unsigned versionPatch; + /// The short hash of the git commit this build is bases on + const static std::string gitRevisionHash; + /// How many commits passed since the tag was last set + const static unsigned commitsAhead; + /// 0 iff there no files were modified in the checkout, 1 else + const static unsigned dirty; + /// The system which has compiled storm + const static std::string systemName; + /// The system version which has compiled storm + const static std::string systemVersion; + /// The build type that was used to build storm + const static std::string buildType; + /// The compiler version that was used to build storm + const static std::string cxxCompiler; + + static std::string shortVersionString() { + std::stringstream sstream; + sstream << "StoRM " << versionMajor << "." << versionMinor << "." << versionPatch; + return sstream.str(); + } + + static std::string longVersionString() { + std::stringstream sstream; + sstream << "Version: " << versionMajor << "." << versionMinor << "." << versionPatch; + if (commitsAhead != 0) { + sstream << " (+" << commitsAhead << " commits)"; + } + sstream << " build from revision " << gitRevisionHash; + if (dirty == 1) { + sstream << " (DIRTY)"; + } + sstream << "." << std::endl; + return sstream.str(); + } + + static std::string buildInfo() { + std::stringstream sstream; + sstream << "Compiled on " << systemName << " " << systemVersion << ","; + sstream << "using " << cxxCompiler << " with " << buildType << " flags."; + return sstream.str(); + } + }; + } +} diff --git a/storm-version.cpp.in b/storm-version.cpp.in new file mode 100644 index 000000000..c35b0c2af --- /dev/null +++ b/storm-version.cpp.in @@ -0,0 +1,28 @@ +#include "src/utility/storm-version.h" + +namespace storm +{ +namespace utility +{ +// The major version of StoRM +const unsigned StormVersion::versionMajor = @STORM_CPP_VERSION_MAJOR@; +// The minor version of StoRM +const unsigned StormVersion::versionMinor = @STORM_CPP_VERSION_MINOR@; +// The patch version of StoRM +const unsigned StormVersion::versionPatch = @STORM_CPP_VERSION_PATCH@; +// The short hash of the git commit this build is bases on +const std::string StormVersion::gitRevisionHash = "@STORM_CPP_VERSION_HASH@"; +// How many commits passed since the tag was last set +const unsigned StormVersion::commitsAhead = @STORM_CPP_VERSION_COMMITS_AHEAD@; +// 0 iff there no files were modified in the checkout, 1 else +const unsigned StormVersion::dirty = @STORM_CPP_VERSION_DIRTY@; +// The system which has compiled storm +const std::string StormVersion::systemName = "@CMAKE_SYSTEM_NAME@"; +// The system version which has compiled storm +const std::string StormVersion::systemVersion = "@CMAKE_SYSTEM_VERSION@"; +// The build type that was used to build storm +const std::string StormVersion::buildType = "@CMAKE_BUILD_TYPE@"; +// The compiler version that was used to build storm +const std::string StormVersion::cxxCompiler = "@STORM_COMPILED_BY@ @CMAKE_CXX_COMPILER_VERSION@"; +} +} \ No newline at end of file diff --git a/storm-version.h.in b/storm-version.h.in deleted file mode 100644 index 5ccac6125..000000000 --- a/storm-version.h.in +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef STORM_GENERATED_VERSION_H_ -#define STORM_GENERATED_VERSION_H_ - -// Version Information -#define STORM_CPP_VERSION_MAJOR @STORM_CPP_VERSION_MAJOR@ // The major version of StoRM -#define STORM_CPP_VERSION_MINOR @STORM_CPP_VERSION_MINOR@ // The minor version of StoRM -#define STORM_CPP_VERSION_PATCH @STORM_CPP_VERSION_PATCH@ // The patch version of StoRM -#define STORM_CPP_VERSION_COMMITS_AHEAD @STORM_CPP_VERSION_COMMITS_AHEAD@ // How many commits passed since the tag was last set -#define STORM_CPP_VERSION_HASH "@STORM_CPP_VERSION_HASH@" // The short hash of the git commit this build is bases on -#define STORM_CPP_VERSION_DIRTY @STORM_CPP_VERSION_DIRTY@ // 0 iff there no files were modified in the checkout, 1 else - -#endif \ No newline at end of file