From dea21b20a0a46974518f52612c152ed4a378c91e Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 16 Jan 2018 20:17:53 +0000 Subject: [PATCH] Remove global GIT_COMMIT_HASH define, use GitVersionHash global var * On windows, the change in a global GIT_COMMIT_HASH define in each project needing it meant a full rebuild every time the commit changed. * Ideally we'd set the define only on one file in each project, but MSBuild doesn't seem to support that. Instead we make a new tiny project that compiles a single cpp exporting a global var, and reference that global var in each other project. --- CMakeLists.txt | 2 +- qrenderdoc/Windows/Dialogs/AboutDialog.cpp | 11 ++-- qrenderdoc/Windows/MainWindow.cpp | 6 +- qrenderdoc/qrenderdoc.pro | 5 ++ qrenderdoc/qrenderdoc_local.vcxproj | 4 +- renderdoc.sln | 11 ++++ renderdoc/CMakeLists.txt | 1 + renderdoc/api/replay/version.cpp | 41 ++++++++++++ renderdoc/api/replay/version.h | 18 +++--- renderdoc/core/android.cpp | 13 +++- renderdoc/core/core.cpp | 2 +- renderdoc/core/crash_handler.h | 2 +- renderdoc/renderdoc.vcxproj | 4 +- ...derdoc.props => renderdoc_version.vcxproj} | 63 ++++++++++++++++--- renderdoc/renderdoc_version.vcxproj.filters | 6 ++ renderdoccmd/CMakeLists.txt | 2 +- renderdoccmd/renderdoccmd.cpp | 2 +- renderdoccmd/renderdoccmd.vcxproj | 4 +- 18 files changed, 158 insertions(+), 39 deletions(-) create mode 100644 renderdoc/api/replay/version.cpp rename renderdoc/{renderdoc.props => renderdoc_version.vcxproj} (56%) create mode 100644 renderdoc/renderdoc_version.vcxproj.filters diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a88e2f86..2b7dede89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ endif() # version setting variables. See renderdoc/api/replay/version.h -set(BUILD_VERSION_HASH "" CACHE STRING "The current git commit hash. See GIT_COMMIT_HASH in renderdoc/api/replay/version.h") +set(BUILD_VERSION_HASH "" CACHE STRING "The current git commit hash. See GIT_COMMIT_HASH in renderdoc/api/replay/version.cpp") option(BUILD_VERSION_STABLE "If this is a stable build. See RENDERDOC_STABLE_BUILD in renderdoc/api/replay/version.h" OFF) set(BUILD_VERSION_DIST_NAME "" CACHE STRING "The name of the distribution. See DISTRIBUTION_NAME in renderdoc/api/replay/version.h") set(BUILD_VERSION_DIST_VER "" CACHE STRING "The distribution-specific version number. See DISTRIBUTION_VERSION in renderdoc/api/replay/version.h") diff --git a/qrenderdoc/Windows/Dialogs/AboutDialog.cpp b/qrenderdoc/Windows/Dialogs/AboutDialog.cpp index e008c63f4..69ec056f4 100644 --- a/qrenderdoc/Windows/Dialogs/AboutDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/AboutDialog.cpp @@ -34,7 +34,7 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDia { ui->setupUi(this); - QString hash = lit(GIT_COMMIT_HASH); + QString hash = QString::fromLatin1(GitVersionHash); if(hash[0] == QLatin1Char('N') && hash[1] == QLatin1Char('O')) { @@ -43,11 +43,10 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDia } else { - ui->version->setText( - QFormatStr("Version %1 (built from %3)") - .arg(lit(FULL_VERSION_STRING)) - .arg(lit("https://github.com/baldurk/renderdoc/commit/" GIT_COMMIT_HASH)) - .arg(lit(GIT_COMMIT_HASH).left(8))); + ui->version->setText(QFormatStr("Version %1 (built from %3)") + .arg(lit(FULL_VERSION_STRING)) + .arg(lit("https://github.com/baldurk/renderdoc/commit/%1").arg(hash)) + .arg(hash.left(8))); } #if defined(DISTRIBUTION_VERSION) diff --git a/qrenderdoc/Windows/MainWindow.cpp b/qrenderdoc/Windows/MainWindow.cpp index f4116497e..a0b5d5a28 100644 --- a/qrenderdoc/Windows/MainWindow.cpp +++ b/qrenderdoc/Windows/MainWindow.cpp @@ -873,7 +873,9 @@ void MainWindow::SetTitle(const QString &filename) if(RENDERDOC_STABLE_BUILD) text += lit(FULL_VERSION_STRING); else - text += tr("Unstable release (%1 - %2)").arg(lit(FULL_VERSION_STRING)).arg(lit(GIT_COMMIT_HASH)); + text += tr("Unstable release (%1 - %2)") + .arg(lit(FULL_VERSION_STRING)) + .arg(QString::fromLatin1(GitVersionHash)); if(QString::fromLatin1(RENDERDOC_GetVersionString()) != lit(MAJOR_MINOR_VERSION_STRING)) text += tr(" - !! VERSION MISMATCH DETECTED !!"); @@ -2181,7 +2183,7 @@ void MainWindow::on_action_Send_Error_Report_triggered() QVariantMap json; json[lit("version")] = lit(FULL_VERSION_STRING); - json[lit("gitcommit")] = lit(GIT_COMMIT_HASH); + json[lit("gitcommit")] = QString::fromLatin1(GitVersionHash); json[lit("replaycrash")] = 1; json[lit("report")] = (QString)report; diff --git a/qrenderdoc/qrenderdoc.pro b/qrenderdoc/qrenderdoc.pro index 6a394c8a6..df4f83920 100644 --- a/qrenderdoc/qrenderdoc.pro +++ b/qrenderdoc/qrenderdoc.pro @@ -91,6 +91,9 @@ win32 { # Link against the core library LIBS += $$DESTDIR/renderdoc.lib + # Link against the version library + LIBS += $$DESTDIR/version.lib + QMAKE_CXXFLAGS_WARN_ON -= -w34100 DEFINES += RENDERDOC_PLATFORM_WIN32 @@ -119,6 +122,8 @@ win32 { SOURCES += $$CMAKE_DIR/qrenderdoc/qrenderdoc_python.cxx SOURCES += $$CMAKE_DIR/qrenderdoc/qrenderdoc.py.c + SOURCES += $$_PRO_FILE_PWD_/../renderdoc/api/replay/version.cpp + CONFIG += warn_off CONFIG += c++14 QMAKE_CFLAGS_WARN_OFF -= -w diff --git a/qrenderdoc/qrenderdoc_local.vcxproj b/qrenderdoc/qrenderdoc_local.vcxproj index 6c34bb88d..6c692e9bd 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj +++ b/qrenderdoc/qrenderdoc_local.vcxproj @@ -1717,6 +1717,9 @@ IF %ERRORLEVEL% NEQ 0 (echo ==================================================== {e2b46d67-90e2-40b6-9597-72930e7845e5} + + {257fd75c-4d17-4a23-a754-23bfd85887a0} + @@ -1839,5 +1842,4 @@ IF %ERRORLEVEL% NEQ 0 (echo ==================================================== - \ No newline at end of file diff --git a/renderdoc.sln b/renderdoc.sln index f4475373d..b91521c82 100644 --- a/renderdoc.sln +++ b/renderdoc.sln @@ -72,6 +72,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pyrenderdoc_module", "qrend EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qrenderdoc_module", "qrenderdoc\Code\pyrenderdoc\qrenderdoc_module.vcxproj", "{61157930-78C3-4355-8B49-4CC91B98F17B}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "version", "renderdoc\renderdoc_version.vcxproj", "{257FD75C-4D17-4A23-A754-23BFD85887A0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Development|x64 = Development|x64 @@ -232,6 +234,14 @@ Global {61157930-78C3-4355-8B49-4CC91B98F17B}.Release|x64.Build.0 = Release|x64 {61157930-78C3-4355-8B49-4CC91B98F17B}.Release|x86.ActiveCfg = Release|Win32 {61157930-78C3-4355-8B49-4CC91B98F17B}.Release|x86.Build.0 = Release|Win32 + {257FD75C-4D17-4A23-A754-23BFD85887A0}.Development|x64.ActiveCfg = Development|x64 + {257FD75C-4D17-4A23-A754-23BFD85887A0}.Development|x64.Build.0 = Development|x64 + {257FD75C-4D17-4A23-A754-23BFD85887A0}.Development|x86.ActiveCfg = Development|Win32 + {257FD75C-4D17-4A23-A754-23BFD85887A0}.Development|x86.Build.0 = Development|Win32 + {257FD75C-4D17-4A23-A754-23BFD85887A0}.Release|x64.ActiveCfg = Release|x64 + {257FD75C-4D17-4A23-A754-23BFD85887A0}.Release|x64.Build.0 = Release|x64 + {257FD75C-4D17-4A23-A754-23BFD85887A0}.Release|x86.ActiveCfg = Release|Win32 + {257FD75C-4D17-4A23-A754-23BFD85887A0}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -262,5 +272,6 @@ Global {A0E6051E-4374-42E0-9F3C-28DFC64A1029} = {89059266-9C4E-4637-AB1D-BFF1DC15096B} {A8998B2D-652A-47F8-955B-5654B222B4EB} = {A0E6051E-4374-42E0-9F3C-28DFC64A1029} {61157930-78C3-4355-8B49-4CC91B98F17B} = {A0E6051E-4374-42E0-9F3C-28DFC64A1029} + {257FD75C-4D17-4A23-A754-23BFD85887A0} = {B5A783D9-AEB9-420D-8E77-D4D930F8D88C} EndGlobalSection EndGlobal diff --git a/renderdoc/CMakeLists.txt b/renderdoc/CMakeLists.txt index 95cc036ad..3268c67b4 100644 --- a/renderdoc/CMakeLists.txt +++ b/renderdoc/CMakeLists.txt @@ -70,6 +70,7 @@ set(sources api/replay/vk_pipestate.h api/replay/version.h api/replay/renderdoc_tostr.inl + api/replay/version.cpp common/common.cpp common/common.h common/custom_assert.h diff --git a/renderdoc/api/replay/version.cpp b/renderdoc/api/replay/version.cpp new file mode 100644 index 000000000..70de3779a --- /dev/null +++ b/renderdoc/api/replay/version.cpp @@ -0,0 +1,41 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2018 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +// By default this is generated by calling out to git directly as long as the build is running from +// within a git clone. Windows users will need VS2015 or above to invoke git. +// +// On windows if you're not running from within git, you can set the hash manually here. On +// non-windows it's recommended to set BUILD_VERSION_HASH in the cmake build command. +// +// On distributed builds this should be set to the last upstream git commit where the build comes +// from. If any later commits are cherry-picked or local patches are applied, this should still +// point to the hash of the tree that the build was based on. +#if !defined(GIT_COMMIT_HASH) +#define GIT_COMMIT_HASH "NO_GIT_COMMIT_HASH_DEFINED_AT_BUILD_TIME" +#endif + +// Note the hash should be precisely 40 characters, as comes from git rev-parse. +extern "C" const char GitVersionHash[41] = GIT_COMMIT_HASH; + +#pragma comment(linker, "/include:GitVersionHash") \ No newline at end of file diff --git a/renderdoc/api/replay/version.h b/renderdoc/api/replay/version.h index e5a725ddf..971bcd69d 100644 --- a/renderdoc/api/replay/version.h +++ b/renderdoc/api/replay/version.h @@ -40,17 +40,13 @@ // set, then just update the version numbers in the build process). // -// This should be set to the last upstream git commit where the build comes from. If any later -// commits are cherry-picked or local patches are applied, this should still point to the hash of -// the tree that the build was based on. -// -// Windows users using VS2015 and above should get this defined as part of the build process as -// long as they are running from within a git clone. If not, it can be manually defined here. -// On other platforms git will be invoked directly if possible, but if the build isn't running -// from within a clone you should set BUILD_VERSION_HASH in the cmake build command. -#if !defined(GIT_COMMIT_HASH) -#define GIT_COMMIT_HASH "NO_GIT_COMMIT_HASH_DEFINED" -#endif +// To prevent a project rebuild cascading when the git commit changes, we declare a char array +// that's implemented in version.inl, which can be included in each module that uses the version. +// It's 41 characters to allow 40 characters of commit hash plus trailing NULL. +// Then the .cpp that includes version.inl is the only one that actually needs to have the hash +// defined properly. +// This replaces the previous GIT_COMMIT_HASH define here. +extern "C" const char GitVersionHash[41]; // If this variable is set to 1, then this build is considered a stable version - based on a tagged // version number upstream, possibly with some patches applied as necessary. diff --git a/renderdoc/core/android.cpp b/renderdoc/core/android.cpp index 99eeb0b88..206a2a8af 100644 --- a/renderdoc/core/android.cpp +++ b/renderdoc/core/android.cpp @@ -28,6 +28,13 @@ #include "core/core.h" #include "strings/string_utils.h" +// we use GIT_COMMIT_HASH here instead of GitVersionHash since the value is actually only used on +// android - where GIT_COMMIT_HASH is available globally. We need to have it available in a static +// initializer at compile time, which wouldn't be possible with GitVersionHash. +#if !defined(GIT_COMMIT_HASH) +#define GIT_COMMIT_HASH "NO_GIT_COMMIT_HASH_DEFINED_AT_BUILD_TIME" +#endif + extern "C" RENDERDOC_API const char RENDERDOC_Version_Tag_String[] = "RenderDoc_build_version: " FULL_VERSION_STRING " from git commit " GIT_COMMIT_HASH; @@ -762,7 +769,7 @@ bool CheckLayerVersion(const string &deviceID, const string &layerName, const st string version = vec[1]; string hash = vec[5]; - if(version == FULL_VERSION_STRING && hash == GIT_COMMIT_HASH) + if(version == FULL_VERSION_STRING && hash == GitVersionHash) { RDCLOG("RenderDoc layer version (%s) and git hash (%s) match.", version.c_str(), hash.c_str()); match = true; @@ -772,7 +779,7 @@ bool CheckLayerVersion(const string &deviceID, const string &layerName, const st RDCLOG( "RenderDoc layer version (%s) and git hash (%s) do NOT match the host version (%s) or git " "hash (%s).", - version.c_str(), hash.c_str(), FULL_VERSION_STRING, GIT_COMMIT_HASH); + version.c_str(), hash.c_str(), FULL_VERSION_STRING, GitVersionHash); } return match; @@ -993,7 +1000,7 @@ bool CheckAndroidServerVersion(const string &deviceID) // Compare the server's versionCode and versionName with the host's for compatibility string hostVersionCode = string(STRINGIZE(RENDERDOC_VERSION_MAJOR)) + string(STRINGIZE(RENDERDOC_VERSION_MINOR)); - string hostVersionName = RENDERDOC_STABLE_BUILD ? MAJOR_MINOR_VERSION_STRING : GIT_COMMIT_HASH; + string hostVersionName = RENDERDOC_STABLE_BUILD ? MAJOR_MINOR_VERSION_STRING : GitVersionHash; // False positives will hurt us, so check for explicit matches if((hostVersionCode == versionCode) && (hostVersionName == versionName)) diff --git a/renderdoc/core/core.cpp b/renderdoc/core/core.cpp index 2c87188d0..b74a1552c 100644 --- a/renderdoc/core/core.cpp +++ b/renderdoc/core/core.cpp @@ -294,7 +294,7 @@ void RenderDoc::Initialise() RDCLOG("RenderDoc v%s %s %s (%s) %s", MAJOR_MINOR_VERSION_STRING, sizeof(uintptr_t) == sizeof(uint64_t) ? "x64" : "x86", - ENABLED(RDOC_RELEASE) ? "Release" : "Development", GIT_COMMIT_HASH, + ENABLED(RDOC_RELEASE) ? "Release" : "Development", GitVersionHash, IsReplayApp() ? "loaded in replay application" : "capturing application"); #if defined(DISTRIBUTION_VERSION) diff --git a/renderdoc/core/crash_handler.h b/renderdoc/core/crash_handler.h index ca8452a92..8c5165bac 100644 --- a/renderdoc/core/crash_handler.h +++ b/renderdoc/core/crash_handler.h @@ -115,7 +115,7 @@ public: breakpadCustomInfo[0].set_value(wideStr.c_str()); wideStr = StringFormat::UTF82Wide(string(RDCGETLOGFILE())); breakpadCustomInfo[1].set_value(wideStr.c_str()); - wideStr = StringFormat::UTF82Wide(string(GIT_COMMIT_HASH)); + wideStr = StringFormat::UTF82Wide(string(GitVersionHash)); breakpadCustomInfo[2].set_value(wideStr.c_str()); google_breakpad::CustomClientInfo custom = {&breakpadCustomInfo[0], diff --git a/renderdoc/renderdoc.vcxproj b/renderdoc/renderdoc.vcxproj index 5de6911ee..d327c3411 100644 --- a/renderdoc/renderdoc.vcxproj +++ b/renderdoc/renderdoc.vcxproj @@ -487,6 +487,9 @@ {88c5dac6-30a0-4cfd-af51-540a977d1f3f} + + {257fd75c-4d17-4a23-a754-23bfd85887a0} + @@ -501,5 +504,4 @@ - \ No newline at end of file diff --git a/renderdoc/renderdoc.props b/renderdoc/renderdoc_version.vcxproj similarity index 56% rename from renderdoc/renderdoc.props rename to renderdoc/renderdoc_version.vcxproj index 9b4503f80..5f7502423 100644 --- a/renderdoc/renderdoc.props +++ b/renderdoc/renderdoc_version.vcxproj @@ -1,13 +1,57 @@ - - + + + + + Development + Win32 + + + Release + Win32 + + + Development + x64 + + + Release + x64 + + + + {257FD75C-4D17-4A23-A754-23BFD85887A0} + Win32Proj + version + 8.1 + version + + + + StaticLibrary + false + v140 + Unicode + + + + + + + + Level3 + Disabled + + + Windows + + + - $([MSBuild]::Unescape("$(DevEnvDir)\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\LibGit2Sharp.dll")) $([MSBuild]::Unescape("$(VSInstallDir)\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\LibGit2Sharp.dll")) - @@ -25,7 +69,7 @@ using System.Runtime.CompilerServices; namespace GitIntrospection { public class GetGitCommit : Microsoft.Build.Utilities.Task { public override bool Execute() { - System.AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { + System.AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { if (args.Name.Contains("LibGit2Sharp")) { return System.Reflection.Assembly.LoadFrom(LibGit2SharpAssemblyPath); } @@ -49,18 +93,19 @@ namespace GitIntrospection { - - - + GIT_COMMIT_HASH="$(CommitId)";%(PreprocessorDefinitions) - + + + + \ No newline at end of file diff --git a/renderdoc/renderdoc_version.vcxproj.filters b/renderdoc/renderdoc_version.vcxproj.filters new file mode 100644 index 000000000..fe080078f --- /dev/null +++ b/renderdoc/renderdoc_version.vcxproj.filters @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/renderdoccmd/CMakeLists.txt b/renderdoccmd/CMakeLists.txt index 9cb42afd9..c03f55812 100644 --- a/renderdoccmd/CMakeLists.txt +++ b/renderdoccmd/CMakeLists.txt @@ -1,4 +1,4 @@ -set(sources renderdoccmd.cpp) +set(sources renderdoccmd.cpp ${CMAKE_SOURCE_DIR}/renderdoc/api/replay/version.cpp) set(includes PRIVATE ${CMAKE_SOURCE_DIR}/renderdoc/api) set(libraries PRIVATE renderdoc) diff --git a/renderdoccmd/renderdoccmd.cpp b/renderdoccmd/renderdoccmd.cpp index 913b93754..302aa6b90 100644 --- a/renderdoccmd/renderdoccmd.cpp +++ b/renderdoccmd/renderdoccmd.cpp @@ -184,7 +184,7 @@ struct VersionCommand : public Command virtual int Execute(cmdline::parser &parser, const CaptureOptions &) { std::cout << "renderdoccmd " << (sizeof(uintptr_t) == sizeof(uint64_t) ? "x64" : "x86") - << " v" MAJOR_MINOR_VERSION_STRING << " built from " << GIT_COMMIT_HASH << std::endl; + << " v" MAJOR_MINOR_VERSION_STRING << " built from " << GitVersionHash << std::endl; #if defined(DISTRIBUTION_VERSION) std::cout << "Packaged for " << DISTRIBUTION_NAME << " (" << DISTRIBUTION_VERSION << ") - " diff --git a/renderdoccmd/renderdoccmd.vcxproj b/renderdoccmd/renderdoccmd.vcxproj index 5a681cffa..ce8032b17 100644 --- a/renderdoccmd/renderdoccmd.vcxproj +++ b/renderdoccmd/renderdoccmd.vcxproj @@ -218,9 +218,11 @@ true false + + {257fd75c-4d17-4a23-a754-23bfd85887a0} + - \ No newline at end of file