Merge pull request #10370 from leoetlino/siof

Fix static initialisation order fiasco issue for Version variables
This commit is contained in:
Mai M 2022-01-13 23:34:55 -05:00 committed by GitHub
commit e8bbfc26fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 86 additions and 54 deletions

View File

@ -299,13 +299,13 @@ JNIEXPORT double JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetInputRa
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env,
jclass)
{
return ToJString(env, Common::scm_rev_str);
return ToJString(env, Common::GetScmRevStr());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env,
jclass)
{
return ToJString(env, Common::scm_rev_git_str);
return ToJString(env, Common::GetScmRevGitStr());
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv*, jclass)

View File

@ -149,8 +149,8 @@ private:
{
// Null-terminator is intentionally not copied.
std::memcpy(&id, "DCAC", sizeof(u32));
std::memcpy(ver, Common::scm_rev_git_str.c_str(),
std::min(Common::scm_rev_git_str.size(), sizeof(ver)));
std::memcpy(ver, Common::GetScmRevGitStr().c_str(),
std::min(Common::GetScmRevGitStr().size(), sizeof(ver)));
}
u32 id = 0;

View File

@ -17,28 +17,61 @@ namespace Common
#define BUILD_TYPE_STR ""
#endif
const std::string scm_rev_str = "Dolphin "
const std::string& GetScmRevStr()
{
static const std::string scm_rev_str = "Dolphin "
#if !SCM_IS_MASTER
"[" SCM_BRANCH_STR "] "
"[" SCM_BRANCH_STR "] "
#endif
#ifdef __INTEL_COMPILER
BUILD_TYPE_STR SCM_DESC_STR "-ICC";
BUILD_TYPE_STR SCM_DESC_STR "-ICC";
#else
BUILD_TYPE_STR SCM_DESC_STR;
BUILD_TYPE_STR SCM_DESC_STR;
#endif
return scm_rev_str;
}
const std::string scm_rev_git_str = SCM_REV_STR;
const std::string scm_desc_str = SCM_DESC_STR;
const std::string scm_branch_str = SCM_BRANCH_STR;
const std::string scm_distributor_str = SCM_DISTRIBUTOR_STR;
const std::string scm_update_track_str = SCM_UPDATE_TRACK_STR;
const std::string& GetScmRevGitStr()
{
static const std::string scm_rev_git_str = SCM_REV_STR;
return scm_rev_git_str;
}
const std::string& GetScmDescStr()
{
static const std::string scm_desc_str = SCM_DESC_STR;
return scm_desc_str;
}
const std::string& GetScmBranchStr()
{
static const std::string scm_branch_str = SCM_BRANCH_STR;
return scm_branch_str;
}
const std::string& GetScmDistributorStr()
{
static const std::string scm_distributor_str = SCM_DISTRIBUTOR_STR;
return scm_distributor_str;
}
const std::string& GetScmUpdateTrackStr()
{
static const std::string scm_update_track_str = SCM_UPDATE_TRACK_STR;
return scm_update_track_str;
}
const std::string& GetNetplayDolphinVer()
{
#ifdef _WIN32
const std::string netplay_dolphin_ver = SCM_DESC_STR " Win";
static const std::string netplay_dolphin_ver = SCM_DESC_STR " Win";
#elif __APPLE__
const std::string netplay_dolphin_ver = SCM_DESC_STR " Mac";
static const std::string netplay_dolphin_ver = SCM_DESC_STR " Mac";
#else
const std::string netplay_dolphin_ver = SCM_DESC_STR " Lin";
static const std::string netplay_dolphin_ver = SCM_DESC_STR " Lin";
#endif
return netplay_dolphin_ver;
}
} // namespace Common

View File

@ -7,12 +7,11 @@
namespace Common
{
// Git version number
extern const std::string scm_desc_str;
extern const std::string scm_branch_str;
extern const std::string scm_rev_str;
extern const std::string scm_rev_git_str;
extern const std::string scm_distributor_str;
extern const std::string scm_update_track_str;
extern const std::string netplay_dolphin_ver;
const std::string& GetScmDescStr();
const std::string& GetScmBranchStr();
const std::string& GetScmRevStr();
const std::string& GetScmRevGitStr();
const std::string& GetScmDistributorStr();
const std::string& GetScmUpdateTrackStr();
const std::string& GetNetplayDolphinVer();
} // namespace Common

View File

@ -381,7 +381,7 @@ const Info<bool> MAIN_FIFOPLAYER_EARLY_MEMORY_UPDATES{
// Main.AutoUpdate
const Info<std::string> MAIN_AUTOUPDATE_UPDATE_TRACK{{System::Main, "AutoUpdate", "UpdateTrack"},
Common::scm_update_track_str};
Common::GetScmUpdateTrackStr()};
const Info<std::string> MAIN_AUTOUPDATE_HASH_OVERRIDE{{System::Main, "AutoUpdate", "HashOverride"},
""};

View File

@ -982,7 +982,7 @@ void UpdateTitle(u32 ElapseTime)
}
}
std::string message = fmt::format("{} | {} | {}", Common::scm_rev_str, SSettings, SFPS);
std::string message = fmt::format("{} | {} | {}", Common::GetScmRevStr(), SSettings, SFPS);
if (Config::Get(Config::MAIN_SHOW_ACTIVE_TITLE))
{
const std::string& title = SConfig::GetInstance().GetTitleDescription();

View File

@ -248,10 +248,10 @@ void DolphinAnalytics::MakeBaseBuilder()
Common::AnalyticsReportBuilder builder;
// Version information.
builder.AddData("version-desc", Common::scm_desc_str);
builder.AddData("version-hash", Common::scm_rev_git_str);
builder.AddData("version-branch", Common::scm_branch_str);
builder.AddData("version-dist", Common::scm_distributor_str);
builder.AddData("version-desc", Common::GetScmDescStr());
builder.AddData("version-hash", Common::GetScmRevGitStr());
builder.AddData("version-branch", Common::GetScmBranchStr());
builder.AddData("version-dist", Common::GetScmDistributorStr());
// Auto-Update information.
builder.AddData("update-track", Config::Get(Config::MAIN_AUTOUPDATE_UPDATE_TRACK));

View File

@ -58,10 +58,10 @@ IPCReply GetVersion(const IOCtlVRequest& request)
return IPCReply(IPC_EINVAL);
}
const auto length = std::min(size_t(request.io_vectors[0].size), Common::scm_desc_str.size());
const auto length = std::min(size_t(request.io_vectors[0].size), Common::GetScmDescStr().size());
Memory::Memset(request.io_vectors[0].address, 0, request.io_vectors[0].size);
Memory::CopyToEmu(request.io_vectors[0].address, Common::scm_desc_str.data(), length);
Memory::CopyToEmu(request.io_vectors[0].address, Common::GetScmDescStr().data(), length);
return IPCReply(IPC_SUCCESS);
}

View File

@ -1471,7 +1471,7 @@ void GetSettings()
s_memcards |= (slot_a_has_raw_memcard || slot_a_has_gci_folder) << 0;
s_memcards |= (slot_b_has_raw_memcard || slot_b_has_gci_folder) << 1;
s_revision = ConvertGitRevisionToBytes(Common::scm_rev_git_str);
s_revision = ConvertGitRevisionToBytes(Common::GetScmRevGitStr());
if (!Config::Get(Config::MAIN_DSP_HLE))
{

View File

@ -229,8 +229,8 @@ bool NetPlayClient::Connect()
{
// send connect message
sf::Packet packet;
packet << Common::scm_rev_git_str;
packet << Common::netplay_dolphin_ver;
packet << Common::GetScmRevGitStr();
packet << Common::GetNetplayDolphinVer();
packet << m_player_name;
Send(packet);
enet_host_flush(m_client);
@ -283,7 +283,7 @@ bool NetPlayClient::Connect()
Player player;
player.name = m_player_name;
player.pid = m_pid;
player.revision = Common::netplay_dolphin_ver;
player.revision = Common::GetNetplayDolphinVer();
// add self to player list
m_players[m_pid] = player;

View File

@ -393,7 +393,7 @@ ConnectionError NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
std::string npver;
rpac >> npver;
// Dolphin netplay version
if (npver != Common::scm_rev_git_str)
if (npver != Common::GetScmRevGitStr())
return ConnectionError::VersionMismatch;
// game is currently running or game start is pending

View File

@ -116,7 +116,7 @@ static bool DoStateVersion(PointerWrap& p, std::string* version_created_by)
version = cookie - COOKIE_BASE;
}
*version_created_by = Common::scm_rev_str;
*version_created_by = Common::GetScmRevStr();
if (version > 42)
p.Do(*version_created_by);
else

View File

@ -125,7 +125,7 @@ RedumpVerifier::DownloadStatus RedumpVerifier::DownloadDatfile(const std::string
const std::optional<std::vector<u8>> result =
request.Get("http://redump.org/datfile/" + system + "/serial,version",
{{"User-Agent", Common::scm_rev_str}});
{{"User-Agent", Common::GetScmRevStr()}});
const std::string output_path = GetPathForSystem(system);

View File

@ -47,12 +47,12 @@ AboutDialog::AboutDialog(QWidget* parent) : QDialog(parent)
<a href='https://forums.dolphin-emu.org/'>%SUPPORT%</a>
)")
.replace(QStringLiteral("%VERSION_STRING%"),
QString::fromUtf8(Common::scm_desc_str.c_str()))
QString::fromUtf8(Common::GetScmDescStr().c_str()))
.replace(QStringLiteral("%BRANCH%"),
// i18n: "Branch" means the version control term, not a literal tree branch.
tr("Branch: %1").arg(QString::fromUtf8(Common::scm_branch_str.c_str())))
tr("Branch: %1").arg(QString::fromUtf8(Common::GetScmBranchStr().c_str())))
.replace(QStringLiteral("%REVISION%"),
tr("Revision: %1").arg(QString::fromUtf8(Common::scm_rev_git_str.c_str())))
tr("Revision: %1").arg(QString::fromUtf8(Common::GetScmRevGitStr().c_str())))
.replace(QStringLiteral("%QT_VERSION%"),
tr("Using Qt %1").arg(QStringLiteral(QT_VERSION_STR)))
.replace(QStringLiteral("%CHECK_FOR_UPDATES%"), tr("Check for updates"))

View File

@ -206,7 +206,7 @@ MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters,
const std::string& movie_path)
: QMainWindow(nullptr)
{
setWindowTitle(QString::fromStdString(Common::scm_rev_str));
setWindowTitle(QString::fromStdString(Common::GetScmRevStr()));
setWindowIcon(Resources::GetAppIcon());
setUnifiedTitleAndToolBarOnMac(true);
setAcceptDrops(true);
@ -1145,7 +1145,7 @@ void MainWindow::HideRenderWidget(bool reinit, bool is_exit)
m_rendering_to_main = false;
m_stack->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
disconnect(Host::GetInstance(), &Host::RequestTitle, this, &MainWindow::setWindowTitle);
setWindowTitle(QString::fromStdString(Common::scm_rev_str));
setWindowTitle(QString::fromStdString(Common::GetScmRevStr()));
}
// The following code works around a driver bug that would lead to Dolphin crashing when changing

View File

@ -158,7 +158,7 @@ void NetPlayBrowser::Refresh()
std::map<std::string, std::string> filters;
if (m_check_hide_incompatible->isChecked())
filters["version"] = Common::scm_desc_str;
filters["version"] = Common::GetScmDescStr();
if (!m_edit_name->text().isEmpty())
filters["name"] = m_edit_name->text().toStdString();
@ -246,7 +246,7 @@ void NetPlayBrowser::UpdateList()
auto* player_count = new QTableWidgetItem(QStringLiteral("%1").arg(entry.player_count));
auto* version = new QTableWidgetItem(QString::fromStdString(entry.version));
const bool enabled = Common::scm_desc_str == entry.version;
const bool enabled = Common::GetScmDescStr() == entry.version;
for (const auto& item : {region, name, password, in_game, game_id, player_count, version})
item->setFlags(enabled ? Qt::ItemIsEnabled | Qt::ItemIsSelectable : Qt::NoItemFlags);

View File

@ -55,7 +55,7 @@ void Updater::OnUpdateAvailable(const NewVersionInformation& info)
"download. "
"You are running %2.<br> Would you like to update?<br><h4>Release Notes:</h4>")
.arg(QString::fromStdString(info.new_shortrev))
.arg(QString::fromStdString(Common::scm_desc_str)));
.arg(QString::fromStdString(Common::GetScmDescStr())));
label->setTextFormat(Qt::RichText);
auto* changelog = new QTextBrowser;

View File

@ -161,7 +161,7 @@ void AutoUpdateChecker::CheckForUpdate(std::string_view update_track,
CleanupFromPreviousUpdate();
#endif
std::string_view version_hash = hash_override.empty() ? Common::scm_rev_git_str : hash_override;
std::string_view version_hash = hash_override.empty() ? Common::GetScmRevGitStr() : hash_override;
std::string url = fmt::format("https://dolphin-emu.org/update/check/v1/{}/{}/{}", update_track,
version_hash, GetPlatformID());

View File

@ -78,7 +78,7 @@ private:
std::unique_ptr<optparse::OptionParser> CreateParser(ParserOptions options)
{
auto parser = std::make_unique<optparse::OptionParser>();
parser->usage("usage: %prog [options]... [FILE]...").version(Common::scm_rev_str);
parser->usage("usage: %prog [options]... [FILE]...").version(Common::GetScmRevStr());
parser->add_option("-u", "--user").action("store").help("User folder path");
parser->add_option("-m", "--movie").action("store").help("Play a movie file");

View File

@ -170,7 +170,7 @@ bool NetPlayIndex::Add(const NetPlaySession& session)
"&password=" + std::to_string(session.has_password) + "&method=" + session.method +
"&server_id=" + session.server_id + "&in_game=" + std::to_string(session.in_game) +
"&port=" + std::to_string(session.port) + "&player_count=" +
std::to_string(session.player_count) + "&version=" + Common::scm_desc_str,
std::to_string(session.player_count) + "&version=" + Common::GetScmDescStr(),
{{"X-Is-Dolphin", "1"}}, Common::HttpRequest::AllowedReturnCodes::All);
if (!response.has_value())

View File

@ -115,7 +115,7 @@ std::optional<Shader::BinaryData> Shader::CompileShader(D3D_FEATURE_LEVEL featur
file << "\n";
file.write(static_cast<const char*>(errors->GetBufferPointer()), errors->GetBufferSize());
file << "\n";
file << "Dolphin Version: " + Common::scm_rev_str + "\n";
file << "Dolphin Version: " + Common::GetScmRevStr() + "\n";
file << "Video Backend: " + g_video_backend->GetDisplayName();
file.close();

View File

@ -363,7 +363,7 @@ bool ProgramShaderCache::CheckShaderCompileResult(GLuint id, GLenum type, std::s
File::OpenFStream(file, filename, std::ios_base::out);
file << s_glsl_header << code << info_log;
file << "\n";
file << "Dolphin Version: " + Common::scm_rev_str + "\n";
file << "Dolphin Version: " + Common::GetScmRevStr() + "\n";
file << "Video Backend: " + g_video_backend->GetDisplayName();
file.close();
@ -408,7 +408,7 @@ bool ProgramShaderCache::CheckProgramLinkResult(GLuint id, std::string_view vcod
file << info_log;
file << "\n";
file << "Dolphin Version: " + Common::scm_rev_str + "\n";
file << "Dolphin Version: " + Common::GetScmRevStr() + "\n";
file << "Video Backend: " + g_video_backend->GetDisplayName();
file.close();

View File

@ -169,7 +169,7 @@ static std::optional<SPIRVCodeVector> CompileShaderToSPV(EShLanguage stage,
}
stream << "\n";
stream << "Dolphin Version: " + Common::scm_rev_str + "\n";
stream << "Dolphin Version: " + Common::GetScmRevStr() + "\n";
stream << "Video Backend: " + g_video_backend->GetDisplayName();
PanicAlertFmt("{} (written to {})", msg, filename);