Skip to content

Commit

Permalink
Misc: Minimise the amount of work done when svnrev.h is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoticgd authored and F0bes committed Nov 12, 2024
1 parent 959be14 commit eeb9193
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 90 deletions.
94 changes: 44 additions & 50 deletions pcsx2-qt/AutoUpdaterDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "QtProgressCallback.h"
#include "QtUtils.h"

#include "pcsx2/BuildVersion.h"
#include "pcsx2/Host.h"
#include "svnrev.h"

#include "updater/UpdaterExtractor.h"

Expand Down Expand Up @@ -47,12 +47,6 @@
// Interval at which HTTP requests are polled.
static constexpr u32 HTTP_POLL_INTERVAL = 10;

// Logic to detect whether we can use the auto updater.
// We use tagged commit, because this gets set on nightly builds.
#if (defined(_WIN32) || defined(__linux__) || defined(__APPLE__)) && GIT_TAGGED_COMMIT

#define AUTO_UPDATER_SUPPORTED 1

#if defined(_WIN32)
#define UPDATE_PLATFORM_STR "Windows"
#elif defined(__linux__)
Expand All @@ -69,10 +63,6 @@ static constexpr u32 HTTP_POLL_INTERVAL = 10;
#define UPDATE_ADDITIONAL_TAGS "SSE4"
#endif

#endif

#ifdef AUTO_UPDATER_SUPPORTED

#define LATEST_RELEASE_URL "https://api.pcsx2.net/v1/%1Releases?pageSize=1"
#define CHANGES_URL "https://api.github.com/repos/PCSX2/pcsx2/compare/%1...%2"

Expand All @@ -87,8 +77,6 @@ static const char* UPDATE_TAGS[] = {"stable", "nightly"};
#define DEFAULT_UPDATER_CHANNEL "nightly"
#endif

#endif

AutoUpdaterDialog::AutoUpdaterDialog(QWidget* parent /* = nullptr */)
: QDialog(parent)
{
Expand All @@ -109,7 +97,11 @@ AutoUpdaterDialog::~AutoUpdaterDialog() = default;

bool AutoUpdaterDialog::isSupported()
{
#ifdef AUTO_UPDATER_SUPPORTED
// Logic to detect whether we can use the auto updater.
// We use tagged commit, because this gets set on nightly builds.
if (!BuildVersion::GitTaggedCommit)
return false;

#ifdef __linux__
// For Linux, we need to check whether we're running from the appimage.
if (!std::getenv("APPIMAGE"))
Expand All @@ -119,50 +111,46 @@ bool AutoUpdaterDialog::isSupported()
}

return true;
#else
#elif defined(_WIN32) || defined(__APPLE__)
// Windows, MacOS - always supported.
return true;
#endif
#else
return false;
#endif
}

QStringList AutoUpdaterDialog::getTagList()
{
#ifdef AUTO_UPDATER_SUPPORTED
if (!isSupported())
return QStringList();

return QStringList(std::begin(UPDATE_TAGS), std::end(UPDATE_TAGS));
#else
return QStringList();
#endif
}

std::string AutoUpdaterDialog::getDefaultTag()
{
#ifdef AUTO_UPDATER_SUPPORTED
if (!isSupported())
return {};

return DEFAULT_UPDATER_CHANNEL;
#else
return {};
#endif
}

QString AutoUpdaterDialog::getCurrentVersion()
{
return QStringLiteral(GIT_TAG);
return QString(BuildVersion::GitTag);
}

QString AutoUpdaterDialog::getCurrentVersionDate()
{
return QStringLiteral(GIT_DATE);
return QString(BuildVersion::GitDate);
}

QString AutoUpdaterDialog::getCurrentUpdateTag() const
{
#ifdef AUTO_UPDATER_SUPPORTED
if (!isSupported())
return QString();

return QString::fromStdString(Host::GetBaseStringSettingValue("AutoUpdater", "UpdateTag", DEFAULT_UPDATER_CHANNEL));
#else
return QString();
#endif
}

void AutoUpdaterDialog::reportError(const char* msg, ...)
Expand Down Expand Up @@ -215,18 +203,21 @@ void AutoUpdaterDialog::queueUpdateCheck(bool display_message)
{
m_display_messages = display_message;

#ifdef AUTO_UPDATER_SUPPORTED
if (!ensureHttpReady())
if (isSupported())
{
if (!ensureHttpReady())
{
emit updateCheckCompleted();
return;
}

m_http->CreateRequest(QStringLiteral(LATEST_RELEASE_URL).arg(getCurrentUpdateTag()).toStdString(),
std::bind(&AutoUpdaterDialog::getLatestReleaseComplete, this, std::placeholders::_1, std::placeholders::_3));
}
else
{
emit updateCheckCompleted();
return;
}

m_http->CreateRequest(QStringLiteral(LATEST_RELEASE_URL).arg(getCurrentUpdateTag()).toStdString(),
std::bind(&AutoUpdaterDialog::getLatestReleaseComplete, this, std::placeholders::_1, std::placeholders::_3));
#else
emit updateCheckCompleted();
#endif
}

void AutoUpdaterDialog::getLatestReleaseComplete(s32 status_code, std::vector<u8> data)
Expand All @@ -236,7 +227,9 @@ void AutoUpdaterDialog::getLatestReleaseComplete(s32 status_code, std::vector<u8
cpuinfo_initialize();
#endif

#ifdef AUTO_UPDATER_SUPPORTED
if (!isSupported())
return;

bool found_update_info = false;

if (status_code == HTTPDownloader::HTTP_STATUS_OK)
Expand Down Expand Up @@ -373,23 +366,25 @@ void AutoUpdaterDialog::getLatestReleaseComplete(s32 status_code, std::vector<u8
checkIfUpdateNeeded();

emit updateCheckCompleted();
#endif
}

void AutoUpdaterDialog::queueGetChanges()
{
#ifdef AUTO_UPDATER_SUPPORTED
if (!ensureHttpReady())
if (!isSupported() || !ensureHttpReady())
return;

m_http->CreateRequest(QStringLiteral(CHANGES_URL).arg(GIT_HASH).arg(m_latest_version).toStdString(),
m_http->CreateRequest(QStringLiteral(CHANGES_URL).arg(BuildVersion::GitHash).arg(m_latest_version).toStdString(),
std::bind(&AutoUpdaterDialog::getChangesComplete, this, std::placeholders::_1, std::placeholders::_3));
#endif
}

void AutoUpdaterDialog::getChangesComplete(s32 status_code, std::vector<u8> data)
{
#ifdef AUTO_UPDATER_SUPPORTED
if (!isSupported())
{
m_ui.downloadAndInstall->setEnabled(true);
return;
}

if (status_code == HTTPDownloader::HTTP_STATUS_OK)
{
QJsonParseError parse_error;
Expand Down Expand Up @@ -456,7 +451,6 @@ void AutoUpdaterDialog::getChangesComplete(s32 status_code, std::vector<u8> data
{
reportError("Failed to download change list: %d", status_code);
}
#endif

m_ui.downloadAndInstall->setEnabled(true);
}
Expand Down Expand Up @@ -542,10 +536,10 @@ void AutoUpdaterDialog::checkIfUpdateNeeded()
const QString last_checked_version(
QString::fromStdString(Host::GetBaseStringSettingValue("AutoUpdater", "LastVersion")));

Console.WriteLn(Color_StrongGreen, "Current version: %s", GIT_TAG);
Console.WriteLn(Color_StrongGreen, "Current version: %s", BuildVersion::GitTag);
Console.WriteLn(Color_StrongYellow, "Latest version: %s", m_latest_version.toUtf8().constData());
Console.WriteLn(Color_StrongOrange, "Last checked version: %s", last_checked_version.toUtf8().constData());
if (m_latest_version == GIT_TAG || m_latest_version == last_checked_version)
if (m_latest_version == BuildVersion::GitTag || m_latest_version == last_checked_version)
{
Console.WriteLn(Color_StrongGreen, "No update needed.");

Expand Down Expand Up @@ -787,7 +781,7 @@ void AutoUpdaterDialog::cleanupAfterUpdate()

static QString UpdateVersionNumberInName(QString name, QStringView new_version)
{
QString current_version_string = QStringLiteral(GIT_TAG);
QString current_version_string(BuildVersion::GitTag);
QStringView current_version = current_version_string;
if (!current_version.empty() && !new_version.empty() && current_version[0] == 'v' && new_version[0] == 'v')
{
Expand Down
1 change: 0 additions & 1 deletion pcsx2-qt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "Settings/MemoryCardCreateDialog.h"
#include "Tools/InputRecording/InputRecordingViewer.h"
#include "Tools/InputRecording/NewInputRecordingDlg.h"
#include "svnrev.h"

#include "pcsx2/Achievements.h"
#include "pcsx2/CDVD/CDVDcommon.h"
Expand Down
4 changes: 2 additions & 2 deletions pcsx2-qt/QtHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include "QtProgressCallback.h"
#include "QtUtils.h"
#include "SetupWizardDialog.h"
#include "svnrev.h"

#include "pcsx2/CDVD/CDVDcommon.h"
#include "pcsx2/Achievements.h"
#include "pcsx2/BuildVersion.h"
#include "pcsx2/CDVD/CDVD.h"
#include "pcsx2/Counters.h"
#include "pcsx2/DebugTools/Debug.h"
Expand Down Expand Up @@ -1468,7 +1468,7 @@ bool Host::RequestResetSettings(bool folders, bool core, bool controllers, bool

QString QtHost::GetAppNameAndVersion()
{
return QStringLiteral("PCSX2 " GIT_REV);
return QString("PCSX2 %1").arg(BuildVersion::GitRev);
}

QString QtHost::GetAppConfigSuffix()
Expand Down
4 changes: 2 additions & 2 deletions pcsx2/Achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define IMGUI_DEFINE_MATH_OPERATORS

#include "Achievements.h"
#include "BuildVersion.h"
#include "CDVD/CDVD.h"
#include "Elfheader.h"
#include "Host.h"
Expand All @@ -16,7 +17,6 @@
#include "Memory.h"
#include "SaveState.h"
#include "VMManager.h"
#include "svnrev.h"
#include "vtlb.h"

#include "common/Assertions.h"
Expand Down Expand Up @@ -3039,7 +3039,7 @@ void Achievements::SwitchToRAIntegration()

void Achievements::RAIntegration::InitializeRAIntegration(void* main_window_handle)
{
RA_InitClient((HWND)main_window_handle, "PCSX2", GIT_TAG);
RA_InitClient((HWND)main_window_handle, "PCSX2", BuildVersion::GitTag);
RA_SetUserAgentDetail(Host::GetHTTPUserAgent().c_str());

RA_InstallSharedFunctions(RACallbackIsActive, RACallbackCauseUnpause, RACallbackCausePause, RACallbackRebuildMenu,
Expand Down
16 changes: 16 additions & 0 deletions pcsx2/BuildVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+

#include "svnrev.h"

namespace BuildVersion
{
const char* GitTag = GIT_TAG;
bool GitTaggedCommit = GIT_TAGGED_COMMIT;
int GitTagHi = GIT_TAG_HI;
int GitTagMid = GIT_TAG_MID;
int GitTagLo = GIT_TAG_LO;
const char* GitRev = GIT_REV;
const char* GitHash = GIT_HASH;
const char* GitDate = GIT_DATE;
} // namespace BuildVersion
18 changes: 18 additions & 0 deletions pcsx2/BuildVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+

#pragma once

// This file provides the same information as svnrev.h except you don't need to
// recompile each object file using it when said information is updated.
namespace BuildVersion
{
extern const char* GitTag;
extern bool GitTaggedCommit;
extern int GitTagHi;
extern int GitTagMid;
extern int GitTagLo;
extern const char* GitRev;
extern const char* GitHash;
extern const char* GitDate;
} // namespace BuildVersion
2 changes: 2 additions & 0 deletions pcsx2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ endif(WIN32)
# Main pcsx2 source
set(pcsx2Sources
Achievements.cpp
BuildVersion.cpp
Cache.cpp
COP0.cpp
COP2.cpp
Expand Down Expand Up @@ -140,6 +141,7 @@ set(pcsx2Sources
# Main pcsx2 header
set(pcsx2Headers
Achievements.h
BuildVersion.h
Cache.h
Common.h
Config.h
Expand Down
10 changes: 5 additions & 5 deletions pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "GS/Renderers/Vulkan/VKShaderCache.h"
#include "GS/Renderers/Vulkan/VKSwapChain.h"

#include "BuildVersion.h"
#include "Host.h"

#include "common/Console.h"
Expand Down Expand Up @@ -103,16 +104,15 @@ VkInstance GSDeviceVK::CreateVulkanInstance(const WindowInfo& wi, OptionalExtens
if (!SelectInstanceExtensions(&enabled_extensions, wi, oe, enable_debug_utils))
return VK_NULL_HANDLE;

// Remember to manually update this every release. We don't pull in svnrev.h here, because
// it's only the major/minor version, and rebuilding the file every time something else changes
// is unnecessary.
VkApplicationInfo app_info = {};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
app_info.pNext = nullptr;
app_info.pApplicationName = "PCSX2";
app_info.applicationVersion = VK_MAKE_VERSION(1, 7, 0);
app_info.applicationVersion = VK_MAKE_VERSION(
BuildVersion::GitTagHi, BuildVersion::GitTagMid, BuildVersion::GitTagLo);
app_info.pEngineName = "PCSX2";
app_info.engineVersion = VK_MAKE_VERSION(1, 7, 0);
app_info.engineVersion = VK_MAKE_VERSION(
BuildVersion::GitTagHi, BuildVersion::GitTagMid, BuildVersion::GitTagLo);
app_info.apiVersion = VK_API_VERSION_1_1;

VkInstanceCreateInfo instance_create_info = {};
Expand Down
4 changes: 2 additions & 2 deletions pcsx2/Host.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+

#include "BuildVersion.h"
#include "GS.h"
#include "GS/Renderers/HW/GSTextureReplacements.h"
#include "Host.h"
#include "LayeredSettingsInterface.h"
#include "VMManager.h"
#include "svnrev.h"

#include "common/Assertions.h"
#include "common/CrashHandler.h"
Expand Down Expand Up @@ -159,7 +159,7 @@ bool Host::ConfirmFormattedMessage(const std::string_view title, const char* for

std::string Host::GetHTTPUserAgent()
{
return fmt::format("PCSX2 " GIT_REV " ({})", GetOSVersionString());
return fmt::format("PCSX2 {} ({})", BuildVersion::GitRev, GetOSVersionString());
}

std::unique_lock<std::mutex> Host::GetSettingsLock()
Expand Down
Loading

0 comments on commit eeb9193

Please sign in to comment.