Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git version info for parent commits (#597) #598

Merged
merged 32 commits into from
Jan 25, 2024

Conversation

bartlettroscoe
Copy link
Member

@bartlettroscoe bartlettroscoe commented Jan 5, 2024

WIP: This PR adds tests and functionality for adding git parent info for:

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
For some reason, mockprogram.py prints an newline that raw git does not.  But
this should work for raw git too.
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).
…euse (#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.
…#597)

Removed trailing whitespace to keep git command outputs consistent with other
functions performing git commands and for the output to be more processable.
@achauphan
Copy link
Collaborator

Forced push for a rebase on dce52b6 which had a typo in the commit message and triggered the codespell.

Make tribits_generate_commit_info_string output commit info based on a passed in
commit sha1.
…est (#597)

Updated mockprogram inputs and outputs to be more specific about which
commit message is being outputted.
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.
Forgot to double quote variable and caused configure failures during Github Actions testing.
@achauphan
Copy link
Collaborator

achauphan commented Jan 13, 2024

We're getting close! From the CDash results, looks like these outputs were not expected for the tests that check for multi-repo version outputs. Going to request a review anyways as I look into this next week.

Tagging because I cannot add @bartlettroscoe as he's owner and @sebrowne as he's not a collaborator

@sebrowne
Copy link
Contributor

Looks fine to me

@bartlettroscoe
Copy link
Member Author

@achauphan, I will add a more detailed review later but I think the issue with the failure of the tests:

Site Build Name Test Name Status Time Details Labels Build Time
ubuntu-latest pr-598_tribits_cmake-3.24.3_makefiles_python-3.8_g++-11_noninja TriBITS_CTestDriver_TribitsExMetaProj_clone_custom_branch_remote Failed 12s 750ms Completed (Failed)   2024-01-12T21:01:39 EST
ubuntu-latest pr-598_tribits_cmake-3.23.1_makefiles_python-3.8_g++-9 TriBITS_CTestDriver_TribitsExMetaProj_clone_custom_branch_remote Failed 11s 740ms Completed (Failed)   2024-01-12T21:01:41 EST
ubuntu-latest pr-598_tribits_cmake-3.25.2_makefiles_python-3.8_g++-11 TriBITS_CTestDriver_TribitsExMetaProj_clone_custom_branch_remote Failed 14s 440ms Completed (Failed)   2024-01-12T21:01:50 EST
ubuntu-latest pr-598_tribits_cmake-3.24.3_makefiles_python-3.8_g++-11_noninja TriBITS_CTestDriver_TribitsExMetaProj_clone_default_branch_remote Failed 15s 80ms Completed (Failed)   2024-01-12T21:01:39 EST
ubuntu-latest pr-598_tribits_cmake-3.23.1_makefiles_python-3.8_g++-9 TriBITS_CTestDriver_TribitsExMetaProj_clone_default_branch_remote Failed 13s 600ms Completed (Failed)   2024-01-12T21:01:41 EST
ubuntu-latest pr-598_tribits_cmake-3.25.2_makefiles_python-3.8_g++-11 TriBITS_CTestDriver_TribitsExMetaProj_clone_default_branch_remote Failed 17s 740ms Completed (Failed)   2024-01-12T21:01:50 EST

shown here. Not clear what the cause is for this but I think that, by default, we should not be printing parent info.

Copy link
Member Author

@bartlettroscoe bartlettroscoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achauphan, this is looking pretty good. It looks like like have have read quite a bit of CMake documentation for all of this new functionality :-)

I have just a few suggestions to improve this:

  1. Add global cmake cache var named something like ${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS and set it to OFF by default. (You would define this next to where the option ${PROJECT_NAME}_GENERATE_REPO_VERSION_FILE is defined.) This will also need to be documented in the file TribitsBuildReferenceBody.rst and optionally also in the file TribitsCoreDetailedReference.rst if projects will be providing a default value ${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS_DEFAULT.

  2. Add the option INCLUDE_PARENT_COMMITS to tribits_generate_single_repo_version_string() and update the code that calls this to pass in that option based on the value of ${PROJECT_NAME}_SHOW_GIT_COMMIT_PARENTS. (The logic to pass in INCLUDE_PARENT_COMMITS or now would be put into the function tribits_generate_repo_version_file_string().) (It would nice if the file TribitsGitRepoVersionInfo.cmake could avoid project-level settings so this could could be reused in non-TriBITS projects in the future. Currently that file does not contain PROJECT_NAME anywhere and there is no concept of a TriBITS Project. In fact, that makes this file TribitsGlobalMacros.cmake a candidate to be moved to tribits/core/utils/, see TriBITS Core Directory Contents.)

  3. Change the git log calls to be in the standard order git log [<options>] [<revision-range>] [[--] <path>...] (see below)

  4. In tribits_generate_single_repo_version_string(), change for a foreach() loop over indexes to a foreach() loop over list elements and change to 1-based parent indexing like Git does (and rename the var index to parentIdx). See below.

  5. Eliminate calling tribits_git_repo_sha1() and just pass in HEAD (see below).

  6. Move the definition of tribits_generate_commit_info_string() below the definition of tribits_generate_single_repo_version_string(). (I have been trying to convert TriBITS code to Clean Code ordering of functions where higher level functions are listed above the functions it calls. This is called called the "Newspaper Metaphor", see "Clean Code" book by Robert Martin.)

  7. See other suggestions below to improve the readability and maintainability of the code (IMHO).

Added global cmake cache variable `<PROJECT_NAME>_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.
Reordered git log arguments to the expected order as well as condensed
cmake command arguments into a single line.
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.
…tput (#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 ;.
Simplified foreach loop in tribits_generate_single_repo_version_string and changed
the parent indexing to be 1-based instead of 0-based.
@achauphan
Copy link
Collaborator

@bartlettroscoe @sebrowne whenever ya'll have time, can ya'll give this another review?

Copy link
Contributor

@sebrowne sebrowne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks fine to me. I made a couple of style-ish recommendations.

So the concept is that TriBITS will provide all of the parents, and then we can process them as we see fit in the CDash analysis?

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm nitpicking, but leave this whitespace alone for git blame purposes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebrowne, I actually requested this to compress the vertical density of the code.

SINGLE_REPO_VERSION INCLUDE_COMMIT_PARENTS)
else()
tribits_generate_single_repo_version_string(
${CMAKE_CURRENT_SOURCE_DIR} SINGLE_REPO_VERSION)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest splitting here for readability/comparability with the if() case.

@achauphan
Copy link
Collaborator

@achauphan, since it took me so long to get to this review, I can make the final changes and get this merged (and set up the snapshot to Trilinos PR). Or if you want to make the final change, I can review that and get it merged. Just let me know.

P.S. I could to document the TriBITS snaphsottting to Trilinos on the Trilinos wiki if you would like to give that a try.

@bartlettroscoe thanks for another round of reviews, this one was kinda fun! Yes, if you could, please go a head and make the final changes and get this snapshotted into Trilinos :)

I would love to go through learning the process of snapshotting this myself, but would like to try to use my time left for this sprint to try and finish up the python tool.

achauphan and others added 4 commits January 23, 2024 17:28
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`
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.
Cleaned up empty lines in `TribitsHelloWorld_Tests.cmake`
@bartlettroscoe
Copy link
Member Author

Yes, if you could, please go a head and make the final changes and get this snapshotted into Trilinos :)

Doing that now ...

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.
…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.
This is a variable that project developers and users should know about.
…up (#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.
…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.
…IT_COMMIT_PARENTS (#597)

We eventually need to use this for all of those vars to make that code more
compact.
@bartlettroscoe
Copy link
Member Author

bartlettroscoe commented Jan 24, 2024

@achauphan, I created the stacked PR:

against this PR for which should contain the final changes needed to merge this PR #598. (A stacked PR makes it easier to review a chuck of commits at one time. But I would still suggest reviewing the commits one-at-a-time.) If you have time to review that stacked PR, please let me know. Otherwise, I will merge that PR to this PR and move forward with the final merge and snapshotting to Trilinos.

I noticed this while looking at the documentation while working on #597.
#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.
…fo-rab

Should be final commits for Git version parent info PR #598 (#597)
Copy link
Collaborator

@rabartlett1972 rabartlett1972 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achauphan reviewed and approved the final set of commits from the stacked PR #601 so when the GHA builds run and pass, this can merge.

@bartlettroscoe bartlettroscoe merged commit 9328b34 into master Jan 25, 2024
6 checks passed
bartlettroscoe added a commit to bartlettroscoe/Trilinos that referenced this pull request Jan 25, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants