Skip to content

Commit

Permalink
Add Git hash and LLVM version info to Spice executable version info (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer authored Jan 4, 2025
1 parent 6913fa4 commit 190fa6f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .run/spice run.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="spice run" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -O0 -d -ir ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<configuration default="false" name="spice run" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -O0 -d -ir ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug-MinGW" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<envs>
<env name="LLVM_ADDITIONAL_FLAGS" value="-lole32 -lws2_32" />
<env name="LLVM_BUILD_INCLUDE_DIR" value="$PROJECT_DIR$/../llvm-project-latest/build/include" />
Expand Down
22 changes: 21 additions & 1 deletion Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")

Expand Down
6 changes: 4 additions & 2 deletions src/util/CommonUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ std::string CommonUtil::getCircularImportMessage(std::stack<const SourceFile *>
*/
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();
}
Expand Down
5 changes: 3 additions & 2 deletions test/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "Driver.h"

#include "util/CommonUtil.h"

// GCOV_EXCL_START

void Driver::createInterface() {
Expand All @@ -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) {
Expand Down

0 comments on commit 190fa6f

Please sign in to comment.