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 committed Nov 8, 2024
1 parent 5441c7e commit aa8d8c7
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 112 deletions.
90 changes: 43 additions & 47 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,12 @@ 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;

#if (defined(_WIN32) || defined(__linux__) || defined(__APPLE__))
#ifdef __linux__
// For Linux, we need to check whether we're running from the appimage.
if (!std::getenv("APPIMAGE"))
Expand All @@ -130,39 +123,36 @@ bool AutoUpdaterDialog::isSupported()

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 +205,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 +229,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 +368,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 +453,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 +538,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
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
4 changes: 2 additions & 2 deletions pcsx2/ImGui/FullscreenUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#define IMGUI_DEFINE_MATH_OPERATORS

#include "BuildVersion.h"
#include "CDVD/CDVDcommon.h"
#include "GS/Renderers/Common/GSDevice.h"
#include "GS/Renderers/Common/GSTexture.h"
Expand All @@ -23,7 +24,6 @@
#include "USB/USB.h"
#include "VMManager.h"
#include "ps2/BiosTools.h"
#include "svnrev.h"

#include "common/Console.h"
#include "common/Error.h"
Expand Down Expand Up @@ -6633,7 +6633,7 @@ void FullscreenUI::DrawAboutWindow()
"This allows you to play PS2 games on your PC, with many additional features and benefits."));
ImGui::NewLine();

ImGui::TextWrapped(FSUI_CSTR("Version: %s"), GIT_REV);
ImGui::TextWrapped(FSUI_CSTR("Version: %s"), BuildVersion::GitRev);
ImGui::NewLine();

ImGui::TextWrapped("%s",
Expand Down
Loading

0 comments on commit aa8d8c7

Please sign in to comment.