-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git info store object #3848
Git info store object #3848
Changes from 3 commits
24104a5
c07a903
57b23dd
0a585ec
ffe0b2f
2762a69
fa5590b
c1c01cc
fc3406e
6dc4793
d2c00b3
883bba7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1124,7 +1124,7 @@ 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-gitinfostore) | ||
|
||
# | ||
# Installation and Packaging | ||
|
@@ -1500,7 +1500,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-gitinfostore gtest gmock) | ||
|
||
# | ||
# Benchmark tests | ||
|
@@ -1607,16 +1607,27 @@ get_target_property(MIXXX_BUILD_FLAGS mixxx-lib COMPILE_OPTIONS) | |
# uses CMAKE_PROJECT_VERSION MIXXX_VERSION_PRERELEASE MIXXX_BUILD_FLAGS | ||
configure_file(src/version.h.in src/version.h @ONLY) | ||
|
||
if(GIT_COMMIT_DATE AND NOT GIT_COMMIT_DATE MATCHES "^[0-9]*-[0-9]*-[0-9]*T[0-9]*\\:[0-9]*\\:[0-9]*[+-][0-9]*\\:[0-9]*$") | ||
message(FATAL_ERROR "GIT_COMMIT_DATE requires strict ISO 8601 format %Y-%m-%dT%H:%M:%SZ") | ||
endif() | ||
|
||
add_custom_target(mixxx-gitinfo | ||
COMMAND ${CMAKE_COMMAND} | ||
-DGIT_DESCRIBE="${GIT_DESCRIBE}" | ||
-DGIT_COMMIT_DATE="${GIT_COMMIT_DATE}" | ||
-DINPUT_FILE="${CMAKE_CURRENT_SOURCE_DIR}/src/gitinfo.h.in" | ||
-DOUTPUT_FILE="${CMAKE_CURRENT_BINARY_DIR}/src/gitinfo.h" | ||
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/gitinfo.cmake" | ||
COMMENT "Update git version information in gitinfo.h" | ||
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/src/gitinfo.h" | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
) | ||
add_dependencies(mixxx-lib mixxx-gitinfo) | ||
|
||
add_library(mixxx-gitinfostore STATIC EXCLUDE_FROM_ALL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for making this a separate library? Why not add it to mixxx-lib instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve build time. Re-linking it to mixxx-lib takes long, even if just the git info changes. |
||
src/util/gitinfostore.cpp | ||
) | ||
target_include_directories(mixxx-gitinfostore PUBLIC src ${CMAKE_BINARY_DIR}/src) | ||
add_dependencies(mixxx-gitinfostore mixxx-gitinfo) | ||
|
||
# Windows-only resource file | ||
if(WIN32) | ||
|
@@ -1639,8 +1650,8 @@ if(WIN32) | |
|
||
# uses MIXXX_YEAR MIXXX_FILEVERSION MIXXX_PRODUCTVERSION MIXXX_VERSION MIXXX_DEBUG MIXXX_PRERELEASE | ||
configure_file( | ||
"${CMAKE_CURRENT_SOURCE_DIR}/src/mixxx.rc.include.template" | ||
"${CMAKE_CURRENT_BINARY_DIR}/src/mixxx.rc.include" | ||
"src/mixxx.rc.include.in" | ||
"src/mixxx.rc.include" | ||
@ONLY | ||
) | ||
add_dependencies(mixxx mixxx-gitinfo) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,73 @@ | ||
# Get the current commit ref | ||
execute_process( | ||
COMMAND git describe --tags --always --dirty=-modified | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
OUTPUT_VARIABLE GIT_DESCRIBE | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
if(NOT GIT_DESCRIBE) | ||
message(NOTICE "Git describe: unknown") | ||
else() | ||
message(NOTICE "Git describe: ${GIT_DESCRIBE}") | ||
string(REGEX MATCH "-modified$" GIT_DIRTY "${GIT_DESCRIBE}") | ||
if (GIT_DIRTY) | ||
message("Git worktree modified: yes") | ||
set(GIT_DIRTY 1) | ||
execute_process( | ||
COMMAND git describe --tags --always --dirty=-modified | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
OUTPUT_VARIABLE GIT_DESCRIBE | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
if(NOT GIT_DESCRIBE) | ||
message(NOTICE "Git describe is unknown, you may set it via GIT_DESCRIBE") | ||
else() | ||
message(NOTICE "Git worktree modified: no") | ||
set(GIT_DIRTY 0) | ||
endif() | ||
endif() | ||
message(NOTICE "Git describe: ${GIT_DESCRIBE}") | ||
string(REGEX MATCH "-modified$" GIT_DIRTY "${GIT_DESCRIBE}") | ||
if (GIT_DIRTY) | ||
message("Git worktree modified: yes") | ||
set(GIT_DIRTY 1) | ||
else() | ||
message(NOTICE "Git worktree modified: no") | ||
set(GIT_DIRTY 0) | ||
endif() | ||
|
||
# Get the current working branch | ||
execute_process( | ||
COMMAND git rev-parse --abbrev-ref HEAD | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
OUTPUT_VARIABLE GIT_BRANCH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
if(NOT GIT_BRANCH) | ||
message(NOTICE "Git branch: unknown") | ||
else() | ||
message(NOTICE "Git branch: ${GIT_BRANCH}") | ||
endif() | ||
|
||
# Get the current working branch | ||
execute_process( | ||
COMMAND git rev-parse --abbrev-ref HEAD | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
OUTPUT_VARIABLE GIT_BRANCH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
if(NOT GIT_BRANCH) | ||
message(NOTICE "Git branch: unknown") | ||
# Get the number of commits on the working branch | ||
execute_process( | ||
COMMAND git rev-list --count --first-parent HEAD | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
OUTPUT_VARIABLE GIT_COMMIT_COUNT | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
if(NOT GIT_COMMIT_COUNT) | ||
message(NOTICE "Git commit count: unknown") | ||
else() | ||
message(NOTICE "Git commit count: ${GIT_COMMIT_COUNT}") | ||
endif() | ||
endif() | ||
else() | ||
message(NOTICE "Git branch: ${GIT_BRANCH}") | ||
message(NOTICE "Git describe: ${GIT_DESCRIBE}") | ||
endif() | ||
|
||
# Get the current commit date | ||
execute_process( | ||
COMMAND git show --quiet --format=%cI --date=short | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
OUTPUT_VARIABLE GIT_COMMIT_DATE | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
if(NOT GIT_COMMIT_DATE) | ||
message(NOTICE "Git commit date: unknown") | ||
else() | ||
message(NOTICE "Git commit date: ${GIT_COMMIT_DATE}") | ||
string(REGEX MATCH "^[0-9][0-9][0-9][0-9]" GIT_COMMIT_YEAR "${GIT_COMMIT_DATE}") | ||
message(NOTICE "Git commit year: ${GIT_COMMIT_YEAR}") | ||
execute_process( | ||
COMMAND git show --quiet --format=%cI --date=short | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
OUTPUT_VARIABLE GIT_COMMIT_DATE | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
endif() | ||
|
||
# Get the number of commits on the working branch | ||
execute_process( | ||
COMMAND git rev-list --count --first-parent HEAD | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
OUTPUT_VARIABLE GIT_COMMIT_COUNT | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
if(NOT GIT_COMMIT_COUNT) | ||
message(NOTICE "Git commit count: unknown") | ||
if(NOT GIT_COMMIT_DATE) | ||
message(NOTICE "Git commit date unknown, using current time for GIT_COMMIT_DATE") | ||
# use current date in case of tar ball builds | ||
string(TIMESTAMP GIT_COMMIT_DATE "%Y-%m-%dT%H:%M:%SZ" UTC) | ||
else() | ||
message(NOTICE "Git commit count: ${GIT_COMMIT_COUNT}") | ||
message(NOTICE "Git commit date: ${GIT_COMMIT_DATE}") | ||
endif() | ||
string(REGEX MATCH "^[0-9][0-9][0-9][0-9]" GIT_COMMIT_YEAR "${GIT_COMMIT_DATE}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<!-- | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated change |
||
Shade, Skin for Mixxx 2.1.x | ||
www.mixxx.org | ||
Copyright (C) 2010-2014 jus <[email protected]> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#define VERSION_STORE | ||
#define GIT_INFO | ||
#include "gitinfo.h" | ||
|
||
#ifdef GIT_COMMIT_YEAR | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "util/gitinfostore.h" | ||
|
||
#define GIT_INFO | ||
#include "gitinfo.h" | ||
|
||
//static | ||
const char* GitInfoStore::branch() { | ||
return GIT_BRANCH; | ||
}; | ||
|
||
//static | ||
const char* GitInfoStore::describe() { | ||
return GIT_DESCRIBE; | ||
}; | ||
|
||
//static | ||
const char* GitInfoStore::date() { | ||
return GIT_COMMIT_DATE; | ||
}; | ||
|
||
//static | ||
int GitInfoStore::commitCount() { | ||
#ifdef GIT_COMMIT_COUNT | ||
return GIT_COMMIT_COUNT; | ||
#else | ||
return 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 maybe? or use std::optional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0 fits, because we have 0 commits if we are off the git worktree |
||
#endif | ||
}; | ||
|
||
//static | ||
bool GitInfoStore::dirty() { | ||
#ifdef GIT_DIRTY | ||
return true; | ||
#else | ||
return false; | ||
#endif | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
class GitInfoStore { | ||
public: | ||
static const char* branch(); | ||
static const char* describe(); | ||
static const char* date(); | ||
int commitCount(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. static? |
||
static bool dirty(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,18 +29,14 @@ | |
#include <vorbis/codec.h> | ||
|
||
#include "version.h" | ||
#define VERSION_STORE | ||
#include "gitinfo.h" | ||
#include "util/gitinfostore.h" | ||
|
||
namespace { | ||
|
||
const QVersionNumber kMixxxVersionNumber = QVersionNumber( | ||
MIXXX_VERSION_MAJOR, MIXXX_VERSION_MINOR, MIXXX_VERSION_PATCH); | ||
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(MIXXX_BUILD_FLAGS); | ||
|
||
} // namespace | ||
|
@@ -65,7 +61,7 @@ QString VersionStore::versionSuffix() { | |
} | ||
|
||
QDateTime VersionStore::date() { | ||
return kGitCommitDate; | ||
return QDateTime::fromString(GitInfoStore::date(), Qt::ISODate); | ||
} | ||
|
||
// static | ||
|
@@ -114,24 +110,24 @@ QString VersionStore::platform() { | |
|
||
// static | ||
QString VersionStore::gitBranch() { | ||
return kGitBranch; | ||
return GitInfoStore::branch(); | ||
} | ||
|
||
// static | ||
QString VersionStore::gitDescribe() { | ||
return kGitDescribe; | ||
return GitInfoStore::describe(); | ||
} | ||
|
||
// static | ||
QString VersionStore::gitVersion() { | ||
QString gitVersion = VersionStore::gitDescribe(); | ||
QString gitVersion = GitInfoStore::describe(); | ||
if (gitVersion.isEmpty()) { | ||
gitVersion = QStringLiteral("unknown"); | ||
} | ||
|
||
QString gitBranch = VersionStore::gitBranch(); | ||
if (!gitBranch.isEmpty()) { | ||
gitVersion.append(QStringLiteral(" (") + gitBranch + QStringLiteral(" branch)")); | ||
gitVersion.append(QStringLiteral(" (") + gitBranch + QChar(')')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay with this change to make the about window a bit less wide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can even remove the branch name if it matches the version There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may, but I don't think it's necessary. In any case this should happen in the cpp code, not in the CMake code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah you already did. |
||
} | ||
|
||
return gitVersion; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about CPackConfig? I think you need to copy these variables into the CPack domain as well, and set them before including the
GitInfo
module.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daschuer ping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, we should allow to use the override values in cpack as well.