From 1e5e09ef17299a3e7fdf3d9affdf97b4133e9a62 Mon Sep 17 00:00:00 2001 From: Anderson Date: Tue, 23 Jan 2024 17:28:45 -0700 Subject: [PATCH] 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" )