Skip to content

Commit

Permalink
Merge pull request #598 from TriBITSPub/597-config-git-version-info
Browse files Browse the repository at this point in the history
Add git version info for parent commits (#597)
  • Loading branch information
bartlettroscoe authored Jan 25, 2024
2 parents cc331f5 + 2f17d8e commit 9328b34
Show file tree
Hide file tree
Showing 13 changed files with 366 additions and 51 deletions.
110 changes: 110 additions & 0 deletions test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,6 +37,115 @@ tribits_add_advanced_test( TribitsHelloWorld
)


tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_one_parent
OVERALL_WORKING_DIRECTORY TEST_NAME
OVERALL_NUM_MPI_PROCS 1
XHOST Windows # We use the 'diff' command below :-(

TEST_0
MESSAGE "Copy the project source so we can copy files into it."
CMND ${CMAKE_COMMAND}
ARGS -E copy_directory
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsHelloWorld
TribitsHelloWorld

TEST_1
MESSAGE "Create a dummy .git directory so it will run git commands"
CMND ${CMAKE_COMMAND} ARGS -E make_directory TribitsHelloWorld/.git

TEST_2
CMND ${CMAKE_COMMAND} ARGS -E copy
${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt
TribitsHelloWorld/.mockprogram_inout.txt

TEST_3
WORKING_DIRECTORY BUILD
CMND ${CMAKE_COMMAND}
ARGS
${TribitsHelloWorld_COMMON_CONFIG_ARGS}
-DTribitsHelloWorld_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsHelloWorld_ENABLE_TESTS=ON
-DTribitsHelloWorld_GENERATE_REPO_VERSION_FILE=ON
-DTribitsHelloWorld_TRACE_DEPENDENCY_HANDLING_ONLY=ON
-DGIT_EXECUTABLE=${${PROJECT_NAME}_TRIBITS_DIR}/python_utils/mockprogram.py
../TribitsHelloWorld
PASS_REGULAR_EXPRESSION_ALL
"a1234tgb .Thu Sep 21 19:19:18 2023 -0400. <[email protected]>"
"This is the HEAD commit summary line"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_4
CMND diff ARGS
${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_one_parent_version.txt
BUILD/TribitsHelloWorldRepoVersion.txt

)
# NOTES:
#
# * The above directory structure is:
#
# TribitsHelloWorld_config_git_version_single_repo_one_parent/
# TribitsHelloWorld/
# .git/
# .mockprogram_inout.txt
# BUILD/
#
# * We don't use cmake -E compare_files because it does not print the diff,
# just gives a non-zero error code.


tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_two_parents
OVERALL_WORKING_DIRECTORY TEST_NAME
OVERALL_NUM_MPI_PROCS 1
XHOST Windows # We use the 'diff' command below :-(

TEST_0
MESSAGE "Copy the project source so we can copy files into it."
CMND ${CMAKE_COMMAND}
ARGS -E copy_directory
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsHelloWorld
TribitsHelloWorld

TEST_1
MESSAGE "Create a dummy .git directory so it will run git commands"
CMND ${CMAKE_COMMAND} ARGS -E make_directory TribitsHelloWorld/.git

TEST_2
CMND ${CMAKE_COMMAND} ARGS -E copy
${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/mockprogram_inout.single_repo_two_parents_version.txt
TribitsHelloWorld/.mockprogram_inout.txt

TEST_3
WORKING_DIRECTORY BUILD
CMND ${CMAKE_COMMAND}
ARGS
${TribitsHelloWorld_COMMON_CONFIG_ARGS}
-DTribitsHelloWorld_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsHelloWorld_ENABLE_TESTS=ON
-DTribitsHelloWorld_GENERATE_REPO_VERSION_FILE=ON
-DTribitsHelloWorld_TRACE_DEPENDENCY_HANDLING_ONLY=ON
-DTribitsHelloWorld_SHOW_GIT_COMMIT_PARENTS=ON
-DGIT_EXECUTABLE=${${PROJECT_NAME}_TRIBITS_DIR}/python_utils/mockprogram.py
../TribitsHelloWorld
PASS_REGULAR_EXPRESSION_ALL
"a1234tgb .Thu Sep 21 19:19:18 2023 -0400. <[email protected]>"
"This is the HEAD commit summary line"
"Parent 1:"
"b5678aop .Thu Sep 20 19:19:18 2023 -0400. <[email protected]>"
"This is parent 1 commit summary line"
"Parent 2:"
"c9101hah .Thu Sep 19 19:19:18 2023 -0400. <[email protected]>"
"This is parent 2 commit summary line"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_4
CMND diff ARGS
${CMAKE_CURRENT_SOURCE_DIR}/configure_git_mockprogram_files/TribitsHelloWorldRepoVersion.single_repo_two_parents_version.txt
BUILD/TribitsHelloWorldRepoVersion.txt

)


tribits_add_advanced_test( TribitsHelloWorld_EXE_DISABLE
OVERALL_WORKING_DIRECTORY TEST_NAME
OVERALL_NUM_MPI_PROCS 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*** Base Git Repo: TribitsHelloWorld
a1234tgb [Thu Sep 21 19:19:18 2023 -0400] <[email protected]>
This is the HEAD commit summary line
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*** Base Git Repo: TribitsHelloWorld
a1234tgb [Thu Sep 21 19:19:18 2023 -0400] <[email protected]>
This is the HEAD commit summary line
*** Parent 1:
b5678aop [Thu Sep 20 19:19:18 2023 -0400] <[email protected]>
This is parent 1 commit summary line
*** Parent 2:
c9101hah [Thu Sep 19 19:19:18 2023 -0400] <[email protected]>
This is parent 2 commit summary line
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> HEAD
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] <[email protected]>
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s HEAD
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: This is the HEAD commit summary line
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%p HEAD
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: b5678aop
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> HEAD
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] <[email protected]>
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s HEAD
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: This is the HEAD commit summary line
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%p HEAD
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: b5678aop c9101hah
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> b5678aop
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: b5678aop [Thu Sep 20 19:19:18 2023 -0400] <[email protected]>
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s b5678aop
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: This is parent 1 commit summary line
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> c9101hah
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: c9101hah [Thu Sep 19 19:19:18 2023 -0400] <[email protected]>
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s c9101hah
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: This is parent 2 commit summary line
5 changes: 3 additions & 2 deletions test/ctest_driver/TribitsExampleMetaProject/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
*** Base Git Repo: TribitsExMetaProj
863461e [Tue Sep 14 15:05:31 2021 -0600] <[email protected]>
Merge branch 'tribits-github-snapshot' (TriBITSPub/TriBITS#299)
*** Parent 1:
e12aad9 [Fri Dec 11 16:17:18 2020 -0700] <[email protected]>
Merge branch 'tribits-github-snapshot' (TriBITSPub/TriBITS#309)
*** Parent 2:
ed38a1f [Tue Sep 14 15:04:06 2021 -0600] <[email protected]>
Automatic snapshot commit from TribitsExampleMetaProject at d1e4913
*** Git Repo: TribitsExampleProject
94c2b12 [Tue Sep 14 15:18:55 2021 -0600] <[email protected]>
Merge branch 'tribits-github-snapshot' (TriBITSPub/TriBITS#299)
*** Parent 1:
59c7057 [Fri Dec 11 16:23:46 2020 -0700] <[email protected]>
Merge branch 'tribits-github-snapshot'
*** Parent 2:
da4197f [Tue Sep 14 15:11:39 2021 -0600] <[email protected]>
Automatic snapshot commit from TribitsExampleProject at d95ddbd
*** Git Repo: TribitsExampleProjectAddons
d846ae1 [Tue Sep 14 15:23:39 2021 -0600] <[email protected]>
Merge branch 'tribits-github-snapshot' (TriBITSPub/TriBITS#299)
*** Parent 1:
226a17e [Tue Feb 19 06:33:23 2019 -0700] <[email protected]>
Update README file (tribitspub/tribits#278)
*** Parent 2:
08f06bb [Tue Sep 14 15:20:24 2021 -0600] <[email protected]>
Automatic snapshot commit from TribitsExampleProjectAddons at abb6694
55 changes: 26 additions & 29 deletions tribits/core/package_arch/TribitsGlobalMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -53,7 +55,6 @@ include(TribitsGetVersionDate)
include(TribitsReportInvalidTribitsUsage)
include(TribitsReadAllProjectDepsFilesCreateDepsGraph)
include(TribitsAdjustPackageEnables)
include(TribitsGitRepoVersionInfo)
include(TribitsSetUpEnabledOnlyDependencies)
include(TribitsConfigureTiming)

Expand Down Expand Up @@ -685,6 +686,9 @@ macro(tribits_define_global_options_and_define_extra_repos)
CACHE BOOL
"Generate the ${PROJECT_NAME}RepoVersion.txt file.")

tribits_advanced_set_cache_var_and_default(${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS
BOOL OFF "Show parents' commit info in the repo version output.")

if ("${${PROJECT_NAME}_GENERATE_VERSION_DATE_FILES_DEFAULT}" STREQUAL "")
set(${PROJECT_NAME}_GENERATE_VERSION_DATE_FILES_DEFAULT OFF)
endif()
Expand Down Expand Up @@ -1207,48 +1211,41 @@ endmacro()

# Get the versions of all the git repos
#
function(tribits_generate_repo_version_file_string PROJECT_REPO_VERSION_FILE_STRING_OUT)
function(tribits_generate_repo_version_file_string projectRepoVersionFileStrOut)

set(REPO_VERSION_FILE_STR "")
set(projectRepoVersionFileStr "")

tribits_generate_single_repo_version_string(
${CMAKE_CURRENT_SOURCE_DIR}
SINGLE_REPO_VERSION)
string(APPEND REPO_VERSION_FILE_STR
${CMAKE_CURRENT_SOURCE_DIR} singleRepoVersionStr
INCLUDE_COMMIT_PARENTS ${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS})
string(APPEND projectRepoVersionFileStr
"*** Base Git Repo: ${PROJECT_NAME}\n"
"${SINGLE_REPO_VERSION}\n" )
"${singleRepoVersionStr}\n" )

set(EXTRAREPO_IDX 0)
foreach(EXTRA_REPO ${${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES})

#print_var(EXTRA_REPO)
#print_var(EXTRAREPO_IDX)
#print_var(${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS)
set(extraRepoIdx 0)
foreach(extraRepo ${${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES})

if (${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS)
# Read from an extra repo file with potentially different dir.
list(GET ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS ${EXTRAREPO_IDX}
EXTRAREPO_DIR )
list(GET ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS ${extraRepoIdx}
extraRepoDir )
else()
# Not read from extra repo file so dir is same as name
set(EXTRAREPO_DIR ${EXTRA_REPO})
set(extraRepoDir ${extraRepo})
endif()
#print_var(EXTRAREPO_DIR)

tribits_generate_single_repo_version_string(
"${CMAKE_CURRENT_SOURCE_DIR}/${EXTRAREPO_DIR}"
SINGLE_REPO_VERSION)
string(APPEND REPO_VERSION_FILE_STR
"*** Git Repo: ${EXTRAREPO_DIR}\n"
"${SINGLE_REPO_VERSION}\n" )

#print_var(REPO_VERSION_FILE_STR)
"${CMAKE_CURRENT_SOURCE_DIR}/${extraRepoDir}" singleRepoVersionStr
INCLUDE_COMMIT_PARENTS ${${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS})
string(APPEND projectRepoVersionFileStr
"*** Git Repo: ${extraRepoDir}\n"
"${singleRepoVersionStr}\n" )

math(EXPR EXTRAREPO_IDX "${EXTRAREPO_IDX}+1")
math(EXPR extraRepoIdx "${extraRepoIdx}+1")

endforeach()

set(${PROJECT_REPO_VERSION_FILE_STRING_OUT} ${REPO_VERSION_FILE_STR} PARENT_SCOPE)
set(${projectRepoVersionFileStrOut} ${projectRepoVersionFileStr} PARENT_SCOPE)

endfunction()

Expand All @@ -1260,17 +1257,17 @@ endfunction()
#
function(tribits_generate_repo_version_output_and_file)
# Get the repos versions
tribits_generate_repo_version_file_string(PROJECT_REPO_VERSION_FILE_STRING)
tribits_generate_repo_version_file_string(projectRepoVersionFileStr)
# Print the versions
message("\n${PROJECT_NAME} repos versions:\n"
"--------------------------------------------------------------------------------\n"
"${PROJECT_REPO_VERSION_FILE_STRING}"
"${projectRepoVersionFileStr}"
" --------------------------------------------------------------------------------\n"
)
#) Write out the version file
file(WRITE
"${CMAKE_CURRENT_BINARY_DIR}/${${PROJECT_NAME}_REPO_VERSION_FILE_NAME}"
"${PROJECT_REPO_VERSION_FILE_STRING}")
"${projectRepoVersionFileStr}")
endfunction()


Expand Down
Loading

0 comments on commit 9328b34

Please sign in to comment.