Skip to content

Commit

Permalink
Merge branch 'tribits_github_snapshot' into tribits-597-git-version-p…
Browse files Browse the repository at this point in the history
…arent-info (TriBITSPub/TriBITS#597)

Main purpose is to pull in the TriBITS PR for getting the git repo parent
commit info:

* TriBITSPub/TriBITS#598
  • Loading branch information
bartlettroscoe committed Jan 25, 2024
2 parents d835e43 + ede2b71 commit afe806a
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 50 deletions.
55 changes: 26 additions & 29 deletions cmake/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
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ function(tribits_git_repo_sha1 gitRepoDir gitRepoSha1Out)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%H"
WORKING_DIRECTORY ${gitRepoDir}
RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput
RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE
)

if (NOT gitCmndRtn STREQUAL 0)
Expand All @@ -105,26 +106,118 @@ function(tribits_git_repo_sha1 gitRepoDir gitRepoSha1Out)
endfunction()


# Run the git log command to get the version info for a git repo
# @FUNCTION: tribits_generate_single_repo_version_string()
#
# Get the formatted string containing the current git repo version.
#
# Usage:
#
# tribits_generate_single_repo_version_string(<gitRepoDir>
# <repoVersionStringOut> [INCLUDE_PARENT_COMMITS ON|OFF])
#
# If the optional argument ``INCLUDE_PARENT_COMMITS <val>`` is passed,
# then the head commit's parent(s) info will be be included in
# the repo version output string formatted.
#
function(tribits_generate_single_repo_version_string gitRepoDir
repoVersionStringOut
)

cmake_parse_arguments( PARSE_ARGV 2
PARSE "" # prefix, optional
"INCLUDE_COMMIT_PARENTS" "" # one_value_keywords, multi_value_keyword
)
tribits_check_for_unparsed_arguments()
tribits_assert_parse_arg_zero_or_one_value(PARSE INCLUDE_COMMIT_PARENTS)

tribits_assert_git_executable()

# A) Get the basic version info.
# A) Get HEAD commit's info

tribits_generate_commit_info_string(${gitRepoDir} HEAD commitInfoString)

set(outStringBuilder ${commitInfoString})

# B) Get all of HEAD commit's parents into a list

execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%h [%ad] <%ae>"
COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%p" HEAD
WORKING_DIRECTORY ${gitRepoDir}
RESULT_VARIABLE gitCmndRtn
OUTPUT_VARIABLE gitCmndOutput
RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE
)

if (NOT gitCmndRtn STREQUAL 0)
message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0"
" with output '${gitCmndOutput}' for sha1 ${gitHeadSha1} of repo ${gitRepoDir}!")
set(headParentList "Error, could not get commit's parents!")
else()
string(REGEX REPLACE " +" ";" headParentList "${gitCmndOutput}")
endif()

list(LENGTH headParentList headNumParents)

# C) Get each parent's commit info and format the output

if (PARSE_INCLUDE_COMMIT_PARENTS)

set(parentIdx 1) # Parent commit indexes are 1-based by git

foreach(parentSha1 IN LISTS headParentList)

# C.1) Get parent commit info string

tribits_generate_commit_info_string(
${gitRepoDir} ${parentSha1}
commitInfoString)

# C.2) Format parent string to be pretty in config output

string(APPEND outStringBuilder
"\n *** Parent ${parentIdx}:")
string(REPLACE "\n" "\n "
commitInfoString "${commitInfoString}")
string(APPEND outStringBuilder "\n ${commitInfoString}" )

math(EXPR parentIdx "${parentIdx}+1")

endforeach()

endif()

set(${repoVersionStringOut} "${outStringBuilder}" PARENT_SCOPE)

endfunction()


# @FUNCTION: tribits_generate_commit_info_string()
#
# Get the formatted commit info containing commit's SHA1,
# author, date, email, and 80 character summary.
#
# Usage:
# tribits_generate_commit_info_string(<gitRepoDir> <gitCommitSha1>
# commitInfoStringOut)
#
# NOTE: Below, it is fine if ${maxSummaryLen} > len(${gitCmndOutput}) as
# string(SUBSTRING ...) will just shorten this to the length of the string.
#
function(tribits_generate_commit_info_string gitRepoDir gitCommitSha1
commitInfoStringOut
)

# A) Get commit hash, author, date, and email

execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%h [%ad] <%ae>" ${gitCommitSha1}
WORKING_DIRECTORY ${gitRepoDir}
RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE
)

if (NOT gitCmndRtn STREQUAL 0)
message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0"
" for repo ${gitRepoDir}!")
" with output '${gitCmndOutput}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!")
set(gitVersionLine "Error, could not get version info!")
else()
set(gitVersionLine "${gitCmndOutput}")
Expand All @@ -133,27 +226,25 @@ function(tribits_generate_single_repo_version_string gitRepoDir
# B) Get the first 80 chars of the summary message for more info

execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%s
COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%s" ${gitCommitSha1}
WORKING_DIRECTORY ${gitRepoDir}
RESULT_VARIABLE gitCmndRtn
OUTPUT_VARIABLE gitCmndOutput
RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE
)

if (NOT gitCmndRtn STREQUAL 0)
message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0"
" for extra repo ${gitRepoDir}!")
" with output '${gitCmndOutput}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!")
set(gitSummaryStr "Error, could not get version summary!")
else()
set(maxSummaryLen 80)
string(SUBSTRING "${gitCmndOutput}" 0 ${maxSummaryLen} gitSummaryStr)
endif()

set(${repoVersionStringOut}
set(${commitInfoStringOut}
"${gitVersionLine}\n${gitSummaryStr}" PARENT_SCOPE)

endfunction()
# NOTE: Above, it is fine if ${maxSummaryLen} > len(${gitCmndOutput}) as
# string(SUBSTRING ...) will just shorten this to the length of the string.


function(tribits_assert_git_executable)
Expand Down
2 changes: 1 addition & 1 deletion cmake/tribits/ctest_driver/TribitsAddDashboardTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#
################################################################################

include(TribitsGitRepoVersionInfo)
include("${CMAKE_CURRENT_LIST_DIR}/../core/utils/TribitsGitRepoVersionInfo.cmake")

#
# Macro that drives a experimental 'dashboard' target
Expand Down
10 changes: 5 additions & 5 deletions cmake/tribits/ctest_driver/TribitsCTestDriverCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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``
#
Expand All @@ -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:
#
Expand Down Expand Up @@ -758,7 +758,7 @@ include(TribitsCTestDriverCoreHelpers)
# These configure options are passed into the ``ctest_configure()`` command in
# the order::
#
# <initial options> ${EXTRA_SYSTEM_CONFIGURE_OPTIONS}} \
# <initial options> ${EXTRA_SYSTEM_CONFIGURE_OPTIONS}} \
# ${EXTRA_CONFIGURE_OPTIONS} ${${PROJECT_NAME}_EXTRA_CONFIGURE_OPTIONS}
#
# **WARNING:** The options listed in ``EXTRA_SYSTEM_CONFIGURE_OPTIONS``,
Expand Down
31 changes: 31 additions & 0 deletions cmake/tribits/doc/build_ref/TribitsBuildReferenceBody.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <Project>_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
-------------------------------------

Expand Down Expand Up @@ -2934,6 +2951,20 @@ NOTE: If the base ``.git/`` directory is missing, then no
printed to cmake STDOUT.


Show parent(s) commit info in the repo version output
----------------------------------------------------

.. _<Project>_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 <Project>_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
---------------------------------

Expand Down
Loading

0 comments on commit afe806a

Please sign in to comment.