2020-07-18 01:20:22 +03:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
2022-03-10 15:59:00 +03:00
|
|
|
find_package(Git QUIET)
|
2020-07-18 01:20:22 +03:00
|
|
|
if (NOT Git_FOUND)
|
2022-03-10 15:59:00 +03:00
|
|
|
message(STATUS "Unable to find git, which is needed for versioning")
|
2020-07-18 01:20:22 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
function(get_git_dir DIRECTORY OUTPUT_VAR)
|
|
|
|
execute_process(
|
|
|
|
COMMAND
|
|
|
|
${GIT_EXECUTABLE} rev-parse --git-dir
|
|
|
|
WORKING_DIRECTORY
|
|
|
|
${DIRECTORY}
|
|
|
|
RESULT_VARIABLE
|
|
|
|
GIT_DIR_RESULT
|
|
|
|
OUTPUT_VARIABLE
|
|
|
|
GIT_DIR_OUTPUT
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
|
|
|
# Allow to fail
|
|
|
|
set(${OUTPUT_VAR} ${GIT_DIR_OUTPUT} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(get_git_current_hash DIRECTORY OUTPUT_VAR)
|
|
|
|
execute_process(
|
|
|
|
COMMAND
|
|
|
|
${GIT_EXECUTABLE} rev-parse --verify HEAD
|
|
|
|
WORKING_DIRECTORY
|
|
|
|
${DIRECTORY}
|
|
|
|
RESULT_VARIABLE
|
|
|
|
GIT_CURRENT_HASH_RESULT
|
|
|
|
OUTPUT_VARIABLE
|
|
|
|
GIT_CURRENT_HASH_OUTPUT
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
|
|
|
if (NOT ("${GIT_CURRENT_HASH_RESULT}" STREQUAL "0"))
|
2022-03-10 15:59:00 +03:00
|
|
|
message(STATUS ${GIT_CURRENT_HASH_OUTPUT})
|
|
|
|
message(STATUS "Failed to get ${DIRECTORY} git hash")
|
|
|
|
else()
|
|
|
|
set(${OUTPUT_VAR} ${GIT_CURRENT_HASH_OUTPUT} PARENT_SCOPE)
|
2020-07-18 01:20:22 +03:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(get_git_remote_url DIRECTORY OUTPUT_VAR)
|
|
|
|
execute_process(
|
|
|
|
COMMAND
|
|
|
|
${GIT_EXECUTABLE} config --get remote.origin.url
|
|
|
|
RESULT_VARIABLE
|
|
|
|
GIT_REMOTE_URL_RESULT
|
|
|
|
OUTPUT_VARIABLE
|
|
|
|
GIT_REMOTE_URL_OUTPUT
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
WORKING_DIRECTORY
|
|
|
|
${DIRECTORY}
|
|
|
|
)
|
|
|
|
|
|
|
|
if (NOT ("${GIT_REMOTE_URL_RESULT}" STREQUAL "0"))
|
|
|
|
message(${GIT_REMOTE_URL_OUTPUT})
|
|
|
|
message(FATAL_ERROR "Failed to get ${DIRECTORY} git remote")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(${OUTPUT_VAR} ${GIT_REMOTE_URL_OUTPUT} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(run_git_submodule_foreach CMD DIRECTORY OUTPUT_VALUE)
|
|
|
|
execute_process(
|
|
|
|
COMMAND
|
|
|
|
${GIT_EXECUTABLE} submodule foreach --quiet --recursive "${CMD}"
|
|
|
|
RESULT_VARIABLE
|
|
|
|
GIT_SUBMODULE_CMD_RESULT
|
|
|
|
OUTPUT_VARIABLE
|
|
|
|
GIT_SUBMODULE_CMD_OUTPUT
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
WORKING_DIRECTORY
|
|
|
|
${DIRECTORY}
|
|
|
|
)
|
|
|
|
|
|
|
|
if (NOT ("${GIT_SUBMODULE_CMD_RESULT}" STREQUAL "0"))
|
|
|
|
message(${GIT_SUBMODULE_CMD_OUTPUT})
|
|
|
|
message(FATAL_ERROR "Failed to run git submodule foreach command: ${CMD} in ${DIRECTORY}")
|
|
|
|
endif()
|
|
|
|
set(${OUTPUT_VALUE} ${GIT_SUBMODULE_CMD_OUTPUT} PARENT_SCOPE)
|
|
|
|
endfunction()
|