diff --git a/CMakeLists.txt b/CMakeLists.txt index 5659177628c41454a9cc070b4e72e4fe4d9f2da8..4ece79962db7aa64e927650330b69b57c77a80f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1211,6 +1211,12 @@ set(MGE_VERSION_SCRIPT ${PROJECT_SOURCE_DIR}/src/version.ld CACHE INTERNAL "Path to linker version script") +execute_process( + COMMAND git log -1 --format=%H + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + OUTPUT_VARIABLE GIT_FULL_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE) + # Write out megbrain_build_config.h It defines macros needed by both megbrain and dnn configure_file(src/megbrain_build_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/genfiles/megbrain_build_config.h) diff --git a/dnn/include/megdnn/common.h b/dnn/include/megdnn/common.h index 09cb70a0886297bf3d66a68388c5a035048e2544..0536f4e8f7d615a5cde0253fd5d285061f4d09a5 100644 --- a/dnn/include/megdnn/common.h +++ b/dnn/include/megdnn/common.h @@ -13,7 +13,6 @@ #include "megbrain_build_config.h" #include "megdnn/oprs/base.h" - #if MGB_ENABLE_GETENV #define MGB_GETENV ::std::getenv #else diff --git a/src/core/impl/version.cpp b/src/core/impl/version.cpp index af76bf1bf7fc991af8c263774a328c0b7fd8ef14..30b9b32c9af897b2141f9a677504d98ab37ccd1b 100644 --- a/src/core/impl/version.cpp +++ b/src/core/impl/version.cpp @@ -10,9 +10,21 @@ */ #include "megbrain/version.h" +#include "megbrain/common.h" using namespace mgb; +//! some sdk do not call mgb::get_version explicitly, so we force show version for +//! debug, mgb_log level is info, sdk may config a higher, need export +//! RUNTIME_OVERRIDE_LOG_LEVEL=0 to force change log level to show version +#ifndef __IN_TEE_ENV__ +static __attribute__((constructor)) void show_version() { + auto v = get_version(); + mgb_log("init Engine with version: %d.%d.%d(%d) at git commitid: %s", v.major, + v.minor, v.patch, v.is_dev, GIT_FULL_HASH); +} +#endif + Version mgb::get_version() { #ifdef MGB_MAJOR return {MGB_MAJOR, MGB_MINOR, MGB_PATCH, MGB_IS_DEV}; diff --git a/src/megbrain_build_config.h.in b/src/megbrain_build_config.h.in index 802d316ea545d3e4293c8bd36ac4fdb5e48495aa..2f198120b8cf8e1f5d4d5ebbcfeef5019b4c7770 100644 --- a/src/megbrain_build_config.h.in +++ b/src/megbrain_build_config.h.in @@ -267,4 +267,6 @@ #define MGE_WIN_DECLSPEC_DATA #endif +#define GIT_FULL_HASH "@GIT_FULL_HASH@" + #endif // _HEADER_MGB_BUILD_CONFIG