From 00b3c6fd3381fa279ec12e2ebea8857fff6751a1 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 4 Jan 2024 16:14:37 -0700 Subject: [PATCH 01/30] Add test TribitsHelloWorld_config_git_version (#597) Added test TribitsHelloWorld_config_git_version that uses mockprogram.py as git to generate and check git version info. ToDo: We should also check the generated TribitsHelloWorldRepoVersion.txt file --- .../TribitsHelloWorld_Tests.cmake | 46 +++++++++++++++++++ .../mockprogram_inout.single_version.txt | 6 +++ 2 files changed, 52 insertions(+) create mode 100644 test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_version.txt diff --git a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake index 69f694fff..cd8cdac82 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,51 @@ tribits_add_advanced_test( TribitsHelloWorld ) +tribits_add_advanced_test( TribitsHelloWorld_config_git_version + OVERALL_WORKING_DIRECTORY TEST_NAME + OVERALL_NUM_MPI_PROCS 1 + + 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_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 + -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 git commit summary line" + ALWAYS_FAIL_ON_NONZERO_RETURN + + ) +# The above directory structure is: +# +# TribitsHelloWorld_config_git_version/ +# TribitsHelloWorld/ +# .git/ +# .mockprogram_inout.txt +# BUILD/ + + 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/mockprogram_inout.single_version.txt b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_version.txt new file mode 100644 index 000000000..3b43f1f3e --- /dev/null +++ b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_version.txt @@ -0,0 +1,6 @@ +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: This is the git commit summary line From 80191d4d5f45881ebd9bb73cc5aa7b4352e5b2cd Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 4 Jan 2024 16:20:45 -0700 Subject: [PATCH 02/30] Print the stdout/stderr from the failed git command (#587) --- tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 1b345ec0a..a6622d501 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -124,7 +124,7 @@ function(tribits_generate_single_repo_version_string gitRepoDir if (NOT gitCmndRtn STREQUAL 0) message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0" - " for repo ${gitRepoDir}!") + " with output '${gitCmndOutput}' for repo ${gitRepoDir}!") set(gitVersionLine "Error, could not get version info!") else() set(gitVersionLine "${gitCmndOutput}") From 98750bbce5a74530c048c253ebeed406e0cba103 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 4 Jan 2024 16:21:40 -0700 Subject: [PATCH 03/30] Strip the whitespace from git command (#597) For some reason, mockprogram.py prints an newline that raw git does not. But this should work for raw git too. --- tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index a6622d501..80b82ed9f 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -120,6 +120,7 @@ function(tribits_generate_single_repo_version_string gitRepoDir WORKING_DIRECTORY ${gitRepoDir} RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) if (NOT gitCmndRtn STREQUAL 0) @@ -137,6 +138,7 @@ function(tribits_generate_single_repo_version_string gitRepoDir WORKING_DIRECTORY ${gitRepoDir} RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) if (NOT gitCmndRtn STREQUAL 0) From 1db93786ad922932d8e4854fa9506c260785e59a Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 4 Jan 2024 16:44:49 -0700 Subject: [PATCH 04/30] Add check of generatead TribitsHelloWorldRepoVersion.txt file (#597) --- .../TribitsHelloWorld_Tests.cmake | 14 +++++++++++++- ...TribitsHelloWorldRepoVersion.single_version.txt | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_version.txt diff --git a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake index cd8cdac82..6ab244848 100644 --- a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake @@ -40,6 +40,7 @@ tribits_add_advanced_test( TribitsHelloWorld tribits_add_advanced_test( TribitsHelloWorld_config_git_version 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." @@ -72,14 +73,25 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version "This is the git commit summary line" ALWAYS_FAIL_ON_NONZERO_RETURN + TEST_4 + CMND diff ARGS + ${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_version.txt + BUILD/TribitsHelloWorldRepoVersion.txt + ) -# The above directory structure is: +# NOTES: +# +# * The above directory structure is: # # TribitsHelloWorld_config_git_version/ # 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_EXE_DISABLE diff --git a/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_version.txt b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_version.txt new file mode 100644 index 000000000..df4d477e6 --- /dev/null +++ b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_version.txt @@ -0,0 +1,3 @@ +*** Base Git Repo: TribitsHelloWorld +a1234tgb [Thu Sep 21 19:19:18 2023 -0400] +This is the git commit summary line From ebd6c6fc2040df76e8f70b0daccf047904637c4f Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Wed, 10 Jan 2024 17:22:36 -0700 Subject: [PATCH 05/30] Renamed test TribitsHelloWorld_config_git_version (#597) Renamed the test TribitsHelloWorld_config_git_version to TribitsHelloWorld_config_git_version_single_repo_one_parent to correctly state the scope of the test and allow for future similar tests with slightly a difference scopes (such as single_repo_two_parents, multi_repo_one_parent, etc). --- test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake | 6 +++--- ...elloWorldRepoVersion.single_repo_one_parent_version.txt} | 0 ...=> mockprogram_inout.single_repo_one_parent_version.txt} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename test/core/ExamplesUnitTests/configure_git_mockprogram_files/{TribitsHelloWorldRepoVersion.single_version.txt => TribitsHelloWorldRepoVersion.single_repo_one_parent_version.txt} (100%) rename test/core/ExamplesUnitTests/configure_git_mockprogram_files/{mockprogram_inout.single_version.txt => mockprogram_inout.single_repo_one_parent_version.txt} (100%) diff --git a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake index 6ab244848..35aa9c4e3 100644 --- a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake @@ -37,7 +37,7 @@ tribits_add_advanced_test( TribitsHelloWorld ) -tribits_add_advanced_test( TribitsHelloWorld_config_git_version +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 :-( @@ -55,7 +55,7 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version TEST_2 CMND ${CMAKE_COMMAND} ARGS -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/mockprogram_inout.single_version.txt + ${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt TribitsHelloWorld/.mockprogram_inout.txt TEST_3 @@ -75,7 +75,7 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version TEST_4 CMND diff ARGS - ${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_version.txt + ${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_one_parent_version.txt BUILD/TribitsHelloWorldRepoVersion.txt ) diff --git a/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_version.txt b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_one_parent_version.txt similarity index 100% rename from test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_version.txt rename to test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_one_parent_version.txt diff --git a/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_version.txt b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt similarity index 100% rename from test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_version.txt rename to test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt From b35e3c934b4935043b744b7aaafe46ab5241f717 Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Thu, 11 Jan 2024 16:48:22 -0700 Subject: [PATCH 06/30] Refactored chunk of tribits_generate_single_repo_version_string for reuse (#597) Moved git commit info functionality of tribits_generate_single_repo_version_string to a separate helper function named tribites_generate_commit_info_string. The core functionality and output is the same. This is in prep for reuse of that functionality inside of the original tribits_generate_single_repo_version string. --- .../TribitsGitRepoVersionInfo.cmake | 52 +++++++++++++------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 80b82ed9f..36320b096 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -105,36 +105,35 @@ 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 gitRepoDir - repoVersionStringOut - ) - - tribits_assert_git_executable() - - # A) Get the basic version info. - +# Run git log to generate a string containing commit sha1, author, date, email +# and the commit summary + +function(tribits_generate_commit_info_string gitRepoDir + commitInfoStringOut + ) + + # A) Get commit hash, author, date, and email + execute_process( COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%h [%ad] <%ae>" WORKING_DIRECTORY ${gitRepoDir} RESULT_VARIABLE gitCmndRtn - OUTPUT_VARIABLE gitCmndOutput + OUTPUT_VARIABLE gitCmndOut 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 repo ${gitRepoDir}!") + " for SHA1 of repo ${gitRepoDir}!") set(gitVersionLine "Error, could not get version info!") else() - set(gitVersionLine "${gitCmndOutput}") + set(gitVersionLine "${gitCmndOut}") endif() # 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" WORKING_DIRECTORY ${gitRepoDir} RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput @@ -143,15 +142,34 @@ function(tribits_generate_single_repo_version_string gitRepoDir if (NOT gitCmndRtn STREQUAL 0) message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0" - " for extra repo ${gitRepoDir}!") + " for SHA1 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() + + + +# Run the git log command to get the version info for a git repo +# +function(tribits_generate_single_repo_version_string gitRepoDir + repoVersionStringOut + ) + + tribits_assert_git_executable() + + # A) Get HEAD commit's info + + tribits_generate_commit_info_string( + ${gitRepoDir} + headCommitInfoString) + + set(${repoVersionStringOut} "${headCommitInfoString}" PARENT_SCOPE) endfunction() # NOTE: Above, it is fine if ${maxSummaryLen} > len(${gitCmndOutput}) as From 8966263b6b1d729dab0550c1ce731942770487bd Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Fri, 12 Jan 2024 10:58:42 -0700 Subject: [PATCH 07/30] Removed trailing whitespace for tribits_git_repo_sha1 git cmnd output (#597) Removed trailing whitespace to keep git command outputs consistent with other functions performing git commands and for the output to be more processable. --- tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 36320b096..68373cca4 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -85,7 +85,9 @@ 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) From fd3a2e967cd3923f8fc63b036cb74a20953c67ba Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Fri, 12 Jan 2024 12:37:17 -0700 Subject: [PATCH 08/30] Add commit sha1 input for tribits_generate_commit_info_string (#597) Make tribits_generate_commit_info_string output commit info based on a passed in commit sha1. --- ...ogram_inout.single_repo_one_parent_version.txt | 7 +++++-- .../package_arch/TribitsGitRepoVersionInfo.cmake | 15 +++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) 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 index 3b43f1f3e..9006e223b 100644 --- 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 @@ -1,6 +1,9 @@ -MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%H +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: a1234tgbhyujkliu126sl12123s +MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%h [%ad] <%ae> MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] -MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s +MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%s MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: This is the git commit summary line diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 68373cca4..d55006368 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -110,14 +110,14 @@ endfunction() # Run git log to generate a string containing commit sha1, author, date, email # and the commit summary -function(tribits_generate_commit_info_string gitRepoDir +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>" + COMMAND ${GIT_EXECUTABLE} log -1 ${gitCommitSha1} "--pretty=format:%h [%ad] <%ae>" WORKING_DIRECTORY ${gitRepoDir} RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOut @@ -126,7 +126,7 @@ function(tribits_generate_commit_info_string gitRepoDir if (NOT gitCmndRtn STREQUAL 0) message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0" - " for SHA1 of repo ${gitRepoDir}!") + " with output '${gitCmndOut}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") set(gitVersionLine "Error, could not get version info!") else() set(gitVersionLine "${gitCmndOut}") @@ -135,7 +135,7 @@ function(tribits_generate_commit_info_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 ${gitCommitSha1} "--pretty=format:%s" WORKING_DIRECTORY ${gitRepoDir} RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput @@ -144,7 +144,7 @@ function(tribits_generate_commit_info_string gitRepoDir if (NOT gitCmndRtn STREQUAL 0) message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0" - " for SHA1 of repo ${gitRepoDir}!") + " with output '${gitCmndOut}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") set(gitSummaryStr "Error, could not get version summary!") else() set(maxSummaryLen 80) @@ -167,8 +167,11 @@ function(tribits_generate_single_repo_version_string gitRepoDir # A) Get HEAD commit's info + tribits_git_repo_sha1(${gitRepoDir} + gitHeadSha1) + tribits_generate_commit_info_string( - ${gitRepoDir} + ${gitRepoDir} ${gitHeadSha1} headCommitInfoString) set(${repoVersionStringOut} "${headCommitInfoString}" PARENT_SCOPE) From be3a494617a3c80f935eadd4939f5c31b959c55e Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Fri, 12 Jan 2024 13:19:33 -0700 Subject: [PATCH 09/30] Updated TribitsHelloWorld_config_git_version_single_repo_one_parent test (#597) Updated mockprogram inputs and outputs to be more specific about which commit message is being outputted. --- test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake | 4 ++-- ...tsHelloWorldRepoVersion.single_repo_one_parent_version.txt | 2 +- .../mockprogram_inout.single_repo_one_parent_version.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake index 35aa9c4e3..696e1dd50 100644 --- a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake @@ -70,7 +70,7 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_one_ ../TribitsHelloWorld PASS_REGULAR_EXPRESSION_ALL "a1234tgb .Thu Sep 21 19:19:18 2023 -0400. " - "This is the git commit summary line" + "This is the HEAD commit summary line" ALWAYS_FAIL_ON_NONZERO_RETURN TEST_4 @@ -83,7 +83,7 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_one_ # # * The above directory structure is: # -# TribitsHelloWorld_config_git_version/ +# TribitsHelloWorld_config_git_version_single_repo_one_parent/ # TribitsHelloWorld/ # .git/ # .mockprogram_inout.txt 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 index df4d477e6..a4e411d90 100644 --- 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 @@ -1,3 +1,3 @@ *** Base Git Repo: TribitsHelloWorld a1234tgb [Thu Sep 21 19:19:18 2023 -0400] -This is the git commit summary line +This is the HEAD 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 index 9006e223b..f60bdeb4b 100644 --- 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 @@ -6,4 +6,4 @@ MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%s MOCK_PROGRAM_RETURN: 0 -MOCK_PROGRAM_OUTPUT: This is the git commit summary line +MOCK_PROGRAM_OUTPUT: This is the HEAD commit summary line From 0dacf471213cd1acf7e961eedcec6423fa6c06b7 Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Fri, 12 Jan 2024 18:18:33 -0700 Subject: [PATCH 10/30] Added git version info for parent commits (#597) If the HEAD sha1 contains more than one parent, include each parent's commit info in the final repoVersionStringOut of tribits_generate_single_repo_version_string. --- .../TribitsHelloWorld_Tests.cmake | 52 ++++++++++ ...ersion.single_repo_two_parents_version.txt | 9 ++ ...m_inout.single_repo_one_parent_version.txt | 3 + ..._inout.single_repo_two_parents_version.txt | 32 +++++++ .../TribitsGitRepoVersionInfo.cmake | 95 ++++++++++++++++--- 5 files changed, 178 insertions(+), 13 deletions(-) create mode 100644 test/core/ExamplesUnitTests/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_two_parents_version.txt create mode 100644 test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_two_parents_version.txt diff --git a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake index 696e1dd50..b60890fb7 100644 --- a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake @@ -94,6 +94,58 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_one_ +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 + -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 0:" + "b5678aop .Thu Sep 20 19:19:18 2023 -0400. " + "This is parent 0 commit summary line" + "Parent 1:" + "c9101hah .Thu Sep 19 19:19:18 2023 -0400. " + "This is parent 1 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_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..53bb4556d --- /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 0: + b5678aop [Thu Sep 20 19:19:18 2023 -0400] + This is parent 0 commit summary line + *** Parent 1: + c9101hah [Thu Sep 19 19:19:18 2023 -0400] + This is parent 1 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 index f60bdeb4b..11c955258 100644 --- 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 @@ -7,3 +7,6 @@ MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] +MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%s +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: This is the HEAD commit summary line +MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%p +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: b5678aop c9101hah +MOCK_PROGRAM_INPUT: log -1 b5678aop --pretty=format:%h [%ad] <%ae> +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: b5678aop [Thu Sep 20 19:19:18 2023 -0400] +MOCK_PROGRAM_INPUT: log -1 b5678aop --pretty=format:%s +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: This is parent 0 commit summary line +MOCK_PROGRAM_INPUT: log -1 c9101hah --pretty=format:%h [%ad] <%ae> +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: c9101hah [Thu Sep 19 19:19:18 2023 -0400] +MOCK_PROGRAM_INPUT: log -1 c9101hah --pretty=format:%s +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: This is parent 1 commit summary line + + + + + + + + diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index d55006368..6842c3c6c 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -107,9 +107,18 @@ function(tribits_git_repo_sha1 gitRepoDir gitRepoSha1Out) endfunction() -# Run git log to generate a string containing commit sha1, author, date, email -# and the commit summary - +# @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 ) @@ -120,16 +129,16 @@ function(tribits_generate_commit_info_string gitRepoDir gitCommitSha1 COMMAND ${GIT_EXECUTABLE} log -1 ${gitCommitSha1} "--pretty=format:%h [%ad] <%ae>" WORKING_DIRECTORY ${gitRepoDir} RESULT_VARIABLE gitCmndRtn - OUTPUT_VARIABLE gitCmndOut + 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 '${gitCmndOut}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") + " with output '${gitCmndOutput}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") set(gitVersionLine "Error, could not get version info!") else() - set(gitVersionLine "${gitCmndOut}") + set(gitVersionLine "${gitCmndOutput}") endif() # B) Get the first 80 chars of the summary message for more info @@ -144,7 +153,7 @@ function(tribits_generate_commit_info_string gitRepoDir gitCommitSha1 if (NOT gitCmndRtn STREQUAL 0) message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0" - " with output '${gitCmndOut}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") + " with output '${gitCmndOutput}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") set(gitSummaryStr "Error, could not get version summary!") else() set(maxSummaryLen 80) @@ -153,11 +162,22 @@ function(tribits_generate_commit_info_string gitRepoDir gitCommitSha1 set(${commitInfoStringOut} "${gitVersionLine}\n${gitSummaryStr}" PARENT_SCOPE) -endfunction() +endfunction() -# Run the git log command to get the version info for a git repo +# @FUNCTION: tribites_generate_single_repo_version_string +# +# Get the formatted string containing the current git repo version. +# +# Usage: +# +# tribits_generate_single_repo_version_string( +# ) +# +# If the latest commit contains more than one parent, this function +# will also include formatted output of the commit info of those +# parents. # function(tribits_generate_single_repo_version_string gitRepoDir repoVersionStringOut @@ -172,13 +192,62 @@ function(tribits_generate_single_repo_version_string gitRepoDir tribits_generate_commit_info_string( ${gitRepoDir} ${gitHeadSha1} - headCommitInfoString) + commitInfoString) + + set(outStringBuilder ${commitInfoString}) + + # B) Get all of HEAD commit's parents into a list + + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 ${gitHeadSha1} "--pretty=format:%p" + 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" + " with output '${gitCmndOutput}' for sha1 ${gitHeadSha1} of repo ${gitRepoDir}!") + set(headParentList "Error, could not get commit's parents!") + else() + string(REPLACE " " ";" headParentList ${gitCmndOutput}) + endif() + + list(LENGTH headParentList headNumParents) + + # C) Get each parent's commit info and format the output + + if (headNumParents GREATER 1) - set(${repoVersionStringOut} "${headCommitInfoString}" PARENT_SCOPE) + # Is there a better way??? Range is inclusive and does not accept expressions?!? + math(EXPR loopMax "${headNumParents}-1") + + foreach(index RANGE ${loopMax}) + + # C.1) Get parent commit info string + + list(GET headParentList ${index} parentSha1) + tribits_generate_commit_info_string( + ${gitRepoDir} ${parentSha1} + commitInfoString) + + # C.2) Format parent string to be pretty in config output + + string(APPEND outStringBuilder + "\n *** Parent ${index}:") + string(REPLACE "\n" "\n " + commitInfoString "${commitInfoString}") + string(CONCAT outStringBuilder + "${outStringBuilder}" "\n ${commitInfoString}" ) + + endforeach() + + endif() + + set(${repoVersionStringOut} "${outStringBuilder}" 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) From f34a4299d039bfbba5af455ee8034b9bc138df83 Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Fri, 12 Jan 2024 18:40:48 -0700 Subject: [PATCH 11/30] Added double quotes around variable (#597) Forgot to double quote variable and caused configure failures during Github Actions testing. --- tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 6842c3c6c..0e34222ab 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -211,7 +211,7 @@ function(tribits_generate_single_repo_version_string gitRepoDir " with output '${gitCmndOutput}' for sha1 ${gitHeadSha1} of repo ${gitRepoDir}!") set(headParentList "Error, could not get commit's parents!") else() - string(REPLACE " " ";" headParentList ${gitCmndOutput}) + string(REPLACE " " ";" headParentList "${gitCmndOutput}") endif() list(LENGTH headParentList headNumParents) From 3af75e3ffe0611b8ec967e247a09ccf244270ae4 Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Fri, 12 Jan 2024 19:00:20 -0700 Subject: [PATCH 12/30] Fix type causing sphinx build to fail (#597) --- tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 0e34222ab..cc8f683bb 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -166,7 +166,7 @@ function(tribits_generate_commit_info_string gitRepoDir gitCommitSha1 endfunction() -# @FUNCTION: tribites_generate_single_repo_version_string +# @FUNCTION: tribits_generate_single_repo_version_string # # Get the formatted string containing the current git repo version. # From a40bd5e6ff0d378a7c2b2d9100b6668b2aae5541 Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Mon, 15 Jan 2024 21:27:43 -0700 Subject: [PATCH 13/30] Added global cmake cache var to show git commit parents (#597) Added global cmake cache variable `_SHOW_GIT_COMMIT_PARENTS:BOOL` that is default to OFF. This will be a project based variable to including parent commit info in the repo version output. --- .../core/package_arch/TribitsGlobalMacros.cmake | 8 ++++++++ .../doc/build_ref/TribitsBuildReferenceBody.rst | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index 63149a375..e5c4d28a2 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -685,6 +685,14 @@ macro(tribits_define_global_options_and_define_extra_repos) CACHE BOOL "Generate the ${PROJECT_NAME}RepoVersion.txt file.") + if ("${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS_DEFAULT}" STREQUAL "") + set(${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS_DEFAULT OFF) + endif() + advanced_set(${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS + ${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS_DEFAULT} + CACHE BOOL + "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() diff --git a/tribits/doc/build_ref/TribitsBuildReferenceBody.rst b/tribits/doc/build_ref/TribitsBuildReferenceBody.rst index 06600479e..92817594c 100644 --- a/tribits/doc/build_ref/TribitsBuildReferenceBody.rst +++ b/tribits/doc/build_ref/TribitsBuildReferenceBody.rst @@ -2934,6 +2934,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 --------------------------------- From 592ea0d56037ef1a4af4ac6f70a0f171d34d7659 Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Mon, 15 Jan 2024 22:26:29 -0700 Subject: [PATCH 14/30] Cleaned up git log and cmake command argument formatting (#597) Reordered git log arguments to the expected order as well as condensed cmake command arguments into a single line. --- ...m_inout.single_repo_one_parent_version.txt | 6 ++--- ..._inout.single_repo_two_parents_version.txt | 22 ++++++------------- .../TribitsGitRepoVersionInfo.cmake | 18 ++++++--------- 3 files changed, 17 insertions(+), 29 deletions(-) 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 index 11c955258..f643a9ab1 100644 --- 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 @@ -1,12 +1,12 @@ MOCK_PROGRAM_INPUT: log -1 --pretty=format:%H MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: a1234tgbhyujkliu126sl12123s -MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%h [%ad] <%ae> +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> a1234tgbhyujkliu126sl12123s MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] -MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%s +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s a1234tgbhyujkliu126sl12123s MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: This is the HEAD commit summary line -MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%p +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%p a1234tgbhyujkliu126sl12123s 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 index e9c4d1de8..be132f67e 100644 --- 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 @@ -1,32 +1,24 @@ MOCK_PROGRAM_INPUT: log -1 --pretty=format:%H MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: a1234tgbhyujkliu126sl12123s -MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%h [%ad] <%ae> +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> a1234tgbhyujkliu126sl12123s MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] -MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%s +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s a1234tgbhyujkliu126sl12123s MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: This is the HEAD commit summary line -MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%p +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%p a1234tgbhyujkliu126sl12123s MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: b5678aop c9101hah -MOCK_PROGRAM_INPUT: log -1 b5678aop --pretty=format:%h [%ad] <%ae> +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 b5678aop --pretty=format:%s +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s b5678aop MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: This is parent 0 commit summary line -MOCK_PROGRAM_INPUT: log -1 c9101hah --pretty=format:%h [%ad] <%ae> +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 c9101hah --pretty=format:%s +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s c9101hah MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: This is parent 1 commit summary line - - - - - - - - diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index cc8f683bb..3fdbac7b2 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -85,8 +85,7 @@ 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 ) @@ -126,10 +125,9 @@ function(tribits_generate_commit_info_string gitRepoDir gitCommitSha1 # A) Get commit hash, author, date, and email execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 ${gitCommitSha1} "--pretty=format:%h [%ad] <%ae>" + COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%h [%ad] <%ae>" ${gitCommitSha1} WORKING_DIRECTORY ${gitRepoDir} - RESULT_VARIABLE gitCmndRtn - OUTPUT_VARIABLE gitCmndOutput + RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) @@ -144,10 +142,9 @@ function(tribits_generate_commit_info_string gitRepoDir gitCommitSha1 # B) Get the first 80 chars of the summary message for more info execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 ${gitCommitSha1} "--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 ) @@ -199,10 +196,9 @@ function(tribits_generate_single_repo_version_string gitRepoDir # B) Get all of HEAD commit's parents into a list execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 ${gitHeadSha1} "--pretty=format:%p" + COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%p" ${gitHeadSha1} WORKING_DIRECTORY ${gitRepoDir} - RESULT_VARIABLE gitCmndRtn - OUTPUT_VARIABLE gitCmndOutput + RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) From e4b19b688f3051f493a308a7dd507ad3be1f3f71 Mon Sep 17 00:00:00 2001 From: Anderson Date: Tue, 16 Jan 2024 14:43:16 -0700 Subject: [PATCH 15/30] Updated tribits_gernerate_single_repo_version_string to use HEAD (#597) Instead of passing in the deferenced HEAD SHA1 to tribites_generate_commit_info_string, simply just pass in the HEAD pointer keyword for Git to deference itself. --- .../mockprogram_inout.single_repo_one_parent_version.txt | 9 +++------ ...mockprogram_inout.single_repo_two_parents_version.txt | 9 +++------ .../core/package_arch/TribitsGitRepoVersionInfo.cmake | 9 ++------- 3 files changed, 8 insertions(+), 19 deletions(-) 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 index f643a9ab1..a406d461e 100644 --- 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 @@ -1,12 +1,9 @@ -MOCK_PROGRAM_INPUT: log -1 --pretty=format:%H -MOCK_PROGRAM_RETURN: 0 -MOCK_PROGRAM_OUTPUT: a1234tgbhyujkliu126sl12123s -MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> a1234tgbhyujkliu126sl12123s +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 a1234tgbhyujkliu126sl12123s +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 a1234tgbhyujkliu126sl12123s +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 index be132f67e..fa4bb6a5e 100644 --- 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 @@ -1,13 +1,10 @@ -MOCK_PROGRAM_INPUT: log -1 --pretty=format:%H -MOCK_PROGRAM_RETURN: 0 -MOCK_PROGRAM_OUTPUT: a1234tgbhyujkliu126sl12123s -MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> a1234tgbhyujkliu126sl12123s +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 a1234tgbhyujkliu126sl12123s +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 a1234tgbhyujkliu126sl12123s +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 diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 3fdbac7b2..6f187887e 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -184,19 +184,14 @@ function(tribits_generate_single_repo_version_string gitRepoDir # A) Get HEAD commit's info - tribits_git_repo_sha1(${gitRepoDir} - gitHeadSha1) - - tribits_generate_commit_info_string( - ${gitRepoDir} ${gitHeadSha1} - commitInfoString) + 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:%p" ${gitHeadSha1} + COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%p" HEAD WORKING_DIRECTORY ${gitRepoDir} RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE From 852e651efe2a9f6ebd07841e377e566fae92ac21 Mon Sep 17 00:00:00 2001 From: Anderson Date: Tue, 16 Jan 2024 14:47:56 -0700 Subject: [PATCH 16/30] Updated to use cmake string(REGEX REPLACE) when converting git log output (#597) In the off chance that Git decides to change the output of git log -1 "--pretty=format:%p", use a regex match and replace in cmake to match consecutive spaces and replace them with a single ;. --- .../mockprogram_inout.single_repo_two_parents_version.txt | 2 +- tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 index fa4bb6a5e..f192681d6 100644 --- 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 @@ -6,7 +6,7 @@ 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_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] diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 6f187887e..32d6ac9d3 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -202,7 +202,7 @@ function(tribits_generate_single_repo_version_string gitRepoDir " with output '${gitCmndOutput}' for sha1 ${gitHeadSha1} of repo ${gitRepoDir}!") set(headParentList "Error, could not get commit's parents!") else() - string(REPLACE " " ";" headParentList "${gitCmndOutput}") + string(REGEX REPLACE " +" ";" headParentList "${gitCmndOutput}") endif() list(LENGTH headParentList headNumParents) From f6b64420289c6fd7dfd105c0d9905590771c99d2 Mon Sep 17 00:00:00 2001 From: Anderson Date: Tue, 16 Jan 2024 14:52:10 -0700 Subject: [PATCH 17/30] Simplified loop and changed to 1-based indexing (#597) Simplified foreach loop in tribits_generate_single_repo_version_string and changed the parent indexing to be 1-based instead of 0-based. --- .../ExamplesUnitTests/TribitsHelloWorld_Tests.cmake | 8 ++++---- ...rldRepoVersion.single_repo_two_parents_version.txt | 8 ++++---- ...kprogram_inout.single_repo_two_parents_version.txt | 4 ++-- .../core/package_arch/TribitsGitRepoVersionInfo.cmake | 11 +++++------ 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake index b60890fb7..c9fe109e5 100644 --- a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake @@ -128,12 +128,12 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_two_ PASS_REGULAR_EXPRESSION_ALL "a1234tgb .Thu Sep 21 19:19:18 2023 -0400. " "This is the HEAD commit summary line" - "Parent 0:" - "b5678aop .Thu Sep 20 19:19:18 2023 -0400. " - "This is parent 0 commit summary line" "Parent 1:" - "c9101hah .Thu Sep 19 19:19:18 2023 -0400. " + "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 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 index 53bb4556d..7a353a348 100644 --- 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 @@ -1,9 +1,9 @@ *** Base Git Repo: TribitsHelloWorld a1234tgb [Thu Sep 21 19:19:18 2023 -0400] This is the HEAD commit summary line - *** Parent 0: - b5678aop [Thu Sep 20 19:19:18 2023 -0400] - This is parent 0 commit summary line *** Parent 1: - c9101hah [Thu Sep 19 19:19:18 2023 -0400] + 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_two_parents_version.txt b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_two_parents_version.txt index f192681d6..97bef2f75 100644 --- 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 @@ -12,10 +12,10 @@ 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 0 commit summary line +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 1 commit summary line +MOCK_PROGRAM_OUTPUT: This is parent 2 commit summary line diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 32d6ac9d3..9c026d4af 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -211,14 +211,11 @@ function(tribits_generate_single_repo_version_string gitRepoDir if (headNumParents GREATER 1) - # Is there a better way??? Range is inclusive and does not accept expressions?!? - math(EXPR loopMax "${headNumParents}-1") + set(parentIdx 1) # Parent commit indexes are 1-based by git - foreach(index RANGE ${loopMax}) + foreach(parentSha1 IN LISTS headParentList) # C.1) Get parent commit info string - - list(GET headParentList ${index} parentSha1) tribits_generate_commit_info_string( ${gitRepoDir} ${parentSha1} commitInfoString) @@ -226,12 +223,14 @@ function(tribits_generate_single_repo_version_string gitRepoDir # C.2) Format parent string to be pretty in config output string(APPEND outStringBuilder - "\n *** Parent ${index}:") + "\n *** Parent ${parentIdx}:") string(REPLACE "\n" "\n " commitInfoString "${commitInfoString}") string(CONCAT outStringBuilder "${outStringBuilder}" "\n ${commitInfoString}" ) + math(EXPR parentIdx "${parentIdx}+1") + endforeach() endif() From 1e5e09ef17299a3e7fdf3d9affdf97b4133e9a62 Mon Sep 17 00:00:00 2001 From: Anderson Date: Tue, 23 Jan 2024 17:28:45 -0700 Subject: [PATCH 18/30] Implemented -DPROJECT_NAME_SHOW_GIT_COMMIT_PARENTS option (#597) Implemented usage of previously added global cmake variable, `PROJECT_NAME_SHOW_GIT_COMMIT_PARENTS` in `tribits_generate_single_repo_version_string`. This is done with an optional argument named INCLUDE_COMMIT_PARENTS whenever calling `tribits_generate_single_repo_version_string` --- .../TribitsHelloWorld_Tests.cmake | 1 + .../TribitsGitRepoVersionInfo.cmake | 21 ++++++++++++------- .../package_arch/TribitsGlobalMacros.cmake | 11 +++++++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake index c9fe109e5..0d674452b 100644 --- a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake @@ -123,6 +123,7 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_two_ -DTribitsHelloWorld_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR} -DTribitsHelloWorld_ENABLE_TESTS=ON -DTribitsHelloWorld_GENERATE_REPO_VERSION_FILE=ON + -DTribitsHelloWorld_SHOW_GIT_COMMIT_PARENTS=ON -DGIT_EXECUTABLE=${${PROJECT_NAME}_TRIBITS_DIR}/python_utils/mockprogram.py ../TribitsHelloWorld PASS_REGULAR_EXPRESSION_ALL diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 9c026d4af..3e3badd43 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -170,16 +170,23 @@ endfunction() # Usage: # # tribits_generate_single_repo_version_string( -# ) +# INCLUDE_PARENT_COMMITS [ON|OFF]) # -# If the latest commit contains more than one parent, this function -# will also include formatted output of the commit info of those -# parents. +# 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 "INCLUDE_COMMIT_PARENTS" # prefix, optional + "" "" # 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 HEAD commit's info @@ -209,13 +216,14 @@ function(tribits_generate_single_repo_version_string gitRepoDir # C) Get each parent's commit info and format the output - if (headNumParents GREATER 1) + 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) @@ -226,8 +234,7 @@ function(tribits_generate_single_repo_version_string gitRepoDir "\n *** Parent ${parentIdx}:") string(REPLACE "\n" "\n " commitInfoString "${commitInfoString}") - string(CONCAT outStringBuilder - "${outStringBuilder}" "\n ${commitInfoString}" ) + string(APPEND outStringBuilder "\n ${commitInfoString}" ) math(EXPR parentIdx "${parentIdx}+1") diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index e5c4d28a2..739d1a53d 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -1219,9 +1219,14 @@ function(tribits_generate_repo_version_file_string PROJECT_REPO_VERSION_FILE_ST set(REPO_VERSION_FILE_STR "") - tribits_generate_single_repo_version_string( - ${CMAKE_CURRENT_SOURCE_DIR} - SINGLE_REPO_VERSION) + if (${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS}) + tribits_generate_single_repo_version_string( + ${CMAKE_CURRENT_SOURCE_DIR} + SINGLE_REPO_VERSION INCLUDE_COMMIT_PARENTS) + else() + tribits_generate_single_repo_version_string( + ${CMAKE_CURRENT_SOURCE_DIR} SINGLE_REPO_VERSION) + endif() string(APPEND REPO_VERSION_FILE_STR "*** Base Git Repo: ${PROJECT_NAME}\n" "${SINGLE_REPO_VERSION}\n" ) From de652b75e601f058ff468f8a944ad35cbfd41904 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 23 Jan 2024 17:29:44 -0700 Subject: [PATCH 19/30] Reorder functions according to clean code ordering (#597) With Clean Code ordering (i.e. the Newspaper Metaphor), in general, the functions should be ordered from top-level to low-level in the calling order. That is, the functions that are called in a given function should be listed below that function. --- .../TribitsGitRepoVersionInfo.cmake | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 3e3badd43..588ee720b 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -106,63 +106,6 @@ function(tribits_git_repo_sha1 gitRepoDir gitRepoSha1Out) 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" - " with output '${gitCmndOutput}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") - set(gitVersionLine "Error, could not get version info!") - else() - set(gitVersionLine "${gitCmndOutput}") - endif() - - # B) Get the first 80 chars of the summary message for more info - - execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%s" ${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" - " 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(${commitInfoStringOut} - "${gitVersionLine}\n${gitSummaryStr}" PARENT_SCOPE) - -endfunction() - - # @FUNCTION: tribits_generate_single_repo_version_string # # Get the formatted string containing the current git repo version. @@ -247,6 +190,63 @@ function(tribits_generate_single_repo_version_string gitRepoDir 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" + " with output '${gitCmndOutput}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") + set(gitVersionLine "Error, could not get version info!") + else() + set(gitVersionLine "${gitCmndOutput}") + endif() + + # B) Get the first 80 chars of the summary message for more info + + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%s" ${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" + " 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(${commitInfoStringOut} + "${gitVersionLine}\n${gitSummaryStr}" PARENT_SCOPE) + +endfunction() + + function(tribits_assert_git_executable) if (NOT GIT_EXECUTABLE) message(SEND_ERROR "ERROR, the program '${GIT_NAME}' could not be found!" From ba7e8dabbcc68bf1c3dde981cd062c5da16ec097 Mon Sep 17 00:00:00 2001 From: Anderson Date: Wed, 17 Jan 2024 12:33:03 -0700 Subject: [PATCH 20/30] Cleaned up empty lines (#597) Cleaned up empty lines in `TribitsHelloWorld_Tests.cmake` --- test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake index 0d674452b..1da097ed0 100644 --- a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake @@ -93,7 +93,6 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_one_ # 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 @@ -145,8 +144,6 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_two_ ) - - tribits_add_advanced_test( TribitsHelloWorld_EXE_DISABLE OVERALL_WORKING_DIRECTORY TEST_NAME OVERALL_NUM_MPI_PROCS 1 From 628b27e11ba1264cfc7b7e37b3850c55e6926fc9 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 23 Jan 2024 17:34:28 -0700 Subject: [PATCH 21/30] Add missing () on function block doc (#597) --- tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 588ee720b..8681324c9 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -106,7 +106,7 @@ function(tribits_git_repo_sha1 gitRepoDir gitRepoSha1Out) endfunction() -# @FUNCTION: tribits_generate_single_repo_version_string +# @FUNCTION: tribits_generate_single_repo_version_string() # # Get the formatted string containing the current git repo version. # From ce4728b0ac85189f0176b8bf0d234984f436314a Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 23 Jan 2024 17:51:35 -0700 Subject: [PATCH 22/30] Switch to one_value_keywords for INCLUDE_COMMIT_PARENTS (#597) This allows the calling code to be more compact. Since this function is not really called by any external users (perhaps ever), this seems like a good trade-off. --- .../package_arch/TribitsGitRepoVersionInfo.cmake | 8 ++++---- .../core/package_arch/TribitsGlobalMacros.cmake | 15 +++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 8681324c9..f7b20ff5b 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -113,9 +113,9 @@ endfunction() # Usage: # # tribits_generate_single_repo_version_string( -# INCLUDE_PARENT_COMMITS [ON|OFF]) +# [INCLUDE_PARENT_COMMITS ON|OFF]) # -# If the optional argument ``INCLUDE_PARENT_COMMITS`` is passed, +# 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. # @@ -124,8 +124,8 @@ function(tribits_generate_single_repo_version_string gitRepoDir ) cmake_parse_arguments( PARSE_ARGV 2 - PARSE "INCLUDE_COMMIT_PARENTS" # prefix, optional - "" "" # one_value_keywords, multi_value_keyword + 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) diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index 739d1a53d..aeecaaf72 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -1219,14 +1219,9 @@ function(tribits_generate_repo_version_file_string PROJECT_REPO_VERSION_FILE_ST set(REPO_VERSION_FILE_STR "") - if (${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS}) - tribits_generate_single_repo_version_string( - ${CMAKE_CURRENT_SOURCE_DIR} - SINGLE_REPO_VERSION INCLUDE_COMMIT_PARENTS) - else() - tribits_generate_single_repo_version_string( - ${CMAKE_CURRENT_SOURCE_DIR} SINGLE_REPO_VERSION) - endif() + tribits_generate_single_repo_version_string( + ${CMAKE_CURRENT_SOURCE_DIR} SINGLE_REPO_VERSION + INCLUDE_COMMIT_PARENTS ${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS}) string(APPEND REPO_VERSION_FILE_STR "*** Base Git Repo: ${PROJECT_NAME}\n" "${SINGLE_REPO_VERSION}\n" ) @@ -1249,8 +1244,8 @@ function(tribits_generate_repo_version_file_string PROJECT_REPO_VERSION_FILE_ST #print_var(EXTRAREPO_DIR) tribits_generate_single_repo_version_string( - "${CMAKE_CURRENT_SOURCE_DIR}/${EXTRAREPO_DIR}" - SINGLE_REPO_VERSION) + "${CMAKE_CURRENT_SOURCE_DIR}/${EXTRAREPO_DIR}" SINGLE_REPO_VERSION + INCLUDE_COMMIT_PARENTS ${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS}) string(APPEND REPO_VERSION_FILE_STR "*** Git Repo: ${EXTRAREPO_DIR}\n" "${SINGLE_REPO_VERSION}\n" ) From 1548b6f34c9125e503bcbf34bd28685967fe2341 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 23 Jan 2024 18:06:11 -0700 Subject: [PATCH 23/30] Speed up Git version info test by setting _TRACE_DEPENDENCY_HANDLING_ONLY=ON (#597) This spead up these tests on my machine 'crf450' from about 3.4 sec to about 0.45 sec. We don't need to enable the compilers and process the package CMakeLists.txt files to test this version info. --- test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake index 1da097ed0..cc20316c8 100644 --- a/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake @@ -66,6 +66,7 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_one_ -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 @@ -122,6 +123,7 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_two_ -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 From 3aa1ea841f1f75f23eed8417c899e04620fd78e6 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 23 Jan 2024 18:26:42 -0700 Subject: [PATCH 24/30] Document _TRACE_DEPENDENCY_HANDLING_ONLY (#597) This is a variable that project developers and users should know about. --- .../doc/build_ref/TribitsBuildReferenceBody.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tribits/doc/build_ref/TribitsBuildReferenceBody.rst b/tribits/doc/build_ref/TribitsBuildReferenceBody.rst index 92817594c..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 ------------------------------------- From b9e7d10618bd0fdc6dc6afdf485221be00eff318 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 23 Jan 2024 18:36:45 -0700 Subject: [PATCH 25/30] Refactor tribits_generate_repo_version_file_string() naming and cleanup (#597) Using camelCase for local vars helps to differentiate from UPPER_CACHE vars for function argument keywords and global vars. I figured I would clean this function up while I was working on it. Now this fits in one screen-shot for me. --- .../package_arch/TribitsGlobalMacros.cmake | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index aeecaaf72..60eb5ba10 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -1215,48 +1215,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 + ${CMAKE_CURRENT_SOURCE_DIR} singleRepoVersionStr INCLUDE_COMMIT_PARENTS ${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS}) - string(APPEND REPO_VERSION_FILE_STR + 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 + "${CMAKE_CURRENT_SOURCE_DIR}/${extraRepoDir}" singleRepoVersionStr INCLUDE_COMMIT_PARENTS ${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS}) - string(APPEND REPO_VERSION_FILE_STR - "*** Git Repo: ${EXTRAREPO_DIR}\n" - "${SINGLE_REPO_VERSION}\n" ) - - #print_var(REPO_VERSION_FILE_STR) + 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() @@ -1268,17 +1261,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() From e30b76e49b5ce275fe2ecb9b62387b25695d91a5 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 23 Jan 2024 18:44:13 -0700 Subject: [PATCH 26/30] Move TribitsGitRepoVersionInfo.cmake from core/package_arch/ to core/utils/ (#597) I noticed that this module does not depend on the TriBITS framework in any way so it should live under the core/utils/ directory to make that clear and to allow easy reuse in non-TriBITS projects that would like to use it. --- tribits/core/package_arch/TribitsGlobalMacros.cmake | 3 ++- .../{package_arch => utils}/TribitsGitRepoVersionInfo.cmake | 0 tribits/ctest_driver/TribitsAddDashboardTarget.cmake | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) rename tribits/core/{package_arch => utils}/TribitsGitRepoVersionInfo.cmake (100%) diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index 60eb5ba10..1830ef076 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) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/utils/TribitsGitRepoVersionInfo.cmake similarity index 100% rename from tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake rename to tribits/core/utils/TribitsGitRepoVersionInfo.cmake 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 From 3bed1f945b5b419d5a5587e2ac28a6d836a8595c Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 23 Jan 2024 18:53:12 -0700 Subject: [PATCH 27/30] Use tribits_advanced_set_cache_var_and_default() for _SHOW_GIT_COMMIT_PARENTS (#597) We eventually need to use this for all of those vars to make that code more compact. --- tribits/core/package_arch/TribitsGlobalMacros.cmake | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index 1830ef076..83c60cd5b 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -686,13 +686,8 @@ macro(tribits_define_global_options_and_define_extra_repos) CACHE BOOL "Generate the ${PROJECT_NAME}RepoVersion.txt file.") - if ("${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS_DEFAULT}" STREQUAL "") - set(${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS_DEFAULT OFF) - endif() - advanced_set(${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS - ${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS_DEFAULT} - CACHE BOOL - "Show parents' commit info in the repo version output.") + 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) From ba27309789ce35ad74654a1302aed4b7b9fef1aa Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Wed, 24 Jan 2024 10:03:46 -0700 Subject: [PATCH 28/30] Document setting _SHOW_GIT_COMMIT_PARENTS_DEFAULT in users/maintainers guide (#597) --- .../doc/guides/TribitsCoreDetailedReference.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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** From 731841e7a8d3d64b8091e8ac6acca80a9e1fcdda Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Wed, 24 Jan 2024 16:24:51 -0700 Subject: [PATCH 29/30] Fix some typos in tribits_ctest_driver() (#597) I noticed this while looking at the documentation while working on #597. --- tribits/ctest_driver/TribitsCTestDriverCore.cmake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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``, From 548a0b96f14393465179d50e1295dbd1a6b388bf Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Wed, 24 Jan 2024 16:28:36 -0700 Subject: [PATCH 30/30] Set -DTribitsExMetaProj_SHOW_GIT_COMMIT_PARENTS=ON for multi-repo test (#597) This sets the option: -DTribitsExMetaProj_SHOW_GIT_COMMIT_PARENTS=ON in the inner CMake configuration with a multi-repo setup so we can test the extraction and printing of the parent commit info. This tests a call of the function tribits_generate_single_repo_version_string() for extra repos from the function tribits_generate_repo_version_file_string(). This test also validates that the correct Git commands are called since this uses real Git on a Git repos. The downside of this updated test is that it makes it a little more difficult to maintain these tests when we have to update these snapshotted Git repos. --- .../TribitsExampleMetaProject/CMakeLists.txt | 5 ++-- ...ojRepoVersion.for-testing.with-parents.txt | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/ctest_driver/TribitsExampleMetaProject/data/TribitsExMetaProjRepoVersion.for-testing.with-parents.txt 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