diff --git a/chatterino.pro b/chatterino.pro index 8461c4ad..03380b71 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -674,12 +674,16 @@ isEmpty(git_release) { git_release=$$system(git describe) } 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. # https://stackoverflow.com/questions/3348711/add-a-define-to-qmake-with-a-value/18343449#18343449 DEFINES += CHATTERINO_GIT_COMMIT=\\\"$$git_commit\\\" DEFINES += CHATTERINO_GIT_RELEASE=\\\"$$git_release\\\" DEFINES += CHATTERINO_GIT_HASH=\\\"$$git_hash\\\" +!isEmpty(git_modified) { + DEFINES += CHATTERINO_GIT_MODIFIED +} CONFIG(debug, debug|release) { message("Building Chatterino2 DEBUG") diff --git a/cmake/GIT.cmake b/cmake/GIT.cmake index 50ff54ec..e5afb582 100644 --- a/cmake/GIT.cmake +++ b/cmake/GIT.cmake @@ -8,12 +8,16 @@ # 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 # 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) set(GIT_HASH "GIT-REPOSITORY-NOT-FOUND") set(GIT_COMMIT "GIT-REPOSITORY-NOT-FOUND") set(GIT_RELEASE "${PROJECT_VERSION}") +set(GIT_MODIFIED 0) if (GIT_EXECUTABLE) execute_process( @@ -49,9 +53,20 @@ if (GIT_EXECUTABLE) OUTPUT_VARIABLE GIT_RELEASE 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_EXECUTABLE) +if (GIT_MODIFIED_OUTPUT) + set(GIT_MODIFIED 1) +endif () + if (DEFINED ENV{GIT_HASH}) set(GIT_HASH "$ENV{GIT_HASH}") endif () @@ -62,4 +77,4 @@ if (DEFINED ENV{GIT_RELEASE}) set(GIT_RELEASE "$ENV{GIT_RELEASE}") endif () -message(STATUS "Injected git values: ${GIT_COMMIT} (${GIT_RELEASE}) ${GIT_HASH}") +message(STATUS "Injected git values: ${GIT_COMMIT} (${GIT_RELEASE}) modified: ${GIT_MODIFIED}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index df836ed3..4372a3d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -638,6 +638,11 @@ target_compile_definitions(${LIBRARY_PROJECT} PUBLIC CHATTERINO_CMAKE_GEN_DATE=\"${cmake_gen_date}\" ) +if (GIT_MODIFIED) + target_compile_definitions(${LIBRARY_PROJECT} PUBLIC + CHATTERINO_GIT_MODIFIED + ) +endif () if (USE_SYSTEM_QTKEYCHAIN) target_compile_definitions(${LIBRARY_PROJECT} PUBLIC CMAKE_BUILD diff --git a/src/common/Version.cpp b/src/common/Version.cpp index 76dc4270..9a5d4e97 100644 --- a/src/common/Version.cpp +++ b/src/common/Version.cpp @@ -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 %1)") + .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 diff --git a/src/common/Version.hpp b/src/common/Version.hpp index 006b0ac5..f8a724fb 100644 --- a/src/common/Version.hpp +++ b/src/common/Version.hpp @@ -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 diff --git a/src/widgets/settingspages/AboutPage.cpp b/src/widgets/settingspages/AboutPage.cpp index cfb9c84e..f4c5dbce 100644 --- a/src/widgets/settingspages/AboutPage.cpp +++ b/src/widgets/settingspages/AboutPage.cpp @@ -46,79 +46,16 @@ AboutPage::AboutPage() } 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("Created by..."); - { - auto created = xd.emplace(); - { - created->setText("Created by fourtf
" "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(); - // { - // github->setText( - // "Chatterino on - // Github"); - // github->setTextFormat(Qt::RichText); - // github->setTextInteractionFlags(Qt::TextBrowserInteraction | - // Qt::LinksAccessibleByKeyboard | - // Qt::LinksAccessibleByKeyboard); - // github->setOpenExternalLinks(true); - // // github->setPalette(palette); - // } - }*/ - // Version auto versionInfo = layout.emplace("Version"); { + auto vbox = versionInfo.emplace(); auto version = Version::instance(); - QString osInfo = QSysInfo::prettyProductName() + - ", kernel: " + QSysInfo::kernelVersion(); - if (version.isFlatpak()) - { - osInfo += ", running from Flatpak"; - } - QString commitHashLink = - QString("%1") - .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(text); - versionLabel->setOpenExternalLinks(true); - versionLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | - Qt::LinksAccessibleByMouse); + auto label = vbox.emplace(version.buildString() + "
" + + version.runningString()); + label->setOpenExternalLinks(true); + label->setTextInteractionFlags(Qt::TextBrowserInteraction); } // 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(buildText); - layout->addStretch(1); }