未验证 提交 34527673 编写于 作者: Y Yang Zhao 提交者: GitHub

[TD-10397]<feature> taosdump add version (#7997)

* add taosdump verison in cmake

* add -V feature

* taosdump add -V/--version
上级 81ae04cb
...@@ -6,6 +6,61 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) ...@@ -6,6 +6,61 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(inc)
AUX_SOURCE_DIRECTORY(. SRC) AUX_SOURCE_DIRECTORY(. SRC)
FIND_PACKAGE(Git)
IF(GIT_FOUND)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} log --pretty=oneline -n 1 ${CMAKE_CURRENT_LIST_DIR}/taosdump.c
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
RESULT_VARIABLE RESULT
OUTPUT_VARIABLE TAOSDUMP_COMMIT_SHA1
)
IF ("${TAOSDUMP_COMMIT_SHA1}" STREQUAL "")
SET(TAOSDUMP_COMMIT_SHA1 "unknown")
ELSE ()
STRING(SUBSTRING "${TAOSDUMP_COMMIT_SHA1}" 0 7 TAOSDUMP_COMMIT_SHA1)
STRING(STRIP "${TAOSDUMP_COMMIT_SHA1}" TAOSDUMP_COMMIT_SHA1)
ENDIF ()
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} status -z -s ${CMAKE_CURRENT_LIST_DIR}/taosdump.c
RESULT_VARIABLE RESULT
OUTPUT_VARIABLE TAOSDUMP_STATUS
)
IF (TD_LINUX)
EXECUTE_PROCESS(
COMMAND bash "-c" "echo '${TAOSDUMP_STATUS}' | awk '{print $1}'"
RESULT_VARIABLE RESULT
OUTPUT_VARIABLE TAOSDUMP_STATUS
)
ENDIF (TD_LINUX)
ELSE()
MESSAGE("Git not found")
SET(TAOSDUMP_COMMIT_SHA1 "unknown")
SET(TAOSDUMP_STATUS "unknown")
ENDIF (GIT_FOUND)
MESSAGE("taosdump's latest commit in short is:" ${TAOSDUMP_COMMIT_SHA1})
STRING(STRIP "${TAOSDUMP_STATUS}" TAOSDUMP_STATUS)
IF (TAOSDUMP_STATUS MATCHES "M")
SET(TAOSDUMP_STATUS "modified")
ELSE()
SET(TAOSDUMP_STATUS "")
ENDIF ()
MESSAGE("taosdump's status is:" ${TAOSDUMP_STATUS})
ADD_DEFINITIONS(-DTAOSDUMP_COMMIT_SHA1="${TAOSDUMP_COMMIT_SHA1}")
ADD_DEFINITIONS(-DTAOSDUMP_STATUS="${TAOSDUMP_STATUS}")
MESSAGE("VERNUMBER is:" ${VERNUMBER})
IF ("${VERNUMBER}" STREQUAL "")
SET(TD_VERSION_NUMBER "TDengine-version-unknown")
ELSE()
SET(TD_VERSION_NUMBER ${VERNUMBER})
ENDIF ()
MESSAGE("TD_VERSION_NUMBER is:" ${TD_VERSION_NUMBER})
ADD_DEFINITIONS(-DTD_VERNUMBER="${TD_VERSION_NUMBER}")
IF (TD_LINUX) IF (TD_LINUX)
ADD_EXECUTABLE(taosdump ${SRC}) ADD_EXECUTABLE(taosdump ${SRC})
IF (TD_SOMODE_STATIC) IF (TD_SOMODE_STATIC)
......
...@@ -386,6 +386,33 @@ struct arguments g_args = { ...@@ -386,6 +386,33 @@ struct arguments g_args = {
0, // dbCount 0, // dbCount
}; };
// get taosdump commit number version
#ifndef TAOSDUMP_COMMIT_SHA1
#define TAOSDUMP_COMMIT_SHA1 "unknown"
#endif
#ifndef TD_VERNUMBER
#define TD_VERNUMBER "unknown"
#endif
#ifndef TAOSDUMP_STATUS
#define TAOSDUMP_STATUS "unknown"
#endif
static void printVersion() {
char tdengine_ver[] = TD_VERNUMBER;
char taosdump_ver[] = TAOSDUMP_COMMIT_SHA1;
char taosdump_status[] = TAOSDUMP_STATUS;
if (strlen(taosdump_status) == 0) {
printf("taosdump version %s-%s\n",
tdengine_ver, taosdump_ver);
} else {
printf("taosdump version %s-%s, status:%s\n",
tdengine_ver, taosdump_ver, taosdump_status);
}
}
UNUSED_FUNC void errorWrongValue(char *program, char *wrong_arg, char *wrong_value) UNUSED_FUNC void errorWrongValue(char *program, char *wrong_arg, char *wrong_value)
{ {
fprintf(stderr, "%s %s: %s is an invalid value\n", program, wrong_arg, wrong_value); fprintf(stderr, "%s %s: %s is an invalid value\n", program, wrong_arg, wrong_value);
...@@ -673,6 +700,10 @@ static void parse_args( ...@@ -673,6 +700,10 @@ static void parse_args(
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
g_args.databases = true; g_args.databases = true;
} else if (0 == strncmp(argv[i], "--version", strlen("--version")) ||
0 == strncmp(argv[i], "-V", strlen("-V"))) {
printVersion();
exit(EXIT_SUCCESS);
} else { } else {
continue; continue;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册