diff --git a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake index 69f694fff..cc20316c8 100644 --- a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake @@ -7,6 +7,7 @@ set(TribitsHelloWorld_COMMON_CONFIG_ARGS ${SERIAL_PASSTHROUGH_CONFIGURE_ARGS} ) + tribits_add_advanced_test( TribitsHelloWorld OVERALL_WORKING_DIRECTORY TEST_NAME OVERALL_NUM_MPI_PROCS 1 @@ -36,6 +37,115 @@ tribits_add_advanced_test( TribitsHelloWorld ) +tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_one_parent + OVERALL_WORKING_DIRECTORY TEST_NAME + OVERALL_NUM_MPI_PROCS 1 + XHOST Windows # We use the 'diff' command below :-( + + TEST_0 + MESSAGE "Copy the project source so we can copy files into it." + CMND ${CMAKE_COMMAND} + ARGS -E copy_directory + ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsHelloWorld + TribitsHelloWorld + + TEST_1 + MESSAGE "Create a dummy .git directory so it will run git commands" + CMND ${CMAKE_COMMAND} ARGS -E make_directory TribitsHelloWorld/.git + + TEST_2 + CMND ${CMAKE_COMMAND} ARGS -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt + TribitsHelloWorld/.mockprogram_inout.txt + + TEST_3 + WORKING_DIRECTORY BUILD + CMND ${CMAKE_COMMAND} + ARGS + ${TribitsHelloWorld_COMMON_CONFIG_ARGS} + -DTribitsHelloWorld_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR} + -DTribitsHelloWorld_ENABLE_TESTS=ON + -DTribitsHelloWorld_GENERATE_REPO_VERSION_FILE=ON + -DTribitsHelloWorld_TRACE_DEPENDENCY_HANDLING_ONLY=ON + -DGIT_EXECUTABLE=${${PROJECT_NAME}_TRIBITS_DIR}/python_utils/mockprogram.py + ../TribitsHelloWorld + PASS_REGULAR_EXPRESSION_ALL + "a1234tgb .Thu Sep 21 19:19:18 2023 -0400. " + "This is the HEAD commit summary line" + ALWAYS_FAIL_ON_NONZERO_RETURN + + TEST_4 + CMND diff ARGS + ${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_one_parent_version.txt + BUILD/TribitsHelloWorldRepoVersion.txt + + ) +# NOTES: +# +# * The above directory structure is: +# +# TribitsHelloWorld_config_git_version_single_repo_one_parent/ +# TribitsHelloWorld/ +# .git/ +# .mockprogram_inout.txt +# BUILD/ +# +# * We don't use cmake -E compare_files because it does not print the diff, +# just gives a non-zero error code. + + +tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_two_parents + OVERALL_WORKING_DIRECTORY TEST_NAME + OVERALL_NUM_MPI_PROCS 1 + XHOST Windows # We use the 'diff' command below :-( + + TEST_0 + MESSAGE "Copy the project source so we can copy files into it." + CMND ${CMAKE_COMMAND} + ARGS -E copy_directory + ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsHelloWorld + TribitsHelloWorld + + TEST_1 + MESSAGE "Create a dummy .git directory so it will run git commands" + CMND ${CMAKE_COMMAND} ARGS -E make_directory TribitsHelloWorld/.git + + TEST_2 + CMND ${CMAKE_COMMAND} ARGS -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/mockprogram_inout.single_repo_two_parents_version.txt + TribitsHelloWorld/.mockprogram_inout.txt + + TEST_3 + WORKING_DIRECTORY BUILD + CMND ${CMAKE_COMMAND} + ARGS + ${TribitsHelloWorld_COMMON_CONFIG_ARGS} + -DTribitsHelloWorld_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR} + -DTribitsHelloWorld_ENABLE_TESTS=ON + -DTribitsHelloWorld_GENERATE_REPO_VERSION_FILE=ON + -DTribitsHelloWorld_TRACE_DEPENDENCY_HANDLING_ONLY=ON + -DTribitsHelloWorld_SHOW_GIT_COMMIT_PARENTS=ON + -DGIT_EXECUTABLE=${${PROJECT_NAME}_TRIBITS_DIR}/python_utils/mockprogram.py + ../TribitsHelloWorld + PASS_REGULAR_EXPRESSION_ALL + "a1234tgb .Thu Sep 21 19:19:18 2023 -0400. " + "This is the HEAD commit summary line" + "Parent 1:" + "b5678aop .Thu Sep 20 19:19:18 2023 -0400. " + "This is parent 1 commit summary line" + "Parent 2:" + "c9101hah .Thu Sep 19 19:19:18 2023 -0400. " + "This is parent 2 commit summary line" + ALWAYS_FAIL_ON_NONZERO_RETURN + + TEST_4 + CMND diff ARGS + ${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_two_parents_version.txt + BUILD/TribitsHelloWorldRepoVersion.txt + + ) + + tribits_add_advanced_test( TribitsHelloWorld_EXE_DISABLE OVERALL_WORKING_DIRECTORY TEST_NAME OVERALL_NUM_MPI_PROCS 1 diff --git a/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_one_parent_version.txt b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_one_parent_version.txt new file mode 100644 index 000000000..a4e411d90 --- /dev/null +++ b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_one_parent_version.txt @@ -0,0 +1,3 @@ +*** Base Git Repo: TribitsHelloWorld +a1234tgb [Thu Sep 21 19:19:18 2023 -0400] +This is the HEAD commit summary line diff --git a/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_two_parents_version.txt b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_two_parents_version.txt new file mode 100644 index 000000000..7a353a348 --- /dev/null +++ b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_two_parents_version.txt @@ -0,0 +1,9 @@ +*** Base Git Repo: TribitsHelloWorld +a1234tgb [Thu Sep 21 19:19:18 2023 -0400] +This is the HEAD commit summary line + *** Parent 1: + b5678aop [Thu Sep 20 19:19:18 2023 -0400] + This is parent 1 commit summary line + *** Parent 2: + c9101hah [Thu Sep 19 19:19:18 2023 -0400] + This is parent 2 commit summary line diff --git a/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt new file mode 100644 index 000000000..a406d461e --- /dev/null +++ b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt @@ -0,0 +1,9 @@ +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> HEAD +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s HEAD +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: This is the HEAD commit summary line +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%p HEAD +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: b5678aop diff --git a/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_two_parents_version.txt b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_two_parents_version.txt new file mode 100644 index 000000000..97bef2f75 --- /dev/null +++ b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_two_parents_version.txt @@ -0,0 +1,21 @@ +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> HEAD +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s HEAD +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: This is the HEAD commit summary line +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%p HEAD +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: b5678aop c9101hah +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> b5678aop +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: b5678aop [Thu Sep 20 19:19:18 2023 -0400] +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s b5678aop +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: This is parent 1 commit summary line +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> c9101hah +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: c9101hah [Thu Sep 19 19:19:18 2023 -0400] +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s c9101hah +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: This is parent 2 commit summary line diff --git a/test/ctest_driver/TribitsExampleMetaProject/CMakeLists.txt b/test/ctest_driver/TribitsExampleMetaProject/CMakeLists.txt index b07cf610e..d2e02af84 100644 --- a/test/ctest_driver/TribitsExampleMetaProject/CMakeLists.txt +++ b/test/ctest_driver/TribitsExampleMetaProject/CMakeLists.txt @@ -124,6 +124,7 @@ tribits_add_advanced_test( CTestDriver_TribitsExMetaProj_clone_default_branch_re ${COMMON_ENV_ARGS} TribitsExMetaProj_ENABLE_SECONDARY_TESTED_CODE=TRUE CTEST_BUILD_NAME=CTestDriver_TribitsExMetaProj_clone_default_branch_remote + TribitsExMetaProj_EXTRA_CONFIGURE_OPTIONS=-DTribitsExMetaProj_SHOW_GIT_COMMIT_PARENTS=ON CTEST_SITE=CustomSite ${CTEST_S_SCRIPT_ARGS} PASS_REGULAR_EXPRESSION_ALL @@ -262,7 +263,7 @@ tribits_add_advanced_test( CTestDriver_TribitsExMetaProj_clone_default_branch_re TEST_8 MESSAGE "Make sure that the file TribitsExMetaProjRepoVersion.txt is correct" CMND diff ARGS - "${CMAKE_CURRENT_LIST_DIR}/data/TribitsExMetaProjRepoVersion.for-testing.txt" + "${CMAKE_CURRENT_LIST_DIR}/data/TribitsExMetaProjRepoVersion.for-testing.with-parents.txt" BUILD/TribitsExMetaProjRepoVersion.txt ALWAYS_FAIL_ON_NONZERO_RETURN @@ -320,7 +321,7 @@ tribits_add_advanced_test( CTestDriver_TribitsExMetaProj_clone_default_branch_re TEST_12 MESSAGE "Make sure that the file TribitsExMetaProjRepoVersion.txt is correct" CMND diff ARGS - "${CMAKE_CURRENT_LIST_DIR}/data/TribitsExMetaProjRepoVersion.for-testing.txt" + "${CMAKE_CURRENT_LIST_DIR}/data/TribitsExMetaProjRepoVersion.for-testing.with-parents.txt" BUILD/TribitsExMetaProjRepoVersion.txt ALWAYS_FAIL_ON_NONZERO_RETURN diff --git a/test/ctest_driver/TribitsExampleMetaProject/data/TribitsExMetaProjRepoVersion.for-testing.with-parents.txt b/test/ctest_driver/TribitsExampleMetaProject/data/TribitsExMetaProjRepoVersion.for-testing.with-parents.txt new file mode 100644 index 000000000..7876d61b3 --- /dev/null +++ b/test/ctest_driver/TribitsExampleMetaProject/data/TribitsExMetaProjRepoVersion.for-testing.with-parents.txt @@ -0,0 +1,27 @@ +*** Base Git Repo: TribitsExMetaProj +863461e [Tue Sep 14 15:05:31 2021 -0600] +Merge branch 'tribits-github-snapshot' (TriBITSPub/TriBITS#299) + *** Parent 1: + e12aad9 [Fri Dec 11 16:17:18 2020 -0700] + Merge branch 'tribits-github-snapshot' (TriBITSPub/TriBITS#309) + *** Parent 2: + ed38a1f [Tue Sep 14 15:04:06 2021 -0600] + Automatic snapshot commit from TribitsExampleMetaProject at d1e4913 +*** Git Repo: TribitsExampleProject +94c2b12 [Tue Sep 14 15:18:55 2021 -0600] +Merge branch 'tribits-github-snapshot' (TriBITSPub/TriBITS#299) + *** Parent 1: + 59c7057 [Fri Dec 11 16:23:46 2020 -0700] + Merge branch 'tribits-github-snapshot' + *** Parent 2: + da4197f [Tue Sep 14 15:11:39 2021 -0600] + Automatic snapshot commit from TribitsExampleProject at d95ddbd +*** Git Repo: TribitsExampleProjectAddons +d846ae1 [Tue Sep 14 15:23:39 2021 -0600] +Merge branch 'tribits-github-snapshot' (TriBITSPub/TriBITS#299) + *** Parent 1: + 226a17e [Tue Feb 19 06:33:23 2019 -0700] + Update README file (tribitspub/tribits#278) + *** Parent 2: + 08f06bb [Tue Sep 14 15:20:24 2021 -0600] + Automatic snapshot commit from TribitsExampleProjectAddons at abb6694 diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index 63149a375..83c60cd5b 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -39,6 +39,8 @@ # Standard TriBITS system includes +include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsGitRepoVersionInfo.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsConstants.cmake") include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsTestCategories.cmake") @@ -53,7 +55,6 @@ include(TribitsGetVersionDate) include(TribitsReportInvalidTribitsUsage) include(TribitsReadAllProjectDepsFilesCreateDepsGraph) include(TribitsAdjustPackageEnables) -include(TribitsGitRepoVersionInfo) include(TribitsSetUpEnabledOnlyDependencies) include(TribitsConfigureTiming) @@ -685,6 +686,9 @@ macro(tribits_define_global_options_and_define_extra_repos) CACHE BOOL "Generate the ${PROJECT_NAME}RepoVersion.txt file.") + tribits_advanced_set_cache_var_and_default(${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS + BOOL OFF "Show parents' commit info in the repo version output.") + if ("${${PROJECT_NAME}_GENERATE_VERSION_DATE_FILES_DEFAULT}" STREQUAL "") set(${PROJECT_NAME}_GENERATE_VERSION_DATE_FILES_DEFAULT OFF) endif() @@ -1207,48 +1211,41 @@ endmacro() # Get the versions of all the git repos # -function(tribits_generate_repo_version_file_string PROJECT_REPO_VERSION_FILE_STRING_OUT) +function(tribits_generate_repo_version_file_string projectRepoVersionFileStrOut) - set(REPO_VERSION_FILE_STR "") + set(projectRepoVersionFileStr "") tribits_generate_single_repo_version_string( - ${CMAKE_CURRENT_SOURCE_DIR} - SINGLE_REPO_VERSION) - string(APPEND REPO_VERSION_FILE_STR + ${CMAKE_CURRENT_SOURCE_DIR} singleRepoVersionStr + INCLUDE_COMMIT_PARENTS ${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS}) + string(APPEND projectRepoVersionFileStr "*** Base Git Repo: ${PROJECT_NAME}\n" - "${SINGLE_REPO_VERSION}\n" ) + "${singleRepoVersionStr}\n" ) - set(EXTRAREPO_IDX 0) - foreach(EXTRA_REPO ${${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES}) - - #print_var(EXTRA_REPO) - #print_var(EXTRAREPO_IDX) - #print_var(${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS) + set(extraRepoIdx 0) + foreach(extraRepo ${${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES}) if (${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS) # Read from an extra repo file with potentially different dir. - list(GET ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS ${EXTRAREPO_IDX} - EXTRAREPO_DIR ) + list(GET ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS ${extraRepoIdx} + extraRepoDir ) else() # Not read from extra repo file so dir is same as name - set(EXTRAREPO_DIR ${EXTRA_REPO}) + set(extraRepoDir ${extraRepo}) endif() - #print_var(EXTRAREPO_DIR) tribits_generate_single_repo_version_string( - "${CMAKE_CURRENT_SOURCE_DIR}/${EXTRAREPO_DIR}" - SINGLE_REPO_VERSION) - string(APPEND REPO_VERSION_FILE_STR - "*** Git Repo: ${EXTRAREPO_DIR}\n" - "${SINGLE_REPO_VERSION}\n" ) - - #print_var(REPO_VERSION_FILE_STR) + "${CMAKE_CURRENT_SOURCE_DIR}/${extraRepoDir}" singleRepoVersionStr + INCLUDE_COMMIT_PARENTS ${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS}) + string(APPEND projectRepoVersionFileStr + "*** Git Repo: ${extraRepoDir}\n" + "${singleRepoVersionStr}\n" ) - math(EXPR EXTRAREPO_IDX "${EXTRAREPO_IDX}+1") + math(EXPR extraRepoIdx "${extraRepoIdx}+1") endforeach() - set(${PROJECT_REPO_VERSION_FILE_STRING_OUT} ${REPO_VERSION_FILE_STR} PARENT_SCOPE) + set(${projectRepoVersionFileStrOut} ${projectRepoVersionFileStr} PARENT_SCOPE) endfunction() @@ -1260,17 +1257,17 @@ endfunction() # function(tribits_generate_repo_version_output_and_file) # Get the repos versions - tribits_generate_repo_version_file_string(PROJECT_REPO_VERSION_FILE_STRING) + tribits_generate_repo_version_file_string(projectRepoVersionFileStr) # Print the versions message("\n${PROJECT_NAME} repos versions:\n" "--------------------------------------------------------------------------------\n" - "${PROJECT_REPO_VERSION_FILE_STRING}" + "${projectRepoVersionFileStr}" " --------------------------------------------------------------------------------\n" ) #) Write out the version file file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${${PROJECT_NAME}_REPO_VERSION_FILE_NAME}" - "${PROJECT_REPO_VERSION_FILE_STRING}") + "${projectRepoVersionFileStr}") endfunction() diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/utils/TribitsGitRepoVersionInfo.cmake similarity index 60% rename from tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake rename to tribits/core/utils/TribitsGitRepoVersionInfo.cmake index 1b345ec0a..f7b20ff5b 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/utils/TribitsGitRepoVersionInfo.cmake @@ -85,7 +85,8 @@ function(tribits_git_repo_sha1 gitRepoDir gitRepoSha1Out) execute_process( COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%H" WORKING_DIRECTORY ${gitRepoDir} - RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput + RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) if (NOT gitCmndRtn STREQUAL 0) @@ -105,26 +106,118 @@ function(tribits_git_repo_sha1 gitRepoDir gitRepoSha1Out) endfunction() -# Run the git log command to get the version info for a git repo +# @FUNCTION: tribits_generate_single_repo_version_string() +# +# Get the formatted string containing the current git repo version. +# +# Usage: +# +# tribits_generate_single_repo_version_string( +# [INCLUDE_PARENT_COMMITS ON|OFF]) +# +# If the optional argument ``INCLUDE_PARENT_COMMITS `` is passed, +# then the head commit's parent(s) info will be be included in +# the repo version output string formatted. # function(tribits_generate_single_repo_version_string gitRepoDir repoVersionStringOut ) + cmake_parse_arguments( PARSE_ARGV 2 + PARSE "" # prefix, optional + "INCLUDE_COMMIT_PARENTS" "" # one_value_keywords, multi_value_keyword + ) + tribits_check_for_unparsed_arguments() + tribits_assert_parse_arg_zero_or_one_value(PARSE INCLUDE_COMMIT_PARENTS) + tribits_assert_git_executable() - # A) Get the basic version info. + # A) Get HEAD commit's info + + tribits_generate_commit_info_string(${gitRepoDir} HEAD commitInfoString) + + set(outStringBuilder ${commitInfoString}) + + # B) Get all of HEAD commit's parents into a list execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%h [%ad] <%ae>" + COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%p" HEAD WORKING_DIRECTORY ${gitRepoDir} - RESULT_VARIABLE gitCmndRtn - OUTPUT_VARIABLE gitCmndOutput + RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE + ) + + if (NOT gitCmndRtn STREQUAL 0) + message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0" + " with output '${gitCmndOutput}' for sha1 ${gitHeadSha1} of repo ${gitRepoDir}!") + set(headParentList "Error, could not get commit's parents!") + else() + string(REGEX REPLACE " +" ";" headParentList "${gitCmndOutput}") + endif() + + list(LENGTH headParentList headNumParents) + + # C) Get each parent's commit info and format the output + + if (PARSE_INCLUDE_COMMIT_PARENTS) + + set(parentIdx 1) # Parent commit indexes are 1-based by git + + foreach(parentSha1 IN LISTS headParentList) + + # C.1) Get parent commit info string + + tribits_generate_commit_info_string( + ${gitRepoDir} ${parentSha1} + commitInfoString) + + # C.2) Format parent string to be pretty in config output + + string(APPEND outStringBuilder + "\n *** Parent ${parentIdx}:") + string(REPLACE "\n" "\n " + commitInfoString "${commitInfoString}") + string(APPEND outStringBuilder "\n ${commitInfoString}" ) + + math(EXPR parentIdx "${parentIdx}+1") + + endforeach() + + endif() + + set(${repoVersionStringOut} "${outStringBuilder}" PARENT_SCOPE) + +endfunction() + + +# @FUNCTION: tribits_generate_commit_info_string() +# +# Get the formatted commit info containing commit's SHA1, +# author, date, email, and 80 character summary. +# +# Usage: +# tribits_generate_commit_info_string( +# commitInfoStringOut) +# +# NOTE: Below, it is fine if ${maxSummaryLen} > len(${gitCmndOutput}) as +# string(SUBSTRING ...) will just shorten this to the length of the string. +# +function(tribits_generate_commit_info_string gitRepoDir gitCommitSha1 + commitInfoStringOut + ) + + # A) Get commit hash, author, date, and email + + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%h [%ad] <%ae>" ${gitCommitSha1} + WORKING_DIRECTORY ${gitRepoDir} + RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) if (NOT gitCmndRtn STREQUAL 0) message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0" - " for repo ${gitRepoDir}!") + " with output '${gitCmndOutput}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") set(gitVersionLine "Error, could not get version info!") else() set(gitVersionLine "${gitCmndOutput}") @@ -133,27 +226,25 @@ function(tribits_generate_single_repo_version_string gitRepoDir # B) Get the first 80 chars of the summary message for more info execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%s + COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%s" ${gitCommitSha1} WORKING_DIRECTORY ${gitRepoDir} - RESULT_VARIABLE gitCmndRtn - OUTPUT_VARIABLE gitCmndOutput + RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) if (NOT gitCmndRtn STREQUAL 0) message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0" - " for extra repo ${gitRepoDir}!") + " with output '${gitCmndOutput}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") set(gitSummaryStr "Error, could not get version summary!") else() set(maxSummaryLen 80) string(SUBSTRING "${gitCmndOutput}" 0 ${maxSummaryLen} gitSummaryStr) endif() - set(${repoVersionStringOut} + set(${commitInfoStringOut} "${gitVersionLine}\n${gitSummaryStr}" PARENT_SCOPE) endfunction() -# NOTE: Above, it is fine if ${maxSummaryLen} > len(${gitCmndOutput}) as -# string(SUBSTRING ...) will just shorten this to the length of the string. function(tribits_assert_git_executable) diff --git a/tribits/ctest_driver/TribitsAddDashboardTarget.cmake b/tribits/ctest_driver/TribitsAddDashboardTarget.cmake index 52851ce3c..6b60d3912 100644 --- a/tribits/ctest_driver/TribitsAddDashboardTarget.cmake +++ b/tribits/ctest_driver/TribitsAddDashboardTarget.cmake @@ -45,7 +45,7 @@ # ################################################################################ -include(TribitsGitRepoVersionInfo) +include("${CMAKE_CURRENT_LIST_DIR}/../core/utils/TribitsGitRepoVersionInfo.cmake") # # Macro that drives a experimental 'dashboard' target diff --git a/tribits/ctest_driver/TribitsCTestDriverCore.cmake b/tribits/ctest_driver/TribitsCTestDriverCore.cmake index 1666f5755..8e6ecfde5 100644 --- a/tribits/ctest_driver/TribitsCTestDriverCore.cmake +++ b/tribits/ctest_driver/TribitsCTestDriverCore.cmake @@ -669,11 +669,11 @@ include(TribitsCTestDriverCoreHelpers) # **Setting variables in the inner CMake configure:** # # It is important to understand that none of the CMake vars that get set in -# the other CTest -S program that calls ``tribits_ctest_driver()`` +# the outer CTest -S program that calls ``tribits_ctest_driver()`` # automatically get passed into the inner configure of the TriBITS CMake # project using the ``ctest_configure()`` command by CMake. From the # perspective of raw CTest and CMake, these are completely separate programs. -# However, the ``tribits_ctest_driver()`` function will forward subset of +# However, the ``tribits_ctest_driver()`` function will forward subset a of # variables documented below into the inner CMake configure. The following # variables that are set in the outer CTest -S program will be passed into the # inner CMake configure by default (but their values they can be overridden by @@ -684,7 +684,7 @@ include(TribitsCTestDriverCoreHelpers) # # Missing extra repos are always ignored in the inner CMake configure. # This is because any problems reading an extra repo will be caught in the -# outer CTest -S drivers script. +# outer CTest -S driver script. # # ``-D${PROJECT_NAME}_ENABLE_ALL_OPTIONAL_PACKAGES:BOOL=ON`` # @@ -699,7 +699,7 @@ include(TribitsCTestDriverCoreHelpers) # may be disabled. (This set may be removed in the future for the # all-at-once mode.) # -# The following variables set in the CTest -S driver script will be passed +# The following variables set in the outer CTest -S driver script will be passed # down into the inner CMake configure through the ``OPTIONS`` variable to the # ``ctest_configure()`` command: # @@ -758,7 +758,7 @@ include(TribitsCTestDriverCoreHelpers) # These configure options are passed into the ``ctest_configure()`` command in # the order:: # -# ${EXTRA_SYSTEM_CONFIGURE_OPTIONS}} \ +# ${EXTRA_SYSTEM_CONFIGURE_OPTIONS}} \ # ${EXTRA_CONFIGURE_OPTIONS} ${${PROJECT_NAME}_EXTRA_CONFIGURE_OPTIONS} # # **WARNING:** The options listed in ``EXTRA_SYSTEM_CONFIGURE_OPTIONS``, diff --git a/tribits/doc/build_ref/TribitsBuildReferenceBody.rst b/tribits/doc/build_ref/TribitsBuildReferenceBody.rst index 06600479e..3ab4ce13f 100644 --- a/tribits/doc/build_ref/TribitsBuildReferenceBody.rst +++ b/tribits/doc/build_ref/TribitsBuildReferenceBody.rst @@ -376,6 +376,7 @@ See the following use cases: * `Enable all packages (and optionally all tests)`_ * `Disable a package and all its dependencies`_ * `Remove all package enables in the cache`_ +* `Speed up debugging dependency handling`_ Determine the list of packages that can be enabled @@ -656,6 +657,22 @@ For example, one would want to do this to avoid more expensive compiler and TPL checks. +Speed up debugging dependency handling ++++++++++++++++++++++++++++++++++++++++ + +To speed up debugging the package enable/disable dependency handling, set the +cache variable:: + + -D _TRACE_DEPENDENCY_HANDLING_ONLY=ON + +This will result in only performing the package enable/disable dependency +handling logic and tracing what would be done to configure the compilers and +configure the various enabled packages but not actually do that work. This +can greatly speed up the time to complete the ``cmake`` configure command when +debugging the dependency handling (or when creating tests that check that +behavior). + + Selecting compiler and linker options ------------------------------------- @@ -2934,6 +2951,20 @@ NOTE: If the base ``.git/`` directory is missing, then no printed to cmake STDOUT. +Show parent(s) commit info in the repo version output +---------------------------------------------------- + +.. __SHOW_GIT_COMMIT_PARENTS: + +When working with local git repos for the project sources, one can include +the repo's head commit parent(s) info in the repo version output using:: + + -D _SHOW_GIT_COMMIT_PARENTS=ON + +For each parent commit, this will include their SHA1, author name, date, email +and its 80 character summary message in the repo version output string. + + Generating git version date files --------------------------------- diff --git a/tribits/doc/guides/TribitsCoreDetailedReference.rst b/tribits/doc/guides/TribitsCoreDetailedReference.rst index 7fbad8103..aa443415c 100644 --- a/tribits/doc/guides/TribitsCoreDetailedReference.rst +++ b/tribits/doc/guides/TribitsCoreDetailedReference.rst @@ -88,6 +88,7 @@ a given TriBITS project are: * `${PROJECT_NAME}_MUST_FIND_ALL_TPL_LIBS`_ * `${PROJECT_NAME}_REQUIRES_PYTHON`_ * `${PROJECT_NAME}_SET_INSTALL_RPATH`_ +* `${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS`_ * `${PROJECT_NAME}_SHOW_TEST_START_END_DATE_TIME`_ * `${PROJECT_NAME}_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES`_ * `${PROJECT_NAME}_TEST_CATEGORIES`_ @@ -651,6 +652,21 @@ These options are described below. Handling`_). +.. _${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS: + +**${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS** + + The cache variable ``${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS`` results in + the repo version file showing the parent commits for each repo commit. By + default, this variable is set to ``OFF`` but projects can set to to ``ON`` + by default by setting:: + + set(${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS_DEFAULT ON) + + in the project's ``ProjectName.cmake`` file. (That way, it will also impact + ``cmake -P`` scripts don't configure the project itself to be built.) + + .. _${PROJECT_NAME}_SHOW_TEST_START_END_DATE_TIME: **${PROJECT_NAME}_SHOW_TEST_START_END_DATE_TIME**