From 620cd1aa35e05099b3f84400dd33afc207c98244 Mon Sep 17 00:00:00 2001 From: romibi Date: Tue, 7 Jun 2016 00:05:49 +0200 Subject: [PATCH] Replace build date with commit date (#159) Alternative to and based on PR #127 https://github.com/quassel/quassel/pull/127 This makes it possible to create reproducible builds. --- CMakeLists.txt | 11 +++++++++++ src/client/clientauthhandler.cpp | 2 +- src/common/quassel.cpp | 11 ++++++----- src/common/quassel.h | 3 +-- src/core/coreauthhandler.cpp | 4 ++-- src/core/corecoreinfo.cpp | 2 +- src/core/coresessioneventprocessor.cpp | 2 +- src/qtui/aboutdlg.cpp | 6 +++--- src/qtui/coreinfodlg.cpp | 2 +- src/qtui/ui/coreinfodlg.ui | 6 +++--- version.h.in | 1 + 11 files changed, 31 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa0b4923..d89a300a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -582,6 +582,16 @@ include(GetGitRevisionDescription) get_git_head_revision(GIT_REFSPEC GIT_HEAD) git_describe(GIT_DESCRIBE --long) +# If in a Git repo we can get the commit-date from a git command +if (GIT_HEAD) + execute_process( + COMMAND git show -s --format=%ct + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endif() + # If not in a Git repo try to read GIT_HEAD and GIT_DESCRIBE from # enviroment if (NOT GIT_HEAD OR NOT GIT_DESCRIBE) @@ -597,6 +607,7 @@ endif() if (NOT GIT_HEAD OR NOT GIT_DESCRIBE) set(GIT_HEAD "") set(GIT_DESCRIBE "") + set(GIT_COMMIT_DATE 0) endif() configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY) diff --git a/src/client/clientauthhandler.cpp b/src/client/clientauthhandler.cpp index fc793097..c8ed7359 100644 --- a/src/client/clientauthhandler.cpp +++ b/src/client/clientauthhandler.cpp @@ -288,7 +288,7 @@ void ClientAuthHandler::startRegistration() useSsl = _account.useSsl(); #endif - _peer->dispatch(RegisterClient(Quassel::buildInfo().fancyVersionString, Quassel::buildInfo().buildDate, useSsl)); + _peer->dispatch(RegisterClient(Quassel::buildInfo().fancyVersionString, Quassel::buildInfo().commitDate, useSsl)); } diff --git a/src/common/quassel.cpp b/src/common/quassel.cpp index a2638595..6671bc47 100644 --- a/src/common/quassel.cpp +++ b/src/common/quassel.cpp @@ -261,15 +261,16 @@ void Quassel::setupBuildInfo() _buildInfo.baseVersion = QUASSEL_VERSION_STRING; _buildInfo.generatedVersion = GIT_DESCRIBE; - // This will be imprecise for incremental builds not touching this file, but we really don't want to always recompile - _buildInfo.buildDate = QString("%1 %2").arg(__DATE__, __TIME__); - // Check if we got a commit hash - if (!QString(GIT_HEAD).isEmpty()) + if (!QString(GIT_HEAD).isEmpty()) { _buildInfo.commitHash = GIT_HEAD; + QDateTime date; + date.setTime_t(GIT_COMMIT_DATE); + _buildInfo.commitDate = date.toString(); + } else if (!QString(DIST_HASH).contains("Format")) { _buildInfo.commitHash = DIST_HASH; - _buildInfo.commitDate = QString(DIST_DATE).toUInt(); + _buildInfo.commitDate = QString(DIST_DATE); } // create a nice version string diff --git a/src/common/quassel.h b/src/common/quassel.h index 3b29521b..ba883b0b 100644 --- a/src/common/quassel.h +++ b/src/common/quassel.h @@ -47,8 +47,7 @@ public: QString baseVersion; QString generatedVersion; QString commitHash; - uint commitDate; - QString buildDate; + QString commitDate; uint protocolVersion; // deprecated diff --git a/src/core/coreauthhandler.cpp b/src/core/coreauthhandler.cpp index 4bd36281..e2b35219 100644 --- a/src/core/coreauthhandler.cpp +++ b/src/core/coreauthhandler.cpp @@ -181,9 +181,9 @@ void CoreAuthHandler::handle(const RegisterClient &msg) int uphours = uptime / 3600; uptime %= 3600; int upmins = uptime / 60; QString coreInfo = tr("Quassel Core Version %1
" - "Built: %2
" + "Version date: %2
" "Up %3d%4h%5m (since %6)").arg(Quassel::buildInfo().fancyVersionString) - .arg(Quassel::buildInfo().buildDate) + .arg(Quassel::buildInfo().commitDate) .arg(updays).arg(uphours, 2, 10, QChar('0')).arg(upmins, 2, 10, QChar('0')).arg(Core::instance()->startTime().toString(Qt::TextDate)); // useSsl and coreInfo are only used for the legacy protocol diff --git a/src/core/corecoreinfo.cpp b/src/core/corecoreinfo.cpp index 2fa5be80..3c1d5fe2 100644 --- a/src/core/corecoreinfo.cpp +++ b/src/core/corecoreinfo.cpp @@ -37,7 +37,7 @@ QVariantMap CoreCoreInfo::coreData() const { QVariantMap data; data["quasselVersion"] = Quassel::buildInfo().fancyVersionString; - data["quasselBuildDate"] = Quassel::buildInfo().buildDate; + data["quasselBuildDate"] = Quassel::buildInfo().commitDate; // "BuildDate" for compatibility data["startTime"] = Core::instance()->startTime(); data["sessionConnectedClients"] = _coreSession->signalProxy()->peerCount(); return data; diff --git a/src/core/coresessioneventprocessor.cpp b/src/core/coresessioneventprocessor.cpp index c32c502d..71619ef1 100644 --- a/src/core/coresessioneventprocessor.cpp +++ b/src/core/coresessioneventprocessor.cpp @@ -1306,5 +1306,5 @@ void CoreSessionEventProcessor::handleCtcpTime(CtcpEvent *e) void CoreSessionEventProcessor::handleCtcpVersion(CtcpEvent *e) { e->setReply(QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org") - .arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate)); + .arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().commitDate)); } diff --git a/src/qtui/aboutdlg.cpp b/src/qtui/aboutdlg.cpp index 211c034a..5661ac93 100644 --- a/src/qtui/aboutdlg.cpp +++ b/src/qtui/aboutdlg.cpp @@ -35,10 +35,10 @@ AboutDlg::AboutDlg(QWidget *parent) ui.setupUi(this); ui.quasselLogo->setPixmap(QIcon(":/icons/quassel-64.png").pixmap(64)); // don't let the icon theme affect our logo here - ui.versionLabel->setText(QString(tr("Version: %1
Protocol version: %2
Built: %3")) + ui.versionLabel->setText(QString(tr("Version: %1
Version date: %2
Protocol version: %3")) .arg(Quassel::buildInfo().fancyVersionString) - .arg(Quassel::buildInfo().protocolVersion) - .arg(Quassel::buildInfo().buildDate)); + .arg(Quassel::buildInfo().commitDate) + .arg(Quassel::buildInfo().protocolVersion)); ui.aboutTextBrowser->setHtml(about()); ui.authorTextBrowser->setHtml(authors()); ui.contributorTextBrowser->setHtml(contributors()); diff --git a/src/qtui/coreinfodlg.cpp b/src/qtui/coreinfodlg.cpp index babb4ad6..8aa738c5 100644 --- a/src/qtui/coreinfodlg.cpp +++ b/src/qtui/coreinfodlg.cpp @@ -38,7 +38,7 @@ CoreInfoDlg::CoreInfoDlg(QWidget *parent) void CoreInfoDlg::coreInfoAvailable() { ui.labelCoreVersion->setText(_coreInfo["quasselVersion"].toString()); - ui.labelCoreBuildDate->setText(_coreInfo["quasselBuildDate"].toString()); + ui.labelCoreVersionDate->setText(_coreInfo["quasselBuildDate"].toString()); // "BuildDate" for compatibility ui.labelClientCount->setNum(_coreInfo["sessionConnectedClients"].toInt()); updateUptime(); startTimer(1000); diff --git a/src/qtui/ui/coreinfodlg.ui b/src/qtui/ui/coreinfodlg.ui index 11982d2d..3e76d349 100644 --- a/src/qtui/ui/coreinfodlg.ui +++ b/src/qtui/ui/coreinfodlg.ui @@ -60,14 +60,14 @@ - Build date: + Version date: - + - <build date> + <version date> diff --git a/version.h.in b/version.h.in index 2cd1232c..59112c92 100644 --- a/version.h.in +++ b/version.h.in @@ -7,6 +7,7 @@ // Determined from Git #define GIT_HEAD "@GIT_HEAD@" #define GIT_DESCRIBE "@GIT_DESCRIBE@" +#define GIT_COMMIT_DATE @GIT_COMMIT_DATE@ // Will be substituted in official tarballs #define DIST_HASH "$Format:%H$" -- 2.20.1