Generate GitCommitHash.cpp during building.

This commit is contained in:
levlam 2022-07-11 12:20:31 +03:00
parent 954444e692
commit 6eb03bdc8b
4 changed files with 11 additions and 34 deletions

View File

@ -153,8 +153,10 @@ if (CLANG OR GCC)
endif() endif()
include(GetGitRevisionDescription) include(GetGitRevisionDescription)
get_git_head_revision(TD_GIT_REFSPEC TD_GIT_COMMIT) get_git_head_revision(TD_GIT_REFSPEC TD_GIT_COMMIT_HASH)
message(STATUS "Git state: ${TD_GIT_COMMIT}") message(STATUS "Git state: ${TD_GIT_COMMIT_HASH}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/td/telegram/GitCommitHash.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/td/telegram/GitCommitHash.cpp" @ONLY)
add_subdirectory(tdtl) add_subdirectory(tdtl)
@ -566,6 +568,7 @@ set(TDLIB_SOURCE
td/telegram/FullMessageId.h td/telegram/FullMessageId.h
td/telegram/Game.h td/telegram/Game.h
td/telegram/GameManager.h td/telegram/GameManager.h
td/telegram/GitCommitHash.h
td/telegram/Global.h td/telegram/Global.h
td/telegram/GroupCallId.h td/telegram/GroupCallId.h
td/telegram/GroupCallManager.h td/telegram/GroupCallManager.h
@ -736,6 +739,8 @@ set(TDLIB_SOURCE
td/telegram/VoiceNotesManager.hpp td/telegram/VoiceNotesManager.hpp
${TL_TD_SCHEME_SOURCE} ${TL_TD_SCHEME_SOURCE}
${CMAKE_CURRENT_BINARY_DIR}/td/telegram/GitCommitHash.cpp
) )
set(MEMPROF_SOURCE set(MEMPROF_SOURCE

View File

@ -4,24 +4,12 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying // Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// //
#include "td/utils/GitInfo.h" #include "td/telegram/GitCommitHash.h"
#if !defined(GIT_COMMIT)
#define GIT_COMMIT "unknown"
#endif
#if !defined(GIT_DIRTY)
#define GIT_DIRTY false
#endif
namespace td { namespace td {
const char *GitInfo::commit() { const char *get_git_commit_hash() {
return GIT_COMMIT; return "@TD_GIT_COMMIT_HASH@";
}
bool GitInfo::is_dirty() {
return GIT_DIRTY;
} }
} // namespace td } // namespace td

View File

@ -8,10 +8,6 @@
namespace td { namespace td {
class GitInfo { const char *get_git_commit_hash();
public:
static const char *commit();
static bool is_dirty();
};
} // namespace td } // namespace td

View File

@ -100,7 +100,6 @@ set(TDUTILS_SOURCE
td/utils/find_boundary.cpp td/utils/find_boundary.cpp
td/utils/FlatHashTable.cpp td/utils/FlatHashTable.cpp
td/utils/FloodControlGlobal.cpp td/utils/FloodControlGlobal.cpp
td/utils/GitInfo.cpp
td/utils/Gzip.cpp td/utils/Gzip.cpp
td/utils/GzipByteFlow.cpp td/utils/GzipByteFlow.cpp
td/utils/Hints.cpp td/utils/Hints.cpp
@ -218,7 +217,6 @@ set(TDUTILS_SOURCE
td/utils/FloodControlGlobal.h td/utils/FloodControlGlobal.h
td/utils/FloodControlStrict.h td/utils/FloodControlStrict.h
td/utils/format.h td/utils/format.h
td/utils/GitInfo.h
td/utils/Gzip.h td/utils/Gzip.h
td/utils/GzipByteFlow.h td/utils/GzipByteFlow.h
td/utils/Hash.h td/utils/Hash.h
@ -342,16 +340,6 @@ set(TDUTILS_TEST_SOURCE
#LIBRARIES #LIBRARIES
add_library(tdutils STATIC ${TDUTILS_SOURCE}) add_library(tdutils STATIC ${TDUTILS_SOURCE})
if (DEFINED TD_GIT_COMMIT)
# this forces the whole tdutils to be recompiled after each commit with Makefile generator as explained at
# https://cmake.org/pipermail/cmake-developers/2012-October/005411.html,
# so this can't be improved for production-ready state
set_property(SOURCE td/utils/GitInfo.cpp APPEND PROPERTY COMPILE_DEFINITIONS "GIT_COMMIT=\"${TD_GIT_COMMIT}\"")
endif()
if (DEFINED TD_GIT_DIRTY)
set_property(SOURCE td/utils/GitInfo.cpp APPEND PROPERTY COMPILE_DEFINITIONS "GIT_DIRTY=true")
endif()
if (NOT CMAKE_CROSSCOMPILING AND TDUTILS_MIME_TYPE) if (NOT CMAKE_CROSSCOMPILING AND TDUTILS_MIME_TYPE)
add_dependencies(tdutils tdmime_auto) add_dependencies(tdutils tdmime_auto)
endif() endif()