Skip to content

Commit

Permalink
Make ptb version copyable (Mudlet#4533)
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Wilczynski <piotr.wilczynski@bisnode.com>
Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
  • Loading branch information
3 people authored Dec 30, 2020
1 parent 4acb825 commit 686a2fe
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,35 @@ if(USE_UPDATER)
endif()

endif()

# Get the latest commit hash
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)

if(GIT_COMMIT_HASH)
target_compile_definitions(${PROJECT_NAME} PRIVATE "-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"")
endif()

# Get the current working branch
execute_process(
COMMAND git describe --all --dirty --broken
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)

if(GIT_BRANCH)
STRING(REGEX REPLACE "heads/" "" GIT_BRANCH ${GIT_BRANCH})

if(GIT_BRANCH MATCHES ".*-dirty$")
STRING(REGEX REPLACE "-dirty$" " (modified)" GIT_BRANCH ${GIT_BRANCH})
endif()

if(GIT_BRANCH MATCHES ".*-broken")
STRING(REGEX REPLACE "-broken" " (broken)" GIT_BRANCH ${GIT_BRANCH})
endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE "-DGIT_BRANCH=\"${GIT_BRANCH}\"")
endif()
28 changes: 25 additions & 3 deletions src/dlgAboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
// Debugging value to display ALL licences in the dialog
// #define DEBUG_SHOWALL

#ifndef GIT_COMMIT_HASH
#define GIT_COMMIT_HASH "?"
#endif

#ifndef GIT_BRANCH
#define GIT_BRANCH "?"
#endif

#include "dlgAboutDialog.h"

Expand Down Expand Up @@ -255,10 +262,11 @@ void dlgAboutDialog::setAboutTab(const QString& htmlHead) const
"<p>Special thanks to <span style=\"color:#bc8942;\"><b>Nick Gammon</b></span> (<a href=\"http://www.gammon.com.au/mushclient/mushclient.htm\">www.gammon.com.au/mushclient/mushclient.htm</a>) for giving us some valued pieces of advice.</p>"));

textBrowser_mudlet->setHtml(
QStringLiteral("<html>%1<body><table border=\"0\" style=\"margin-top:36px; margin-bottom:36px; margin-left:36px; margin-right:36px;\" width=\"100%\" cellspacing=\"2\" cellpadding=\"0\">\n"
QStringLiteral("<html>%1<body><table border=\"0\" style=\"margin:18px 36px;\" width=\"100%\" cellspacing=\"2\" cellpadding=\"0\">\n"
"%2</table>\n"
"%3</body></html>")
.arg(htmlHead, aboutMudletHeader, aboutMudletBody));
"%3"
"%4</body></html>")
.arg(htmlHead, aboutMudletHeader, createBuildInfo(), aboutMudletBody));
// clang-format on
}

Expand Down Expand Up @@ -1062,3 +1070,17 @@ void dlgAboutDialog::setSupportersTab(const QString& htmlHead)
textBrowser_supporters->setDocument(supportersDocument.get());
textBrowser_supporters->setOpenExternalLinks(true);
}

QString dlgAboutDialog::createBuildInfo() const {

QString commitHash = !QByteArray(GIT_COMMIT_HASH).isEmpty() ? QStringLiteral(GIT_COMMIT_HASH) : QStringLiteral("?");
QString branch = !QByteArray(GIT_BRANCH).isEmpty() ? QStringLiteral(GIT_BRANCH) : QStringLiteral("?");
return QStringLiteral("<table border=\"0\" style=\"margin-bottom:18px; margin-left:36px; margin-right:36px;\" width=\"100%\" cellspacing=\"2\" cellpadding=\"0\">\n")
.append(QStringLiteral("<tr><td colspan=\"2\" style=\"font-weight: 800\">%1</td></tr>").arg(tr("Technical information:")))
.append(QStringLiteral("<tr><td style=\"padding-right: 10px;\">%1<td>%2</td></tr>").arg(tr("Version"), mudlet::self()->version))
.append(QStringLiteral("<tr><td style=\"padding-right: 10px;\">%1</td><td>%2</td></tr>").arg(tr("OS"), QSysInfo::prettyProductName()))
.append(QStringLiteral("<tr><td style=\"padding-right: 10px;\">%1</td><td>%2</td></tr>").arg(tr("CPU"), QSysInfo::currentCpuArchitecture()))
.append(QStringLiteral("<tr><td style=\"padding-right: 10px;\">%1</td><td>%2</td></tr>").arg(tr("Branch"), branch))
.append(QStringLiteral("<tr><td style=\"padding-right: 10px;\">%1</td><td>%2</td></tr>").arg(tr("Commit"), commitHash))
.append(QStringLiteral("</table>"));
}
1 change: 1 addition & 0 deletions src/dlgAboutDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class dlgAboutDialog : public QDialog, public Ui::about_dialog
void setThirdPartyTab(const QString& htmlHead) const;
void setSupportersTab(const QString &htmlHead);
QString createMakerHTML(const aboutMaker&) const;
QString createBuildInfo() const;
};

#endif // MUDLET_DLGABOUTDIALOG_H
25 changes: 25 additions & 0 deletions src/mudlet.pro
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,31 @@ isEmpty( BUILD ) {
BUILD = "-dev"
}

$$system(git --version, blob, GIT_STATUS)
isEqual(GIT_STATUS, 0) {
# Git command appeared to work - so get a description of the current
# repository state
GIT_DESCRIPTION=$$system(git describe --all --dirty --broken)
GIT_COMMITHASH=$$system(git rev-parse --short HEAD)
# remove the leading "head/"
GIT_DESCRIPTION=$$replace(GIT_DESCRIPTION, "heads/", "")
# Split it on hyphens
SPLIT_GIT_DESCRIPTION=$$split(GIT_DESCRIPTION, -)
# Get the last part so we can check if it is "broken" or "dirty"
LAST_GIT_DESCRIPTION=$$last(SPLIT_GIT_DESCRIPTION)
contains(LAST_GIT_DESCRIPTION, "broken" ) {
warning( "Main Git repository has a problem." )
GIT_DESCRIPTION=$$replace(GIT_DESCRIPTION, "-broken", " (broken)")
} else {
contains(LAST_GIT_DESCRIPTION, "dirty" ) {
GIT_DESCRIPTION=$$replace(GIT_DESCRIPTION, "-dirty", " (modified)")
}
}
!build_pass : message("Using a git description of: \"$${GIT_DESCRIPTION}\", Git SHA1 is: $${GIT_COMMITHASH}")
DEFINES += GIT_COMMIT_HASH=\\\"$${GIT_COMMITHASH}\\\"
DEFINES += GIT_BRANCH=\\\"\"$${GIT_DESCRIPTION}\"\\\"
}

# As the above also modifies the splash screen image (so developers get reminded
# what they are working with!) Packagers (e.g. for Linux distributions) will
# want to set the environmental variable WITH_VARIABLE_SPLASH_SCREEN to NO so
Expand Down

0 comments on commit 686a2fe

Please sign in to comment.