Organized version information (#3781)

added new `GIT_MODIFIED` variable - used to determine whether the vcs tree was compiled or not at the time of building the app
added information about running in DEBUG mode which might be very helpful to determine whether one is running a DEBUG build, e.g. in the process of troubleshooting/determining crash causes

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Kasia 2022-06-04 21:00:42 +02:00 committed by GitHub
parent a693bc23f8
commit a7939b727f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 145 additions and 83 deletions

View file

@ -674,12 +674,16 @@ isEmpty(git_release) {
git_release=$$system(git describe) git_release=$$system(git describe)
} }
git_hash = $$str_member($$git_commit, 0, 8) git_hash = $$str_member($$git_commit, 0, 8)
git_modified=$$system(git status --porcelain -z)
# Passing strings as defines requires you to use this weird triple-escape then quotation mark syntax. # Passing strings as defines requires you to use this weird triple-escape then quotation mark syntax.
# https://stackoverflow.com/questions/3348711/add-a-define-to-qmake-with-a-value/18343449#18343449 # https://stackoverflow.com/questions/3348711/add-a-define-to-qmake-with-a-value/18343449#18343449
DEFINES += CHATTERINO_GIT_COMMIT=\\\"$$git_commit\\\" DEFINES += CHATTERINO_GIT_COMMIT=\\\"$$git_commit\\\"
DEFINES += CHATTERINO_GIT_RELEASE=\\\"$$git_release\\\" DEFINES += CHATTERINO_GIT_RELEASE=\\\"$$git_release\\\"
DEFINES += CHATTERINO_GIT_HASH=\\\"$$git_hash\\\" DEFINES += CHATTERINO_GIT_HASH=\\\"$$git_hash\\\"
!isEmpty(git_modified) {
DEFINES += CHATTERINO_GIT_MODIFIED
}
CONFIG(debug, debug|release) { CONFIG(debug, debug|release) {
message("Building Chatterino2 DEBUG") message("Building Chatterino2 DEBUG")

View file

@ -8,12 +8,16 @@
# GIT_RELEASE # GIT_RELEASE
# If the git binary is found and the git work tree is intact, GIT_RELEASE is worked out using the `git describe` command # If the git binary is found and the git work tree is intact, GIT_RELEASE is worked out using the `git describe` command
# The value of GIT_RELEASE can be overriden by defining the GIT_RELEASE environment variable # The value of GIT_RELEASE can be overriden by defining the GIT_RELEASE environment variable
# GIT_MODIFIED
# If the git binary is found and the git work tree is intact, GIT_MODIFIED is worked out by checking if output of `git status --porcelain -z` command is empty
# The value of GIT_MODIFIED cannot be overriden
find_package(Git) find_package(Git)
set(GIT_HASH "GIT-REPOSITORY-NOT-FOUND") set(GIT_HASH "GIT-REPOSITORY-NOT-FOUND")
set(GIT_COMMIT "GIT-REPOSITORY-NOT-FOUND") set(GIT_COMMIT "GIT-REPOSITORY-NOT-FOUND")
set(GIT_RELEASE "${PROJECT_VERSION}") set(GIT_RELEASE "${PROJECT_VERSION}")
set(GIT_MODIFIED 0)
if (GIT_EXECUTABLE) if (GIT_EXECUTABLE)
execute_process( execute_process(
@ -49,9 +53,20 @@ if (GIT_EXECUTABLE)
OUTPUT_VARIABLE GIT_RELEASE OUTPUT_VARIABLE GIT_RELEASE
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
) )
execute_process(
COMMAND ${GIT_EXECUTABLE} status --porcelain -z
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_MODIFIED_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif (GIT_REPOSITORY_FOUND) endif (GIT_REPOSITORY_FOUND)
endif (GIT_EXECUTABLE) endif (GIT_EXECUTABLE)
if (GIT_MODIFIED_OUTPUT)
set(GIT_MODIFIED 1)
endif ()
if (DEFINED ENV{GIT_HASH}) if (DEFINED ENV{GIT_HASH})
set(GIT_HASH "$ENV{GIT_HASH}") set(GIT_HASH "$ENV{GIT_HASH}")
endif () endif ()
@ -62,4 +77,4 @@ if (DEFINED ENV{GIT_RELEASE})
set(GIT_RELEASE "$ENV{GIT_RELEASE}") set(GIT_RELEASE "$ENV{GIT_RELEASE}")
endif () endif ()
message(STATUS "Injected git values: ${GIT_COMMIT} (${GIT_RELEASE}) ${GIT_HASH}") message(STATUS "Injected git values: ${GIT_COMMIT} (${GIT_RELEASE}) modified: ${GIT_MODIFIED}")

View file

@ -638,6 +638,11 @@ target_compile_definitions(${LIBRARY_PROJECT} PUBLIC
CHATTERINO_CMAKE_GEN_DATE=\"${cmake_gen_date}\" CHATTERINO_CMAKE_GEN_DATE=\"${cmake_gen_date}\"
) )
if (GIT_MODIFIED)
target_compile_definitions(${LIBRARY_PROJECT} PUBLIC
CHATTERINO_GIT_MODIFIED
)
endif ()
if (USE_SYSTEM_QTKEYCHAIN) if (USE_SYSTEM_QTKEYCHAIN)
target_compile_definitions(${LIBRARY_PROJECT} PUBLIC target_compile_definitions(${LIBRARY_PROJECT} PUBLIC
CMAKE_BUILD CMAKE_BUILD

View file

@ -16,13 +16,15 @@ Version::Version()
this->commitHash_ = this->commitHash_ =
QString(FROM_EXTERNAL_DEFINE(CHATTERINO_GIT_HASH)).remove('"'); QString(FROM_EXTERNAL_DEFINE(CHATTERINO_GIT_HASH)).remove('"');
// Date of build file generation (≈ date of build) #ifdef CHATTERINO_GIT_MODIFIED
this->isModified_ = true;
#endif
#ifdef CHATTERINO_CMAKE_GEN_DATE #ifdef CHATTERINO_CMAKE_GEN_DATE
this->dateOfBuild_ = this->dateOfBuild_ =
QString(FROM_EXTERNAL_DEFINE(CHATTERINO_CMAKE_GEN_DATE)).remove('"'); QString(FROM_EXTERNAL_DEFINE(CHATTERINO_CMAKE_GEN_DATE)).remove('"');
#endif #endif
// "Full" version string, as displayed in window title
this->fullVersion_ = "Chatterino "; this->fullVersion_ = "Chatterino ";
if (Modes::instance().isNightly) if (Modes::instance().isNightly)
{ {
@ -31,11 +33,18 @@ Version::Version()
this->fullVersion_ += this->version_; this->fullVersion_ += this->version_;
#ifndef NDEBUG
this->fullVersion_ += " DEBUG";
#endif
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX) || defined(Q_OS_MACOS) #if defined(Q_OS_WIN) || defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
this->isSupportedOS_ = true; this->isSupportedOS_ = true;
#else #else
this->isSupportedOS_ = false; this->isSupportedOS_ = false;
#endif #endif
this->generateBuildString();
this->generateRunningString();
} }
const Version &Version::instance() const Version &Version::instance()
@ -59,6 +68,11 @@ const QString &Version::commitHash() const
return this->commitHash_; return this->commitHash_;
} }
const bool &Version::isModified() const
{
return this->isModified_;
}
const QString &Version::dateOfBuild() const const QString &Version::dateOfBuild() const
{ {
return this->dateOfBuild_; return this->dateOfBuild_;
@ -74,4 +88,81 @@ bool Version::isFlatpak() const
return QFileInfo::exists("/.flatpak-info"); return QFileInfo::exists("/.flatpak-info");
} }
QStringList Version::buildTags() const
{
QStringList tags;
tags.append("Qt " QT_VERSION_STR);
#ifdef USEWINSDK
tags.append("Windows SDK");
#endif
#ifdef _MSC_FULL_VER
tags.append("MSVC " + QString::number(_MSC_FULL_VER, 10));
#endif
return tags;
}
const QString &Version::buildString() const
{
return this->buildString_;
}
const QString &Version::runningString() const
{
return this->runningString_;
}
void Version::generateBuildString()
{
// e.g. Chatterino 2.3.5 or Chatterino Nightly 2.3.5
auto s = this->fullVersion();
// Add commit information
s +=
QString(
R"( (commit <a href="https://github.com/Chatterino/chatterino2/commit/%1">%1</a>)")
.arg(this->commitHash());
if (this->isModified())
{
s += " modified)";
}
else
{
s += ")";
}
s += " built";
// If the build is a nightly build (decided with modes atm), include build date information
if (Modes::instance().isNightly)
{
s += " on " + this->dateOfBuild();
}
// Append build tags (e.g. compiler, qt version etc)
s += " with " + this->buildTags().join(", ");
this->buildString_ = s;
}
void Version::generateRunningString()
{
auto s = QString("Running on %1, kernel: %2")
.arg(QSysInfo::prettyProductName(), QSysInfo::kernelVersion());
if (this->isFlatpak())
{
s += ", running from Flatpak";
}
if (!this->isSupportedOS())
{
s += " (unsupported OS)";
}
this->runningString_ = s;
}
} // namespace chatterino } // namespace chatterino

View file

@ -26,19 +26,41 @@ public:
const QString &version() const; const QString &version() const;
const QString &commitHash() const; const QString &commitHash() const;
// Whether or not the vcs tree had any changes at the time of build
const bool &isModified() const;
// Date of build file generation (≈ date of build)
const QString &dateOfBuild() const; const QString &dateOfBuild() const;
// "Full" version string, as displayed in window title
const QString &fullVersion() const; const QString &fullVersion() const;
const bool &isSupportedOS() const; const bool &isSupportedOS() const;
bool isFlatpak() const; bool isFlatpak() const;
// Returns a list of tags for this build, e.g. what compiler was used, what Qt version etc
QStringList buildTags() const;
// Returns a string containing build information of this Chatterino binary
const QString &buildString() const;
// Returns a string about the current running system
const QString &runningString() const;
private: private:
Version(); Version();
QString version_; QString version_;
QString commitHash_; QString commitHash_;
bool isModified_{false};
QString dateOfBuild_; QString dateOfBuild_;
QString fullVersion_; QString fullVersion_;
bool isSupportedOS_; bool isSupportedOS_;
QString buildString_;
// Generate a build string (e.g. Chatterino 2.3.5 (commit ...)) and store it in buildString_ for future use
void generateBuildString();
QString runningString_;
// Generate a running string (e.g. Running on Arch Linux, kernel 5.14.3) and store it in runningString_ for future use
void generateRunningString();
}; };
}; // namespace chatterino }; // namespace chatterino

View file

@ -46,79 +46,16 @@ AboutPage::AboutPage()
} }
logo->setScaledContents(true); logo->setScaledContents(true);
// this does nothing
// QPalette palette;
// palette.setColor(QPalette::Text, Qt::white);
// palette.setColor(QPalette::Link, "#a5cdff");
// palette.setColor(QPalette::LinkVisited, "#a5cdff");
/*auto xd = layout.emplace<QGroupBox>("Created by...");
{
auto created = xd.emplace<QLabel>();
{
created->setText("Created by <a
href=\"https://github.com/fourtf\">fourtf</a><br>" "with big help from
pajlada."); created->setTextFormat(Qt::RichText);
created->setTextInteractionFlags(Qt::TextBrowserInteraction |
Qt::LinksAccessibleByKeyboard |
Qt::LinksAccessibleByKeyboard);
created->setOpenExternalLinks(true);
// created->setPalette(palette);
}
// auto github = xd.emplace<QLabel>();
// {
// github->setText(
// "<a
href=\"https://github.com/fourtf/chatterino2\">Chatterino on
// Github</a>");
// github->setTextFormat(Qt::RichText);
// github->setTextInteractionFlags(Qt::TextBrowserInteraction |
// Qt::LinksAccessibleByKeyboard |
// Qt::LinksAccessibleByKeyboard);
// github->setOpenExternalLinks(true);
// // github->setPalette(palette);
// }
}*/
// Version // Version
auto versionInfo = layout.emplace<QGroupBox>("Version"); auto versionInfo = layout.emplace<QGroupBox>("Version");
{ {
auto vbox = versionInfo.emplace<QVBoxLayout>();
auto version = Version::instance(); auto version = Version::instance();
QString osInfo = QSysInfo::prettyProductName() +
", kernel: " + QSysInfo::kernelVersion();
if (version.isFlatpak())
{
osInfo += ", running from Flatpak";
}
QString commitHashLink = auto label = vbox.emplace<QLabel>(version.buildString() + "<br>" +
QString("<a " version.runningString());
"href=\"https://github.com/Chatterino/chatterino2/" label->setOpenExternalLinks(true);
"commit/%1\">%1</a>") label->setTextInteractionFlags(Qt::TextBrowserInteraction);
.arg(version.commitHash());
QString nightlyBuildInfo;
if (Modes::instance().isNightly)
{
nightlyBuildInfo =
QString(", built on %1").arg(version.dateOfBuild());
}
QString supportedOS;
if (!version.isSupportedOS())
{
supportedOS = "(unsupported OS)";
}
QString text = QString("%1 (commit %2%3) running on %4 %5")
.arg(version.fullVersion(), commitHashLink,
nightlyBuildInfo, osInfo, supportedOS);
auto versionLabel = versionInfo.emplace<QLabel>(text);
versionLabel->setOpenExternalLinks(true);
versionLabel->setTextInteractionFlags(Qt::TextSelectableByMouse |
Qt::LinksAccessibleByMouse);
} }
// About Chatterino // About Chatterino
@ -256,18 +193,6 @@ AboutPage::AboutPage()
} }
} }
auto buildInfo = QStringList();
buildInfo += "Qt " QT_VERSION_STR;
#ifdef USEWINSDK
buildInfo += "Windows SDK";
#endif
#ifdef _MSC_FULL_VER
buildInfo += "MSVC " + QString::number(_MSC_FULL_VER, 10);
#endif
auto buildText = QString("Built with " + buildInfo.join(", "));
layout.emplace<QLabel>(buildText);
layout->addStretch(1); layout->addStretch(1);
} }