From 42e305bb9d1babef9bb66a8d376289e8aebed671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 5 Apr 2014 22:58:47 +0200 Subject: Get rid of long rebuilds because of minor cmake config changes --- CMakeLists.txt | 5 +- Config.cpp.in | 65 ++++++++++++++++++++++++ Config.h | 86 +++++++++++++++++++++++++++++++ MultiMC.cpp | 18 +++---- MultiMC.h | 8 --- MultiMCVersion.h | 96 ----------------------------------- config.h.in | 40 --------------- gui/MainWindow.cpp | 12 ++--- gui/dialogs/AboutDialog.cpp | 17 ++++--- logic/MinecraftProcess.cpp | 3 +- logic/updater/DownloadUpdateTask.cpp | 29 ++++++----- logic/updater/NotificationChecker.cpp | 13 +++-- logic/updater/UpdateChecker.cpp | 5 +- tests/tst_UpdateChecker.cpp | 3 +- 14 files changed, 207 insertions(+), 193 deletions(-) create mode 100644 Config.cpp.in create mode 100644 Config.h delete mode 100644 MultiMCVersion.h delete mode 100644 config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 38f70b7e..38313a42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,7 +179,7 @@ ELSE() ENDIF() ######## Configure header ######## -configure_file("${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_BINARY_DIR}/include/config.h") +configure_file("${PROJECT_SOURCE_DIR}/Config.cpp.in" "${PROJECT_BINARY_DIR}/Config.cpp") ######## Other Stuff ######## @@ -257,8 +257,9 @@ SET(MULTIMC_SOURCES # Application base MultiMC.h MultiMC.cpp -MultiMCVersion.h MMCError.h +Config.h +${PROJECT_BINARY_DIR}/Config.cpp # Logging logger/QsDebugOutput.cpp diff --git a/Config.cpp.in b/Config.cpp.in new file mode 100644 index 00000000..4d3d0079 --- /dev/null +++ b/Config.cpp.in @@ -0,0 +1,65 @@ +#include "Config.h" + +Config BuildConfig; + +Config::Config() +{ + static bool ON = true; + static bool OFF = false; + // Version information + VERSION_MAJOR = @MultiMC_VERSION_MAJOR@; + VERSION_MINOR = @MultiMC_VERSION_MINOR@; + VERSION_HOTFIX = @MultiMC_VERSION_HOTFIX@; + VERSION_BUILD = @MultiMC_VERSION_BUILD@; + VERSION_TYPE = "@MultiMC_VERSION_TYPE@"; + + if(VERSION_TYPE == "Release") + versionTypeEnum = Release; + else if(VERSION_TYPE == "ReleaseCandidate") + versionTypeEnum = ReleaseCandidate; + else if(VERSION_TYPE == "Development") + versionTypeEnum = Development; + else + versionTypeEnum = Custom; + VERSION_CHANNEL = "@MultiMC_VERSION_CHANNEL@"; + BUILD_PLATFORM = "@MultiMC_BUILD_PLATFORM@"; + CHANLIST_URL = "@MultiMC_CHANLIST_URL@"; + NOTIFICATION_URL = "@MultiMC_NOTIFICATION_URL@"; + FULL_VERSION_STR = "@MultiMC_VERSION_MAJOR@.@MultiMC_VERSION_MINOR@.@MultiMC_VERSION_BUILD@"; + + UPDATER_DRY_RUN = @MultiMC_UPDATER_DRY_RUN@; + UPDATER_FORCE_LOCAL = @MultiMC_UPDATER_FORCE_LOCAL@; + + GIT_COMMIT = "@MultiMC_GIT_COMMIT@"; + VERSION_STR = "@MultiMC_VERSION_STRING@"; + NEWS_RSS_URL = "@MultiMC_NEWS_RSS_URL@"; +} + +QString Config::versionTypeName() const +{ + switch (versionTypeEnum) + { + case Release: + return "Stable Release"; + case ReleaseCandidate: + return "Release Candidate"; + case Development: + return "Development"; + case Custom: + default: + return "Custom"; + } +} + +QString Config::printableVersionString() const +{ + QString vstr = QString("%1.%2").arg(QString::number(VERSION_MAJOR), QString::number(VERSION_MINOR)); + + if (VERSION_HOTFIX > 0) vstr += "." + QString::number(VERSION_HOTFIX); + + // If the build is a development build or release candidate, add that info to the end. + if (versionTypeEnum == Development) vstr += "-dev" + QString::number(VERSION_BUILD); + else if (versionTypeEnum == ReleaseCandidate) vstr += "-rc" + QString::number(VERSION_BUILD); + + return vstr; +} diff --git a/Config.h b/Config.h new file mode 100644 index 00000000..baf2ad6d --- /dev/null +++ b/Config.h @@ -0,0 +1,86 @@ +#pragma once +#include + +/** + * \brief The Config class holds all the build-time information passed from the build system. + */ +class Config +{ +public: + Config(); + /// The major version number. + int VERSION_MAJOR; + /// The minor version number. + int VERSION_MINOR; + /// The hotfix number. + int VERSION_HOTFIX; + /// The build number. + int VERSION_BUILD; + /// The build type, as specified at build time. + QString VERSION_TYPE; + + /// The build type, transformed. + enum Type + { + /// Version type for stable release builds. + Release, + + /// Version type for release candidates. + ReleaseCandidate, + + /// Version type for development builds. + Development, + + /// Version type for custom builds. This is the default when no version type is specified. + Custom + } versionTypeEnum; + + /** + * The version channel + * This is used by the updater to determine what channel the current version came from. + */ + QString VERSION_CHANNEL; + + /// A short string identifying this build's platform. For example, "lin64" or "win32". + QString BUILD_PLATFORM; + + /// URL for the updater's channel + QString CHANLIST_URL; + + /// URL for notifications + QString NOTIFICATION_URL; + + /// Used for matching notifications + QString FULL_VERSION_STR; + + /// enabled for updater dry run + bool UPDATER_DRY_RUN; + + /// enabled for updater dry run + bool UPDATER_FORCE_LOCAL; + + /// The commit hash of this build + QString GIT_COMMIT; + + /// This is printed on start to standard output + QString VERSION_STR; + + /** + * This is used to fetch the news RSS feed. + * It defaults in CMakeLists.txt to "http://multimc.org/rss.xml" + */ + QString NEWS_RSS_URL; + + /** + * \brief Converts the Version to a string. + * \return The version number in string format (major.minor.revision.build). + */ + QString printableVersionString() const; + + /** + * returns a string representation of the version channel type, suitable for printing. + */ + QString versionTypeName() const; +}; + +extern Config BuildConfig; diff --git a/MultiMC.cpp b/MultiMC.cpp index f6e4e995..50a01f91 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -1,4 +1,6 @@ #include "MultiMC.h" +#include "Config.h" + #include #include #include @@ -50,9 +52,7 @@ static const int APPDATA_BUFFER_SIZE = 1024; using namespace Util::Commandline; MultiMC::MultiMC(int &argc, char **argv, bool root_override) - : QApplication(argc, argv), - m_version{VERSION_MAJOR, VERSION_MINOR, VERSION_HOTFIX, VERSION_BUILD, - MultiMCVersion::VERSION_TYPE, VERSION_CHANNEL, BUILD_PLATFORM} + : QApplication(argc, argv) { setOrganizationName("MultiMC"); setApplicationName("MultiMC5"); @@ -111,8 +111,8 @@ MultiMC::MultiMC(int &argc, char **argv, bool root_override) // display version and exit if (args["version"].toBool()) { - std::cout << "Version " << VERSION_STR << std::endl; - std::cout << "Git " << GIT_COMMIT << std::endl; + std::cout << "Version " << BuildConfig.VERSION_STR.toStdString() << std::endl; + std::cout << "Git " << BuildConfig.GIT_COMMIT.toStdString() << std::endl; m_status = MultiMC::Succeeded; return; } @@ -165,8 +165,8 @@ MultiMC::MultiMC(int &argc, char **argv, bool root_override) initLogger(); QLOG_INFO() << "MultiMC 5, (c) 2013 MultiMC Contributors"; - QLOG_INFO() << "Version : " << VERSION_STR; - QLOG_INFO() << "Git commit : " << GIT_COMMIT; + QLOG_INFO() << "Version : " << BuildConfig.VERSION_STR; + QLOG_INFO() << "Git commit : " << BuildConfig.GIT_COMMIT; if (adjustedBy.size()) { QLOG_INFO() << "Work dir before adjustment : " << origcwdPath; @@ -193,7 +193,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool root_override) m_notificationChecker.reset(new NotificationChecker()); // initialize the news checker - m_newsChecker.reset(new NewsChecker(NEWS_RSS_URL)); + m_newsChecker.reset(new NewsChecker(BuildConfig.NEWS_RSS_URL)); // initialize the status checker m_statusChecker.reset(new StatusChecker()); @@ -333,7 +333,7 @@ void MultiMC::initGlobalSettings() { m_settings.reset(new INISettingsObject("multimc.cfg", this)); // Updates - m_settings->registerSetting("UpdateChannel", version().channel); + m_settings->registerSetting("UpdateChannel", BuildConfig.VERSION_CHANNEL); m_settings->registerSetting("AutoUpdate", true); // Notifications diff --git a/MultiMC.h b/MultiMC.h index f03ed259..cb37b1e6 100644 --- a/MultiMC.h +++ b/MultiMC.h @@ -1,8 +1,6 @@ #pragma once -#include "config.h" #include -#include "MultiMCVersion.h" #include #include "logger/QsLog.h" #include "logger/QsLogDest.h" @@ -87,11 +85,6 @@ public: return m_status; } - MultiMCVersion version() - { - return m_version; - } - std::shared_ptr qnam() { return m_qnam; @@ -227,5 +220,4 @@ private: QString origcwdPath; Status m_status = MultiMC::Failed; - MultiMCVersion m_version; }; diff --git a/MultiMCVersion.h b/MultiMCVersion.h deleted file mode 100644 index 811b9076..00000000 --- a/MultiMCVersion.h +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -/*! - * \brief The Version class represents a MultiMC version. - */ -struct MultiMCVersion -{ - enum Type - { - //! Version type for stable release builds. - Release, - - //! Version type for release candidates. - ReleaseCandidate, - - //! Version type for development builds. - Development, - - //! Version type for custom builds. This is the default when no version type is specified. - Custom - }; - - /*! - * \brief Converts the Version to a string. - * \return The version number in string format (major.minor.revision.build). - */ - QString toString() const - { - QString vstr = QString("%1.%2").arg( - QString::number(major), - QString::number(minor)); - - if (hotfix > 0) vstr += "." + QString::number(hotfix); - - // If the build is a development build or release candidate, add that info to the end. - if (type == Development) vstr += "-dev" + QString::number(build); - else if (type == ReleaseCandidate) vstr += "-rc" + QString::number(build); - - return vstr; - } - - QString typeName() const - { - switch (type) - { - case Release: - return "Stable Release"; - case ReleaseCandidate: - return "Release Candidate"; - case Development: - return "Development"; - case Custom: - default: - return "Custom"; - } - } - - //! The major version number. - int major; - - //! The minor version number. - int minor; - - //! The hotfix number. - int hotfix; - - //! The build number. - int build; - - //! The build type. - Type type; - - //! The build channel. - QString channel; - - //! A short string identifying the platform that this version is for. For example, lin64 or win32. - QString platform; -}; - diff --git a/config.h.in b/config.h.in deleted file mode 100644 index 16e9f54e..00000000 --- a/config.h.in +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -// Version information -#define VERSION_MAJOR @MultiMC_VERSION_MAJOR@ -#define VERSION_MINOR @MultiMC_VERSION_MINOR@ -#define VERSION_HOTFIX @MultiMC_VERSION_HOTFIX@ -#define VERSION_BUILD @MultiMC_VERSION_BUILD@ -#define VERSION_TYPE @MultiMC_VERSION_TYPE@ - -// The version channel. This is used by the updater to determine what channel the current version came from. -#define VERSION_CHANNEL "@MultiMC_VERSION_CHANNEL@" - -// A short string identifying this build's platform. For example, "lin64" or "win32". -#define BUILD_PLATFORM "@MultiMC_BUILD_PLATFORM@" - -// URL for the updater's channel -#define CHANLIST_URL "@MultiMC_CHANLIST_URL@" - -// URL for notifications -#define NOTIFICATION_URL "@MultiMC_NOTIFICATION_URL@" - -// Used for matching notifications -#define FULL_VERSION_STR "@MultiMC_VERSION_MAJOR@.@MultiMC_VERSION_MINOR@.@MultiMC_VERSION_BUILD@" - -// enabled for updater dry run -#cmakedefine MultiMC_UPDATER_DRY_RUN - -// enabled for updater dry run -#cmakedefine MultiMC_UPDATER_FORCE_LOCAL - -// The commit hash of this build -#define GIT_COMMIT "@MultiMC_GIT_COMMIT@" - -// This is printed on start to standard output -#define VERSION_STR "@MultiMC_VERSION_STRING@" - -// This is used to fetch the news RSS feed. -// It defaults in CMakeLists.txt to "http://multimc.org/rss.xml" -#define NEWS_RSS_URL "@MultiMC_NEWS_RSS_URL@" - diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 480ee3b1..e4d28ca3 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -17,6 +17,7 @@ * limitations under the License. */ #include "MultiMC.h" +#include "Config.h" #include "MainWindow.h" #include "ui_MainWindow.h" @@ -107,9 +108,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); - QString winTitle = QString("MultiMC 5 - Version %1").arg(MMC->version().toString()); - if (!MMC->version().platform.isEmpty()) - winTitle += " on " + MMC->version().platform; + QString winTitle = QString("MultiMC 5 - Version %1").arg(BuildConfig.printableVersionString()); + if (!BuildConfig.BUILD_PLATFORM.isEmpty()) + winTitle += " on " + BuildConfig.BUILD_PLATFORM; setWindowTitle(winTitle); // OSX magic. @@ -709,9 +710,8 @@ void MainWindow::downloadUpdates(QString repo, int versionId, bool installOnExit if (updateDlg.exec(&updateTask)) { UpdateFlags baseFlags = None; -#ifdef MultiMC_UPDATER_DRY_RUN - baseFlags |= DryRun; -#endif + if(BuildConfig.UPDATER_DRY_RUN) + baseFlags |= DryRun; if (installOnExit) MMC->installUpdates(updateTask.updateFilesDir(), baseFlags | OnExit); else diff --git a/gui/dialogs/AboutDialog.cpp b/gui/dialogs/AboutDialog.cpp index 35c85815..944a61c8 100644 --- a/gui/dialogs/AboutDialog.cpp +++ b/gui/dialogs/AboutDialog.cpp @@ -18,6 +18,7 @@ #include #include "MultiMC.h" #include "gui/Platform.h" +#include "Config.h" AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDialog) { @@ -27,19 +28,19 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDia ui->urlLabel->setOpenExternalLinks(true); ui->icon->setPixmap(QIcon(":/icons/multimc/scalable/apps/multimc.svg").pixmap(64)); - ui->title->setText("MultiMC 5 " + MMC->version().toString()); + ui->title->setText("MultiMC 5 " + BuildConfig.printableVersionString()); - ui->versionLabel->setText(tr("Version") +": " + MMC->version().toString()); - ui->vtypeLabel->setText(tr("Version Type") +": " + MMC->version().typeName()); - ui->platformLabel->setText(tr("Platform") +": " + MMC->version().platform); + ui->versionLabel->setText(tr("Version") +": " + BuildConfig.printableVersionString()); + ui->vtypeLabel->setText(tr("Version Type") +": " + BuildConfig.versionTypeName()); + ui->platformLabel->setText(tr("Platform") +": " + BuildConfig.BUILD_PLATFORM); - if (MMC->version().build >= 0) - ui->buildNumLabel->setText(tr("Build Number") +": " + QString::number(MMC->version().build)); + if (BuildConfig.VERSION_BUILD >= 0) + ui->buildNumLabel->setText(tr("Build Number") +": " + QString::number(BuildConfig.VERSION_BUILD)); else ui->buildNumLabel->setVisible(false); - if (!MMC->version().channel.isEmpty()) - ui->channelLabel->setText(tr("Channel") +": " + MMC->version().channel); + if (!BuildConfig.VERSION_CHANNEL.isEmpty()) + ui->channelLabel->setText(tr("Channel") +": " + BuildConfig.VERSION_CHANNEL); else ui->channelLabel->setVisible(false); diff --git a/logic/MinecraftProcess.cpp b/logic/MinecraftProcess.cpp index 90767d9e..7b97b717 100644 --- a/logic/MinecraftProcess.cpp +++ b/logic/MinecraftProcess.cpp @@ -15,6 +15,7 @@ * limitations under the License. */ #include "MultiMC.h" +#include "Config.h" #include "MinecraftProcess.h" @@ -432,7 +433,7 @@ QStringList MinecraftProcess::javaArguments() const void MinecraftProcess::arm() { - emit log("MultiMC version: " + MMC->version().toString() + "\n\n"); + emit log("MultiMC version: " + BuildConfig.printableVersionString() + "\n\n"); emit log("Minecraft folder is:\n" + workingDirectory() + "\n\n"); if (!preLaunch()) diff --git a/logic/updater/DownloadUpdateTask.cpp b/logic/updater/DownloadUpdateTask.cpp index 83679f19..1a423210 100644 --- a/logic/updater/DownloadUpdateTask.cpp +++ b/logic/updater/DownloadUpdateTask.cpp @@ -16,6 +16,8 @@ #include "DownloadUpdateTask.h" #include "MultiMC.h" +#include "Config.h" + #include "logic/updater/UpdateChecker.h" #include "logic/net/NetJob.h" #include "pathutils.h" @@ -29,7 +31,7 @@ DownloadUpdateTask::DownloadUpdateTask(QString repoUrl, int versionId, QObject *parent) : Task(parent) { - m_cVersionId = MMC->version().build; + m_cVersionId = BuildConfig.VERSION_BUILD; m_nRepoUrl = repoUrl; m_nVersionId = versionId; @@ -58,7 +60,7 @@ void DownloadUpdateTask::processChannels() } QList channels = checker->getChannelList(); - QString channelId = MMC->version().channel; + QString channelId = BuildConfig.VERSION_CHANNEL; m_cRepoUrl.clear(); // Search through the channel list for a channel with the correct ID. @@ -405,17 +407,18 @@ DownloadUpdateTask::processFileLists(NetJob *job, if (isUpdater) { -#ifdef MultiMC_UPDATER_FORCE_LOCAL - QLOG_DEBUG() << "Skipping updater download and using local version."; -#else - auto cache_entry = MMC->metacache()->resolveEntry("root", entry.path); - QLOG_DEBUG() << "Updater will be in " << cache_entry->getFullPath(); - // force check. - cache_entry->stale = true; - - auto download = CacheDownload::make(QUrl(source.url), cache_entry); - job->addNetAction(download); -#endif + if(BuildConfig.UPDATER_FORCE_LOCAL) + QLOG_DEBUG() << "Skipping updater download and using local version."; + else + { + auto cache_entry = MMC->metacache()->resolveEntry("root", entry.path); + QLOG_DEBUG() << "Updater will be in " << cache_entry->getFullPath(); + // force check. + cache_entry->stale = true; + + auto download = CacheDownload::make(QUrl(source.url), cache_entry); + job->addNetAction(download); + } } else { diff --git a/logic/updater/NotificationChecker.cpp b/logic/updater/NotificationChecker.cpp index 191e90a3..39da362b 100644 --- a/logic/updater/NotificationChecker.cpp +++ b/logic/updater/NotificationChecker.cpp @@ -5,11 +5,11 @@ #include #include "MultiMC.h" -#include "MultiMCVersion.h" +#include "Config.h" #include "logic/net/CacheDownload.h" NotificationChecker::NotificationChecker(QObject *parent) - : QObject(parent), m_notificationsUrl(QUrl(NOTIFICATION_URL)) + : QObject(parent), m_notificationsUrl(QUrl(BuildConfig.NOTIFICATION_URL)) { // this will call checkForNotifications once the event loop is running QMetaObject::invokeMethod(this, "checkForNotifications", Qt::QueuedConnection); @@ -93,13 +93,12 @@ void NotificationChecker::downloadSucceeded(int) bool NotificationChecker::NotificationEntry::applies() const { - MultiMCVersion version = MMC->version(); - bool channelApplies = channel.isEmpty() || channel == version.channel; - bool platformApplies = platform.isEmpty() || platform == version.platform; + bool channelApplies = channel.isEmpty() || channel == BuildConfig.VERSION_CHANNEL; + bool platformApplies = platform.isEmpty() || platform == BuildConfig.BUILD_PLATFORM; bool fromApplies = - from.isEmpty() || from == FULL_VERSION_STR || !versionLessThan(FULL_VERSION_STR, from); + from.isEmpty() || from == BuildConfig.FULL_VERSION_STR || !versionLessThan(BuildConfig.FULL_VERSION_STR, from); bool toApplies = - to.isEmpty() || to == FULL_VERSION_STR || !versionLessThan(to, FULL_VERSION_STR); + to.isEmpty() || to == BuildConfig.FULL_VERSION_STR || !versionLessThan(to, BuildConfig.FULL_VERSION_STR); return channelApplies && platformApplies && fromApplies && toApplies; } diff --git a/logic/updater/UpdateChecker.cpp b/logic/updater/UpdateChecker.cpp index 8e2aa8b3..57ddfb0b 100644 --- a/logic/updater/UpdateChecker.cpp +++ b/logic/updater/UpdateChecker.cpp @@ -16,6 +16,7 @@ #include "UpdateChecker.h" #include "MultiMC.h" +#include "Config.h" #include "logger/QsLog.h" @@ -30,7 +31,7 @@ UpdateChecker::UpdateChecker() { - m_channelListUrl = CHANLIST_URL; + m_channelListUrl = BuildConfig.CHANLIST_URL; m_updateChecking = false; m_chanListLoading = false; m_checkUpdateWaiting = false; @@ -148,7 +149,7 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) // We've got the version with the greatest ID number. Now compare it to our current build // number and update if they're different. int newBuildNumber = newestVersion.value("Id").toVariant().toInt(); - if (newBuildNumber != MMC->version().build) + if (newBuildNumber != BuildConfig.VERSION_BUILD) { QLOG_DEBUG() << "Found newer version with ID" << newBuildNumber; // Update! diff --git a/tests/tst_UpdateChecker.cpp b/tests/tst_UpdateChecker.cpp index 0dcb242f..40232afe 100644 --- a/tests/tst_UpdateChecker.cpp +++ b/tests/tst_UpdateChecker.cpp @@ -4,6 +4,7 @@ #include "depends/settings/settingsobject.h" #include "depends/settings/setting.h" +#include "Config.h" #include "TestUtil.h" #include "logic/updater/UpdateChecker.h" @@ -154,7 +155,7 @@ slots: QFETCH(QList, result); MMC->settings()->set("UpdateChannel", channel); - MMC->m_version.build = currentBuild; + BuildConfig.VERSION_BUILD = currentBuild; UpdateChecker checker; checker.setChannelListUrl(channelUrl); -- cgit v1.2.3