From 190fa6f84382f310fd789d841968fa0c0f14576c Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Sun, 5 Jan 2025 00:07:44 +0100 Subject: [PATCH] Add Git hash and LLVM version info to Spice executable version info (#695) --- .run/spice run.run.xml | 2 +- Options.cmake | 22 +++++++++++++++++++++- src/util/CommonUtil.cpp | 6 ++++-- test/driver/Driver.cpp | 5 +++-- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.run/spice run.run.xml b/.run/spice run.run.xml index f1152f57e..f3466021c 100644 --- a/.run/spice run.run.xml +++ b/.run/spice run.run.xml @@ -1,5 +1,5 @@ - + diff --git a/Options.cmake b/Options.cmake index 713830ddd..8cc5039da 100644 --- a/Options.cmake +++ b/Options.cmake @@ -39,8 +39,28 @@ set(SPICE_VERSION "dev" CACHE STRING "Spice build version") add_definitions(-DSPICE_VERSION="${SPICE_VERSION}") message(STATUS "Spice: Build version is set to '${SPICE_VERSION}'") +# Spice Git hash (defaults to current Git hash) +execute_process( + COMMAND git rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE SPICE_GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) +if(NOT SPICE_GIT_HASH) + set(SPICE_GIT_HASH "dev" CACHE STRING "Spice Git hash") +endif() +add_definitions(-DSPICE_GIT_HASH="${SPICE_GIT_HASH}") +message(STATUS "Spice: Git hash is set to '${SPICE_GIT_HASH}'") + # Spice built by -set(SPICE_BUILT_BY "$ENV{USERNAME}" CACHE STRING "Spice built by person") +if(DEFINED ENV{USERNAME}) + set(SPICE_BUILT_BY "$ENV{USERNAME}") +elseif(DEFINED ENV{USER}) + set(SPICE_BUILT_BY "$ENV{USER}") +else() + set(SPICE_BUILT_BY "unknown") +endif() +set(SPICE_BUILT_BY "${SPICE_BUILT_BY}" CACHE STRING "Spice built by person") add_definitions(-DSPICE_BUILT_BY="${SPICE_BUILT_BY}") message(STATUS "Spice: Built by is set to '${SPICE_BUILT_BY}'") diff --git a/src/util/CommonUtil.cpp b/src/util/CommonUtil.cpp index 5cec21163..4e3296acc 100644 --- a/src/util/CommonUtil.cpp +++ b/src/util/CommonUtil.cpp @@ -166,8 +166,10 @@ std::string CommonUtil::getCircularImportMessage(std::stack */ std::string CommonUtil::getVersionInfo() { std::stringstream versionString; - versionString << "spice version " << SPICE_VERSION << " " << SPICE_TARGET_OS << "/" << SPICE_TARGET_ARCH << "\n"; - versionString << "built by: " << SPICE_BUILT_BY << "\n\n"; + versionString << "Spice version: " << SPICE_VERSION << " " << SPICE_TARGET_OS << "/" << SPICE_TARGET_ARCH << "\n"; + versionString << "Git hash: " << SPICE_GIT_HASH << "\n"; + versionString << "LLVM version: " << LLVM_VERSION_STRING << "\n"; + versionString << "built by: " << SPICE_BUILT_BY << "\n\n"; versionString << "(c) Marc Auberer 2021-2025"; return versionString.str(); } diff --git a/test/driver/Driver.cpp b/test/driver/Driver.cpp index a1cf41b4a..9340e1273 100644 --- a/test/driver/Driver.cpp +++ b/test/driver/Driver.cpp @@ -2,6 +2,8 @@ #include "Driver.h" +#include "util/CommonUtil.h" + // GCOV_EXCL_START void Driver::createInterface() { @@ -14,8 +16,7 @@ void Driver::createInterface() { // Add version flag const std::string versionName(SPICE_VERSION); const std::string builtBy(SPICE_BUILT_BY); - const std::string versionString = "Spice version " + versionName + "\nbuilt by: " + builtBy + "\n\n(c) Marc Auberer 2021-2025"; - app.set_version_flag("--version,-v", versionString); + app.set_version_flag("--version,-v", spice::compiler::CommonUtil::getVersionInfo()); } void Driver::addOptions(bool &updateRefs, bool &runBenchmarks, bool &enableLeakDetection, bool &skipNonGitHubTests) {