Skip to content

Commit

Permalink
Add CMake option to not treat test data as a repository
Browse files Browse the repository at this point in the history
  • Loading branch information
ramtingh committed Jan 22, 2022
1 parent fc720c0 commit 912b960
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ endif()
option( VMTK_USE_SUPERBUILD
"Build VMTK and the projects it depends on via SuperBuild.cmake." ON )

option( VMTK_TEST_SUBMODULE
"Check and update VMTK Test data repository" ON )

# Git setup
if (VMTK_USE_SUPERBUILD OR VMTK_BUILD_TESTING)
if (VMTK_USE_SUPERBUILD OR VMTK_TEST_SUBMODULE)
if( NOT GIT_EXECUTABLE )
find_package( Git REQUIRED )
endif()
Expand Down
38 changes: 21 additions & 17 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,30 @@ foreach (SCRIPT_FILE ${VMTK_TESTING_INIT_SRC})
configure_file(${VMTK_TESTING_SOURCE_DIR}/${SCRIPT_FILE} ${VMTK_TESTING_INSTALL_LIB_DIR}/${SCRIPT_FILE} COPYONLY)
endforeach ()

# Check if submodule is clean
execute_process(
COMMAND ${GIT_EXECUTABLE} status --porcelain ${VMTK_TESTING_SOURCE_DIR}/vmtk-test-data
WORKING_DIRECTORY ${VMTK_TESTING_SOURCE_DIR}
RESULT_VARIABLE error_code
OUTPUT_VARIABLE repo_status
)
if(error_code)
message(FATAL_ERROR "Failed to get the status")
if (VMTK_TEST_SUBMODULE)
# Check if submodule is clean
execute_process(
COMMAND ${GIT_EXECUTABLE} status --porcelain ${VMTK_TESTING_SOURCE_DIR}/vmtk-test-data
WORKING_DIRECTORY ${VMTK_TESTING_SOURCE_DIR}
RESULT_VARIABLE error_code
OUTPUT_VARIABLE repo_status
)
if(error_code)
message(FATAL_ERROR "Failed to get the status")
endif()

string(LENGTH "${repo_status}" unclean_status)

# If not in clean state do not overwrite
if(unclean_status)
message(WARNING "Test data repo in unclean state, will not overwrite test data")
else()
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init -- ${VMTK_TESTING_SOURCE_DIR}/vmtk-test-data
WORKING_DIRECTORY ${VMTK_TESTING_SOURCE_DIR})
endif()
endif()

string(LENGTH "${repo_status}" unclean_status)

# If not in clean state do not overwrite
if(unclean_status)
message(WARNING "Test data repo in unclean state, will not overwrite test data")
else()
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init -- ${VMTK_TESTING_SOURCE_DIR}/vmtk-test-data
WORKING_DIRECTORY ${VMTK_TESTING_SOURCE_DIR})
endif()

if(NOT VMTK_TESTING_DATA_INSTALL_LIB_DIR)
set(VMTK_TESTING_DATA_INSTALL_LIB_DIR ${CMAKE_BINARY_DIR}/tests)
Expand Down

0 comments on commit 912b960

Please sign in to comment.