Browse Source

updated git version retrieval cmake plugin

tempestpy_adaptions
dehnert 7 years ago
parent
commit
869271259e
  1. 52
      resources/cmake/macros/GetGitRevisionDescription.cmake
  2. 13
      resources/cmake/macros/GetGitRevisionDescription.cmake.in

52
resources/cmake/macros/GetGitRevisionDescription.cmake

@ -18,6 +18,12 @@
# and adjusting the output so that it tests false if there was no exact # and adjusting the output so that it tests false if there was no exact
# matching tag. # matching tag.
# #
# git_local_changes(<var>)
#
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
# Uses the return code of "git diff-index --quiet HEAD --".
# Does not regard untracked files.
#
# Requires CMake 2.6 or newer (uses the 'function' command) # Requires CMake 2.6 or newer (uses the 'function' command)
# #
# Original Author: # Original Author:
@ -37,10 +43,10 @@ set(__get_git_revision_description YES)
# We must run the following at "include" time, not at function call time, # We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file # to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir GetGitRevisionDescription.cmake PATH)
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
function(get_git_head_revision _refspecvar _hashvar) function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR ${PROJECT_SOURCE_DIR})
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git") set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
@ -71,7 +77,7 @@ function(get_git_head_revision _refspecvar _hashvar)
set(HEAD_FILE "${GIT_DATA}/HEAD") set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
configure_file("${PROJECT_SOURCE_DIR}/resources/cmake/macros/GetGitRevisionDescription.cmake.in"
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake" "${GIT_DATA}/grabRef.cmake"
@ONLY) @ONLY)
include("${GIT_DATA}/grabRef.cmake") include("${GIT_DATA}/grabRef.cmake")
@ -110,7 +116,7 @@ function(git_describe _var)
${hash} ${hash}
${ARGN} ${ARGN}
WORKING_DIRECTORY WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE RESULT_VARIABLE
res res
OUTPUT_VARIABLE OUTPUT_VARIABLE
@ -124,7 +130,12 @@ function(git_describe _var)
set(${_var} "${out}" PARENT_SCOPE) set(${_var} "${out}" PARENT_SCOPE)
endfunction() endfunction()
function(git_describe_checkout _var)
function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
function(git_local_changes _var)
if(NOT GIT_FOUND) if(NOT GIT_FOUND)
find_package(Git QUIET) find_package(Git QUIET)
endif() endif()
@ -138,39 +149,20 @@ function(git_describe_checkout _var)
return() return()
endif() endif()
# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()
#message(STATUS "Arguments to execute_process: ${ARGN}")
execute_process(COMMAND execute_process(COMMAND
"${GIT_EXECUTABLE}" "${GIT_EXECUTABLE}"
describe
--tags
--dirty=-dirty
--long
${ARGN}
diff-index --quiet HEAD --
WORKING_DIRECTORY WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE RESULT_VARIABLE
res res
OUTPUT_VARIABLE OUTPUT_VARIABLE
out out
ERROR_QUIET ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
if(res EQUAL 0)
set(${_var} "CLEAN" PARENT_SCOPE)
else()
set(${_var} "DIRTY" PARENT_SCOPE)
endif() endif()
set(${_var} "${out}" PARENT_SCOPE)
endfunction() endfunction()
function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()

13
resources/cmake/macros/GetGitRevisionDescription.cmake.in

@ -1,4 +1,4 @@
#
#
# Internal file for GetGitRevisionDescription.cmake # Internal file for GetGitRevisionDescription.cmake
# #
# Requires CMake 2.6 or newer (uses the 'function' command) # Requires CMake 2.6 or newer (uses the 'function' command)
@ -23,9 +23,12 @@ if(HEAD_CONTENTS MATCHES "ref")
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}") if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
set(HEAD_HASH "${HEAD_REF}")
else()
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_HASH "${CMAKE_MATCH_1}")
endif()
endif() endif()
else() else()
# detached HEAD # detached HEAD
@ -35,4 +38,4 @@ endif()
if(NOT HEAD_HASH) if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH) string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()
endif()
Loading…
Cancel
Save