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.
This commit is contained in:
baldurk
2018-01-16 20:17:53 +00:00
parent 654fa1bb6c
commit dea21b20a0
18 changed files with 158 additions and 39 deletions
+1 -1
View File
@@ -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")
+5 -6
View File
@@ -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 <a href='%2'>%3</a>)")
.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 <a href='%2'>%3</a>)")
.arg(lit(FULL_VERSION_STRING))
.arg(lit("https://github.com/baldurk/renderdoc/commit/%1").arg(hash))
.arg(hash.left(8)));
}
#if defined(DISTRIBUTION_VERSION)
+4 -2
View File
@@ -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;
+5
View File
@@ -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
+3 -1
View File
@@ -1717,6 +1717,9 @@ IF %ERRORLEVEL% NEQ 0 (echo ====================================================
<ProjectReference Include="..\renderdoc\renderdoc.vcxproj">
<Project>{e2b46d67-90e2-40b6-9597-72930e7845e5}</Project>
</ProjectReference>
<ProjectReference Include="..\renderdoc\renderdoc_version.vcxproj">
<Project>{257fd75c-4d17-4a23-a754-23bfd85887a0}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resources\qrenderdoc.rc">
@@ -1839,5 +1842,4 @@ IF %ERRORLEVEL% NEQ 0 (echo ====================================================
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<Import Project="$(SolutionDir)\renderdoc\renderdoc.props" />
</Project>
+11
View File
@@ -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
+1
View File
@@ -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
+41
View File
@@ -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")
+7 -11
View File
@@ -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.
+10 -3
View File
@@ -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))
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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],
+3 -1
View File
@@ -487,6 +487,9 @@
<ProjectReference Include="driver\vulkan\renderdoc_vulkan.vcxproj">
<Project>{88c5dac6-30a0-4cfd-af51-540a977d1f3f}</Project>
</ProjectReference>
<ProjectReference Include="renderdoc_version.vcxproj">
<Project>{257fd75c-4d17-4a23-a754-23bfd85887a0}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
@@ -501,5 +504,4 @@
<Copy SourceFiles="$(ProjectDir)3rdparty\dbghelp\$(Platform)\dbghelp.dll" DestinationFolder="$(OutDir)">
</Copy>
</Target>
<Import Project="$(SolutionDir)\renderdoc\renderdoc.props" />
</Project>
@@ -1,13 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Development|Win32">
<Configuration>Development</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Development|x64">
<Configuration>Development</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{257FD75C-4D17-4A23-A754-23BFD85887A0}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>version</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<ProjectName>version</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<!-- Thanks to https://stackoverflow.com/a/43815817/4070143 -->
<!-- fetch the path of the assembly, and unescape it so MSBuild doesn't choke on brackets in "Program Files (x86)" -->
<PropertyGroup>
<LibGit2SharpPath>$([MSBuild]::Unescape("$(DevEnvDir)\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\LibGit2Sharp.dll"))</LibGit2SharpPath>
<LibGit2SharpPath Condition="!exists('$(LibGit2SharpPath)')">$([MSBuild]::Unescape("$(VSInstallDir)\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\LibGit2Sharp.dll"))</LibGit2SharpPath>
</PropertyGroup>
<!-- Declare the task with some inline code -->
<UsingTask TaskName="GetGitCommit" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
@@ -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) =&gt; {
if (args.Name.Contains("LibGit2Sharp")) {
return System.Reflection.Assembly.LoadFrom(LibGit2SharpAssemblyPath);
}
@@ -49,18 +93,19 @@ namespace GitIntrospection {
</Code>
</Task>
</UsingTask>
<!-- Only actually run the task if we located the assembly for LibGit2Sharp. Otherwise silently skip this step. -->
<Target Name="RunTask" BeforeTargets="PrepareForBuild" Condition="exists('$(LibGit2SharpPath)')">
<GetGitCommit Repository="$(SolutionDir)" LibGit2SharpAssemblyPath="$(LibGit2SharpPath)" ContinueOnError="WarnAndContinue">
<Output TaskParameter="Sha1" PropertyName="CommitId" />
</GetGitCommit>
<Message Text="Building from Git commit $(CommitId)" />
<ItemGroup Condition="$(CommitId.Length) > 0">
<ItemGroup Condition="$(CommitId.Length) &gt; 0">
<ClCompile>
<PreprocessorDefinitions>GIT_COMMIT_HASH="$(CommitId)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemGroup>
</Target>
</Project>
<ItemGroup>
<ClCompile Include="api\replay\version.cpp" />
</ItemGroup>
</Project>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="api\replay\version.cpp" />
</ItemGroup>
</Project>
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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 << ") - "
+3 -1
View File
@@ -218,9 +218,11 @@
<LinkLibraryDependencies>true</LinkLibraryDependencies>
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
</ProjectReference>
<ProjectReference Include="..\renderdoc\renderdoc_version.vcxproj">
<Project>{257fd75c-4d17-4a23-a754-23bfd85887a0}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<Import Project="$(SolutionDir)\renderdoc\renderdoc.props" />
</Project>