Skip to content

Commit

Permalink
Implemented -DPROJECT_NAME_SHOW_GIT_COMMIT_PARENTS option (TriBITSPub…
Browse files Browse the repository at this point in the history
…#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`
  • Loading branch information
achauphan authored and bartlettroscoe committed Jan 24, 2024
1 parent f6b6442 commit 1e5e09e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,23 @@ endfunction()
# Usage:
#
# tribits_generate_single_repo_version_string(<gitRepoDir>
# <repoVersionStringOut>)
# <repoVersionStringOut> 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
Expand Down Expand Up @@ -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)
Expand All @@ -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")

Expand Down
11 changes: 8 additions & 3 deletions tribits/core/package_arch/TribitsGlobalMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down

0 comments on commit 1e5e09e

Please sign in to comment.