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:
+93
-2
@@ -16,13 +16,15 @@ Version::Version()
|
||||
this->commitHash_ =
|
||||
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
|
||||
this->dateOfBuild_ =
|
||||
QString(FROM_EXTERNAL_DEFINE(CHATTERINO_CMAKE_GEN_DATE)).remove('"');
|
||||
#endif
|
||||
|
||||
// "Full" version string, as displayed in window title
|
||||
this->fullVersion_ = "Chatterino ";
|
||||
if (Modes::instance().isNightly)
|
||||
{
|
||||
@@ -31,11 +33,18 @@ Version::Version()
|
||||
|
||||
this->fullVersion_ += this->version_;
|
||||
|
||||
#ifndef NDEBUG
|
||||
this->fullVersion_ += " DEBUG";
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
|
||||
this->isSupportedOS_ = true;
|
||||
#else
|
||||
this->isSupportedOS_ = false;
|
||||
#endif
|
||||
|
||||
this->generateBuildString();
|
||||
this->generateRunningString();
|
||||
}
|
||||
|
||||
const Version &Version::instance()
|
||||
@@ -59,6 +68,11 @@ const QString &Version::commitHash() const
|
||||
return this->commitHash_;
|
||||
}
|
||||
|
||||
const bool &Version::isModified() const
|
||||
{
|
||||
return this->isModified_;
|
||||
}
|
||||
|
||||
const QString &Version::dateOfBuild() const
|
||||
{
|
||||
return this->dateOfBuild_;
|
||||
@@ -74,4 +88,81 @@ bool Version::isFlatpak() const
|
||||
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
|
||||
|
||||
@@ -26,19 +26,41 @@ public:
|
||||
|
||||
const QString &version() 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;
|
||||
// "Full" version string, as displayed in window title
|
||||
const QString &fullVersion() const;
|
||||
const bool &isSupportedOS() 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:
|
||||
Version();
|
||||
|
||||
QString version_;
|
||||
QString commitHash_;
|
||||
bool isModified_{false};
|
||||
QString dateOfBuild_;
|
||||
QString fullVersion_;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user