Use configure_file in CMake to force rebuild if git commit changes

* We also only use GIT_COMMIT_HASH where necessary to avoid rebuilding many
  files for no reason, including splitting version.cpp out into a separate
  project as we do with VS since otherwise changing its preprocessor defines
  rebuilds the whole renderdoc project.
* At the same time, move the git hash to be internal only so we don't have to
  try to link version.cpp into other projects like renderdoccmd or qrenderdoc.
This commit is contained in:
baldurk
2019-06-20 19:14:14 +01:00
parent cfa8e7c83e
commit 38f0d27901
13 changed files with 42 additions and 21 deletions
+21 -2
View File
@@ -65,7 +65,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.cpp")
set(BUILD_VERSION_HASH "" CACHE STRING "The current git commit hash. See renderdoc/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")
@@ -134,7 +134,26 @@ endfunction(get_git_hash)
# get git commit hash
get_git_hash(GIT_COMMIT_HASH)
string(STRIP ${GIT_COMMIT_HASH} GIT_COMMIT_HASH)
add_definitions(-DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git/HEAD")
# Use configure_file to force a re-configure if the HEAD file changes. That means changing branch.
# The re-configure will pick up a new git commit hash above, if it exists and is valid.
# This will be slightly redundant if BUILD_VERSION_HASH is specified but that is not a case we expect to care about.
configure_file("${CMAKE_SOURCE_DIR}/.git/HEAD" "${CMAKE_BINARY_DIR}/git_HEAD" COPYONLY)
# in addition, if HEAD is a ref, do the same on the file it's pointing to (since HEAD won't change for commits to the current branch)
# if we change branch then this will correspondingly
file(READ ${CMAKE_SOURCE_DIR}/.git/HEAD HEAD_CONTENTS)
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if("${HEAD_CONTENTS}" MATCHES "ref: ")
string(REPLACE "ref: " "" REF_LOCATION "${HEAD_CONTENTS}")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git/${REF_LOCATION}")
configure_file("${CMAKE_SOURCE_DIR}/.git/${REF_LOCATION}" "${CMAKE_BINARY_DIR}/git_ref" COPYONLY)
endif()
endif()
endif()
project(RenderDoc CXX C)
-4
View File
@@ -153,10 +153,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
endif()
# propagate build version info. Lots of escaping needed here to pass ""s into the define value
file(APPEND
${CMAKE_BINARY_DIR}/qrenderdoc/qrenderdoc_cmake.pri
"DEFINES+=GIT_COMMIT_HASH='\\\\\"${GIT_COMMIT_HASH}\\\\\"'\n")
if(BUILD_VERSION_STABLE)
file(APPEND
${CMAKE_BINARY_DIR}/qrenderdoc/qrenderdoc_cmake.pri
+1 -1
View File
@@ -183,7 +183,7 @@ int main(int argc, char *argv[])
if(parser.isSet(versionOption))
{
printf("QRenderDoc v%s (%s)\n", MAJOR_MINOR_VERSION_STRING, GitVersionHash);
printf("QRenderDoc v%s (%s)\n", MAJOR_MINOR_VERSION_STRING, RENDERDOC_GetCommitHash());
#if defined(DISTRIBUTION_VERSION)
printf("Packaged for %s - %s\n", DISTRIBUTION_NAME, DISTRIBUTION_CONTACT);
#endif
+1 -1
View File
@@ -34,7 +34,7 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDia
{
ui->setupUi(this);
QString hash = QString::fromLatin1(GitVersionHash);
QString hash = QString::fromLatin1(RENDERDOC_GetCommitHash());
if(hash[0] == QLatin1Char('N') && hash[1] == QLatin1Char('O'))
{
+2 -2
View File
@@ -1015,7 +1015,7 @@ void MainWindow::SetTitle(const QString &filename)
else
text += tr("Unstable release (%1 - %2)")
.arg(lit(FULL_VERSION_STRING))
.arg(QString::fromLatin1(GitVersionHash));
.arg(QString::fromLatin1(RENDERDOC_GetCommitHash()));
if(IsRunningAsAdmin())
text += tr(" (Administrator)");
@@ -2631,7 +2631,7 @@ void MainWindow::on_action_Send_Error_Report_triggered()
QVariantMap json;
json[lit("version")] = lit(FULL_VERSION_STRING);
json[lit("gitcommit")] = QString::fromLatin1(GitVersionHash);
json[lit("gitcommit")] = QString::fromLatin1(RENDERDOC_GetCommitHash());
json[lit("replaycrash")] = 1;
json[lit("report")] = (QString)report;
-2
View File
@@ -124,8 +124,6 @@ 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
+6 -1
View File
@@ -93,7 +93,6 @@ 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
@@ -473,6 +472,12 @@ list(APPEND renderdoc_objects
$<TARGET_OBJECTS:rdoc>
${data_objects})
add_library(rdoc_version OBJECT replay/version.cpp)
target_compile_definitions(rdoc_version PRIVATE -DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
list(APPEND renderdoc_objects
$<TARGET_OBJECTS:rdoc_version>)
# posix_libentry must be the last so that library_loaded is called after
# static objects are constructed. We guarantee this happens after even
# any other static libraries that we link by making it its own static
+6 -4
View File
@@ -41,12 +41,14 @@
//
// 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.
// that's implemented in version.cpp, which is linked into the core module.
// 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.
// Then version.cpp is the only thing that needs to be rebuilt when the git commit changes
//
// Only available internally, external users should use RENDERDOC_GetCommitHash()
#if defined(RENDERDOC_EXPORTS)
extern "C" const char GitVersionHash[41];
#endif
// 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.
+1 -1
View File
@@ -122,6 +122,6 @@ namespace GitIntrospection {
</ItemGroup>
</Target>
<ItemGroup>
<ClCompile Include="api\replay\version.cpp" />
<ClCompile Include="replay\version.cpp" />
</ItemGroup>
</Project>
+1 -1
View File
@@ -1,6 +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" />
<ClCompile Include="replay\version.cpp" />
</ItemGroup>
</Project>
+1 -1
View File
@@ -1,4 +1,4 @@
set(sources renderdoccmd.cpp ${CMAKE_SOURCE_DIR}/renderdoc/api/replay/version.cpp)
set(sources renderdoccmd.cpp)
set(includes PRIVATE ${CMAKE_SOURCE_DIR}/renderdoc/api)
set(libraries PRIVATE renderdoc)
+2 -1
View File
@@ -171,7 +171,8 @@ 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 " << GitVersionHash << std::endl;
<< " v" MAJOR_MINOR_VERSION_STRING << " built from " << RENDERDOC_GetCommitHash()
<< std::endl;
#if defined(DISTRIBUTION_VERSION)
std::cout << "Packaged for " << DISTRIBUTION_NAME << " (" << DISTRIBUTION_VERSION << ") - "