Re: [PATCH 5/8] cmake: support for testing git when building out of the source tree
- From
Sibi Siddharthan <sibisiddharthan.github@gmail.com>
- Date
- Apr 24, 2020, 21:32 UTC
- Message-ID
- <CAKiG+9V=bJNqrHRy8y8cbjkgzrmhOMMz47+8fgfQARAetx4MFQ@mail.gmail.com>
- In-Reply-To
- <20200424173433.GL1949@danh.dev>
On Fri, Apr 24, 2020 at 11:04 PM Danh Doan <congdanhqx@gmail.com> wrote:
Show 41 quoted lines
>
> On 2020-04-24 04:01:34+0000, Sibi Siddharthan via GitGitGadget <gitgitgadget@gmail.com> wrote:
> > From: Sibi Siddharthan <sibisiddharthan.github@gmail.com>
> >
> > This patch allows git to be tested when performin out of source builds.
> >
> > This involves changing GIT_BUILD_DIR in t/test-lib.sh to point to the
> > build directory. Also some miscellaneous copies from the source directory
> > to the build directory.
> > The copies are:
> > t/chainlint.sed needed by a bunch of test scripts
> > po/is.po needed by t0204-gettext-rencode-sanity
> > mergetools/tkdiff needed by t7800-difftool
> > contrib/completion/git-prompt.sh needed by t9903-bash-prompt
> > contrib/completion/git-completion.bash needed by t9902-completion
> > contrib/svn-fe/svnrdump_sim.py needed by t9020-remote-svn
> >
> > NOTE: t/test-lib.sh is only modified when tests are run not during
> > the build or configure.
> > The trash directory is still srcdir/t
> >
> > Signed-off-by: Sibi Siddharthan <sibisiddharthan.github@gmail.com>
> > ---
> > CMakeLists.txt | 19 +++++++++++++++++++
> > 1 file changed, 19 insertions(+)
> >
> > diff --git a/CMakeLists.txt b/CMakeLists.txt
> > index 141ccefa559..29a23eb11f7 100644
> > --- a/CMakeLists.txt
> > +++ b/CMakeLists.txt
> > @@ -812,6 +812,25 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n"
> > file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
> > file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
> >
> > +#Make the tests work when building out of the source tree
> > +if(NOT ${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
>
> IIRC, CMake recommends _NOT_ expand variable inside if()
> This very inconsistent recommendation of CMake (when should I use
> ${var} and when should I use var?) is one of reason I hate CMake
>I know, I got taken aback at first, but then you get used to it.
Show 5 quoted lines
> > + file(RELATIVE_PATH BUILD_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/CMakeCache.txt)
> > + string(REPLACE "/CMakeCache.txt" "" BUILD_DIR_RELATIVE ${BUILD_DIR_RELATIVE})
>
> I don't know what is going on here!
>We are trying find the relative path to the build directory from the source directory file(RELATIVE_PATH ...) requires a file in the to "whatever" directory. The one file that is always present in the build directory after a CMake configure is CMakeCache.txt, so we use that. Then we remove "CMakeCache.txt" from the variable "BUILD_DIR_RELATIVE" to get the actual relative path.
Show 26 quoted lines
> > + #Setting the build directory in test-lib.sh before running tests
> > + file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake
> > + "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \"GIT_BUILD_DIR=(.*)\")\n"
> > + "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\n"
> > + "string(REPLACE \"\${GIT_BUILD_DIR_REPL}\" \"GIT_BUILD_DIR=\\\"$TEST_DIRECTORY\\\"/../${BUILD_DIR_RELATIVE}\" content \"\${content}\")\n"
> > + "file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \${content})")
> > + #misc copies
> > + file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.sed DESTINATION ${CMAKE_BINARY_DIR}/t/)
>
> So, some sed will be used in Windows without POSIX-like system,
> interesting!
>
> > + file(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)
> > + file(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)
> > + file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
> > + file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
> > + file(COPY ${CMAKE_SOURCE_DIR}/contrib/svn-fe/svnrdump_sim.py DESTINATION ${CMAKE_BINARY_DIR}/contrib/svn-fe/)
> > +endif()
> > +
> > file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
>
> Remember cmake won't be re-run if nothing was changed in CMakeList.txt
> If I only change some code, and I decided the change I make should be
> tested by a-new-and-independent-test-script.
> I need to re-run cmake manually! I don't like it, at all.
>No you don't have re-run CMake.
> > -- > Danh
Thank You, Sibi Siddharthan