Commit 0e8e95f4 authored by Rashad Kanavath's avatar Rashad Kanavath

CMake: check otb and otb-data git status and report their log & branch names

parent 1ea8978d
if(EXISTS "${PROJECT_SOURCE_DIR}/.hg")
find_package(Mercurial)
if(Mercurial_FOUND)
message(STATUS "Repository status :")
Mercurial_WC_IDENTIFY(${PROJECT_SOURCE_DIR} OTB)
message(STATUS " Mercurial version is ${Mercurial_VERSION_HG}")
message(STATUS " Repository revision is ${OTB_WC_REVISION}")
set(OTB_WC_REVISION ${OTB_WC_REVISION} CACHE STRING "Repository version" FORCE)
mark_as_advanced(OTB_WC_REVISION)
if(OTB_WC_STATUS)
message(STATUS " Local file modifications:")
string(REPLACE "\n" "\n-- " OTB_WC_STATUS_PRETTYPRINT " ${OTB_WC_STATUS}")
message(STATUS "${OTB_WC_STATUS_PRETTYPRINT}")
else()
message(STATUS " No files modified locally")
function(repository_status root_repo_dir result_var1)
if(NOT EXISTS "${root_repo_dir}/.git")
return()
endif()
string(REGEX REPLACE "\n" ";" OTB_WC_STATUS "${OTB_WC_STATUS}")
set(OTB_WC_STATUS ${OTB_WC_STATUS} CACHE STRING "Repository status" FORCE)
mark_as_advanced(OTB_WC_STATUS)
endif()
endif()
if(EXISTS "${PROJECT_SOURCE_DIR}/.git")
find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%H --oneline
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE OTB_GIT_LAST_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if(NOT GIT_FOUND)
message(STATUS "git not found. Make sure git can be found in your PATH. (source status will not be reported)")
set(${result_var1})
return()
endif()
execute_process(COMMAND ${GIT_EXECUTABLE} config --get remote.origin.url
WORKING_DIRECTORY ${root_repo_dir}
OUTPUT_VARIABLE git_remote_origin_url
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if(git_remote_origin_url)
get_filename_component(dir_name ${git_remote_origin_url} NAME)
else()
get_filename_component(dir_name ${root_repo_dir} NAME)
endif()
#git symbolic-ref --short -q HEAD does not work on older git version
#rather than checking for git version. it is better to not use that
#option and employ cmake stuff to do the work
execute_process(COMMAND ${GIT_EXECUTABLE} symbolic-ref -q HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE OTB_GIT_SYMBOLIC_REF_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%H --oneline
WORKING_DIRECTORY ${root_repo_dir}
OUTPUT_VARIABLE last_commit_id
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
get_filename_component(OTB_GIT_BRANCH ${OTB_GIT_SYMBOLIC_REF_OUTPUT} NAME)
#git symbolic-ref --short -q HEAD does not work on older git version
#rather than checking for git version. it is better to not use that
#option and employ cmake stuff to do the work
execute_process(COMMAND ${GIT_EXECUTABLE} symbolic-ref -q HEAD
WORKING_DIRECTORY ${root_repo_dir}
OUTPUT_VARIABLE git_symbolic_ref_output
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%H
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE OTB_WC_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
execute_process(COMMAND ${GIT_EXECUTABLE} status -s
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE OTB_WC_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
message(STATUS "Repository status :")
message(STATUS " Repository revision is ${OTB_WC_REVISION}")
if(OTB_WC_STATUS)
message(STATUS " Local file modifications:")
string(REPLACE "\n" "\n-- " OTB_WC_STATUS_PRETTYPRINT " ${OTB_WC_STATUS}")
message(STATUS "${OTB_WC_STATUS_PRETTYPRINT}")
else()
message(STATUS " No files modified locally")
endif()
set(branch_name)
if(git_symbolic_ref_output)
get_filename_component(branch_name ${git_symbolic_ref_output} NAME)
endif()
endif()
if(OTB_DATA_ROOT)
if(EXISTS "${OTB_DATA_ROOT}/.hg")
if(NOT Mercurial_FOUND)
find_package(Mercurial)
endif()
if(Mercurial_FOUND)
Mercurial_WC_IDENTIFY(${OTB_DATA_ROOT} OTB_DATA)
set(OTB_DATA_WC_REVISION ${OTB_DATA_WC_REVISION} CACHE STRING "Repository version" FORCE)
mark_as_advanced(OTB_DATA_WC_REVISION)
endif()
endif()
set(return_msg "${dir_name} repository info: \n")
set(return_msg "${return_msg} git log -1 --oneline = [${last_commit_id}] \n")
set(return_msg "${return_msg} git symbolic-ref -q HEAD = ${branch_name}")
set(${result_var1} ${return_msg} PARENT_SCOPE)
if(EXISTS "${OTB_DATA_ROOT}/.git")
if(NOT GIT_FOUND)
find_package(Git)
endif()
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%H
WORKING_DIRECTORY ${OTB_DATA_ROOT}
OUTPUT_VARIABLE OTB_DATA_WC_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
set(OTB_DATA_WC_REVISION ${OTB_DATA_WC_REVISION} CACHE STRING "Repository version" FORCE)
mark_as_advanced(OTB_DATA_WC_REVISION)
endif()
#print other information inside function call
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%H
WORKING_DIRECTORY ${root_repo_dir}
OUTPUT_VARIABLE OTB_WC_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
execute_process(COMMAND ${GIT_EXECUTABLE} status -s
WORKING_DIRECTORY ${root_repo_dir}
OUTPUT_VARIABLE OTB_WC_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
message(STATUS "Repository status (${dir_name}) :")
message(STATUS " Repository revision is ${OTB_WC_REVISION}")
if(OTB_WC_STATUS)
message(STATUS " Local file modifications (${dir_name}) :")
string(REPLACE "\n" "\n-- " OTB_WC_STATUS_PRETTYPRINT " ${OTB_WC_STATUS}")
message(STATUS "${OTB_WC_STATUS_PRETTYPRINT}")
else()
message(STATUS " No files modified locally (${dir_name})")
endif()
endif()
endfunction()
......@@ -68,6 +68,20 @@ include(OTBModuleMacros)
include(OTBModuleRemote)
include(OTBModuleTest)
repository_status(${PROJECT_SOURCE_DIR} OTB_GIT_STATUS_MESSAGE)
#-----------------------------------------------------------------------------
# Configure the default OTB_DATA_ROOT for the location of OTB Data.
find_path(OTB_DATA_ROOT
NAMES README-OTB-Data
HINTS $ENV{OTB_DATA_ROOT} ${OTB_SOURCE_DIR}/../OTB-Data
)
mark_as_advanced(OTB_DATA_ROOT)
if(OTB_DATA_ROOT)
repository_status(${OTB_DATA_ROOT} OTB_DATA_GIT_STATUS_MESSAGE)
endif()
set(main_project_name ${_OTBModuleMacros_DEFAULT_LABEL})
#-----------------------------------------------------------------------------
......@@ -204,14 +218,6 @@ option(BUILD_EXAMPLES "Build the Examples directory." OFF)
#----------------------------------------------------------------------------
set(OTB_TEST_OUTPUT_DIR "${OTB_BINARY_DIR}/Testing/Temporary")
#-----------------------------------------------------------------------------
# Configure the default OTB_DATA_ROOT for the location of OTB Data.
find_path(OTB_DATA_ROOT
NAMES README-OTB-Data
HINTS $ENV{OTB_DATA_ROOT} ${OTB_SOURCE_DIR}/../OTB-Data
)
mark_as_advanced(OTB_DATA_ROOT)
option(OTB_DATA_USE_LARGEINPUT "Use Large inputs images test." OFF)
mark_as_advanced(OTB_DATA_USE_LARGEINPUT)
if(OTB_DATA_USE_LARGEINPUT)
......@@ -376,7 +382,7 @@ add_custom_target(uninstall
#macro to put a fixed space between key, value in summary
macro(get_white_spaces var res)
string(LENGTH "${var}" len)
math(EXPR required_spaces "22 - ${len}")
math(EXPR required_spaces "23 - ${len}")
set(${res})
foreach(loop_var RANGE ${required_spaces})
set(${res} "${${res}} ")
......@@ -385,8 +391,10 @@ endmacro()
message("\n======================= Begin of OTB cmake summary =======================\n")
message("git log -1 --oneline = [${OTB_GIT_LAST_COMMIT}]")
message("git symbolic-ref -q HEAD = ${OTB_GIT_BRANCH}")
message( ${OTB_GIT_STATUS_MESSAGE})
if(OTB_DATA_GIT_STATUS_MESSAGE)
message( ${OTB_DATA_GIT_STATUS_MESSAGE})
endif()
set(option_list ${OTB_MODULE_ACTIVATION_OPTION_LIST})
list(SORT option_list)
......@@ -406,6 +414,7 @@ foreach(otb_option
${option_list}
OTB_WRAP_PYTHON
OTB_WRAP_JAVA
OTB_DATA_ROOT
)
get_white_spaces("${otb_option}" spaces)
message("${otb_option} ${spaces} = ${${otb_option}}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment