How to upgrade GoogleTest?

ITK has quite an old version of GoogleTest. The last update appears to be two years ago, by Francois Budin @fbudin:

This old version of GoogleTest produces some static analysis warnings (like "warning C26477: Use ‘nullptr’) that are solved by now.

Could ITK’s GoogleTest be upgraded from the old master revision to the latest tagged release, https://github.com/google/googletest/releases/tag/release-1.10.0 ?

I tried so by running ./UpdateFromUpstream.sh from Windows GitBash, but now my local clone is full of conflicts :cry:

$ ./UpdateFromUpstream.sh
Created upstream snapshot branch ‘upstream-googletest’.
Performing inexact rename detection: 100% (666708/666708), done.
CONFLICT (file location): googletest/src/gtest-matchers.cc added in upstream-googletest inside a directory that was renamed in HEAD, suggesting it should perhaps be moved to Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/src/gtest-matchers.cc.
CONFLICT (rename/delete): googletest/include/gtest/internal/gtest-tuple.h.pump deleted in upstream-googletest and renamed to Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/include/gtest/internal/gtest-tuple.h.pump in HEAD. Version HEAD of Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/include/gtest/internal/gtest-tuple.h.pump left in tree.

CONFLICT (content): Merge conflict in Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/CMakeLists.txt
Auto-merging CMakeLists.txt
CONFLICT (content): Merge conflict in CMakeLists.txt
Automatic merge failed; fix conflicts and then commit the result.
error: The branch ‘upstream-googletest’ is not fully merged.
If you are sure you want to delete it, run ‘git branch -D upstream-googletest’.

cedekker@2-lkeb-17-nde1 MINGW64 /f/X/Src/I/ITK/Modules/ThirdParty/GoogleTest (master|MERGING)
$

@Niels_Dekker thanks for upgrading our Google Test! :clap: :pray:

Try running UpdateFromUpstream.sh from the top level of the repository, i.e.

cd ITK
git checkout -b googletest-update
 ./Modules/ThirdParty/GoogleTest/UpdateFromUpstream.sh

Thanks for your encouragement, Matt. Unfortunately, even when following your recipe, I still get:

cedekker@2-lkeb-17-nde1 MINGW64 /f/X/Src/I/ITK (master)
$ git checkout -b googletest-update
Switched to a new branch ‘googletest-update’
M Modules/ThirdParty/GoogleTest/UpdateFromUpstream.sh

cedekker@2-lkeb-17-nde1 MINGW64 /f/X/Src/I/ITK (googletest-update)
$ ./Modules/ThirdParty/GoogleTest/UpdateFromUpstream.sh
Created upstream snapshot branch ‘upstream-googletest’.
Performing inexact rename detection: 100% (666708/666708), done.
CONFLICT (file location): googletest/src/gtest-matchers.cc added in upstream-googletest inside a directory that was renamed in HEAD, suggesting it should perhaps be moved to Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/src/gtest-matchers.cc.

CONFLICT (content): Merge conflict in CMakeLists.txt
Automatic merge failed; fix conflicts and then commit the result.
error: The branch ‘upstream-googletest’ is not fully merged.
If you are sure you want to delete it, run ‘git branch -D upstream-googletest’.

cedekker@2-lkeb-17-nde1 MINGW64 /f/X/Src/I/ITK (googletest-update|MERGING)
$

Do you have a clue?

I think @blowekamp was involved with initial addition of Google Test to ITK. He might have more information.

This indicates that this file was modified locally – it may help to start from a fresh Git repository clone.

When I run the script locally, the result is:

❯ ./Modules/ThirdParty/GoogleTest/UpdateFromUpstream.sh
Created upstream snapshot branch 'upstream-googletest'.
Removing
Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/include/gtest/internal/gtest-type-util.h.pump
Removing
Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/include/gtest/internal/gtest-tuple.h.pump
Removing
Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/include/gtest/internal/gtest-tuple.h
Removing
Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/include/gtest/internal/gtest-param-util-generated.h.pump
Removing
Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/include/gtest/internal/gtest-param-util-generated.h
Removing
Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/include/gtest/internal/gtest-linked_ptr.h
Removing
Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/include/gtest/gtest-param-test.h.pump
Auto-merging
Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/CMakeLists.txt
CONFLICT (content): Merge conflict in
Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/CMakeLists.txt
Auto-merging Modules/ThirdParty/GoogleTest/src/itkgoogletest/CMakeLists.txt
CONFLICT (content): Merge conflict in
Modules/ThirdParty/GoogleTest/src/itkgoogletest/CMakeLists.txt
Automatic merge failed; fix conflicts and then commit the result.
error: The branch 'upstream-googletest' is not fully merged.
If you are sure you want to delete it, run 'git branch -D
upstream-googletest'.

In this case, there are two files that have merge conflicts, which is reasonable.

What git version do you have? I tested with 2.22.0.

$ git --version
git version 2.22.0.windows.1

Going home now, hopefully tomorrow another try!

1 Like

Sure it is! I changed upstream_git_branch='master' to upstream_git_branch='release-1.10.0', in UpdateFromUpstream.sh, in order to get the latest tagged release of GoogleTest. Should that work well, or am I doing something wrong?

1 Like

Maybe try v1.10.x to get the branch instead of the tag.

Update: I just made a new fork (removing my old one), did a new clone, and did the two instructions you suggested in GitBash. It still produces merge conflicts. Do you have any more suggestion? It says now:

cedekker@2-lkeb-17-nde1 MINGW64 /f/X/Src/I/ITK (master)
$ git checkout -b googletest-update
Switched to a new branch ‘googletest-update’

cedekker@2-lkeb-17-nde1 MINGW64 /f/X/Src/I/ITK (googletest-update)
$ ./Modules/ThirdParty/GoogleTest/UpdateFromUpstream.sh
Created upstream snapshot branch ‘upstream-googletest’.
Performing inexact rename detection: 100% (666708/666708), done.
CONFLICT (file location): googletest/src/gtest-matchers.cc added in upstream-googletest inside a directory that was renamed in HEAD, suggesting it should perhaps be moved to Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/src/gtest-matchers.cc.

Auto-merging Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/CMakeLists.txt
CONFLICT (content): Merge conflict in Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/CMakeLists.txt
Auto-merging CMakeLists.txt
CONFLICT (content): Merge conflict in CMakeLists.txt
Automatic merge failed; fix conflicts and then commit the result.
error: The branch ‘upstream-googletest’ is not fully merged.
If you are sure you want to delete it, run ‘git branch -D upstream-googletest’.

cedekker@2-lkeb-17-nde1 MINGW64 /f/X/Src/I/ITK (googletest-update|MERGING)

Those are the conflicts I got too. And the got log indicates those are local changes.

Try doing the update on the old commit where the library was last updated then merging master into the updated branch.

1 Like

Thanks for confirming those conflicts, @blowekamp Sorry but git/shell scripting is not my best talent. Could you please try to get it to work, and make the pull request to upgrade GoogleTest? Or is anyone else volunteering? :smiley:

Done:

The local changes were to support VS 20012 and CMP00063. I reverted to “their” changes.

2 Likes

That’s really great, Bradley! :sunny: So how did you avoid (or fix) the git merge conflicts that I got, when i tried to do it?

Did you not notice this explanation?

1 Like

I guess I did not read carefully enough :smiley_cat: Hopefully future ITK GoogleTest upgrades will be easier than this one! GoogleTest v1.10.0 by blowekamp · Pull Request #1487 · InsightSoftwareConsortium/ITK · GitHub still says “This branch cannot be rebased due to conflicts”, is that a problem? Well, we’ll see…!