diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f31fb58a74c..99367e0fdd45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -321,7 +321,7 @@ endif() # Get the current commit ref execute_process( - COMMAND git describe --tags --always --dirty=-modified + COMMAND git describe --tags --always WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE GIT_DESCRIBE OUTPUT_STRIP_TRAILING_WHITESPACE @@ -333,20 +333,6 @@ else() message(STATUS "Git describe: ${GIT_DESCRIBE}") endif() -# Get the current commit date -execute_process( - COMMAND git show --quiet --format=%cI --date=short - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_DATE - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET -) -if(NOT GIT_COMMIT_DATE) - message(STATUS "Git commit date: unknown") -else() - message(STATUS "Git commit date: ${GIT_COMMIT_DATE}") -endif() - # Get the current working branch execute_process( COMMAND git rev-parse --abbrev-ref HEAD @@ -372,18 +358,8 @@ execute_process( if(NOT GIT_COMMIT_COUNT) set(GIT_COMMIT_COUNT "unknown") endif() - -# Check if the worktree is dirty -execute_process( - COMMAND git diff --quiet - RESULT_VARIABLE GIT_WORKTREE_DIRTY - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - ERROR_QUIET -) -if(GIT_WORKTREE_DIRTY EQUAL "1") - set(GIT_COMMIT_COUNT "${GIT_COMMIT_COUNT}+") -endif() message(STATUS "Git commit count: ${GIT_COMMIT_COUNT}") + if(MSVC) # sccache support find_program(SCCACHE_EXECUTABLE "sccache") @@ -1190,7 +1166,22 @@ endif() # The mixxx executable add_executable(mixxx WIN32 src/main.cpp) set_target_properties(mixxx-lib PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}") -target_link_libraries(mixxx PUBLIC mixxx-lib) +target_link_libraries(mixxx PUBLIC mixxx-lib mixxx-build-date) + +add_library(mixxx-build-date STATIC EXCLUDE_FROM_ALL + ${CMAKE_BINARY_DIR}/src/builddate.cpp +) +target_include_directories(mixxx-build-date PUBLIC src) + +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/src/builddate.cpp + DEPENDS mixxx-lib src/builddate.cpp.in + COMMAND ${CMAKE_COMMAND} + -D CMAKE_BINARY_DIR_=${CMAKE_BINARY_DIR} + -D CMAKE_SOURCE_DIR_=${CMAKE_SOURCE_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/builddate.cmake + VERBATIM +) # # Installation and Packaging @@ -1566,7 +1557,7 @@ add_executable(mixxx-test src/test/wwidgetstack_test.cpp ) set_target_properties(mixxx-test PROPERTIES AUTOMOC ON) -target_link_libraries(mixxx-test PUBLIC mixxx-lib gtest gmock) +target_link_libraries(mixxx-test PUBLIC mixxx-lib mixxx-build-date gtest gmock) # # Benchmark tests diff --git a/cmake/builddate.cmake b/cmake/builddate.cmake new file mode 100644 index 000000000000..d19b902454e1 --- /dev/null +++ b/cmake/builddate.cmake @@ -0,0 +1,27 @@ +# Check if the worktree is dirty +execute_process( + COMMAND git diff --quiet + RESULT_VARIABLE DIRTY + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR_} + ERROR_QUIET +) + +if(DIRTY EQUAL "1") + message(STATUS "Git worktree is dirty") + # This depends on mixxx-lib so it will pick a new date + # Whenever mixxx-lib has changed. + string(TIMESTAMP BUILD_DATE "%Y-%m-%dT%H:%M:%SZ" UTC) +else() + message(STATUS "Git worktree is clean") + # Get the current commit date in case the build tree is unchanged + # The leads to reproducible builds + execute_process( + COMMAND git show --quiet --format=%cI --date=short + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR_} + OUTPUT_VARIABLE BUILD_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) +endif() + +configure_file(${CMAKE_SOURCE_DIR_}/src/builddate.cpp.in ${CMAKE_BINARY_DIR_}/src/builddate.cpp @ONLY) diff --git a/src/builddate.cpp.in b/src/builddate.cpp.in new file mode 100644 index 000000000000..61021ce190e9 --- /dev/null +++ b/src/builddate.cpp.in @@ -0,0 +1,11 @@ +#include "builddate.h" + +//static +const char* BuildDate::date() { + return "@BUILD_DATE@"; +}; + +//static +bool BuildDate::dirty() { + return static_cast(1); +}; diff --git a/src/builddate.h b/src/builddate.h new file mode 100644 index 000000000000..9a97077906e9 --- /dev/null +++ b/src/builddate.h @@ -0,0 +1,7 @@ +#pragma once + +class BuildDate { + public: + static const char* date(); + static bool dirty(); +}; diff --git a/src/dialog/dlgaboutdlg.ui b/src/dialog/dlgaboutdlg.ui index 22cf96e86886..028e94299cd9 100644 --- a/src/dialog/dlgaboutdlg.ui +++ b/src/dialog/dlgaboutdlg.ui @@ -91,7 +91,7 @@ - Git Commit Date: + Date: @@ -136,6 +136,9 @@ Unknown + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + diff --git a/src/util/versionstore.cpp b/src/util/versionstore.cpp index 6a42509ce944..9822361bfd74 100644 --- a/src/util/versionstore.cpp +++ b/src/util/versionstore.cpp @@ -29,6 +29,7 @@ #include #define VERSION_STORE +#include "builddate.h" #include "version.h" namespace { @@ -39,7 +40,6 @@ const QString kMixxxVersionSuffix = QString(MIXXX_VERSION_SUFFIX); const QString kMixxx = QStringLiteral("Mixxx"); const QString kGitBranch = QString(GIT_BRANCH); const QString kGitDescribe = QString(GIT_DESCRIBE); -const QDateTime kGitCommitDate = QDateTime::fromString(GIT_COMMIT_DATE, Qt::ISODate); const QString kBuildFlags = QString(BUILD_FLAGS); } // namespace @@ -64,7 +64,7 @@ QString VersionStore::versionSuffix() { } QDateTime VersionStore::date() { - return kGitCommitDate; + return QDateTime::fromString(BuildDate::date(), Qt::ISODate); } // static @@ -128,6 +128,10 @@ QString VersionStore::gitVersion() { gitVersion = QStringLiteral("unknown"); } + if (BuildDate::dirty()) { + gitVersion.append(QStringLiteral("-modified")); + } + QString gitBranch = VersionStore::gitBranch(); if (!gitBranch.isEmpty()) { gitVersion.append(QStringLiteral(" (") + gitBranch + QStringLiteral(" branch)"));