{"thread":{"id":"58666","subject":"[PATCH 1/9] cmake: don't copy chainlint.pl to build directory","startedAt":"2022-10-21T09:44:58Z","lastAt":"2022-12-08T00:25:07Z","messageCount":113,"participants":["Ævar Arnfjörð Bjarmason","Johannes Schindelin","Phillip Wood","Eric Sunshine","Taylor Blau"],"isPatch":true,"patchVersion":1,"patchTotal":9},"messages":[{"id":"465443","messageId":"patch-1.9-16c99177e6d-20221021T091013Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"[PATCH 1/9] cmake: don't copy chainlint.pl to build directory","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T09:44:14Z","receivedAt":"2022-10-21T09:44:58Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When [1] made this copy of \"chainlint.sed\" the script was invoked in\nthe test-lib.sh as:\n\n\t[...] sed -f \"$GIT_BUILD_DIR/t/chainlint.sed\" [...]\n\nBut when [2] replaced \"chainlint.sed\" with a \"chainlint.pl\" it also\nreplaced that \"$GIT_BUILD_DIR\" with \"$TEST_DIRECTORY\", invoking it as:\n\n\t\"$PERL_PATH\" \"$TEST_DIRECTORY/chainlint.pl\" \"$0\"\n\nSo this line could have been deleted in [2] but wasn't. Let's do that\nnow.\n\n1. 7f5397a07c6 (cmake: support for testing git when building out of\n   the source tree, 2020-06-26)\n2. 23a14f30166 (test-lib: replace chainlint.sed with chainlint.pl,\n   2022-09-01)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 787738e6fa3..fd0c6ef4971 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1083,7 +1083,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \t\t\"string(REPLACE \\\"\\${GIT_BUILD_DIR_REPL}\\\" \\\"GIT_BUILD_DIR=\\\\\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\\\\\"\\\" content \\\"\\${content}\\\")\\n\"\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \\${content})\")\n \t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)\n \tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n \tfile(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n \tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n-- \n2.38.0.1205.gcea0601d673\n\n"},{"id":"465444","messageId":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","threadId":"58666","inReplyTo":null,"subject":"[PATCH 0/9] cmake: fix *nix & general issues, no test-lib.sh editing, ctest in CI","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T09:44:13Z","receivedAt":"2022-10-21T09:45:01Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Tue, Oct 18 2022, Johannes Schindelin wrote:\n\n[For context:\nhttps://lore.kernel.org/git/on2q3qos-sr0n-0p8p-606p-5pq39n46qq4q@tzk.qr/\nis upthread of here, but spinning this off into another thread]\n\n>> Re my earlier feedback, I came up with this as an alternative, which\n>> nicely allows us to have \"cmake\" and \"make\" play together, you can even\n>> run them concurrently!:\n>>\n>>      https://github.com/avar/git/commit/30f2265fd07aee97ea66f6e84a824d85d241e245\n>\n> This approach _still_ modifies the `test-lib.sh`, which is the entire\n> reason for the patch under review.\n>\n> I hope you find an elegant, user-friendly alternative that leaves\n> `test-lib.sh` unmodified even when building via CMake. I would gladly take\n> that and drop my `GIT-BUILD-DIR` patch.\n\nYou did ask for it :)\n\nTo clarify, what I had upthread was a patch on the way towards a\nsolution that didn't edit t/test-lib.sh at all, but that patch itself\nwasn't sufficient. It's the equivalent of 3/9 here.\n\nThis series:\n\n * Can be grabbed at\n   https://github.com/avar/git/tree/avar/cmake-test-path\n\n * Conflicts with js/cmake-updates[1], although I've seen it go in &\n   out of {gitster,git}/seen (currently in gitster/seen, not in\n   git.git's \"seen\".\n\n   But the conflict is easily fixed to keep both, see below.\n\n * Fixes numerous bugs in the current cmake recipe, running \"ctest\"\n   was a dumpster fire on Linux, after this with 9/9 we can run our\n   whole test suite in CI on ubuntu-latest:\n   https://github.com/avar/git/actions/runs/3293378319/jobs/5431721245\n\n * Handles the case where you want to build with cmake and have \"(cd t\n   && ./t0001-init.sh)\" just work, i.e. we spot that we have a built\n   \"contrib/buildsystems/out\" and use that.\n\n * I pushed out a \"js/cmake-update-ci\" in my repo, which is a (rebased\n   on master) \"js/cmake-updates\" plus the 9/9 here:\n   https://github.com/avar/git/actions/runs/3294352976/jobs/5432095664\n\n   Some of those failures are due to orthagonal fixes here, e.g. you\n   clearly haven't been testing cmake+ctest on Linux, or you'd have\n   seen the issue 2/9 fixes, a lot of failures are due to a missing\n   \"chmod +x\".\n\n   But others are due to e.g. your [2] missing a lot of cases. 3/9 and\n   8/9 cover some of those, i.e. the Windows CI skips a lot of tests\n   (e.g. all Perl + Python stuff), no libpcre2 etc. So a lot of\n   failures were related to that.\n\n * I also merged this with yours at\n   https://github.com/avar/git/tree/avar/cmake-test-path-plus-js/cmake-updates\n\n   The --remerge-diff of the resulting merge commit is, with\n   un-indented inline commentary:\n\n\tdiff --git a/.gitignore b/.gitignore\n\tindex cb0231fb401..62720c6135d 100644\n\t--- a/.gitignore\n\t+++ b/.gitignore\n\t@@ -1,5 +1,4 @@\n\t /fuzz_corpora\n\t-/GIT-BUILD-DIR\n\t /GIT-BUILD-OPTIONS\n\t /GIT-CFLAGS\n\t /GIT-LDFLAGS\n\tdiff --git a/Makefile b/Makefile\n\tindex 9e3c4588e7d..d93ad956e58 100644\n\t--- a/Makefile\n\t+++ b/Makefile\n\t@@ -3041,7 +3041,6 @@ else\n\t \t@echo RUNTIME_PREFIX=\\'false\\' >>$@+\n\t endif\n\t \t@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi\n\t-\t@if test -f GIT-BUILD-DIR; then rm GIT-BUILD-DIR; fi\n\n\n   As yuo asked for: We can get what you want without\n   GIT-BUILD-DIR. When we run via \"ctest\" we pass\n   GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR}, and when we run ad-hoc the\n   test-lib.sh checks \"contrib/buildsystems/out\" and uses it if we\n   have a built git there, but not in ../git.\n\n\t ### Detect Python interpreter path changes\n\t ifndef NO_PYTHON\n\tdiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n\tremerge CONFLICT (content): Merge conflict in contrib/buildsystems/CMakeLists.txt\n\tindex bfc4d87026b..fafe6d9cb95 100644\n\t--- a/contrib/buildsystems/CMakeLists.txt\n\t+++ b/contrib/buildsystems/CMakeLists.txt\n\t@@ -1081,24 +1081,6 @@ if(USE_VCPKG)\n\t \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n\t endif()\n\n\t-<<<<<<< b81f18dec61 (CI: add a \"linux-cmake-test\" to run cmake & ctest on linux)\n\t-=======\n\t-#Make the tests work when building out of the source tree\n\t-get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n\t-if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n\t-\t#Setting the build directory in test-lib.sh before running tests\n\t-\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n\t-\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n\t-\t#misc copies\n\t-\tfile(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)\n\t-\tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n\t-\tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n\t-\tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n\t-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n\t-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n\t-endif()\n\t-\n\t->>>>>>> 27870f309d0 (cmake: increase time-out for a long-running test)\n\t file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n\n   This whole \"copy stuff and munge test-lib.sh\" part is gone in my\n   version. Rather than copy over mergetools/* the relevant tests know\n   where to find it (it doesn't need to be built at all).\n\n\t #test\n\t@@ -1106,11 +1088,7 @@ set(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n\t separate_arguments(GIT_TEST_OPTS)\n\t foreach(tsh ${test_scipts})\n\t \tadd_test(NAME ${tsh}\n\t-<<<<<<< b81f18dec61 (CI: add a \"linux-cmake-test\" to run cmake & ctest on linux)\n\t-\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n\t-=======\n\t-\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n\t->>>>>>> 27870f309d0 (cmake: increase time-out for a long-running test)\n\t+\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx ${GIT_TEST_OPTS}\n\t \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n\t endforeach()\n\n   I did not include your \"--no-bin-wrappers --no-chain-lint -vx\"\n   change.\n\n   As 7/9 here shows I pick up GIT_TEST_OPTS from the environment, so\n   if you want to set these you can set them in the environment.\n\n   But your 1/5[3] adds these partially for speeding up things on\n   Windows, but as this series shows this also runs on\n   Linux. Therefore if we still want this I'd think we'd at least want\n   to make it specific to that platform (per [4]).\n\n\tdiff --git a/t/test-lib.sh b/t/test-lib.sh\n\tindex 333079d9127..284b619708a 100644\n\t--- a/t/test-lib.sh\n\t+++ b/t/test-lib.sh\n\t@@ -69,16 +69,6 @@ then\n\t \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n\t \texit 1\n\t fi\n\t-if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n\t-then\n\t-\tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n\t-\t# On Windows, we must convert Windows paths lest they contain a colon\n\t-\tcase \"$(uname -s)\" in\n\t-\t*MINGW*)\n\t-\t\tGIT_BUILD_DIR=\"$(cygpath -au \"$GIT_BUILD_DIR\")\"\n\t-\t\t;;\n\t-\tesac\n\t-fi\n\n   The changes I needed to the test-lib.sh are above this context.\n\n\t # Prepend a string to a VAR using an arbitrary \":\" delimiter, not\n\t # adding the delimiter if VAR or VALUE is empty. I.e. a generalized:\n\n   Elided here is the inclusion of your 5/5[5], which didn't\n   conflict. If we'd like to keep it it probably makes sense to make\n   it Windows-specific too, I don't see that being needed on Linux.\n\n   Aside from this topic I'd be curious to know if you see the same\n   slowdown with my [6], i.e. once git-submodule.sh has gone away. For\n   me it's ~25% faster than \"master\", but I'd expect on a system with\n   high fork overhead that would be a lot higher.\n\n1. https://lore.kernel.org/git/pull.1320.v3.git.1666090745.gitgitgadget@gmail.com/\n2. https://lore.kernel.org/git/9faca9d5cbe706c00d03ca2a125f2e113294a548.1666090745.git.gitgitgadget@gmail.com/\n3. https://lore.kernel.org/git/356b2e9a1007bcd1382f26f333926ff0d5b9abe2.1666090745.git.gitgitgadget@gmail.com/\n4. https://lore.kernel.org/git/221018.865yghi6nv.gmgdl@evledraar.gmail.com/\n5. https://lore.kernel.org/git/40cf872f48386f8eca0fa814e4cdfb0ded915ed8.1666090745.git.gitgitgadget@gmail.com/\n6. https://lore.kernel.org/git/cover-00.10-00000000000-20221017T115544Z-avarab@gmail.com/\n\nÆvar Arnfjörð Bjarmason (9):\n  cmake: don't copy chainlint.pl to build directory\n  cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n  cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n  cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n  test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n  cmake: use GIT_TEST_BUILD_DIR instead of editing hack\n  cmake: support using GIT_TEST_OPTS from the environment\n  cmake: copy over git-p4.py for t983[56] perforce test\n  CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n\n .github/workflows/main.yml          |  3 +++\n ci/run-build-and-tests.sh           | 13 +++++++++--\n contrib/buildsystems/CMakeLists.txt | 33 +++++++++++----------------\n t/README                            |  3 +++\n t/lib-gettext.sh                    |  2 +-\n t/lib-gitweb.sh                     |  2 +-\n t/t7609-mergetool--lib.sh           |  2 +-\n t/t9902-completion.sh               | 14 ++++++------\n t/t9903-bash-prompt.sh              |  2 +-\n t/test-lib.sh                       | 35 +++++++++++++++++++++++++++--\n 10 files changed, 74 insertions(+), 35 deletions(-)\n\n-- \n2.38.0.1205.gcea0601d673\n\n"},{"id":"465445","messageId":"patch-2.9-2c1d194e590-20221021T091013Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"[PATCH 2/9] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T09:44:15Z","receivedAt":"2022-10-21T09:45:04Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The cmake recipe added in [1] did not create the bin-wrappers/*\ndirectory, and thus fell back on running the tests with the equivalent\nof \"--no-bin-wrappers\".\n\nThus the. \"t/test-lib.sh\" would be unable to find \"bin-wrappers/git\",\nand we'd fall back on \"GIT_EXEC_PATH=$GIT_BUILD_DIR\" using the\nfallback behavior added in [2]:\n\n\t$ ./t0001-init.sh\n\t<GIT_BUILD_DIR>/t/../contrib/buildsystems/out/bin-wrappers/git is not executable; using GIT_EXEC_PATH\n\nOr rather, this is what would have happened on *nix, but until [3]\nthere wasn't any non-Windows support for \"cmake\". On Windows it didn't\nmatter that the bin-wrappers weren't made executable, since there's no\nexecutable bit, instead the emulation layer looks at whether a file\nhas a shebang.\n\nBut with [3] we've effectively used the semi-equivalent of\n\"--no-bin-wrappers\" unintentionally on *nix, and furthermore because\nwe didn't make these executable\n\nIn addition, we'd fail any test that needed to invoke one of our built\nshell, perl or Python scripts on *nix. E.g. t0012-help.sh would fail\non a test that tried to invoke \"git web--browse\". I.e. the equivalent\nof this (in the \"out\" directory) would happen:\n\n\t$ ./git --exec-path=$PWD web--browse\n\tgit: 'web--browse' is not a git command. See 'git --help'.\n\nWhich we can fix by \"chmod +x\"-ing the built \"git-web--browse\":\n\n\t$ chmod +x git-web--browse\n\t$ ./git --exec-path=$PWD web--browse\n\tusage: git web--browse [--browser=browser|--tool=browser] [--config=conf.var] url/file ...\n\nThe same goes for e.g. the \"git-p4\" tests, which would fail because\nour built \"git-p4\" wasn't executable, etc.\n\nThis change should ideally use file(CHMOD ...), but that's much newer\nthan our required cmake version[1].\n\n1. a30e4c531d9 (Merge branch 'ss/cmake-build', 2020-08-11)\n2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n3. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n4. https://cmake.org/cmake/help/latest/command/file.html#chmod\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex fd0c6ef4971..464c41a1fdf 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -836,6 +836,7 @@ foreach(script ${git_shell_scripts})\n \tstring(REPLACE \"@@PERL@@\" \"${PERL_PATH}\" content \"${content}\")\n \tstring(REPLACE \"@@PAGER_ENV@@\" \"LESS=FRX LV=-c\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n endforeach()\n \n #perl scripts\n@@ -851,12 +852,14 @@ foreach(script ${git_perl_scripts})\n \tstring(REPLACE \"#!/usr/bin/perl\" \"#!/usr/bin/perl\\n${perl_header}\\n\" content \"${content}\")\n \tstring(REPLACE \"@@GIT_VERSION@@\" \"${PROJECT_VERSION}\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n endforeach()\n \n #python script\n file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n+execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/git-p4)\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n@@ -995,6 +998,7 @@ foreach(script ${wrapper_scripts})\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"${script}${EXE_EXTENSION}\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/${script})\n endforeach()\n \n foreach(script ${wrapper_test_scripts})\n@@ -1002,12 +1006,14 @@ foreach(script ${wrapper_test_scripts})\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"t/helper/${script}${EXE_EXTENSION}\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/${script})\n endforeach()\n \n file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n string(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n string(REPLACE \"@@PROG@@\" \"git-cvsserver\" content \"${content}\")\n file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})\n+execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver)\n \n #options for configuring test options\n option(PERL_TESTS \"Perform tests that use perl\" ON)\n-- \n2.38.0.1205.gcea0601d673\n\n"},{"id":"465446","messageId":"patch-4.9-52cd674d5b8-20221021T091013Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"[PATCH 4/9] cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T09:44:17Z","receivedAt":"2022-10-21T09:45:06Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When we build with libpcre2 which cmake has supported since [1] we\nneed to set \"USE_LIBPCRE2='YesPlease'\" (or similar) in\n\"GIT-BUILD-OPTIONS\".\n\nWithout this e.g. t7810-grep.sh will fail, as it has tests that rely\non the behavior of !PCRE2. The reason this hasn't been noticed is that\nthe Windows CI doesn't have access to libpcre2.\n\n1. 80431510a2b (cmake: add pcre2 support, 2022-05-24)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 84f5132f1ee..725b3f2ac82 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1063,6 +1063,9 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PYTHON_PATH='${PYTHON_PATH}'\\\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"TAR='${TAR}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_CURL='${NO_CURL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_EXPAT='${NO_EXPAT}'\\n\")\n+if(PCRE2_FOUND)\n+\tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"USE_LIBPCRE2='YesPlease'\\n\")\n+endif()\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PERL='${NO_PERL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PTHREADS='${NO_PTHREADS}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\\n\")\n-- \n2.38.0.1205.gcea0601d673\n\n"},{"id":"465447","messageId":"patch-5.9-6199a913c0a-20221021T091013Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"[PATCH 5/9] test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T09:44:18Z","receivedAt":"2022-10-21T09:45:11Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Compliment the existing GIT_TEST_INSTALLED variable added in [1] with\none that allows for testing a git built in a directory that's not\n\"../\".\n\nInstead of \"test this installed git\" (\"GIT_TEST_INSTALLED\"), this new\n\"GIT_TEST_BUILD_DIR\" is a \"test this built directory over\nthere\". E.g. this will pass all tests:\n\n\tgit clone --depth=1 https://github.com/git/git.git git1\n\tcp -R git1 git2\n\tmake -C git1\n\t[apply this change to git2]\n\t(cd git2 && GIT_TEST_BUILD_DIR=\"$PWD/../git1\" make -C t prove)\n\n1. 6720721e152 (test-lib.sh: Allow running the test suite against\n   installed git, 2009-03-16)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/README      | 3 +++\n t/test-lib.sh | 4 ++++\n 2 files changed, 7 insertions(+)\n\ndiff --git a/t/README b/t/README\nindex 979b2d4833d..fc0daef2e41 100644\n--- a/t/README\n+++ b/t/README\n@@ -231,6 +231,9 @@ override the location of the dashed-form subcommands (what\n GIT_EXEC_PATH would be used for during normal operation).\n GIT_TEST_EXEC_PATH defaults to `$GIT_TEST_INSTALLED/git --exec-path`.\n \n+Similar to GIT_TEST_INSTALLED, GIT_TEST_BUILD_DIR can be pointed to\n+another git.git checkout's build directory, to test its built binaries\n+against the tests in this checkout.\n \n Skipping Tests\n --------------\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex d2e5dee6c89..41b1ddc96ff 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -47,6 +47,10 @@ fi\n # its build directory.\n GIT_SOURCE_DIR=\"${TEST_DIRECTORY%/t}\"\n GIT_BUILD_DIR=\"$GIT_SOURCE_DIR\"\n+if test -n \"$GIT_TEST_BUILD_DIR\"\n+then\n+\tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n+fi\n \n if test \"$TEST_DIRECTORY\" = \"$GIT_BUILD_DIR\"\n then\n-- \n2.38.0.1205.gcea0601d673\n\n"},{"id":"465448","messageId":"patch-6.9-45f1a4e6f93-20221021T091013Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"[PATCH 6/9] cmake: use GIT_TEST_BUILD_DIR instead of editing hack","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T09:44:19Z","receivedAt":"2022-10-21T09:45:15Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When cmake builds git in \"contrib/buildsystems/out\" it will create a\n\"t/\" directory there containing only the \"t/helper/test-tool\", but for\nrunning the tests with \"cmake\" it cd's to the \"real\" t/ directory, and\nruns the tests from there.\n\nTo get the test-lib.sh to locate \"git\" and other binaries in\n\"../contrib/buildsystems/out/\" rather than \"../\" we have since [1]\nbeen editing the \"GIT_BUILD_DIR\" assignment in test-lib.sh in-place.\n\nThis has meant that when testing cmake we've had to \"git reset --hard\"\nbefore running \"make\" again.\n\nWhat this build infrastructure really wanted was some feature like the\n\"GIT_TEST_BUILD_DIR\" variable added in the preceding commit, so let's\nmake use of it.\n\nEven though \"ctest\" will work with this approach, one advantage of the\nprevious arrangement was that we could:\n\n\tA. Build with cmake\n\tB. cd t\n\tC. Run a test\n\nAnd have the test itself know to locate and use the cmake binaries,\nthis workflow was documented in [2]. The \"t/test-lib\".sh modification\nhere is so that we can support this use-case.\n\nAs [3] notes \"contrib/buildsystems/out\" isn't just the directory that\nhappens to be documented in \"contrib/buildsystems/CMakeLists.txt\", but\nthe one that VS will use when building git.\n\nTo make it clear what's happening we emit a \"setup: \" from the\ntest-lib.sh to note that we used this fallback method:\n\n\t$ ./t0001-init.sh\n\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n\tok 1 - plain\n\t[...]\n\nNote: the \"On Windows[...]\" part of this is lifted from [4].\n\n1. 7f5397a07c6 (cmake: support for testing git when building out of\n   the source tree, 2020-06-26)\n2. f2f1250c47f (cmake (Windows): recommend using Visual Studio's\n   built-in CMake support, 2020-09-30)\n3. 3eccc7b99d4 (cmake: ignore files generated by CMake as run in\n   Visual Studio, 2020-09-25)\n4. https://lore.kernel.org/git/5b0c2a150e9fce1ca0284d65628b42ed5a7aad9a.1666090745.git.gitgitgadget@gmail.com/\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 15 +--------------\n t/test-lib.sh                       | 19 +++++++++++++++++++\n 2 files changed, 20 insertions(+), 14 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 725b3f2ac82..91b7009f4fd 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1080,25 +1080,12 @@ if(USE_VCPKG)\n \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n endif()\n \n-#Make the tests work when building out of the source tree\n-get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n-if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n-\tfile(RELATIVE_PATH BUILD_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/CMakeCache.txt)\n-\tstring(REPLACE \"/CMakeCache.txt\" \"\" BUILD_DIR_RELATIVE ${BUILD_DIR_RELATIVE})\n-\t#Setting the build directory in test-lib.sh before running tests\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n-\t\t\"file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \\\"GIT_BUILD_DIR=(.*)\\\")\\n\"\n-\t\t\"file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\\n\"\n-\t\t\"string(REPLACE \\\"\\${GIT_BUILD_DIR_REPL}\\\" \\\"GIT_BUILD_DIR=\\\\\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\\\\\"\\\" content \\\"\\${content}\\\")\\n\"\n-\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \\${content})\")\n-endif()\n-\n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n \n #test\n foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n-\t\tCOMMAND ${SH_EXE} ${tsh}\n+\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh}\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n endforeach()\n \ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 41b1ddc96ff..284b619708a 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -47,9 +47,21 @@ fi\n # its build directory.\n GIT_SOURCE_DIR=\"${TEST_DIRECTORY%/t}\"\n GIT_BUILD_DIR=\"$GIT_SOURCE_DIR\"\n+GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=\n if test -n \"$GIT_TEST_BUILD_DIR\"\n then\n \tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n+elif ! test -x \"$GIT_BUILD_DIR/git\" &&\n+     test -x \"$GIT_BUILD_DIR/contrib/buildsystems/out/git\"\n+then\n+\tGIT_BUILD_DIR=\"$GIT_SOURCE_DIR/contrib/buildsystems/out\"\n+\tGIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=t\n+\t# On Windows, we must convert Windows paths lest they contain a colon\n+\tcase \"$(uname -s)\" in\n+\t*MINGW*)\n+\t\tGIT_BUILD_DIR=\"$(cygpath -au \"$GIT_BUILD_DIR\")\"\n+\t\t;;\n+\tesac\n fi\n \n if test \"$TEST_DIRECTORY\" = \"$GIT_BUILD_DIR\"\n@@ -1630,6 +1642,13 @@ remove_trash_directory \"$TRASH_DIRECTORY\" || {\n \tBAIL_OUT 'cannot prepare test area'\n }\n \n+# Emitting this now because earlier we didn't have \"say\", but not in\n+# anything using lib-subtest.sh\n+if test -n \"$GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT\" && test -t 1\n+then\n+\tsay \"setup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\"\n+fi\n+\n remove_trash=t\n if test -z \"$TEST_NO_CREATE_REPO\"\n then\n-- \n2.38.0.1205.gcea0601d673\n\n"},{"id":"465449","messageId":"patch-3.9-addaf73992f-20221021T091013Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"[PATCH 3/9] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T09:44:16Z","receivedAt":"2022-10-21T09:45:16Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When git is built and tested with cmake & ctest we usually do that\noutside of the top-level source directory. E.g.\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out\n\tmake -C contrib/buildsystems/out\n\tctest -j$(nproc) --test-dir contrib/buildsystems/out\n\nSince the test-lib.sh makes assumptions about the TEST_DIRECTORY being\nthe \"t\" subdirectory of the top-level \"$GIT_BUILD_DIR\", the cmake\nrecipe has needed to copy various assets to that\n\"contrib/buildsystems/out\" directory.\n\nLet's instead teach the test-lib.sh that there's such a thing as the\n\"$GIT_SOURCE_DIR\" distinct from the \"$GIT_BUILD_DIR\".\n\nJust as the \"$TEST_DIRECTORY\" always points to our actual \"t\"\ndirectory (not the \"[...]/out/t\" cmake creates), this new\n\"$GIT_SOURCE_DIR\" will always be the top-level source directory.\n\nSo even though the \"GIT_BUILD_DIR=(.*)\" line in t/test-lib.sh will\nstill be altered by CMakeLists.txt, that recipe will no longer need to\ncopy over various things from our source directory, as the tests now\nknow where to find those assets.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt |  5 -----\n t/lib-gettext.sh                    |  2 +-\n t/lib-gitweb.sh                     |  2 +-\n t/t7609-mergetool--lib.sh           |  2 +-\n t/t9902-completion.sh               | 14 +++++++-------\n t/t9903-bash-prompt.sh              |  2 +-\n t/test-lib.sh                       | 12 ++++++++++--\n 7 files changed, 21 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 464c41a1fdf..84f5132f1ee 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1088,11 +1088,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \t\t\"file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\\n\"\n \t\t\"string(REPLACE \\\"\\${GIT_BUILD_DIR_REPL}\\\" \\\"GIT_BUILD_DIR=\\\\\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\\\\\"\\\" content \\\"\\${content}\\\")\\n\"\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \\${content})\")\n-\t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\ndiff --git a/t/lib-gettext.sh b/t/lib-gettext.sh\nindex cc6bb2cdeaa..dcd6e9c3f75 100644\n--- a/t/lib-gettext.sh\n+++ b/t/lib-gettext.sh\n@@ -7,7 +7,7 @@\n . ./test-lib.sh\n \n GIT_TEXTDOMAINDIR=\"$GIT_BUILD_DIR/po/build/locale\"\n-GIT_PO_PATH=\"$GIT_BUILD_DIR/po\"\n+GIT_PO_PATH=\"$GIT_SOURCE_DIR/po\"\n export GIT_TEXTDOMAINDIR GIT_PO_PATH\n \n if test -n \"$GIT_TEST_INSTALLED\"\ndiff --git a/t/lib-gitweb.sh b/t/lib-gitweb.sh\nindex 1f32ca66ea5..6f68df247af 100644\n--- a/t/lib-gitweb.sh\n+++ b/t/lib-gitweb.sh\n@@ -49,7 +49,7 @@ EOF\n \t\terror \"Cannot find gitweb at $GITWEB_TEST_INSTALLED.\"\n \t\tsay \"# Testing $SCRIPT_NAME\"\n \telse # normal case, use source version of gitweb\n-\t\tSCRIPT_NAME=\"$GIT_BUILD_DIR/gitweb/gitweb.perl\"\n+\t\tSCRIPT_NAME=\"$GIT_SOURCE_DIR/gitweb/gitweb.perl\"\n \tfi\n \texport SCRIPT_NAME\n }\ndiff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh\nindex 8b1c3bd39f2..2090d12a489 100755\n--- a/t/t7609-mergetool--lib.sh\n+++ b/t/t7609-mergetool--lib.sh\n@@ -8,7 +8,7 @@ TEST_PASSES_SANITIZE_LEAK=true\n . ./test-lib.sh\n \n test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '\n-\t. \"$GIT_BUILD_DIR\"/mergetools/vimdiff &&\n+\t. \"$GIT_SOURCE_DIR\"/mergetools/vimdiff &&\n \trun_unit_tests\n '\n \ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 43de868b800..1bd4cae92fe 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -33,7 +33,7 @@ complete ()\n GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'\n GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\"\n \n # We don't need this function to actually join words or do anything special.\n # Also, it's cleaner to avoid touching bash's internal completion variables.\n@@ -2567,7 +2567,7 @@ test_expect_success 'sourcing the completion script clears cached commands' '\n \t(\n \t\t__git_compute_all_commands &&\n \t\tverbose test -n \"$__git_all_commands\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_all_commands\"\n \t)\n '\n@@ -2576,7 +2576,7 @@ test_expect_success 'sourcing the completion script clears cached merge strategi\n \t(\n \t\t__git_compute_merge_strategies &&\n \t\tverbose test -n \"$__git_merge_strategies\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_merge_strategies\"\n \t)\n '\n@@ -2587,7 +2587,7 @@ test_expect_success 'sourcing the completion script clears cached --options' '\n \t\tverbose test -n \"$__gitcomp_builtin_checkout\" &&\n \t\t__gitcomp_builtin notes_edit &&\n \t\tverbose test -n \"$__gitcomp_builtin_notes_edit\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_checkout\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_notes_edit\"\n \t)\n@@ -2599,7 +2599,7 @@ test_expect_success 'option aliases are not shown by default' '\n \n test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&\n \t\ttest_completion \"git clone --recurs\" <<-\\EOF\n \t\t--recurse-submodules Z\n@@ -2610,7 +2610,7 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \n test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n \n \t\t# Just mainporcelain, not plumbing commands\n@@ -2622,7 +2622,7 @@ test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_\n \n test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n \t\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex d459fae6551..06f0abfc294 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -10,7 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./lib-bash.sh\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-prompt.sh\"\n \n actual=\"$TRASH_DIRECTORY/actual\"\n c_red='\\\\[\\\\e[31m\\\\]'\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 6ca68311eb9..d2e5dee6c89 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -41,7 +41,13 @@ then\n \t# elsewhere\n \tTEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY\n fi\n-GIT_BUILD_DIR=\"${TEST_DIRECTORY%/t}\"\n+\n+# The GIT_{SOURCE,BUILD}_DIR is always the same, except when\n+# CMakeLists.txt replaces the \"GIT_BUILD_DIR\" line with the path to\n+# its build directory.\n+GIT_SOURCE_DIR=\"${TEST_DIRECTORY%/t}\"\n+GIT_BUILD_DIR=\"$GIT_SOURCE_DIR\"\n+\n if test \"$TEST_DIRECTORY\" = \"$GIT_BUILD_DIR\"\n then\n \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n@@ -1437,7 +1443,7 @@ then\n \t\tmake_valgrind_symlink $file\n \tdone\n \t# special-case the mergetools loadables\n-\tmake_symlink \"$GIT_BUILD_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n+\tmake_symlink \"$GIT_SOURCE_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n \tOLDIFS=$IFS\n \tIFS=:\n \tfor path in $PATH\n@@ -1490,6 +1496,8 @@ GIT_CONFIG_NOSYSTEM=1\n GIT_ATTR_NOSYSTEM=1\n GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\"\n export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES\n+MERGE_TOOLS_DIR=\"$GIT_SOURCE_DIR/mergetools\"\n+export MERGE_TOOLS_DIR\n \n if test -z \"$GIT_TEST_CMP\"\n then\n-- \n2.38.0.1205.gcea0601d673\n\n"},{"id":"465450","messageId":"patch-7.9-fc9f036695f-20221021T091013Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"[PATCH 7/9] cmake: support using GIT_TEST_OPTS from the environment","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T09:44:20Z","receivedAt":"2022-10-21T09:45:20Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Get \"GIT_TEST_OPTS\" from the environment, and use it to pass arguments\nto tests. This allows for passing arguments to tests with e.g.:\n\n\tGIT_TEST_OPTS=\"--verbose --debug\" cmake .; ctest -R t0001 --verbose\n\nThere's some overlap with this and what was suggested in [1], but as\nnoted there we're not passing \"--verbose\" and friends unconditionally,\nso a plain \"ctest\" invocation without a \"cmake\" re-build won't pick up\nthe options.\n\n1. https://lore.kernel.org/git/356b2e9a1007bcd1382f26f333926ff0d5b9abe2.1666090745.git.gitgitgadget@gmail.com/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 91b7009f4fd..8e29e3f514b 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1083,9 +1083,11 @@ endif()\n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n \n #test\n+set(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n+separate_arguments(GIT_TEST_OPTS)\n foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n-\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh}\n+\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n endforeach()\n \n-- \n2.38.0.1205.gcea0601d673\n\n"},{"id":"465451","messageId":"patch-8.9-56102c2a4bf-20221021T091013Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"[PATCH 8/9] cmake: copy over git-p4.py for t983[56] perforce test","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T09:44:21Z","receivedAt":"2022-10-21T09:45:21Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] two git-p4 tests have relied on there being a \"git-p4.py\" in\nthe build directory, but the cmake recipe was not updated to account\nfor this. Let's copy the \"git-p4.py\" over.\n\nWe could also change the test to e.g. grab the built \"git-p4\" and\nalter its shebang, which would be friendly to GIT_TEST_INSTALLED, but\nlet's just do the bare minimum here to get cmake+ctest working without\naltering the test itself.\n\nThe reason this hasn't been caught by \"vs-build\" and \"vs-test\" is\nbecause those tests added in [2] invoke \"cmake\" with\n\"-DPYTHON_TESTS=OFF\", and therefore we'd skip this part of the git-p4\ntests before getting past the \"do we have python?\" check. Even if we\ngot past that the Windows CI wouldn't have a \"p4\" or \"p4d\" binary\ninstalled, so we'd skip the tests anyway.\n\nIn a subsequent commit we'll run \"cmake\" and \"ctest\" in CI with\n\"ubuntu-latest\", so we'll need this \"git-p4.py\" file.\n\n1. f7b5ff607fa (git-p4: improve encoding handling to support\n   inconsistent encodings, 2022-04-30)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 8e29e3f514b..4f5e43e0aad 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -860,6 +860,7 @@ file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/git-p4)\n+file(COPY ${CMAKE_SOURCE_DIR}/git-p4.py DESTINATION ${CMAKE_BINARY_DIR}/)\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n-- \n2.38.0.1205.gcea0601d673\n\n"},{"id":"465452","messageId":"patch-9.9-b81f18dec61-20221021T091013Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"[PATCH 9/9] CI: add a \"linux-cmake-test\" to run cmake & ctest on linux","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T09:44:22Z","receivedAt":"2022-10-21T09:45:23Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] the \"cmake\" build method should work properly on Linux, but\nas seen in preceding commits there were various bugs in it, which are\nhopefully now all fixed.\n\nTo ensure that it doesn't break again let's add a \"linux-cmake-ctest\"\ntarget to build and test \"cmake\" on Linux, in addition to that we'll\nalso run the tests with \"ctest\" instead of \"make\" or \"prove\", so we\ncan assert that testing with that method works..\n\nThis also stress tests running \"cmake\" (and \"ctest\") out of a build\ndirectory that isn't the top-level. The \"vs-build\" job uses \"cmake\"\nsince [2], but clobbers the top-level \"Makefile\" and builds in the\ntop-level directory.\n\nThat was the reason for why we didn't spot that various tests still\nrequired missing \"mergetools/*\" etc, which was fixed by using\n\"$GIT_SOURCE_DIR\" in a preceding commit.\n\nSince the \"ci/lib.sh\" already creates and exports a\nGIT_TEST_OPTS=\"...\" we'll pick that up in our CI, see the preceding\ncommit. Because we pass the \"--verbose-log -x\n--github-workflow-markup\" in the GitHub CI as a result the interaction\nwith \"handle_failed_tests\" here works correctly. I.e. on failure we'll\nhave saved \"t/test-results/*.{exit,out,markup}\" files relevant to the\nfailing test(s).\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .github/workflows/main.yml |  3 +++\n ci/run-build-and-tests.sh  | 13 +++++++++++--\n 2 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/.github/workflows/main.yml b/.github/workflows/main.yml\nindex 831f4df56c5..f15c77c1ed1 100644\n--- a/.github/workflows/main.yml\n+++ b/.github/workflows/main.yml\n@@ -238,6 +238,9 @@ jobs:\n             os: ubuntu\n             cc_package: gcc-8\n             pool: ubuntu-latest\n+          - jobname: linux-cmake-ctest\n+            cc: gcc\n+            pool: ubuntu-latest\n           - jobname: osx-clang\n             cc: clang\n             pool: macos-latest\ndiff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh\nindex 8ebff425967..a3ae5ff3972 100755\n--- a/ci/run-build-and-tests.sh\n+++ b/ci/run-build-and-tests.sh\n@@ -45,10 +45,19 @@ pedantic)\n \t;;\n esac\n \n-group Build make\n+mc=\n+if test \"$jobname\" = \"linux-cmake-ctest\"\n+then\n+\tcb=contrib/buildsystems\n+\tgroup CMake cmake -S \"$cb\" -B \"$cb/out\"\n+\tmc=\"-C $cb/out\"\n+fi\n+\n+group Build make $mc\n+\n if test -n \"$run_tests\"\n then\n-\tgroup \"Run tests\" make test ||\n+\tgroup \"Run tests\" make $mc test ||\n \thandle_failed_tests\n fi\n check_unignored_build_artifacts\n-- \n2.38.0.1205.gcea0601d673\n\n"},{"id":"465453","messageId":"s42p6rn0-s5oo-2874-636p-2541n475p045@tzk.qr","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"Re: [PATCH 0/9] cmake: fix *nix & general issues, no test-lib.sh editing, ctest in CI","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2022-10-21T10:29:39Z","receivedAt":"2022-10-21T10:29:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Ævar,\n\nOn Fri, 21 Oct 2022, Ævar Arnfjörð Bjarmason wrote:\n\n> On Tue, Oct 18 2022, Johannes Schindelin wrote:\n>\n> [For context:\n> https://lore.kernel.org/git/on2q3qos-sr0n-0p8p-606p-5pq39n46qq4q@tzk.qr/\n> is upthread of here, but spinning this off into another thread]\n>\n> >> Re my earlier feedback, I came up with this as an alternative, which\n> >> nicely allows us to have \"cmake\" and \"make\" play together, you can even\n> >> run them concurrently!:\n> >>\n> >>      https://github.com/avar/git/commit/30f2265fd07aee97ea66f6e84a824d85d241e245\n> >\n> > This approach _still_ modifies the `test-lib.sh`, which is the entire\n> > reason for the patch under review.\n> >\n> > I hope you find an elegant, user-friendly alternative that leaves\n> > `test-lib.sh` unmodified even when building via CMake. I would gladly take\n> > that and drop my `GIT-BUILD-DIR` patch.\n>\n> You did ask for it :)\n\nWell, I asked for something elegant, which in my mind is always something\nsuccinct. A 9-patch series is not succinct ;-)\n\nSadly, I am already struggling to whittle down my work queue as it is, and\nam quite deer-in-the-headlights about having to find the time to review\nanything longer than a short patch in addition to what is already in the\nqueue :-(\n\nHopefully next week.\n\nThank you for working on this,\nJohannes\n"},{"id":"465462","messageId":"0fda0e54-0432-7690-74a7-3d1a59923e0c@dunelm.org.uk","threadId":"58666","inReplyTo":"patch-2.9-2c1d194e590-20221021T091013Z-avarab@gmail.com","subject":"Re: [PATCH 2/9] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-10-21T14:18:16Z","receivedAt":"2022-10-21T14:18:23Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Ævar\n\nOn 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n> diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n> index fd0c6ef4971..464c41a1fdf 100644\n> --- a/contrib/buildsystems/CMakeLists.txt\n> +++ b/contrib/buildsystems/CMakeLists.txt\n> @@ -836,6 +836,7 @@ foreach(script ${git_shell_scripts})\n>   \tstring(REPLACE \"@@PERL@@\" \"${PERL_PATH}\" content \"${content}\")\n>   \tstring(REPLACE \"@@PAGER_ENV@@\" \"LESS=FRX LV=-c\" content \"${content}\")\n>   \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n> +\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n\nI think it would be nicer to add a write_script function\n\nfunction(write_script path content)\n        file(WRITE ${path} ${content})\n        file(CHMOD ${path} FILE_PERMISSIONS OWNER_READ OWNER_WRITE \nOWNER_EXECUTE)\nendfunction()\n\nand then do\n\n-       file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+       write_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n\nrather than executing chmod each time\n\nBest Wishes\n\nPhillip\n"},{"id":"465463","messageId":"d6e2baab-be26-66d1-f07c-134eb6fe06fd@dunelm.org.uk","threadId":"58666","inReplyTo":"patch-6.9-45f1a4e6f93-20221021T091013Z-avarab@gmail.com","subject":"Re: [PATCH 6/9] cmake: use GIT_TEST_BUILD_DIR instead of editing hack","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-10-21T14:18:24Z","receivedAt":"2022-10-21T14:18:34Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Ævar\n\nOn 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n> When cmake builds git in \"contrib/buildsystems/out\" it will create a\n> \"t/\" directory there containing only the \"t/helper/test-tool\", but for\n> running the tests with \"cmake\" it cd's to the \"real\" t/ directory, and\n> runs the tests from there.\n> \n> To get the test-lib.sh to locate \"git\" and other binaries in\n> \"../contrib/buildsystems/out/\" rather than \"../\" we have since [1]\n> been editing the \"GIT_BUILD_DIR\" assignment in test-lib.sh in-place.\n> \n> This has meant that when testing cmake we've had to \"git reset --hard\"\n> before running \"make\" again.\n> \n> What this build infrastructure really wanted was some feature like the\n> \"GIT_TEST_BUILD_DIR\" variable added in the preceding commit, so let's\n> make use of it.\n\nLets squash that commit into this one, so we can see how it is used when \nit is added.\n\n> Even though \"ctest\" will work with this approach, one advantage of the\n> previous arrangement was that we could:\n> \n> \tA. Build with cmake\n> \tB. cd t\n> \tC. Run a test\n> \n> And have the test itself know to locate and use the cmake binaries,\n> this workflow was documented in [2]. The \"t/test-lib\".sh modification\n> here is so that we can support this use-case.\n> \n> As [3] notes \"contrib/buildsystems/out\" isn't just the directory that\n> happens to be documented in \"contrib/buildsystems/CMakeLists.txt\", but\n> the one that VS will use when building git.\n\nThat may be the directory that VS uses when building git, but it is \npossible to specify a different build directory when running cmake.\n\n> To make it clear what's happening we emit a \"setup: \" from the\n> test-lib.sh to note that we used this fallback method:\n> \n> \t$ ./t0001-init.sh\n> \tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n> \tok 1 - plain\n> \t[...]\n> \n> Note: the \"On Windows[...]\" part of this is lifted from [4].\n> \n> 1. 7f5397a07c6 (cmake: support for testing git when building out of\n>     the source tree, 2020-06-26)\n> 2. f2f1250c47f (cmake (Windows): recommend using Visual Studio's\n>     built-in CMake support, 2020-09-30)\n> 3. 3eccc7b99d4 (cmake: ignore files generated by CMake as run in\n>     Visual Studio, 2020-09-25)\n> 4. https://lore.kernel.org/git/5b0c2a150e9fce1ca0284d65628b42ed5a7aad9a.1666090745.git.gitgitgadget@gmail.com/\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>   contrib/buildsystems/CMakeLists.txt | 15 +--------------\n>   t/test-lib.sh                       | 19 +++++++++++++++++++\n>   2 files changed, 20 insertions(+), 14 deletions(-)\n> \n> diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n> index 725b3f2ac82..91b7009f4fd 100644\n> --- a/contrib/buildsystems/CMakeLists.txt\n> +++ b/contrib/buildsystems/CMakeLists.txt\n> @@ -1080,25 +1080,12 @@ if(USE_VCPKG)\n>   \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n>   endif()\n>   \n> -#Make the tests work when building out of the source tree\n> -get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n> -if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n> -\tfile(RELATIVE_PATH BUILD_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/CMakeCache.txt)\n> -\tstring(REPLACE \"/CMakeCache.txt\" \"\" BUILD_DIR_RELATIVE ${BUILD_DIR_RELATIVE})\n> -\t#Setting the build directory in test-lib.sh before running tests\n> -\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n> -\t\t\"file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \\\"GIT_BUILD_DIR=(.*)\\\")\\n\"\n> -\t\t\"file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\\n\"\n> -\t\t\"string(REPLACE \\\"\\${GIT_BUILD_DIR_REPL}\\\" \\\"GIT_BUILD_DIR=\\\\\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\\\\\"\\\" content \\\"\\${content}\\\")\\n\"\n> -\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \\${content})\")\n> -endif()\n> -\n>   file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n>   \n>   #test\n>   foreach(tsh ${test_scipts})\n>   \tadd_test(NAME ${tsh}\n> -\t\tCOMMAND ${SH_EXE} ${tsh}\n> +\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh}\n\nI'm not sure about using env on windows, can we use ${SH_EXE} -c instead \nto avoid creating an extra process?\n\n\tCOMMAND ${SH_EXE} -c [[GIT_TEST_BUILD_DIR=\"$1\"; . \"$2\"]] \"${tsh}\" \n\"${CMAKE_BINARY_DIR}\" \"${tsh}\"\n\n>   \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n>   endforeach()\n>   \n> diff --git a/t/test-lib.sh b/t/test-lib.sh\n> index 41b1ddc96ff..284b619708a 100644\n> --- a/t/test-lib.sh\n> +++ b/t/test-lib.sh\n> @@ -47,9 +47,21 @@ fi\n>   # its build directory.\n>   GIT_SOURCE_DIR=\"${TEST_DIRECTORY%/t}\"\n>   GIT_BUILD_DIR=\"$GIT_SOURCE_DIR\"\n> +GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=\n>   if test -n \"$GIT_TEST_BUILD_DIR\"\n>   then\n>   \tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n> +elif ! test -x \"$GIT_BUILD_DIR/git\" &&\n> +     test -x \"$GIT_BUILD_DIR/contrib/buildsystems/out/git\"\n\nI'm really not keen on hard coding the CMAKE_BINARY_DIR. One of the \npositive things about dscho's approach is that it does not hard code the \nbuild directory. I'm not convinced this approach is an improvement.\n\nBest Wishes\n\nPhillip\n\n> +then\n> +\tGIT_BUILD_DIR=\"$GIT_SOURCE_DIR/contrib/buildsystems/out\"\n> +\tGIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=t\n> +\t# On Windows, we must convert Windows paths lest they contain a colon\n> +\tcase \"$(uname -s)\" in\n> +\t*MINGW*)\n> +\t\tGIT_BUILD_DIR=\"$(cygpath -au \"$GIT_BUILD_DIR\")\"\n> +\t\t;;\n> +\tesac\n>   fi\n>   \n>   if test \"$TEST_DIRECTORY\" = \"$GIT_BUILD_DIR\"\n> @@ -1630,6 +1642,13 @@ remove_trash_directory \"$TRASH_DIRECTORY\" || {\n>   \tBAIL_OUT 'cannot prepare test area'\n>   }\n>   \n> +# Emitting this now because earlier we didn't have \"say\", but not in\n> +# anything using lib-subtest.sh\n> +if test -n \"$GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT\" && test -t 1\n> +then\n> +\tsay \"setup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\"\n> +fi\n> +\n>   remove_trash=t\n>   if test -z \"$TEST_NO_CREATE_REPO\"\n>   then\n"},{"id":"465464","messageId":"830905ef-fb90-9b2a-c40a-67cf24f7a24b@dunelm.org.uk","threadId":"58666","inReplyTo":"patch-7.9-fc9f036695f-20221021T091013Z-avarab@gmail.com","subject":"Re: [PATCH 7/9] cmake: support using GIT_TEST_OPTS from the environment","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-10-21T14:18:30Z","receivedAt":"2022-10-21T14:18:40Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Ævar\n\nOn 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n> Get \"GIT_TEST_OPTS\" from the environment, and use it to pass arguments\n> to tests. This allows for passing arguments to tests with e.g.:\n> \n> \tGIT_TEST_OPTS=\"--verbose --debug\" cmake .; ctest -R t0001 --verbose\n> \n> There's some overlap with this and what was suggested in [1], but as\n> noted there we're not passing \"--verbose\" and friends unconditionally,\n> so a plain \"ctest\" invocation without a \"cmake\" re-build won't pick up\n> the options.\n\nThe aim of dscho's patch was to make debugging information available in \nthe test logs without the user having to do anything, now to get that \ninformation every user has to set GIT_TEST_OPTS=\"--no-bin-wrappers \n--no-chain-lint -vx\" when running cmake.\n\nI think it would be helpful to have some default options set if the user \ndoes not pass GIT_TEST_OPTS. Ideally one would be able to do\n\n\tGIT_TEST_OPTS=... ctest\n\nand have the tests pick up the options at runtime. Following on from my \nprevious comment, if we used \"sh -c\" to launch the tests we could have \nsomething like\n\n\tCOMMAND ${SH_EXE} -c [[GIT_TEST_BUILD_DIR=\"$1\"; . \"$2\" \n${GIT_TEST_OPTS:---no-bin-wrappers --no-chain-lint -vx}]] \"${tsh}\" \n\"${CMAKE_BINARY_DIR}\" \"${tsh}\"\n\nBest Wishes\n\nPhillip\n\n\n> 1. https://lore.kernel.org/git/356b2e9a1007bcd1382f26f333926ff0d5b9abe2.1666090745.git.gitgitgadget@gmail.com/\n> \n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>   contrib/buildsystems/CMakeLists.txt | 4 +++-\n>   1 file changed, 3 insertions(+), 1 deletion(-)\n> \n> diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n> index 91b7009f4fd..8e29e3f514b 100644\n> --- a/contrib/buildsystems/CMakeLists.txt\n> +++ b/contrib/buildsystems/CMakeLists.txt\n> @@ -1083,9 +1083,11 @@ endif()\n>   file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n>   \n>   #test\n> +set(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n> +separate_arguments(GIT_TEST_OPTS)\n>   foreach(tsh ${test_scipts})\n>   \tadd_test(NAME ${tsh}\n> -\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh}\n> +\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n>   \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n>   endforeach()\n>   \n"},{"id":"465465","messageId":"49d65210-583b-67a2-1ad5-c7166e81396e@dunelm.org.uk","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"Re: [PATCH 0/9] cmake: fix *nix & general issues, no test-lib.sh editing, ctest in CI","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-10-21T14:27:39Z","receivedAt":"2022-10-21T14:28:17Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n\nI think this series contains a couple of interesting ideas but I'm not \nsure hard coding the build directory or removing the default test \noptions are improvements on dscho's series.\n\nCombining fixes for cmake and linux with changes for running ctest on \nwindows is not particularly helpful and would be better as two separate \nseries. We really need to have a clear policy of what the status of \nbuilding with cmake on linux is. I think having a usable cmake build on \nlinux could be useful for anyone making changes to CMakeLists.txt as \nthey can do some testing and debugging locally before running our ci to \ncheck it works on windows but I'm not sure  we need to support it as an \nalternative to the Makefile.\n\nBest Wishes\n\nPhillip\n\n> On Tue, Oct 18 2022, Johannes Schindelin wrote:\n> \n> [For context:\n> https://lore.kernel.org/git/on2q3qos-sr0n-0p8p-606p-5pq39n46qq4q@tzk.qr/\n> is upthread of here, but spinning this off into another thread]\n> \n>>> Re my earlier feedback, I came up with this as an alternative, which\n>>> nicely allows us to have \"cmake\" and \"make\" play together, you can even\n>>> run them concurrently!:\n>>>\n>>>       https://github.com/avar/git/commit/30f2265fd07aee97ea66f6e84a824d85d241e245\n>>\n>> This approach _still_ modifies the `test-lib.sh`, which is the entire\n>> reason for the patch under review.\n>>\n>> I hope you find an elegant, user-friendly alternative that leaves\n>> `test-lib.sh` unmodified even when building via CMake. I would gladly take\n>> that and drop my `GIT-BUILD-DIR` patch.\n> \n> You did ask for it :)\n> \n> To clarify, what I had upthread was a patch on the way towards a\n> solution that didn't edit t/test-lib.sh at all, but that patch itself\n> wasn't sufficient. It's the equivalent of 3/9 here.\n> \n> This series:\n> \n>   * Can be grabbed at\n>     https://github.com/avar/git/tree/avar/cmake-test-path\n> \n>   * Conflicts with js/cmake-updates[1], although I've seen it go in &\n>     out of {gitster,git}/seen (currently in gitster/seen, not in\n>     git.git's \"seen\".\n> \n>     But the conflict is easily fixed to keep both, see below.\n> \n>   * Fixes numerous bugs in the current cmake recipe, running \"ctest\"\n>     was a dumpster fire on Linux, after this with 9/9 we can run our\n>     whole test suite in CI on ubuntu-latest:\n>     https://github.com/avar/git/actions/runs/3293378319/jobs/5431721245\n> \n>   * Handles the case where you want to build with cmake and have \"(cd t\n>     && ./t0001-init.sh)\" just work, i.e. we spot that we have a built\n>     \"contrib/buildsystems/out\" and use that.\n> \n>   * I pushed out a \"js/cmake-update-ci\" in my repo, which is a (rebased\n>     on master) \"js/cmake-updates\" plus the 9/9 here:\n>     https://github.com/avar/git/actions/runs/3294352976/jobs/5432095664\n> \n>     Some of those failures are due to orthagonal fixes here, e.g. you\n>     clearly haven't been testing cmake+ctest on Linux, or you'd have\n>     seen the issue 2/9 fixes, a lot of failures are due to a missing\n>     \"chmod +x\".\n> \n>     But others are due to e.g. your [2] missing a lot of cases. 3/9 and\n>     8/9 cover some of those, i.e. the Windows CI skips a lot of tests\n>     (e.g. all Perl + Python stuff), no libpcre2 etc. So a lot of\n>     failures were related to that.\n> \n>   * I also merged this with yours at\n>     https://github.com/avar/git/tree/avar/cmake-test-path-plus-js/cmake-updates\n> \n>     The --remerge-diff of the resulting merge commit is, with\n>     un-indented inline commentary:\n> \n> \tdiff --git a/.gitignore b/.gitignore\n> \tindex cb0231fb401..62720c6135d 100644\n> \t--- a/.gitignore\n> \t+++ b/.gitignore\n> \t@@ -1,5 +1,4 @@\n> \t /fuzz_corpora\n> \t-/GIT-BUILD-DIR\n> \t /GIT-BUILD-OPTIONS\n> \t /GIT-CFLAGS\n> \t /GIT-LDFLAGS\n> \tdiff --git a/Makefile b/Makefile\n> \tindex 9e3c4588e7d..d93ad956e58 100644\n> \t--- a/Makefile\n> \t+++ b/Makefile\n> \t@@ -3041,7 +3041,6 @@ else\n> \t \t@echo RUNTIME_PREFIX=\\'false\\' >>$@+\n> \t endif\n> \t \t@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi\n> \t-\t@if test -f GIT-BUILD-DIR; then rm GIT-BUILD-DIR; fi\n> \n> \n>     As yuo asked for: We can get what you want without\n>     GIT-BUILD-DIR. When we run via \"ctest\" we pass\n>     GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR}, and when we run ad-hoc the\n>     test-lib.sh checks \"contrib/buildsystems/out\" and uses it if we\n>     have a built git there, but not in ../git.\n> \n> \t ### Detect Python interpreter path changes\n> \t ifndef NO_PYTHON\n> \tdiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n> \tremerge CONFLICT (content): Merge conflict in contrib/buildsystems/CMakeLists.txt\n> \tindex bfc4d87026b..fafe6d9cb95 100644\n> \t--- a/contrib/buildsystems/CMakeLists.txt\n> \t+++ b/contrib/buildsystems/CMakeLists.txt\n> \t@@ -1081,24 +1081,6 @@ if(USE_VCPKG)\n> \t \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n> \t endif()\n> \n> \t-<<<<<<< b81f18dec61 (CI: add a \"linux-cmake-test\" to run cmake & ctest on linux)\n> \t-=======\n> \t-#Make the tests work when building out of the source tree\n> \t-get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n> \t-if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n> \t-\t#Setting the build directory in test-lib.sh before running tests\n> \t-\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n> \t-\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n> \t-\t#misc copies\n> \t-\tfile(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)\n> \t-\tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n> \t-\tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n> \t-\tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n> \t-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n> \t-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n> \t-endif()\n> \t-\n> \t->>>>>>> 27870f309d0 (cmake: increase time-out for a long-running test)\n> \t file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n> \n>     This whole \"copy stuff and munge test-lib.sh\" part is gone in my\n>     version. Rather than copy over mergetools/* the relevant tests know\n>     where to find it (it doesn't need to be built at all).\n> \n> \t #test\n> \t@@ -1106,11 +1088,7 @@ set(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n> \t separate_arguments(GIT_TEST_OPTS)\n> \t foreach(tsh ${test_scipts})\n> \t \tadd_test(NAME ${tsh}\n> \t-<<<<<<< b81f18dec61 (CI: add a \"linux-cmake-test\" to run cmake & ctest on linux)\n> \t-\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n> \t-=======\n> \t-\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n> \t->>>>>>> 27870f309d0 (cmake: increase time-out for a long-running test)\n> \t+\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx ${GIT_TEST_OPTS}\n> \t \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n> \t endforeach()\n> \n>     I did not include your \"--no-bin-wrappers --no-chain-lint -vx\"\n>     change.\n> \n>     As 7/9 here shows I pick up GIT_TEST_OPTS from the environment, so\n>     if you want to set these you can set them in the environment.\n> \n>     But your 1/5[3] adds these partially for speeding up things on\n>     Windows, but as this series shows this also runs on\n>     Linux. Therefore if we still want this I'd think we'd at least want\n>     to make it specific to that platform (per [4]).\n> \n> \tdiff --git a/t/test-lib.sh b/t/test-lib.sh\n> \tindex 333079d9127..284b619708a 100644\n> \t--- a/t/test-lib.sh\n> \t+++ b/t/test-lib.sh\n> \t@@ -69,16 +69,6 @@ then\n> \t \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n> \t \texit 1\n> \t fi\n> \t-if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n> \t-then\n> \t-\tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n> \t-\t# On Windows, we must convert Windows paths lest they contain a colon\n> \t-\tcase \"$(uname -s)\" in\n> \t-\t*MINGW*)\n> \t-\t\tGIT_BUILD_DIR=\"$(cygpath -au \"$GIT_BUILD_DIR\")\"\n> \t-\t\t;;\n> \t-\tesac\n> \t-fi\n> \n>     The changes I needed to the test-lib.sh are above this context.\n> \n> \t # Prepend a string to a VAR using an arbitrary \":\" delimiter, not\n> \t # adding the delimiter if VAR or VALUE is empty. I.e. a generalized:\n> \n>     Elided here is the inclusion of your 5/5[5], which didn't\n>     conflict. If we'd like to keep it it probably makes sense to make\n>     it Windows-specific too, I don't see that being needed on Linux.\n> \n>     Aside from this topic I'd be curious to know if you see the same\n>     slowdown with my [6], i.e. once git-submodule.sh has gone away. For\n>     me it's ~25% faster than \"master\", but I'd expect on a system with\n>     high fork overhead that would be a lot higher.\n> \n> 1. https://lore.kernel.org/git/pull.1320.v3.git.1666090745.gitgitgadget@gmail.com/\n> 2. https://lore.kernel.org/git/9faca9d5cbe706c00d03ca2a125f2e113294a548.1666090745.git.gitgitgadget@gmail.com/\n> 3. https://lore.kernel.org/git/356b2e9a1007bcd1382f26f333926ff0d5b9abe2.1666090745.git.gitgitgadget@gmail.com/\n> 4. https://lore.kernel.org/git/221018.865yghi6nv.gmgdl@evledraar.gmail.com/\n> 5. https://lore.kernel.org/git/40cf872f48386f8eca0fa814e4cdfb0ded915ed8.1666090745.git.gitgitgadget@gmail.com/\n> 6. https://lore.kernel.org/git/cover-00.10-00000000000-20221017T115544Z-avarab@gmail.com/\n> \n> Ævar Arnfjörð Bjarmason (9):\n>    cmake: don't copy chainlint.pl to build directory\n>    cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n>    cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n>    cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n>    test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n>    cmake: use GIT_TEST_BUILD_DIR instead of editing hack\n>    cmake: support using GIT_TEST_OPTS from the environment\n>    cmake: copy over git-p4.py for t983[56] perforce test\n>    CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n> \n>   .github/workflows/main.yml          |  3 +++\n>   ci/run-build-and-tests.sh           | 13 +++++++++--\n>   contrib/buildsystems/CMakeLists.txt | 33 +++++++++++----------------\n>   t/README                            |  3 +++\n>   t/lib-gettext.sh                    |  2 +-\n>   t/lib-gitweb.sh                     |  2 +-\n>   t/t7609-mergetool--lib.sh           |  2 +-\n>   t/t9902-completion.sh               | 14 ++++++------\n>   t/t9903-bash-prompt.sh              |  2 +-\n>   t/test-lib.sh                       | 35 +++++++++++++++++++++++++++--\n>   10 files changed, 74 insertions(+), 35 deletions(-)\n> \n"},{"id":"465466","messageId":"221021.86czalfda4.gmgdl@evledraar.gmail.com","threadId":"58666","inReplyTo":"0fda0e54-0432-7690-74a7-3d1a59923e0c@dunelm.org.uk","subject":"Re: [PATCH 2/9] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T14:43:07Z","receivedAt":"2022-10-21T14:43:24Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Oct 21 2022, Phillip Wood wrote:\n\n> Hi Ævar\n>\n> On 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n>> diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n>> index fd0c6ef4971..464c41a1fdf 100644\n>> --- a/contrib/buildsystems/CMakeLists.txt\n>> +++ b/contrib/buildsystems/CMakeLists.txt\n>> @@ -836,6 +836,7 @@ foreach(script ${git_shell_scripts})\n>>   \tstring(REPLACE \"@@PERL@@\" \"${PERL_PATH}\" content \"${content}\")\n>>   \tstring(REPLACE \"@@PAGER_ENV@@\" \"LESS=FRX LV=-c\" content \"${content}\")\n>>   \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n>> +\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n>\n> I think it would be nicer to add a write_script function\n>\n> function(write_script path content)\n>        file(WRITE ${path} ${content})\n>        file(CHMOD ${path} FILE_PERMISSIONS OWNER_READ OWNER_WRITE\n>        OWNER_EXECUTE)\n> endfunction()\n>\n> and then do\n>\n> -       file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n> +       write_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n>\n> rather than executing chmod each time\n\nThanks, I'll use that. It looks much nicer.\n"},{"id":"465479","messageId":"221021.868rl9faf2.gmgdl@evledraar.gmail.com","threadId":"58666","inReplyTo":"d6e2baab-be26-66d1-f07c-134eb6fe06fd@dunelm.org.uk","subject":"Re: [PATCH 6/9] cmake: use GIT_TEST_BUILD_DIR instead of editing hack","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T14:43:18Z","receivedAt":"2022-10-21T15:48:22Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Oct 21 2022, Phillip Wood wrote:\n\n> On 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n>> When cmake builds git in \"contrib/buildsystems/out\" it will create a\n>> \"t/\" directory there containing only the \"t/helper/test-tool\", but for\n>> running the tests with \"cmake\" it cd's to the \"real\" t/ directory, and\n>> runs the tests from there.\n>> To get the test-lib.sh to locate \"git\" and other binaries in\n>> \"../contrib/buildsystems/out/\" rather than \"../\" we have since [1]\n>> been editing the \"GIT_BUILD_DIR\" assignment in test-lib.sh in-place.\n>> This has meant that when testing cmake we've had to \"git reset\n>> --hard\"\n>> before running \"make\" again.\n>> What this build infrastructure really wanted was some feature like\n>> the\n>> \"GIT_TEST_BUILD_DIR\" variable added in the preceding commit, so let's\n>> make use of it.\n>\n> Lets squash that commit into this one, so we can see how it is used\n> when it is added.\n\nHeh, I did that to begin with, but found that the commit message &\nchange was too long & trying to explain two different things.\n\nSince GIT_TEST_BUILD_DIR (like GIT_TEST_INSTALLED) is something you can\nuse stand-alone I prefer to keep it this way. The commit message shows\nhow you can use it without anything to do with cmake, and then later\n(here) we can use it for cmake...\n\n>> Even though \"ctest\" will work with this approach, one advantage of the\n>> previous arrangement was that we could:\n>> \tA. Build with cmake\n>> \tB. cd t\n>> \tC. Run a test\n>> And have the test itself know to locate and use the cmake binaries,\n>> this workflow was documented in [2]. The \"t/test-lib\".sh modification\n>> here is so that we can support this use-case.\n>> As [3] notes \"contrib/buildsystems/out\" isn't just the directory\n>> that\n>> happens to be documented in \"contrib/buildsystems/CMakeLists.txt\", but\n>> the one that VS will use when building git.\n>\n> That may be the directory that VS uses when building git, but it is\n> possible to specify a different build directory when running cmake.\n\nPossible, but important enough to care? It's what it does by default,\nand we have /contrib/buildsystems/out in the top-level .gitignore.\n\nI could bring it back, basically the GIT-BUILD-DIR again, but is the\nedge case worth worrying about? This DWIM behavior of \"build with cmake,\ncd and run the the test\" is something I think we can safely assume is OK\nto restrict to the defaults.\n\nOnce you're off the defaults and e.g. want a dir in /run/user or\nwhatever it's also easy to set GIT_TEST_BUILD_DIR to that. The\n\"contrib/buildsystem/out\" assumption is just so it works by default\nwithout tweaking.\n\n>>   \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n>>   endif()\n>>   -#Make the tests work when building out of the source tree\n>> -get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n>> -if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n>> -\tfile(RELATIVE_PATH BUILD_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/CMakeCache.txt)\n>> -\tstring(REPLACE \"/CMakeCache.txt\" \"\" BUILD_DIR_RELATIVE ${BUILD_DIR_RELATIVE})\n>> -\t#Setting the build directory in test-lib.sh before running tests\n>> -\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n>> -\t\t\"file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \\\"GIT_BUILD_DIR=(.*)\\\")\\n\"\n>> -\t\t\"file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\\n\"\n>> -\t\t\"string(REPLACE \\\"\\${GIT_BUILD_DIR_REPL}\\\" \\\"GIT_BUILD_DIR=\\\\\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\\\\\"\\\" content \\\"\\${content}\\\")\\n\"\n>> -\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \\${content})\")\n>> -endif()\n>> -\n>>   file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n>>     #test\n>>   foreach(tsh ${test_scipts})\n>>   \tadd_test(NAME ${tsh}\n>> -\t\tCOMMAND ${SH_EXE} ${tsh}\n>> +\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh}\n>\n> I'm not sure about using env on windows, \n\nIn general, if it didn't work a lot of our test suite would fail, so\nit's definitely supported, and since this is only used to run tests it\nshould be OK with portability.\n\nBut I don't have a Windows dev environment other than the CI, are you\nable to test this & check if it works?\n\n> can we use ${SH_EXE} -c\n> instead to avoid creating an extra process?\n>\n> \tCOMMAND ${SH_EXE} -c [[GIT_TEST_BUILD_DIR=\"$1\"; . \"$2\"]]\n> \t\"${tsh}\" \"${CMAKE_BINARY_DIR}\" \"${tsh}\"\n\nNeat, so that \"[[...]]\" syntax makes sure we don't have any quoting\nissues?\n\n>\n>>   \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n>>   endforeach()\n>>   diff --git a/t/test-lib.sh b/t/test-lib.sh\n>> index 41b1ddc96ff..284b619708a 100644\n>> --- a/t/test-lib.sh\n>> +++ b/t/test-lib.sh\n>> @@ -47,9 +47,21 @@ fi\n>>   # its build directory.\n>>   GIT_SOURCE_DIR=\"${TEST_DIRECTORY%/t}\"\n>>   GIT_BUILD_DIR=\"$GIT_SOURCE_DIR\"\n>> +GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=\n>>   if test -n \"$GIT_TEST_BUILD_DIR\"\n>>   then\n>>   \tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n>> +elif ! test -x \"$GIT_BUILD_DIR/git\" &&\n>> +     test -x \"$GIT_BUILD_DIR/contrib/buildsystems/out/git\"\n>\n> I'm really not keen on hard coding the CMAKE_BINARY_DIR. One of the\n> positive things about dscho's approach is that it does not hard code\n> the build directory. I'm not convinced this approach is an\n> improvement.\n\nSee above.\n\nThanks for the careful review!\n"},{"id":"465480","messageId":"221021.864jvxfa3c.gmgdl@evledraar.gmail.com","threadId":"58666","inReplyTo":"830905ef-fb90-9b2a-c40a-67cf24f7a24b@dunelm.org.uk","subject":"Re: [PATCH 7/9] cmake: support using GIT_TEST_OPTS from the environment","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T15:45:34Z","receivedAt":"2022-10-21T15:52:26Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Oct 21 2022, Phillip Wood wrote:\n\n> Hi Ævar\n>\n> On 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n>> Get \"GIT_TEST_OPTS\" from the environment, and use it to pass arguments\n>> to tests. This allows for passing arguments to tests with e.g.:\n>> \tGIT_TEST_OPTS=\"--verbose --debug\" cmake .; ctest -R t0001\n>> --verbose\n>> There's some overlap with this and what was suggested in [1], but as\n>> noted there we're not passing \"--verbose\" and friends unconditionally,\n>> so a plain \"ctest\" invocation without a \"cmake\" re-build won't pick up\n>> the options.\n>\n> The aim of dscho's patch was to make debugging information available\n> in the test logs without the user having to do anything, now to get\n> that information every user has to set\n> GIT_TEST_OPTS=\"--no-bin-wrappers --no-chain-lint -vx\" when running\n> cmake.\n>\n> I think it would be helpful to have some default options set if the\n> user does not pass GIT_TEST_OPTS. Ideally one would be able to do\n>\n> \tGIT_TEST_OPTS=... ctest\n>\n> and have the tests pick up the options at runtime. Following on from\n> my previous comment, if we used \"sh -c\" to launch the tests we could\n> have something like\n>\n> \tCOMMAND ${SH_EXE} -c [[GIT_TEST_BUILD_DIR=\"$1\"; . \"$2\"\n> \t${GIT_TEST_OPTS:---no-bin-wrappers --no-chain-lint -vx}]]\n> \t\"${tsh}\" \"${CMAKE_BINARY_DIR}\" \"${tsh}\"\n\nThat sounds reasonable to me. FWIW I looked into\n$CTEST_INTERACTIVE_DEBUG_MODE for this purpose, i.e. to stick something\nlike this in test-lib.sh:\n\n\tif test -n \"$CTEST_INTERACTIVE_DEBUG_MODE\"\n\tthen\n\t\tverbose=t\n\t\ttrace=t\n\tfi\n\nBut I was hoping for some way to tell that \"ctest\" was in \"--verbose\"\nmode, but AFAICT there's no way to get at that without something like\ncompat/linux/procinfo.c (basically a fancier way of parsing \"ps auxf\").\n\nAnyway, as noted in my review of dscho's series I thought this part of\nit was odd/outdated given that this thing runs on Linux (mostly, but\nentirely after this series).\n\nI.e. why would we hardcode Windows-specific trade-offs into a portable\nbuild-system, and if you do want e.g. \"--no-bin-wrappers\" why would you\nwant that just when you run \"cmake\", not \"make\"? Surely if we're pushing\nfor a new default it should be agnostic to the user's build system.\n\nBut in any case I think if we're pushing for new (or cmake-specific)\nopinionated defaults it makes sense to split those up & justify them\nseparately from bug fixes or workarounds.\n\nE.g. 2/9 in this series makes much of the tests pass on *nix, but so\ndoes \"--no-bin-wrappers\", but just because it happens to bypass the\nbroken-on-master bin-wrappers/* made by cmake.\n\n"},{"id":"465481","messageId":"221021.86zgdpdud6.gmgdl@evledraar.gmail.com","threadId":"58666","inReplyTo":"49d65210-583b-67a2-1ad5-c7166e81396e@dunelm.org.uk","subject":"Re: [PATCH 0/9] cmake: fix *nix & general issues, no test-lib.sh editing, ctest in CI","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-21T15:55:11Z","receivedAt":"2022-10-21T16:17:19Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Oct 21 2022, Phillip Wood wrote:\n\n> On 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n>\n> I think this series contains a couple of interesting ideas[...]\n\nc'mon :) Getting it to a 100%[1] pass rate on *nix from 76%[2] & having\n\"ctest\" running in CI now is a bit more than an interesting idea :)\n\n> but I'm not sure hard coding the build directory or removing the\n> default test options are improvements on dscho's series.\n\nI replied to most of that in [3], but wanted to add that while I think\nit makes sense to get bugfixes for the system in first before behavior\nchanges (especially Makefile-divergent behavior changes) I'm not going\nto pick that particular hill to die on.\n\nSo if the consensus is that we want it too I'd be happy to bundle it all\ntogether in a way that one-to-one maps to the features / behavior\nchanges Johannes submitted (especially as he's short on time[4]).\n\nI started looking at this because I have changes locally that make the\nMakefile much faster by replacing all that FORCE shell-out stuff with\nbuilt-in Makefile functions, which really cuts down on the fixed cost of\nrunning \"make\" (really helpful in large interactive rebases).\n\nSneaking a \"while generating this file, let's remove this other file\"\ninto the Makefile dependency DAG is pretty much free as long as\neverything's a FORCE'd shellscript, but that approach would block\nrepresenting that data in Make's native way of viewing dependencies\n(which is much faster).\n\nBut anyway, if there's an insistance on the GIT-BUILD-DIR approach that\ncan be made to work with that also, in a way that I believe satisfies\nthe stated use-case.\n\n> Combining fixes for cmake and linux with changes for running ctest on\n> windows is not particularly helpful and would be better as two\n> separate series.\n\nI guess, in summary (G = general, N = *nix, W = Windows) fix:\n\n 1/9: G\n 2/9: N\n 3/9: G\n 5/9: G\n 6/9: G\n 7/9: G\n 8/9: G\n 9/9: G\n\nSo, aside from the \"chmod +x\" which we need on *nix it's all general\nfixes (and 9/9 while adding an Ubuntu job will stress CMake paths used\non Windows too).\n\n> We really need to have a clear policy of what the\n> status of building with cmake on linux is. I think having a usable\n> cmake build on linux could be useful for anyone making changes to\n> CMakeLists.txt as they can do some testing and debugging locally\n> before running our ci to check it works on windows but I'm not sure\n> we need to support it as an alternative to the Makefile.\n\nI wish we didn't have it at all, but I also don't use Windows/VS, or\nanything that benefits from cmake's IDE integration over plain old make,\nso it doesn't scratch my itch.\n\nI'm not advocating for removing it, mind you, that's just my knee-jerk\nreaction.\n\nBut I think it's clearly here to stay, so we're going to have to live\nwith it, and seemingly maintain both in perpetuity.\n\nGiven that it's staying, and that our answer to \"cmake is broken\" has by\ndefault been \"it needs fixing before the topic breaking it is merged\"\n(and not \"people who use this cmake contrib thing should fix it\neventually\") this series makes it *much* easier to deal with it for\nthose of us who use *nix for development.\n\nI had a few local topics that broke cmake in one minor way or another,\nwhich I knew about. But before this (and f31b6244950 (Merge branch\n'yw/cmake-updates', 2022-06-07) earlier this year) seeing why it was\nbreaking involved long ping-pongs with the GitHub Windows CI.\n\nBut once I got this working I could fix several of those issues in a\nfew minutes, because I could run the full cmake/ctest featureset\nlocally.\n\nSo I think this makes it much more useful, and as the above \"G/N/W\"\nsummary shows it's really not a burden to make CMakeLists.txt portable.\n\n1. https://github.com/avar/git/actions/runs/3294344038/jobs/5432094502#step:4:2787\n2. https://github.com/avar/git/actions/runs/3294352976/jobs/5432095664#step:4:2785\n3. https://lore.kernel.org/git/221021.864jvxfa3c.gmgdl@evledraar.gmail.com/\n4. https://lore.kernel.org/git/s42p6rn0-s5oo-2874-636p-2541n475p045@tzk.qr/\n\n>> On Tue, Oct 18 2022, Johannes Schindelin wrote:\n>> [For context:\n>> https://lore.kernel.org/git/on2q3qos-sr0n-0p8p-606p-5pq39n46qq4q@tzk.qr/\n>> is upthread of here, but spinning this off into another thread]\n>> \n>>>> Re my earlier feedback, I came up with this as an alternative, which\n>>>> nicely allows us to have \"cmake\" and \"make\" play together, you can even\n>>>> run them concurrently!:\n>>>>\n>>>>       https://github.com/avar/git/commit/30f2265fd07aee97ea66f6e84a824d85d241e245\n>>>\n>>> This approach _still_ modifies the `test-lib.sh`, which is the entire\n>>> reason for the patch under review.\n>>>\n>>> I hope you find an elegant, user-friendly alternative that leaves\n>>> `test-lib.sh` unmodified even when building via CMake. I would gladly take\n>>> that and drop my `GIT-BUILD-DIR` patch.\n>> You did ask for it :)\n>> To clarify, what I had upthread was a patch on the way towards a\n>> solution that didn't edit t/test-lib.sh at all, but that patch itself\n>> wasn't sufficient. It's the equivalent of 3/9 here.\n>> This series:\n>>   * Can be grabbed at\n>>     https://github.com/avar/git/tree/avar/cmake-test-path\n>>   * Conflicts with js/cmake-updates[1], although I've seen it go in\n>> &\n>>     out of {gitster,git}/seen (currently in gitster/seen, not in\n>>     git.git's \"seen\".\n>>     But the conflict is easily fixed to keep both, see below.\n>>   * Fixes numerous bugs in the current cmake recipe, running \"ctest\"\n>>     was a dumpster fire on Linux, after this with 9/9 we can run our\n>>     whole test suite in CI on ubuntu-latest:\n>>     https://github.com/avar/git/actions/runs/3293378319/jobs/5431721245\n>>   * Handles the case where you want to build with cmake and have\n>> \"(cd t\n>>     && ./t0001-init.sh)\" just work, i.e. we spot that we have a built\n>>     \"contrib/buildsystems/out\" and use that.\n>>   * I pushed out a \"js/cmake-update-ci\" in my repo, which is a\n>> (rebased\n>>     on master) \"js/cmake-updates\" plus the 9/9 here:\n>>     https://github.com/avar/git/actions/runs/3294352976/jobs/5432095664\n>>     Some of those failures are due to orthagonal fixes here,\n>> e.g. you\n>>     clearly haven't been testing cmake+ctest on Linux, or you'd have\n>>     seen the issue 2/9 fixes, a lot of failures are due to a missing\n>>     \"chmod +x\".\n>>     But others are due to e.g. your [2] missing a lot of cases. 3/9\n>> and\n>>     8/9 cover some of those, i.e. the Windows CI skips a lot of tests\n>>     (e.g. all Perl + Python stuff), no libpcre2 etc. So a lot of\n>>     failures were related to that.\n>>   * I also merged this with yours at\n>>     https://github.com/avar/git/tree/avar/cmake-test-path-plus-js/cmake-updates\n>>     The --remerge-diff of the resulting merge commit is, with\n>>     un-indented inline commentary:\n>> \tdiff --git a/.gitignore b/.gitignore\n>> \tindex cb0231fb401..62720c6135d 100644\n>> \t--- a/.gitignore\n>> \t+++ b/.gitignore\n>> \t@@ -1,5 +1,4 @@\n>> \t /fuzz_corpora\n>> \t-/GIT-BUILD-DIR\n>> \t /GIT-BUILD-OPTIONS\n>> \t /GIT-CFLAGS\n>> \t /GIT-LDFLAGS\n>> \tdiff --git a/Makefile b/Makefile\n>> \tindex 9e3c4588e7d..d93ad956e58 100644\n>> \t--- a/Makefile\n>> \t+++ b/Makefile\n>> \t@@ -3041,7 +3041,6 @@ else\n>> \t \t@echo RUNTIME_PREFIX=\\'false\\' >>$@+\n>> \t endif\n>> \t \t@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi\n>> \t-\t@if test -f GIT-BUILD-DIR; then rm GIT-BUILD-DIR; fi\n>> \n>>     As yuo asked for: We can get what you want without\n>>     GIT-BUILD-DIR. When we run via \"ctest\" we pass\n>>     GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR}, and when we run ad-hoc the\n>>     test-lib.sh checks \"contrib/buildsystems/out\" and uses it if we\n>>     have a built git there, but not in ../git.\n>> \t ### Detect Python interpreter path changes\n>> \t ifndef NO_PYTHON\n>> \tdiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n>> \tremerge CONFLICT (content): Merge conflict in contrib/buildsystems/CMakeLists.txt\n>> \tindex bfc4d87026b..fafe6d9cb95 100644\n>> \t--- a/contrib/buildsystems/CMakeLists.txt\n>> \t+++ b/contrib/buildsystems/CMakeLists.txt\n>> \t@@ -1081,24 +1081,6 @@ if(USE_VCPKG)\n>> \t \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n>> \t endif()\n>> \t-<<<<<<< b81f18dec61 (CI: add a \"linux-cmake-test\" to run\n>> cmake & ctest on linux)\n>> \t-=======\n>> \t-#Make the tests work when building out of the source tree\n>> \t-get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n>> \t-if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n>> \t-\t#Setting the build directory in test-lib.sh before running tests\n>> \t-\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n>> \t-\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n>> \t-\t#misc copies\n>> \t-\tfile(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)\n>> \t-\tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n>> \t-\tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n>> \t-\tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n>> \t-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n>> \t-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n>> \t-endif()\n>> \t-\n>> \t->>>>>>> 27870f309d0 (cmake: increase time-out for a long-running test)\n>> \t file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n>>     This whole \"copy stuff and munge test-lib.sh\" part is gone in my\n>>     version. Rather than copy over mergetools/* the relevant tests know\n>>     where to find it (it doesn't need to be built at all).\n>> \t #test\n>> \t@@ -1106,11 +1088,7 @@ set(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n>> \t separate_arguments(GIT_TEST_OPTS)\n>> \t foreach(tsh ${test_scipts})\n>> \t \tadd_test(NAME ${tsh}\n>> \t-<<<<<<< b81f18dec61 (CI: add a \"linux-cmake-test\" to run cmake & ctest on linux)\n>> \t-\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n>> \t-=======\n>> \t-\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n>> \t->>>>>>> 27870f309d0 (cmake: increase time-out for a long-running test)\n>> \t+\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx ${GIT_TEST_OPTS}\n>> \t \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n>> \t endforeach()\n>>     I did not include your \"--no-bin-wrappers --no-chain-lint -vx\"\n>>     change.\n>>     As 7/9 here shows I pick up GIT_TEST_OPTS from the environment,\n>> so\n>>     if you want to set these you can set them in the environment.\n>>     But your 1/5[3] adds these partially for speeding up things on\n>>     Windows, but as this series shows this also runs on\n>>     Linux. Therefore if we still want this I'd think we'd at least want\n>>     to make it specific to that platform (per [4]).\n>> \tdiff --git a/t/test-lib.sh b/t/test-lib.sh\n>> \tindex 333079d9127..284b619708a 100644\n>> \t--- a/t/test-lib.sh\n>> \t+++ b/t/test-lib.sh\n>> \t@@ -69,16 +69,6 @@ then\n>> \t \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n>> \t \texit 1\n>> \t fi\n>> \t-if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n>> \t-then\n>> \t-\tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n>> \t-\t# On Windows, we must convert Windows paths lest they contain a colon\n>> \t-\tcase \"$(uname -s)\" in\n>> \t-\t*MINGW*)\n>> \t-\t\tGIT_BUILD_DIR=\"$(cygpath -au \"$GIT_BUILD_DIR\")\"\n>> \t-\t\t;;\n>> \t-\tesac\n>> \t-fi\n>>     The changes I needed to the test-lib.sh are above this context.\n>> \t # Prepend a string to a VAR using an arbitrary \":\" delimiter,\n>> not\n>> \t # adding the delimiter if VAR or VALUE is empty. I.e. a generalized:\n>>     Elided here is the inclusion of your 5/5[5], which didn't\n>>     conflict. If we'd like to keep it it probably makes sense to make\n>>     it Windows-specific too, I don't see that being needed on Linux.\n>>     Aside from this topic I'd be curious to know if you see the same\n>>     slowdown with my [6], i.e. once git-submodule.sh has gone away. For\n>>     me it's ~25% faster than \"master\", but I'd expect on a system with\n>>     high fork overhead that would be a lot higher.\n>> 1. https://lore.kernel.org/git/pull.1320.v3.git.1666090745.gitgitgadget@gmail.com/\n>> 2. https://lore.kernel.org/git/9faca9d5cbe706c00d03ca2a125f2e113294a548.1666090745.git.gitgitgadget@gmail.com/\n>> 3. https://lore.kernel.org/git/356b2e9a1007bcd1382f26f333926ff0d5b9abe2.1666090745.git.gitgitgadget@gmail.com/\n>> 4. https://lore.kernel.org/git/221018.865yghi6nv.gmgdl@evledraar.gmail.com/\n>> 5. https://lore.kernel.org/git/40cf872f48386f8eca0fa814e4cdfb0ded915ed8.1666090745.git.gitgitgadget@gmail.com/\n>> 6. https://lore.kernel.org/git/cover-00.10-00000000000-20221017T115544Z-avarab@gmail.com/\n>> Ævar Arnfjörð Bjarmason (9):\n>>    cmake: don't copy chainlint.pl to build directory\n>>    cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n>>    cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n>>    cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n>>    test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n>>    cmake: use GIT_TEST_BUILD_DIR instead of editing hack\n>>    cmake: support using GIT_TEST_OPTS from the environment\n>>    cmake: copy over git-p4.py for t983[56] perforce test\n>>    CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n>>   .github/workflows/main.yml          |  3 +++\n>>   ci/run-build-and-tests.sh           | 13 +++++++++--\n>>   contrib/buildsystems/CMakeLists.txt | 33 +++++++++++----------------\n>>   t/README                            |  3 +++\n>>   t/lib-gettext.sh                    |  2 +-\n>>   t/lib-gitweb.sh                     |  2 +-\n>>   t/t7609-mergetool--lib.sh           |  2 +-\n>>   t/t9902-completion.sh               | 14 ++++++------\n>>   t/t9903-bash-prompt.sh              |  2 +-\n>>   t/test-lib.sh                       | 35 +++++++++++++++++++++++++++--\n>>   10 files changed, 74 insertions(+), 35 deletions(-)\n>> \n\n"},{"id":"465706","messageId":"a083087d-969c-55dd-2ac7-5aaf4e7c7ff6@dunelm.org.uk","threadId":"58666","inReplyTo":"221021.86zgdpdud6.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH 0/9] cmake: fix *nix & general issues, no test-lib.sh editing, ctest in CI","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-10-25T13:22:17Z","receivedAt":"2022-10-25T13:22:25Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 21/10/2022 16:55, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Fri, Oct 21 2022, Phillip Wood wrote:\n> \n>> On 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n>>\n>> I think this series contains a couple of interesting ideas[...]\n> \n> c'mon :) Getting it to a 100%[1] pass rate on *nix from 76%[2] & having\n> \"ctest\" running in CI now is a bit more than an interesting idea :)\n\nIt's certainly useful, I didn't think the fix which is \"make the scripts \nexecutable\" was particularly interesting. I'm more interested in the \nideas around making the tests run without editing them or writing \nGIT-BUILD-DIR and being able to change the arguments passed to tests \nwhen running ctest.\n\nBest Wishes\n\nPhillip\n"},{"id":"465707","messageId":"c3d27586-f5b5-4e3f-9cbb-8cd31ac8887e@dunelm.org.uk","threadId":"58666","inReplyTo":"221021.868rl9faf2.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH 6/9] cmake: use GIT_TEST_BUILD_DIR instead of editing hack","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-10-25T13:29:23Z","receivedAt":"2022-10-25T13:29:33Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 21/10/2022 15:43, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Fri, Oct 21 2022, Phillip Wood wrote:\n>> Lets squash that commit into this one, so we can see how it is used\n>> when it is added.\n> \n> Heh, I did that to begin with, but found that the commit message &\n> change was too long & trying to explain two different things.\n> \n> Since GIT_TEST_BUILD_DIR (like GIT_TEST_INSTALLED) is something you can\n> use stand-alone I prefer to keep it this way. The commit message shows\n> how you can use it without anything to do with cmake, and then later\n> (here) we can use it for cmake...\n\nWe're only adding it because we want to use it with cmake though and the \nonly way to see if the previous patch is correct is to start using it.\n\n>>>    file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n>>>      #test\n>>>    foreach(tsh ${test_scipts})\n>>>    \tadd_test(NAME ${tsh}\n>>> -\t\tCOMMAND ${SH_EXE} ${tsh}\n>>> +\t\tCOMMAND env GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR} ${SH_EXE} ${tsh}\n>>\n>> I'm not sure about using env on windows,\n> \n> In general, if it didn't work a lot of our test suite would fail, so\n> it's definitely supported, and since this is only used to run tests it\n> should be OK with portability.\n> \n> But I don't have a Windows dev environment other than the CI, are you\n> able to test this & check if it works?\n\nI keep meaning to set up a git build on windows but I haven't got round \nto it. Using \"sh -c\" also gives us more flexibility in later patches.\n\n>> can we use ${SH_EXE} -c\n>> instead to avoid creating an extra process?\n>>\n>> \tCOMMAND ${SH_EXE} -c [[GIT_TEST_BUILD_DIR=\"$1\"; . \"$2\"]]\n>> \t\"${tsh}\" \"${CMAKE_BINARY_DIR}\" \"${tsh}\"\n> \n> Neat, so that \"[[...]]\" syntax makes sure we don't have any quoting\n> issues?\n\nYes, it works like lua. \nhttps://cmake.org/cmake/help/latest/manual/cmake-language.7.html#bracket-argument\n\nBest Wishes\n\nPhillip\n"},{"id":"465708","messageId":"494668dc-9df0-ee20-1cc1-bd5f01d1dc19@dunelm.org.uk","threadId":"58666","inReplyTo":"221021.864jvxfa3c.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH 7/9] cmake: support using GIT_TEST_OPTS from the environment","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-10-25T13:38:09Z","receivedAt":"2022-10-25T13:38:20Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 21/10/2022 16:45, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Fri, Oct 21 2022, Phillip Wood wrote:\n> \n>> Hi Ævar\n>>\n>> On 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n>>> Get \"GIT_TEST_OPTS\" from the environment, and use it to pass arguments\n>>> to tests. This allows for passing arguments to tests with e.g.:\n>>> \tGIT_TEST_OPTS=\"--verbose --debug\" cmake .; ctest -R t0001\n>>> --verbose\n>>> There's some overlap with this and what was suggested in [1], but as\n>>> noted there we're not passing \"--verbose\" and friends unconditionally,\n>>> so a plain \"ctest\" invocation without a \"cmake\" re-build won't pick up\n>>> the options.\n>>\n>> The aim of dscho's patch was to make debugging information available\n>> in the test logs without the user having to do anything, now to get\n>> that information every user has to set\n>> GIT_TEST_OPTS=\"--no-bin-wrappers --no-chain-lint -vx\" when running\n>> cmake.\n>>\n>> I think it would be helpful to have some default options set if the\n>> user does not pass GIT_TEST_OPTS. Ideally one would be able to do\n>>\n>> \tGIT_TEST_OPTS=... ctest\n>>\n>> and have the tests pick up the options at runtime. Following on from\n>> my previous comment, if we used \"sh -c\" to launch the tests we could\n>> have something like\n>>\n>> \tCOMMAND ${SH_EXE} -c [[GIT_TEST_BUILD_DIR=\"$1\"; . \"$2\"\n>> \t${GIT_TEST_OPTS:---no-bin-wrappers --no-chain-lint -vx}]]\n>> \t\"${tsh}\" \"${CMAKE_BINARY_DIR}\" \"${tsh}\"\n> \n> That sounds reasonable to me. FWIW I looked into\n> $CTEST_INTERACTIVE_DEBUG_MODE for this purpose, i.e. to stick something\n> like this in test-lib.sh:\n> \n> \tif test -n \"$CTEST_INTERACTIVE_DEBUG_MODE\"\n> \tthen\n> \t\tverbose=t\n> \t\ttrace=t\n> \tfi\n\nI think it is useful to have -vx set even if we're not passing --verbose \nto ctest as if a test fails we've got the information to debug it stored \nin ctest's log without having to re-run the test.\n\n> But I was hoping for some way to tell that \"ctest\" was in \"--verbose\"\n> mode, but AFAICT there's no way to get at that without something like\n> compat/linux/procinfo.c (basically a fancier way of parsing \"ps auxf\").\n> \n> Anyway, as noted in my review of dscho's series I thought this part of\n> it was odd/outdated given that this thing runs on Linux (mostly, but\n> entirely after this series).\n> \n> I.e. why would we hardcode Windows-specific trade-offs into a portable\n> build-system, and if you do want e.g. \"--no-bin-wrappers\" why would you\n> want that just when you run \"cmake\", not \"make\"? Surely if we're pushing\n> for a new default it should be agnostic to the user's build system.\n> \n> But in any case I think if we're pushing for new (or cmake-specific)\n> opinionated defaults it makes sense to split those up & justify them\n> separately from bug fixes or workarounds.\n> \n> E.g. 2/9 in this series makes much of the tests pass on *nix, but so\n> does \"--no-bin-wrappers\", but just because it happens to bypass the\n> broken-on-master bin-wrappers/* made by cmake.\n\nI agree that --no-chain-lint --no-bin-wrappers are there just for \nwindows. We could quite easily add those just for windows builds but the \ncmake build is basically only there for windows and the linux support is \njust there to allow testing the cmake build without having to run the ci.\n\nBest Wishes\n\nPhillip\n"},{"id":"465730","messageId":"221025.86bkpzd4i0.gmgdl@evledraar.gmail.com","threadId":"58666","inReplyTo":"494668dc-9df0-ee20-1cc1-bd5f01d1dc19@dunelm.org.uk","subject":"Re: [PATCH 7/9] cmake: support using GIT_TEST_OPTS from the environment","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-25T20:18:08Z","receivedAt":"2022-10-25T20:37:18Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Tue, Oct 25 2022, Phillip Wood wrote:\n\n> On 21/10/2022 16:45, Ævar Arnfjörð Bjarmason wrote:\n>> On Fri, Oct 21 2022, Phillip Wood wrote:\n>> \n>>> Hi Ævar\n>>>\n>>> On 21/10/2022 10:44, Ævar Arnfjörð Bjarmason wrote:\n>>>> Get \"GIT_TEST_OPTS\" from the environment, and use it to pass arguments\n>>>> to tests. This allows for passing arguments to tests with e.g.:\n>>>> \tGIT_TEST_OPTS=\"--verbose --debug\" cmake .; ctest -R t0001\n>>>> --verbose\n>>>> There's some overlap with this and what was suggested in [1], but as\n>>>> noted there we're not passing \"--verbose\" and friends unconditionally,\n>>>> so a plain \"ctest\" invocation without a \"cmake\" re-build won't pick up\n>>>> the options.\n>>>\n>>> The aim of dscho's patch was to make debugging information available\n>>> in the test logs without the user having to do anything, now to get\n>>> that information every user has to set\n>>> GIT_TEST_OPTS=\"--no-bin-wrappers --no-chain-lint -vx\" when running\n>>> cmake.\n>>>\n>>> I think it would be helpful to have some default options set if the\n>>> user does not pass GIT_TEST_OPTS. Ideally one would be able to do\n>>>\n>>> \tGIT_TEST_OPTS=... ctest\n>>>\n>>> and have the tests pick up the options at runtime. Following on from\n>>> my previous comment, if we used \"sh -c\" to launch the tests we could\n>>> have something like\n>>>\n>>> \tCOMMAND ${SH_EXE} -c [[GIT_TEST_BUILD_DIR=\"$1\"; . \"$2\"\n>>> \t${GIT_TEST_OPTS:---no-bin-wrappers --no-chain-lint -vx}]]\n>>> \t\"${tsh}\" \"${CMAKE_BINARY_DIR}\" \"${tsh}\"\n>> That sounds reasonable to me. FWIW I looked into\n>> $CTEST_INTERACTIVE_DEBUG_MODE for this purpose, i.e. to stick something\n>> like this in test-lib.sh:\n>> \tif test -n \"$CTEST_INTERACTIVE_DEBUG_MODE\"\n>> \tthen\n>> \t\tverbose=t\n>> \t\ttrace=t\n>> \tfi\n>\n> I think it is useful to have -vx set even if we're not passing\n> --verbose to ctest[...]\n\nYeah, and to clarify, that's basically what this is, i.e. you don't need\nto pass --verbose.\n\n> [...] as if a test fails we've got the information to debug it stored\n> in ctest's log without having to re-run the test.\n\nYes, that's sounds useful, but I'm still entirely unclear on why that\nneeds to be build-system specific.\n\nI.e. you'll have the same with \"make test\" and \"--verbose-log\", with\nctest the equivalent of a hypothetical \"--tee-to-al-log\" is the default,\nso we're partway towards a \"--verbose-log\".\n\nIs it just an omission and we should add it to t/Makefile and/or\nt/test-lib.sh eventually, or something cmake/ctest-specific in some way\nI don't get?\n\n>> But I was hoping for some way to tell that \"ctest\" was in \"--verbose\"\n>> mode, but AFAICT there's no way to get at that without something like\n>> compat/linux/procinfo.c (basically a fancier way of parsing \"ps auxf\").\n>> Anyway, as noted in my review of dscho's series I thought this part\n>> of\n>> it was odd/outdated given that this thing runs on Linux (mostly, but\n>> entirely after this series).\n>> I.e. why would we hardcode Windows-specific trade-offs into a\n>> portable\n>> build-system, and if you do want e.g. \"--no-bin-wrappers\" why would you\n>> want that just when you run \"cmake\", not \"make\"? Surely if we're pushing\n>> for a new default it should be agnostic to the user's build system.\n>> But in any case I think if we're pushing for new (or cmake-specific)\n>> opinionated defaults it makes sense to split those up & justify them\n>> separately from bug fixes or workarounds.\n>> E.g. 2/9 in this series makes much of the tests pass on *nix, but so\n>> does \"--no-bin-wrappers\", but just because it happens to bypass the\n>> broken-on-master bin-wrappers/* made by cmake.\n>\n> I agree that --no-chain-lint --no-bin-wrappers are there just for\n> windows. We could quite easily add those just for windows builds but\n> the cmake build is basically only there for windows and the linux\n> support is just there to allow testing the cmake build without having\n> to run the ci.\n\nThat part makes sense.\n"},{"id":"465851","messageId":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-0.9-00000000000-20221021T091013Z-avarab@gmail.com","subject":"[PATCH v2 00/11] cmake: document, fix on *nix, add CI","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:41Z","receivedAt":"2022-10-27T03:27:07Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This topig gets our tests from passing ~80% with ctest on *nix to\npassing 100%. Now on top of next's js/cmake-updates. Comments inline\non patches:n\n\nÆvar Arnfjörð Bjarmason (11):\n  cmake: don't \"mkdir -p\" and \"cd\" in build instructions\n  cmake: update instructions for portable CMakeLists.txt\n\nThese are new, and document how to use cmake+ctest, and make the\ninstructions more OS-agnostic.\n\n  cmake: don't copy chainlint.pl to build directory\n\nSame, except to rebase on js/cmake-updates.\n\n  cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n\nI tried to use the suggested \"write_script\" function, but couldn't get\npast cmake quoting issues. So the commit message is updated, but the\nchange is the same.\n\n  cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n  cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n  test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n  Makefile + cmake: use environment, not GIT-BUILD-DIR\n\nGeneralize the whole \"test a build dir over there\", and have cmake &\nmake not step on each other's toes.\n\n  cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n\nThe test param defaults in js/cmake-updates are kept on Windows, all\nplatforms benefit from having an easier way to provide custom test\noptions.\n\n  cmake: copy over git-p4.py for t983[56] perforce test\n\nNow at 101% tests passing :)\n\n  CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n\nSee the CI (and topic itself) at https://github.com/avar/git/actions/runs/3333306724/jobs/5515607569\n\n .github/workflows/main.yml          |   3 +\n .gitignore                          |   1 -\n Makefile                            |   1 -\n ci/run-build-and-tests.sh           |  13 ++-\n contrib/buildsystems/CMakeLists.txt | 133 +++++++++++++++++++++-------\n t/README                            |   3 +\n t/lib-gettext.sh                    |   2 +-\n t/lib-gitweb.sh                     |   2 +-\n t/t7609-mergetool--lib.sh           |   2 +-\n t/t9902-completion.sh               |  14 +--\n t/t9903-bash-prompt.sh              |   2 +-\n t/test-lib.sh                       |  27 +++++-\n 12 files changed, 152 insertions(+), 51 deletions(-)\n\nRange-diff against v1:\n 1:  16c99177e6d <  -:  ----------- cmake: don't copy chainlint.pl to build directory\n -:  ----------- >  1:  667a2bd5271 cmake: don't \"mkdir -p\" and \"cd\" in build instructions\n -:  ----------- >  2:  9e2470dcb95 cmake: update instructions for portable CMakeLists.txt\n -:  ----------- >  3:  2d7d9742a73 cmake: don't copy chainlint.pl to build directory\n 2:  2c1d194e590 !  4:  ea8a3feec81 cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n    @@ Metadata\n      ## Commit message ##\n         cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n     \n    -    The cmake recipe added in [1] did not create the bin-wrappers/*\n    -    directory, and thus fell back on running the tests with the equivalent\n    -    of \"--no-bin-wrappers\".\n    +    Since the cmake file was made to run on *nix in [1] running the tests\n    +    with \"ctest\" broken, because we'd attempt to invoke our bin-wrappers/,\n    +    but they didn't have the executable bit.\n     \n    -    Thus the. \"t/test-lib.sh\" would be unable to find \"bin-wrappers/git\",\n    -    and we'd fall back on \"GIT_EXEC_PATH=$GIT_BUILD_DIR\" using the\n    -    fallback behavior added in [2]:\n    +    In the best case, the \"t/test-lib.sh\" would be unable to find\n    +    \"bin-wrappers/git\", and we'd fall back on\n    +    \"GIT_EXEC_PATH=$GIT_BUILD_DIR\" using the fallback behavior added in\n    +    [2]:\n     \n                 $ ./t0001-init.sh\n                 <GIT_BUILD_DIR>/t/../contrib/buildsystems/out/bin-wrappers/git is not executable; using GIT_EXEC_PATH\n     \n    -    Or rather, this is what would have happened on *nix, but until [3]\n    -    there wasn't any non-Windows support for \"cmake\". On Windows it didn't\n    -    matter that the bin-wrappers weren't made executable, since there's no\n    -    executable bit, instead the emulation layer looks at whether a file\n    -    has a shebang.\n    +    This was recently somewhat swept under the rug in [3], as ctest would\n    +    run them with \"--no-bin-wrappers\". But still with [3], running e.g.:\n     \n    -    But with [3] we've effectively used the semi-equivalent of\n    -    \"--no-bin-wrappers\" unintentionally on *nix, and furthermore because\n    -    we didn't make these executable\n    +            cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Debug &&\n    +            make -C contrib/buildsystems/out &&\n    +            ctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\" --output-on-failure\n     \n    -    In addition, we'd fail any test that needed to invoke one of our built\n    -    shell, perl or Python scripts on *nix. E.g. t0012-help.sh would fail\n    -    on a test that tried to invoke \"git web--browse\". I.e. the equivalent\n    -    of this (in the \"out\" directory) would happen:\n    +    Fails around 20% of our testts on *nix. So even with [3] we'd fail any\n    +    test that needed to invoke one of our built shell, perl or Python\n    +    scripts on *nix. E.g. t0012-help.sh would fail on a test that tried to\n    +    invoke \"git web--browse\". The equivalent of this (in the \"out\"\n    +    directory) would happen:\n     \n                 $ ./git --exec-path=$PWD web--browse\n                 git: 'web--browse' is not a git command. See 'git --help'.\n    @@ Commit message\n                 usage: git web--browse [--browser=browser|--tool=browser] [--config=conf.var] url/file ...\n     \n         The same goes for e.g. the \"git-p4\" tests, which would fail because\n    -    our built \"git-p4\" wasn't executable, etc.\n    +    our built \"git-p4\" wasn't executable, etc. There's also a few other\n    +    outstanding issues, which will be fixed in subsequent commits.\n     \n    -    This change should ideally use file(CHMOD ...), but that's much newer\n    -    than our required cmake version[1].\n    +    This change should ideally use file(CHMOD ...), but the \"file(CHMOD\"\n    +    feature is much newer than our required cmake version[5].\n     \n    -    1. a30e4c531d9 (Merge branch 'ss/cmake-build', 2020-08-11)\n    +    Before this change:\n    +\n    +            80% tests passed, 196 tests failed out of 977\n    +\n    +    After:\n    +\n    +            99% tests passed, 5 tests failed out of 977\n    +\n    +    The remaining failures will be addressed in subsequent commits.\n    +\n    +    There was a suggestion of using a function to abstract this away[6],\n    +    which sounds good. But after spending too long trying to get all\n    +    combinations of \"${content}\" and ${content} (unqoted) in the function\n    +    and its callers working I wasn't able to fix the quoting issues it\n    +    introduced.\n    +\n    +    A lot of this is duplicated already, we can follow-up at some other\n    +    time with refactoring, and address any tricky quoting issues in\n    +    calling function with these parameters then.\n    +\n    +    1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n         2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n    -    3. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n    -    4. https://cmake.org/cmake/help/latest/command/file.html#chmod\n    +    3. 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n    +       runs, 2022-10-18)\n    +    4. a30e4c531d9 (Merge branch 'ss/cmake-build', 2020-08-11)\n    +    5. https://cmake.org/cmake/help/latest/command/file.html#chmod\n    +    6. https://lore.kernel.org/git/0fda0e54-0432-7690-74a7-3d1a59923e0c@dunelm.org.uk/\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n 3:  addaf73992f !  5:  6387682db06 cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n    @@ Commit message\n         recipe has needed to copy various assets to that\n         \"contrib/buildsystems/out\" directory.\n     \n    -    Let's instead teach the test-lib.sh that there's such a thing as the\n    -    \"$GIT_SOURCE_DIR\" distinct from the \"$GIT_BUILD_DIR\".\n    +    But we've only been doing this for the subsets of tests that run on\n    +    Windows, and which have otherwise been covered by that CI target. The\n    +    CI target builds (among other things) with \"-DPERL_TESTS=OFF\n    +    -DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON\", see [1]. Furthermore, the\n    +    CI isn't testing from the \"contrib/buildsystems/out\" directory,\n    +    instead it clobbers the top-level MAkefile.\n    +\n    +    There was a recent commit to fix a subset of these issues, see\n    +    6a83b5f0810 (cmake: copy the merge tools for testing, 2022-10-18).\n    +\n    +    Let's stop going for that approach, and instead teach the test-lib.sh\n    +    that there's such a thing as the \"$GIT_SOURCE_DIR\" distinct from the\n    +    \"$GIT_BUILD_DIR\".\n     \n         Just as the \"$TEST_DIRECTORY\" always points to our actual \"t\"\n         directory (not the \"[...]/out/t\" cmake creates), this new\n         \"$GIT_SOURCE_DIR\" will always be the top-level source directory.\n     \n    -    So even though the \"GIT_BUILD_DIR=(.*)\" line in t/test-lib.sh will\n    -    still be altered by CMakeLists.txt, that recipe will no longer need to\n    -    copy over various things from our source directory, as the tests now\n    -    know where to find those assets.\n    +    With this change we now pass 3/5 of the tests that we still had\n    +    failing with the fixes in the preceding commit.\n    +\n    +    1. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n    +       job, 2020-06-26)\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n      ## contrib/buildsystems/CMakeLists.txt ##\n     @@ contrib/buildsystems/CMakeLists.txt: if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n    - \t\t\"file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\\n\"\n    - \t\t\"string(REPLACE \\\"\\${GIT_BUILD_DIR_REPL}\\\" \\\"GIT_BUILD_DIR=\\\\\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\\\\\"\\\" content \\\"\\${content}\\\")\\n\"\n    - \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \\${content})\")\n    + \t#Setting the build directory in test-lib.sh before running tests\n    + \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n    + \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n     -\t#misc copies\n     -\tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n    --\tfile(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n    +-\tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n    +-\tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n     -\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n     -\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n      endif()\n    @@ t/t9903-bash-prompt.sh: export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n     \n      ## t/test-lib.sh ##\n     @@ t/test-lib.sh: then\n    - \t# elsewhere\n    - \tTEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY\n    + \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n    + \texit 1\n      fi\n    --GIT_BUILD_DIR=\"${TEST_DIRECTORY%/t}\"\n    -+\n    -+# The GIT_{SOURCE,BUILD}_DIR is always the same, except when\n    -+# CMakeLists.txt replaces the \"GIT_BUILD_DIR\" line with the path to\n    -+# its build directory.\n    -+GIT_SOURCE_DIR=\"${TEST_DIRECTORY%/t}\"\n    -+GIT_BUILD_DIR=\"$GIT_SOURCE_DIR\"\n     +\n    - if test \"$TEST_DIRECTORY\" = \"$GIT_BUILD_DIR\"\n    ++# For CMake the top-level source directory is different from our build\n    ++# directory. With the top-level Makefile they're the same.\n    ++GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n    + if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n      then\n    - \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n    + \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n     @@ t/test-lib.sh: then\n      \t\tmake_valgrind_symlink $file\n      \tdone\n 4:  52cd674d5b8 !  6:  29a9811857f cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n    @@ Commit message\n         on the behavior of !PCRE2. The reason this hasn't been noticed is that\n         the Windows CI doesn't have access to libpcre2.\n     \n    +    With this the remaining two failures we had left after the preceding\n    +    step are resolved, but note that that test run didn't include the\n    +    git-p4 tests, which a subsequent commit will address).\n    +\n         1. 80431510a2b (cmake: add pcre2 support, 2022-05-24)\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n 5:  6199a913c0a !  7:  a9ea3867f5f test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n    @@ Commit message\n                 [apply this change to git2]\n                 (cd git2 && GIT_TEST_BUILD_DIR=\"$PWD/../git1\" make -C t prove)\n     \n    +    This facility and file-based instructions to have the test suite use\n    +    another build directory[2] are mutually exclusive, but in a subsequent\n    +    commit we'll make CMake use this instead.\n    +\n         1. 6720721e152 (test-lib.sh: Allow running the test suite against\n            installed git, 2009-03-16)\n    +    2. 350a005e366 (cmake: avoid editing t/test-lib.sh, 2022-10-18)\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n    @@ t/README: override the location of the dashed-form subcommands (what\n     \n      ## t/test-lib.sh ##\n     @@ t/test-lib.sh: fi\n    - # its build directory.\n    - GIT_SOURCE_DIR=\"${TEST_DIRECTORY%/t}\"\n    - GIT_BUILD_DIR=\"$GIT_SOURCE_DIR\"\n    + # For CMake the top-level source directory is different from our build\n    + # directory. With the top-level Makefile they're the same.\n    + GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n    +-if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n     +if test -n \"$GIT_TEST_BUILD_DIR\"\n     +then\n     +\tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n    -+fi\n    - \n    - if test \"$TEST_DIRECTORY\" = \"$GIT_BUILD_DIR\"\n    ++elif test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n      then\n    + \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n    + \t# On Windows, we must convert Windows paths lest they contain a colon\n 6:  45f1a4e6f93 <  -:  ----------- cmake: use GIT_TEST_BUILD_DIR instead of editing hack\n 7:  fc9f036695f <  -:  ----------- cmake: support using GIT_TEST_OPTS from the environment\n -:  ----------- >  8:  51bb01b99d4 Makefile + cmake: use environment, not GIT-BUILD-DIR\n -:  ----------- >  9:  9f5276d79c9 cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n 8:  56102c2a4bf = 10:  ef6a304368c cmake: copy over git-p4.py for t983[56] perforce test\n 9:  b81f18dec61 = 11:  158a41ca7a4 CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465852","messageId":"patch-v2-01.11-667a2bd5271-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 01/11] cmake: don't \"mkdir -p\" and \"cd\" in build instructions","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:42Z","receivedAt":"2022-10-27T03:27:12Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Use the \"-S\" and -B\" flags instead of \"mkdir -p\" and \"cd\". The \"-p\"\nflag to \"mkdir\" wasn't needed as \"contrib/buildsystems\" is tracked,\nand the rest of this is now easier to copy/paste into a shell without\nhaving one's directory changed.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 3957e4cf8cd..494da807c53 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -16,9 +16,7 @@ though, therefore the `File>Open>Folder...` option is preferred.\n \n Instructions to run CMake manually:\n \n-    mkdir -p contrib/buildsystems/out\n-    cd contrib/buildsystems/out\n-    cmake ../ -DCMAKE_BUILD_TYPE=Release\n+    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n \n This will build the git binaries in contrib/buildsystems/out\n directory (our top-level .gitignore file knows to ignore contents of\n@@ -36,8 +34,8 @@ NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual St\n this option is ignored\n \n This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n-Run `make` to build Git on Linux/*BSD/MacOS.\n-Open git.sln on Windows and build Git.\n+Run `make -C contrib/buildsystems` to build Git on Linux/*BSD/MacOS.\n+Open contrib/buildsystems/git.sln on Windows and build Git.\n \n NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n to use another tool say `ninja` add this to the command line when configuring.\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465853","messageId":"patch-v2-02.11-9e2470dcb95-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 02/11] cmake: update instructions for portable CMakeLists.txt","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:43Z","receivedAt":"2022-10-27T03:27:16Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The instructions for running CMake went back & forth between *nix,\nWindows and Visual Studio instructions Let's create headings and split\nthe existing instructions up into those new sections.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 66 +++++++++++++++++++++--------\n 1 file changed, 48 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 494da807c53..a76a3c46767 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -4,7 +4,48 @@\n \n #[[\n \n-Instructions how to use this in Visual Studio:\n+== Overview ==\n+\n+The top-level Makefile is Git's primary build environment, and a lot\n+of things are missing (and probably always will be) from this CMake\n+alternative.\n+\n+The primary use-case for maintaining this CMake build recipe is to\n+have nicer IDE integration on Windows. To get Visual Studio-specific\n+instructions see \"== Visual Studio & Windows ==\" below.\n+\n+== Creating a build recipe ==\n+\n+To create the build recipe run:\n+\n+    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n+\n+For alternative \"-DCMAKE_BUILD_TYPE=<type>\" flags see instructions\n+under the \"== -DCMAKE_BUILD_TYPE=<type> ==\" heading below.\n+\n+== Building ==\n+\n+One the recipe is created a build recipe will be created. For Windows\n+Open contrib/buildsystems/git.sln on Windows and build Git. Or use the\n+\"msbuild\" command-line tool (see our own \".github/workflows/main.yml\"\n+for a real example):\n+\n+\tmsbuild git.sln\n+\n+On all other platforms running \"cmake\" will generate a Makefile, to\n+build with it run:\n+\n+\tmake -C contrib/buildsystems/out\n+\n+It's also possible to use other generators, e.g. Ninja has arguably\n+slightly better output. Add \"-G Ninja\" to the cmake command above,\n+then e.g.:\n+\n+\tninja -C contrib/buildsystems/out\n+\n+== Visual Studio & Windows ==\n+\n+To use this in Visual Studio:\n \n Open the worktree as a folder. Visual Studio 2019 and later will detect\n the CMake configuration automatically and set everything up for you,\n@@ -14,14 +55,15 @@ Note: Visual Studio also has the option of opening `CMakeLists.txt`\n directly; Using this option, Visual Studio will not find the source code,\n though, therefore the `File>Open>Folder...` option is preferred.\n \n-Instructions to run CMake manually:\n-\n-    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n-\n-This will build the git binaries in contrib/buildsystems/out\n+Following the instructions above will build the git binaries in the contrib/buildsystems/out\n directory (our top-level .gitignore file knows to ignore contents of\n this directory).\n \n+By default CMake will install vcpkg locally to your source tree on configuration,\n+to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n+\n+== -DCMAKE_BUILD_TYPE=<type> ==\n+\n Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding\n compiler flags\n Debug : -g\n@@ -32,18 +74,6 @@ empty(default) :\n \n NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n this option is ignored\n-\n-This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n-Run `make -C contrib/buildsystems` to build Git on Linux/*BSD/MacOS.\n-Open contrib/buildsystems/git.sln on Windows and build Git.\n-\n-NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n-to use another tool say `ninja` add this to the command line when configuring.\n-`-G Ninja`\n-\n-NOTE: By default CMake will install vcpkg locally to your source tree on configuration,\n-to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n-\n ]]\n cmake_minimum_required(VERSION 3.14)\n \n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465854","messageId":"patch-v2-03.11-2d7d9742a73-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 03/11] cmake: don't copy chainlint.pl to build directory","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:44Z","receivedAt":"2022-10-27T03:27:17Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When [1] made this copy of \"chainlint.sed\" the script was invoked in\nthe test-lib.sh as:\n\n\t[...] sed -f \"$GIT_BUILD_DIR/t/chainlint.sed\" [...]\n\nBut when [2] replaced \"chainlint.sed\" with a \"chainlint.pl\" it also\nreplaced that \"$GIT_BUILD_DIR\" with \"$TEST_DIRECTORY\", invoking it as:\n\n\t\"$PERL_PATH\" \"$TEST_DIRECTORY/chainlint.pl\" \"$0\"\n\nSo this line could have been deleted in [2] but wasn't. Let's do that\nnow.\n\n1. 7f5397a07c6 (cmake: support for testing git when building out of\n   the source tree, 2020-06-26)\n2. 23a14f30166 (test-lib: replace chainlint.sed with chainlint.pl,\n   2022-09-01)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex a76a3c46767..4db4997ff0c 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1106,7 +1106,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n \t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)\n \tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n \tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n \tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465855","messageId":"patch-v2-05.11-6387682db06-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 05/11] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:46Z","receivedAt":"2022-10-27T03:27:22Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When git is built and tested with cmake & ctest we usually do that\noutside of the top-level source directory. E.g.\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out\n\tmake -C contrib/buildsystems/out\n\tctest -j$(nproc) --test-dir contrib/buildsystems/out\n\nSince the test-lib.sh makes assumptions about the TEST_DIRECTORY being\nthe \"t\" subdirectory of the top-level \"$GIT_BUILD_DIR\", the cmake\nrecipe has needed to copy various assets to that\n\"contrib/buildsystems/out\" directory.\n\nBut we've only been doing this for the subsets of tests that run on\nWindows, and which have otherwise been covered by that CI target. The\nCI target builds (among other things) with \"-DPERL_TESTS=OFF\n-DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON\", see [1]. Furthermore, the\nCI isn't testing from the \"contrib/buildsystems/out\" directory,\ninstead it clobbers the top-level MAkefile.\n\nThere was a recent commit to fix a subset of these issues, see\n6a83b5f0810 (cmake: copy the merge tools for testing, 2022-10-18).\n\nLet's stop going for that approach, and instead teach the test-lib.sh\nthat there's such a thing as the \"$GIT_SOURCE_DIR\" distinct from the\n\"$GIT_BUILD_DIR\".\n\nJust as the \"$TEST_DIRECTORY\" always points to our actual \"t\"\ndirectory (not the \"[...]/out/t\" cmake creates), this new\n\"$GIT_SOURCE_DIR\" will always be the top-level source directory.\n\nWith this change we now pass 3/5 of the tests that we still had\nfailing with the fixes in the preceding commit.\n\n1. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt |  6 ------\n t/lib-gettext.sh                    |  2 +-\n t/lib-gitweb.sh                     |  2 +-\n t/t7609-mergetool--lib.sh           |  2 +-\n t/t9902-completion.sh               | 14 +++++++-------\n t/t9903-bash-prompt.sh              |  2 +-\n t/test-lib.sh                       |  8 +++++++-\n 7 files changed, 18 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 1ae6832dc26..1c271395ed0 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1111,12 +1111,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \t#Setting the build directory in test-lib.sh before running tests\n \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n-\t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n-\tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n-\tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\ndiff --git a/t/lib-gettext.sh b/t/lib-gettext.sh\nindex cc6bb2cdeaa..dcd6e9c3f75 100644\n--- a/t/lib-gettext.sh\n+++ b/t/lib-gettext.sh\n@@ -7,7 +7,7 @@\n . ./test-lib.sh\n \n GIT_TEXTDOMAINDIR=\"$GIT_BUILD_DIR/po/build/locale\"\n-GIT_PO_PATH=\"$GIT_BUILD_DIR/po\"\n+GIT_PO_PATH=\"$GIT_SOURCE_DIR/po\"\n export GIT_TEXTDOMAINDIR GIT_PO_PATH\n \n if test -n \"$GIT_TEST_INSTALLED\"\ndiff --git a/t/lib-gitweb.sh b/t/lib-gitweb.sh\nindex 1f32ca66ea5..6f68df247af 100644\n--- a/t/lib-gitweb.sh\n+++ b/t/lib-gitweb.sh\n@@ -49,7 +49,7 @@ EOF\n \t\terror \"Cannot find gitweb at $GITWEB_TEST_INSTALLED.\"\n \t\tsay \"# Testing $SCRIPT_NAME\"\n \telse # normal case, use source version of gitweb\n-\t\tSCRIPT_NAME=\"$GIT_BUILD_DIR/gitweb/gitweb.perl\"\n+\t\tSCRIPT_NAME=\"$GIT_SOURCE_DIR/gitweb/gitweb.perl\"\n \tfi\n \texport SCRIPT_NAME\n }\ndiff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh\nindex 8b1c3bd39f2..2090d12a489 100755\n--- a/t/t7609-mergetool--lib.sh\n+++ b/t/t7609-mergetool--lib.sh\n@@ -8,7 +8,7 @@ TEST_PASSES_SANITIZE_LEAK=true\n . ./test-lib.sh\n \n test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '\n-\t. \"$GIT_BUILD_DIR\"/mergetools/vimdiff &&\n+\t. \"$GIT_SOURCE_DIR\"/mergetools/vimdiff &&\n \trun_unit_tests\n '\n \ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 43de868b800..1bd4cae92fe 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -33,7 +33,7 @@ complete ()\n GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'\n GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\"\n \n # We don't need this function to actually join words or do anything special.\n # Also, it's cleaner to avoid touching bash's internal completion variables.\n@@ -2567,7 +2567,7 @@ test_expect_success 'sourcing the completion script clears cached commands' '\n \t(\n \t\t__git_compute_all_commands &&\n \t\tverbose test -n \"$__git_all_commands\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_all_commands\"\n \t)\n '\n@@ -2576,7 +2576,7 @@ test_expect_success 'sourcing the completion script clears cached merge strategi\n \t(\n \t\t__git_compute_merge_strategies &&\n \t\tverbose test -n \"$__git_merge_strategies\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_merge_strategies\"\n \t)\n '\n@@ -2587,7 +2587,7 @@ test_expect_success 'sourcing the completion script clears cached --options' '\n \t\tverbose test -n \"$__gitcomp_builtin_checkout\" &&\n \t\t__gitcomp_builtin notes_edit &&\n \t\tverbose test -n \"$__gitcomp_builtin_notes_edit\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_checkout\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_notes_edit\"\n \t)\n@@ -2599,7 +2599,7 @@ test_expect_success 'option aliases are not shown by default' '\n \n test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&\n \t\ttest_completion \"git clone --recurs\" <<-\\EOF\n \t\t--recurse-submodules Z\n@@ -2610,7 +2610,7 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \n test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n \n \t\t# Just mainporcelain, not plumbing commands\n@@ -2622,7 +2622,7 @@ test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_\n \n test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n \t\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex d459fae6551..06f0abfc294 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -10,7 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./lib-bash.sh\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-prompt.sh\"\n \n actual=\"$TRASH_DIRECTORY/actual\"\n c_red='\\\\[\\\\e[31m\\\\]'\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 6db377f68b8..36358811a0f 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -47,6 +47,10 @@ then\n \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n \texit 1\n fi\n+\n+# For CMake the top-level source directory is different from our build\n+# directory. With the top-level Makefile they're the same.\n+GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n@@ -1447,7 +1451,7 @@ then\n \t\tmake_valgrind_symlink $file\n \tdone\n \t# special-case the mergetools loadables\n-\tmake_symlink \"$GIT_BUILD_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n+\tmake_symlink \"$GIT_SOURCE_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n \tOLDIFS=$IFS\n \tIFS=:\n \tfor path in $PATH\n@@ -1500,6 +1504,8 @@ GIT_CONFIG_NOSYSTEM=1\n GIT_ATTR_NOSYSTEM=1\n GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\"\n export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES\n+MERGE_TOOLS_DIR=\"$GIT_SOURCE_DIR/mergetools\"\n+export MERGE_TOOLS_DIR\n \n if test -z \"$GIT_TEST_CMP\"\n then\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465856","messageId":"patch-v2-04.11-ea8a3feec81-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 04/11] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:45Z","receivedAt":"2022-10-27T03:27:24Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since the cmake file was made to run on *nix in [1] running the tests\nwith \"ctest\" broken, because we'd attempt to invoke our bin-wrappers/,\nbut they didn't have the executable bit.\n\nIn the best case, the \"t/test-lib.sh\" would be unable to find\n\"bin-wrappers/git\", and we'd fall back on\n\"GIT_EXEC_PATH=$GIT_BUILD_DIR\" using the fallback behavior added in\n[2]:\n\n\t$ ./t0001-init.sh\n\t<GIT_BUILD_DIR>/t/../contrib/buildsystems/out/bin-wrappers/git is not executable; using GIT_EXEC_PATH\n\nThis was recently somewhat swept under the rug in [3], as ctest would\nrun them with \"--no-bin-wrappers\". But still with [3], running e.g.:\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Debug &&\n\tmake -C contrib/buildsystems/out &&\n\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\" --output-on-failure\n\nFails around 20% of our testts on *nix. So even with [3] we'd fail any\ntest that needed to invoke one of our built shell, perl or Python\nscripts on *nix. E.g. t0012-help.sh would fail on a test that tried to\ninvoke \"git web--browse\". The equivalent of this (in the \"out\"\ndirectory) would happen:\n\n\t$ ./git --exec-path=$PWD web--browse\n\tgit: 'web--browse' is not a git command. See 'git --help'.\n\nWhich we can fix by \"chmod +x\"-ing the built \"git-web--browse\":\n\n\t$ chmod +x git-web--browse\n\t$ ./git --exec-path=$PWD web--browse\n\tusage: git web--browse [--browser=browser|--tool=browser] [--config=conf.var] url/file ...\n\nThe same goes for e.g. the \"git-p4\" tests, which would fail because\nour built \"git-p4\" wasn't executable, etc. There's also a few other\noutstanding issues, which will be fixed in subsequent commits.\n\nThis change should ideally use file(CHMOD ...), but the \"file(CHMOD\"\nfeature is much newer than our required cmake version[5].\n\nBefore this change:\n\n\t80% tests passed, 196 tests failed out of 977\n\nAfter:\n\n\t99% tests passed, 5 tests failed out of 977\n\nThe remaining failures will be addressed in subsequent commits.\n\nThere was a suggestion of using a function to abstract this away[6],\nwhich sounds good. But after spending too long trying to get all\ncombinations of \"${content}\" and ${content} (unqoted) in the function\nand its callers working I wasn't able to fix the quoting issues it\nintroduced.\n\nA lot of this is duplicated already, we can follow-up at some other\ntime with refactoring, and address any tricky quoting issues in\ncalling function with these parameters then.\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n3. 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n   runs, 2022-10-18)\n4. a30e4c531d9 (Merge branch 'ss/cmake-build', 2020-08-11)\n5. https://cmake.org/cmake/help/latest/command/file.html#chmod\n6. https://lore.kernel.org/git/0fda0e54-0432-7690-74a7-3d1a59923e0c@dunelm.org.uk/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 4db4997ff0c..1ae6832dc26 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -864,6 +864,7 @@ foreach(script ${git_shell_scripts})\n \tstring(REPLACE \"@@PERL@@\" \"${PERL_PATH}\" content \"${content}\")\n \tstring(REPLACE \"@@PAGER_ENV@@\" \"LESS=FRX LV=-c\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n endforeach()\n \n #perl scripts\n@@ -879,12 +880,14 @@ foreach(script ${git_perl_scripts})\n \tstring(REPLACE \"#!/usr/bin/perl\" \"#!/usr/bin/perl\\n${perl_header}\\n\" content \"${content}\")\n \tstring(REPLACE \"@@GIT_VERSION@@\" \"${PROJECT_VERSION}\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n endforeach()\n \n #python script\n file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n+execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/git-p4)\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n@@ -1023,6 +1026,7 @@ foreach(script ${wrapper_scripts})\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"${script}${EXE_EXTENSION}\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/${script})\n endforeach()\n \n foreach(script ${wrapper_test_scripts})\n@@ -1030,12 +1034,14 @@ foreach(script ${wrapper_test_scripts})\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"t/helper/${script}${EXE_EXTENSION}\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/${script})\n endforeach()\n \n file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n string(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n string(REPLACE \"@@PROG@@\" \"git-cvsserver\" content \"${content}\")\n file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})\n+execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver)\n \n #options for configuring test options\n option(PERL_TESTS \"Perform tests that use perl\" ON)\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465857","messageId":"patch-v2-06.11-29a9811857f-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 06/11] cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:47Z","receivedAt":"2022-10-27T03:27:44Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When we build with libpcre2 which cmake has supported since [1] we\nneed to set \"USE_LIBPCRE2='YesPlease'\" (or similar) in\n\"GIT-BUILD-OPTIONS\".\n\nWithout this e.g. t7810-grep.sh will fail, as it has tests that rely\non the behavior of !PCRE2. The reason this hasn't been noticed is that\nthe Windows CI doesn't have access to libpcre2.\n\nWith this the remaining two failures we had left after the preceding\nstep are resolved, but note that that test run didn't include the\ngit-p4 tests, which a subsequent commit will address).\n\n1. 80431510a2b (cmake: add pcre2 support, 2022-05-24)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 1c271395ed0..e9f979c4e5c 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1091,6 +1091,9 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PYTHON_PATH='${PYTHON_PATH}'\\\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"TAR='${TAR}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_CURL='${NO_CURL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_EXPAT='${NO_EXPAT}'\\n\")\n+if(PCRE2_FOUND)\n+\tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"USE_LIBPCRE2='YesPlease'\\n\")\n+endif()\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PERL='${NO_PERL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PTHREADS='${NO_PTHREADS}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\\n\")\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465858","messageId":"patch-v2-08.11-51bb01b99d4-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 08/11] Makefile + cmake: use environment, not GIT-BUILD-DIR","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:49Z","receivedAt":"2022-10-27T03:27:54Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the method used to have building with \"cmake\" followed by\nrunning the tests manually work without creating inter-dependency issues with the Makefile.\n\nPer ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18) and\nthe surrounding discussion the goal of that change was to have\nbuilding with cmake and:\n\n\t(cd t && ./t0001-init.sh)\n\nWork, to do so we need some way to make the test-lib.sh aware that we\nhave a build in contrib/buildsystems/out. The downside of doing it via\nthe GIT-BUILD-DIR facility in ee9e66e4e76 is:\n\n- A \"remove this file while at it\" only fits into the Makefile\n  dependency graph if we \"FORCE\" a shell command to be run, so doing it\n  this way precludes speeding up the Makefile by e.g. making use of the\n  \"$(file)\" function (for which I've got follow-up patches).\n\n- If you build with make, then with cmake, and then e.g.:\n\n\tmake -C t prove\n\n  We'll run the tests against the cmake version of the tests, not the\n  \"make\" built ones. It's important to get any subtle interaction\n  between two conflicting build systems right.\n\nNow we'll instead:\n\n- Check if the top-level \"git\" exists, if not we'll look in\n  \"contrib/buildsystems/out/git\", and when running interactively inform\n  the user about the fallback being picked.\n\n\t$ ./t0001-init.sh\n\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n\tok 1 - plain\n\t[...]\n\n- This also makes things more obvious on the cmake side, because we'll\n  now use an environment variable to select the test environment, which\n  ctest it notes in its verbose output, e.g.:\n\n\t[...]\n\t2: Test command: /bin/sh \"/home/avar/g/git/contrib/buildsystems/../../t/t0001-init.sh\" \"--no-bin-wrappers\" \"--no-chain-lint\" \"-vx\"\n\t2: Working Directory: /home/avar/g/git/contrib/buildsystems/../../t\n\t2: Environment variables:\n\t2:  GIT_TEST_BUILD_DIR=/home/avar/g/git/contrib/buildsystems/out\n\t[...]\n\n   See [1] for the relevant cmake language references.\n\n- We don't support an arbitrary build directory outside of\n  \"contrib/buildsystems/out\". This is OK because the reason for doing\n  this part is to support the workflow documented in [2].\n\n  As [3] notes \"contrib/buildsystems/out\" isn't just the directory that\n  happens to be documented in \"contrib/buildsystems/CMakeLists.txt\", but\n  the one that VS will use when building git.\n\n1. https://cmake.org/cmake/help/latest/command/set_property.html\n   https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#test-properties\n   https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#cmake-language-lists\n1. f2f1250c47f (cmake (Windows): recommend using Visual Studio's\n   built-in CMake support, 2020-09-30)\n2. 3eccc7b99d4 (cmake: ignore files generated by CMake as run in\n   Visual Studio, 2020-09-25)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .gitignore                          |  1 -\n Makefile                            |  1 -\n contrib/buildsystems/CMakeLists.txt | 10 ++--------\n t/test-lib.sh                       | 16 ++++++++++++++--\n 4 files changed, 16 insertions(+), 12 deletions(-)\n\ndiff --git a/.gitignore b/.gitignore\nindex cb0231fb401..62720c6135d 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -1,5 +1,4 @@\n /fuzz_corpora\n-/GIT-BUILD-DIR\n /GIT-BUILD-OPTIONS\n /GIT-CFLAGS\n /GIT-LDFLAGS\ndiff --git a/Makefile b/Makefile\nindex 4659d89275c..85f03c6aed1 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -3042,7 +3042,6 @@ else\n \t@echo RUNTIME_PREFIX=\\'false\\' >>$@+\n endif\n \t@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi\n-\t@if test -f GIT-BUILD-DIR; then rm GIT-BUILD-DIR; fi\n \n ### Detect Python interpreter path changes\n ifndef NO_PYTHON\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex e9f979c4e5c..0bd4a36b2bf 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1108,14 +1108,6 @@ if(USE_VCPKG)\n \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n endif()\n \n-#Make the tests work when building out of the source tree\n-get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n-if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n-\t#Setting the build directory in test-lib.sh before running tests\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n-\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n-endif()\n-\n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n \n #test\n@@ -1123,6 +1115,8 @@ foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n \t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n+       set_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n+\t\t    GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\t\t\n endforeach()\n \n # This test script takes an extremely long time and is known to time out even\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 388774a0aa0..ce319c9963e 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -51,12 +51,17 @@ fi\n # For CMake the top-level source directory is different from our build\n # directory. With the top-level Makefile they're the same.\n GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n+\n+GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=\n if test -n \"$GIT_TEST_BUILD_DIR\"\n then\n \tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n-elif test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n+elif ! test -x \"$GIT_BUILD_DIR/git\" &&\n+     test -x \"$GIT_BUILD_DIR/contrib/buildsystems/out/git\"\n then\n-\tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n+\tGIT_BUILD_DIR=\"$GIT_SOURCE_DIR/contrib/buildsystems/out\"\n+\tGIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=t\n+\n \t# On Windows, we must convert Windows paths lest they contain a colon\n \tcase \"$(uname -s)\" in\n \t*MINGW*)\n@@ -1637,6 +1642,13 @@ remove_trash_directory \"$TRASH_DIRECTORY\" || {\n \tBAIL_OUT 'cannot prepare test area'\n }\n \n+# Emitting this now because earlier we didn't have \"say\", but not in\n+# anything using lib-subtest.sh\n+if test -n \"$GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT\" && test -t 1\n+then\n+\tsay \"setup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\"\n+fi\n+\n remove_trash=t\n if test -z \"$TEST_NO_CREATE_REPO\"\n then\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465859","messageId":"patch-v2-07.11-a9ea3867f5f-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 07/11] test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:48Z","receivedAt":"2022-10-27T03:28:01Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Compliment the existing GIT_TEST_INSTALLED variable added in [1] with\none that allows for testing a git built in a directory that's not\n\"../\".\n\nInstead of \"test this installed git\" (\"GIT_TEST_INSTALLED\"), this new\n\"GIT_TEST_BUILD_DIR\" is a \"test this built directory over\nthere\". E.g. this will pass all tests:\n\n\tgit clone --depth=1 https://github.com/git/git.git git1\n\tcp -R git1 git2\n\tmake -C git1\n\t[apply this change to git2]\n\t(cd git2 && GIT_TEST_BUILD_DIR=\"$PWD/../git1\" make -C t prove)\n\nThis facility and file-based instructions to have the test suite use\nanother build directory[2] are mutually exclusive, but in a subsequent\ncommit we'll make CMake use this instead.\n\n1. 6720721e152 (test-lib.sh: Allow running the test suite against\n   installed git, 2009-03-16)\n2. 350a005e366 (cmake: avoid editing t/test-lib.sh, 2022-10-18)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/README      | 3 +++\n t/test-lib.sh | 5 ++++-\n 2 files changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/t/README b/t/README\nindex 979b2d4833d..fc0daef2e41 100644\n--- a/t/README\n+++ b/t/README\n@@ -231,6 +231,9 @@ override the location of the dashed-form subcommands (what\n GIT_EXEC_PATH would be used for during normal operation).\n GIT_TEST_EXEC_PATH defaults to `$GIT_TEST_INSTALLED/git --exec-path`.\n \n+Similar to GIT_TEST_INSTALLED, GIT_TEST_BUILD_DIR can be pointed to\n+another git.git checkout's build directory, to test its built binaries\n+against the tests in this checkout.\n \n Skipping Tests\n --------------\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 36358811a0f..388774a0aa0 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -51,7 +51,10 @@ fi\n # For CMake the top-level source directory is different from our build\n # directory. With the top-level Makefile they're the same.\n GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n-if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n+if test -n \"$GIT_TEST_BUILD_DIR\"\n+then\n+\tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n+elif test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n \t# On Windows, we must convert Windows paths lest they contain a colon\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465860","messageId":"patch-v2-09.11-9f5276d79c9-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 09/11] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:50Z","receivedAt":"2022-10-27T03:28:12Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The rationale for adding \"--no-bin-wrappers\" and \"--no-chain-lint\" in\n2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\nruns, 2022-10-18) was those options slowed down the tests considerably\non Windows.\n\nBut since f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\nand with the preceding commits cmake and ctest are not\nWindows-specific anymore.\n\nSo let's set those same options by default on Windows, but do so with\nthe set() facility. As noted in cmake's documentation[1] this\nintegrates nicely with e.g. cmake-gui.\n\nOn *nix we don't set any custom options. The change in 2ea1d8b5563\ndidn't discuss why Windows should have divergent defaults with \"cmake\"\nand \"make\", but such reasons presumably don't apply on *nix. I for one\nam happy with the same defaults as the tests have when running via the\nMakefile.\n\nWith the \"message()\" addition we'll emit this when running cmake:\n\n\tGenerating hook-list.h\n\t-- Using user-selected test options: -vixd\n\t-- Configuring done\n\t-- Generating done\n\t-- Build files have been written to: /home/avar/g/git/contrib/buildsystems/out\n\nUnfortunately cmake doesn't support a non-hacky way to pass variables\nto ctest without re-running cmake itself, so when re-running tests via\ncmake and wanting to change the test defaults we'll need:\n\n\tGIT_TEST_OPTS=-i cmake -S contrib/buildsystems -B contrib/buildsystems/out &&\n\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out -R t0071 --verbose\n\n1. https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 46 +++++++++++++++++++++++++++--\n 1 file changed, 44 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 0bd4a36b2bf..35b12493cbc 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -49,7 +49,7 @@ To use this in Visual Studio:\n \n Open the worktree as a folder. Visual Studio 2019 and later will detect\n the CMake configuration automatically and set everything up for you,\n-ready to build. You can then run the tests in `t/` via a regular Git Bash.\n+ready to build. See \"== Running the tests ==\" below for running the tests.\n \n Note: Visual Studio also has the option of opening `CMakeLists.txt`\n directly; Using this option, Visual Studio will not find the source code,\n@@ -74,6 +74,35 @@ empty(default) :\n \n NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n this option is ignored\n+\n+== Running the tests ==\n+\n+Once we've built in \"contrib/buildsystems/out\" the tests can be run at\n+the top-level (note: not the generated \"contrib/buildsystems/out/t/\"\n+drectory). If no top-level build is found (as created with the\n+Makefile) the t/test-lib.sh will discover the git in\n+\"contrib/buildsystems/out\" on e.g.:\n+\n+\t(cd t && ./t0001-init.sh)\n+\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n+\t[...]\n+\n+The tests can also be run with ctest, e.g. after building with \"cmake\"\n+and \"make\" or \"msbuild\" run, from the top-level e.g.:\n+\n+\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\"--output-on-failure\n+\n+Options can be passed by setting GIT_TEST_OPTIONS before invoking\n+cmake. E.g. on a Linux system with systemd the tests can be sped up by\n+using a ramdisk for the scratch files:\n+\n+\tGIT_TEST_OPTS=\"--root=/run/user/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n+\t[...]\n+\t-- Using user-selected test options: --root=/run/user/1001/ctest\n+\n+Then running the tests with \"ctest\" (here with --jobs=\"$(nproc)\"):\n+\n+\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out\n ]]\n cmake_minimum_required(VERSION 3.14)\n \n@@ -1110,10 +1139,23 @@ endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n \n+string(COMPARE NOTEQUAL \"$ENV{GIT_TEST_OPTS}\" \"\" HAVE_USER_GIT_TEST_OPTS)\n+if(HAVE_USER_GIT_TEST_OPTS)\n+\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n+\tmessage(STATUS \"Using user-selected test options: ${GIT_TEST_OPTS}\")\n+elseif(WIN32)\n+\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\")\n+\tmessage(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n+else()\n+\tset(GIT_TEST_OPTS \"\")\n+\tmessage(STATUS \"No custom test options selected, set e.g. GIT_TEST_OPTS=\\\"-vixd\\\"\")\n+endif()\n+separate_arguments(GIT_TEST_OPTS)\n+\n #test\n foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n-\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n+\t\tCOMMAND ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n        set_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n \t\t    GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\t\t\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465861","messageId":"patch-v2-10.11-ef6a304368c-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 10/11] cmake: copy over git-p4.py for t983[56] perforce test","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:51Z","receivedAt":"2022-10-27T03:28:15Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] two git-p4 tests have relied on there being a \"git-p4.py\" in\nthe build directory, but the cmake recipe was not updated to account\nfor this. Let's copy the \"git-p4.py\" over.\n\nWe could also change the test to e.g. grab the built \"git-p4\" and\nalter its shebang, which would be friendly to GIT_TEST_INSTALLED, but\nlet's just do the bare minimum here to get cmake+ctest working without\naltering the test itself.\n\nThe reason this hasn't been caught by \"vs-build\" and \"vs-test\" is\nbecause those tests added in [2] invoke \"cmake\" with\n\"-DPYTHON_TESTS=OFF\", and therefore we'd skip this part of the git-p4\ntests before getting past the \"do we have python?\" check. Even if we\ngot past that the Windows CI wouldn't have a \"p4\" or \"p4d\" binary\ninstalled, so we'd skip the tests anyway.\n\nIn a subsequent commit we'll run \"cmake\" and \"ctest\" in CI with\n\"ubuntu-latest\", so we'll need this \"git-p4.py\" file.\n\n1. f7b5ff607fa (git-p4: improve encoding handling to support\n   inconsistent encodings, 2022-04-30)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 35b12493cbc..6c5954aca25 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -917,6 +917,7 @@ file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/git-p4)\n+file(COPY ${CMAKE_SOURCE_DIR}/git-p4.py DESTINATION ${CMAKE_BINARY_DIR}/)\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465862","messageId":"patch-v2-11.11-158a41ca7a4-20221027T032622Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v2 11/11] CI: add a \"linux-cmake-test\" to run cmake & ctest on linux","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-10-27T03:26:52Z","receivedAt":"2022-10-27T03:28:58Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] the \"cmake\" build method should work properly on Linux, but\nas seen in preceding commits there were various bugs in it, which are\nhopefully now all fixed.\n\nTo ensure that it doesn't break again let's add a \"linux-cmake-ctest\"\ntarget to build and test \"cmake\" on Linux, in addition to that we'll\nalso run the tests with \"ctest\" instead of \"make\" or \"prove\", so we\ncan assert that testing with that method works..\n\nThis also stress tests running \"cmake\" (and \"ctest\") out of a build\ndirectory that isn't the top-level. The \"vs-build\" job uses \"cmake\"\nsince [2], but clobbers the top-level \"Makefile\" and builds in the\ntop-level directory.\n\nThat was the reason for why we didn't spot that various tests still\nrequired missing \"mergetools/*\" etc, which was fixed by using\n\"$GIT_SOURCE_DIR\" in a preceding commit.\n\nSince the \"ci/lib.sh\" already creates and exports a\nGIT_TEST_OPTS=\"...\" we'll pick that up in our CI, see the preceding\ncommit. Because we pass the \"--verbose-log -x\n--github-workflow-markup\" in the GitHub CI as a result the interaction\nwith \"handle_failed_tests\" here works correctly. I.e. on failure we'll\nhave saved \"t/test-results/*.{exit,out,markup}\" files relevant to the\nfailing test(s).\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .github/workflows/main.yml |  3 +++\n ci/run-build-and-tests.sh  | 13 +++++++++++--\n 2 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/.github/workflows/main.yml b/.github/workflows/main.yml\nindex 831f4df56c5..f15c77c1ed1 100644\n--- a/.github/workflows/main.yml\n+++ b/.github/workflows/main.yml\n@@ -238,6 +238,9 @@ jobs:\n             os: ubuntu\n             cc_package: gcc-8\n             pool: ubuntu-latest\n+          - jobname: linux-cmake-ctest\n+            cc: gcc\n+            pool: ubuntu-latest\n           - jobname: osx-clang\n             cc: clang\n             pool: macos-latest\ndiff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh\nindex 8ebff425967..a3ae5ff3972 100755\n--- a/ci/run-build-and-tests.sh\n+++ b/ci/run-build-and-tests.sh\n@@ -45,10 +45,19 @@ pedantic)\n \t;;\n esac\n \n-group Build make\n+mc=\n+if test \"$jobname\" = \"linux-cmake-ctest\"\n+then\n+\tcb=contrib/buildsystems\n+\tgroup CMake cmake -S \"$cb\" -B \"$cb/out\"\n+\tmc=\"-C $cb/out\"\n+fi\n+\n+group Build make $mc\n+\n if test -n \"$run_tests\"\n then\n-\tgroup \"Run tests\" make test ||\n+\tgroup \"Run tests\" make $mc test ||\n \thandle_failed_tests\n fi\n check_unignored_build_artifacts\n-- \n2.38.0.1250.ge066ede4da3\n\n"},{"id":"465863","messageId":"CAPig+cShURmL4JD4M1Pb5PdGXt6aHxKJKsRa6bS-tAQdZ-LhhA@mail.gmail.com","threadId":"58666","inReplyTo":"patch-v2-02.11-9e2470dcb95-20221027T032622Z-avarab@gmail.com","subject":"Re: [PATCH v2 02/11] cmake: update instructions for portable CMakeLists.txt","fromName":"Eric Sunshine","fromEmail":"ericsunshine@gmail.com","sentAt":"2022-10-27T03:35:03Z","receivedAt":"2022-10-27T03:35:23Z","isPatch":true,"sender":{"key":"ericsunshine@gmail.com","avatar":null},"body":"On Wed, Oct 26, 2022 at 11:27 PM Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n> The instructions for running CMake went back & forth between *nix,\n> Windows and Visual Studio instructions Let's create headings and split\n> the existing instructions up into those new sections.\n>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n> diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n> @@ -4,7 +4,48 @@\n> +== Building ==\n> +\n> +One the recipe is created a build recipe will be created.\n\nFirst sentence seems to be gobbledygook. I _think_ you wanted to say\n\"Once the recipe is created, something, something, something\", though\nI don't know what \"something\" was supposed to be.\n\n> +[...] For Windows\n> +Open contrib/buildsystems/git.sln on Windows and build Git. Or use the\n\nToo many \"Windows\".\n\n> +\"msbuild\" command-line tool (see our own \".github/workflows/main.yml\"\n> +for a real example):\n> +\n> +       msbuild git.sln\n> +\n> +On all other platforms running \"cmake\" will generate a Makefile, to\n> +build with it run:\n\ns/,/;/\n\n> +       make -C contrib/buildsystems/out\n"},{"id":"466241","messageId":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"[PATCH v3 00/12] cmake: document, fix on *nix, add CI","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:24Z","receivedAt":"2022-11-01T22:51:54Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This topic gets our tests from passing ~80% with ctest on *nix to\npassing 100%. Now on top of master, as js/cmake-updates landed.\n\nSee passing CI job for \"cmake + ctest\" on Ubuntu at:\nhttps://github.com/avar/git/actions/runs/3370930115/jobs/5593431733\n\nChanges since the v2:\n\n * Documentation rewording/updates/grammar fixes, thanks to Eric\n   Sunshine.\n\n * A whitespace nit for set_property(), I wasn't using the indenting\n   style that's prevalent in the CMakeLists.txt (not our usual \"align\n   the argument list\" tab-indent).\n\n * Added a Windows ifdef around the recent timeout increase for a\n   single submodule test (not an issue on *nix).\n\nÆvar Arnfjörð Bjarmason (12):\n  cmake: don't \"mkdir -p\" and \"cd\" in build instructions\n  cmake: update instructions for portable CMakeLists.txt\n  cmake: don't copy chainlint.pl to build directory\n  cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n  cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n  cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n  test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n  Makefile + cmake: use environment, not GIT-BUILD-DIR\n  cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n  cmake: increase test timeout on Windows only\n  cmake: copy over git-p4.py for t983[56] perforce test\n  CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n\n .github/workflows/main.yml          |   3 +\n .gitignore                          |   1 -\n Makefile                            |   1 -\n ci/run-build-and-tests.sh           |  13 ++-\n contrib/buildsystems/CMakeLists.txt | 141 +++++++++++++++++++++-------\n t/README                            |   3 +\n t/lib-gettext.sh                    |   2 +-\n t/lib-gitweb.sh                     |   2 +-\n t/t7609-mergetool--lib.sh           |   2 +-\n t/t9902-completion.sh               |  14 +--\n t/t9903-bash-prompt.sh              |   2 +-\n t/test-lib.sh                       |  27 +++++-\n 12 files changed, 157 insertions(+), 54 deletions(-)\n\nRange-diff against v2:\n 1:  667a2bd5271 =  1:  028fa1436d8 cmake: don't \"mkdir -p\" and \"cd\" in build instructions\n 2:  9e2470dcb95 !  2:  7a21f4aa24c cmake: update instructions for portable CMakeLists.txt\n    @@ contrib/buildsystems/CMakeLists.txt\n     +\n     +== Building ==\n     +\n    -+One the recipe is created a build recipe will be created. For Windows\n    -+Open contrib/buildsystems/git.sln on Windows and build Git. Or use the\n    ++The \"cmake\" command creates a build file from this recipe. For Windows\n    ++Open contrib/buildsystems/git.sln and build Git. Or use the\n     +\"msbuild\" command-line tool (see our own \".github/workflows/main.yml\"\n     +for a real example):\n     +\n     +\tmsbuild git.sln\n     +\n    -+On all other platforms running \"cmake\" will generate a Makefile, to\n    ++On all other platforms running \"cmake\" will generate a Makefile; to\n     +build with it run:\n     +\n     +\tmake -C contrib/buildsystems/out\n 3:  2d7d9742a73 =  3:  3bfa873e792 cmake: don't copy chainlint.pl to build directory\n 4:  ea8a3feec81 =  4:  ad551f53de9 cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n 5:  6387682db06 =  5:  5c7b64286ce cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n 6:  29a9811857f =  6:  cba90650879 cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n 7:  a9ea3867f5f =  7:  bd7fb1eec24 test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n 8:  51bb01b99d4 !  8:  fd3e6be5689 Makefile + cmake: use environment, not GIT-BUILD-DIR\n    @@ contrib/buildsystems/CMakeLists.txt: foreach(tsh ${test_scipts})\n      \tadd_test(NAME ${tsh}\n      \t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n      \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n    -+       set_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n    -+\t\t    GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\t\t\n    ++\tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n    ++\t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n      endforeach()\n      \n      # This test script takes an extremely long time and is known to time out even\n 9:  9f5276d79c9 !  9:  8a660a2baa4 cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n    @@ contrib/buildsystems/CMakeLists.txt: endif()\n     -\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n     +\t\tCOMMAND ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n      \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n    -        set_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n    - \t\t    GIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\t\t\n    + \tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n    + \t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n -:  ----------- > 10:  966fec83b77 cmake: increase test timeout on Windows only\n10:  ef6a304368c = 11:  aad17d8f858 cmake: copy over git-p4.py for t983[56] perforce test\n11:  158a41ca7a4 = 12:  c27f620dfa3 CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466240","messageId":"patch-v3-01.12-028fa1436d8-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 01/12] cmake: don't \"mkdir -p\" and \"cd\" in build instructions","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:25Z","receivedAt":"2022-11-01T22:51:55Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Use the \"-S\" and -B\" flags instead of \"mkdir -p\" and \"cd\". The \"-p\"\nflag to \"mkdir\" wasn't needed as \"contrib/buildsystems\" is tracked,\nand the rest of this is now easier to copy/paste into a shell without\nhaving one's directory changed.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 3957e4cf8cd..494da807c53 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -16,9 +16,7 @@ though, therefore the `File>Open>Folder...` option is preferred.\n \n Instructions to run CMake manually:\n \n-    mkdir -p contrib/buildsystems/out\n-    cd contrib/buildsystems/out\n-    cmake ../ -DCMAKE_BUILD_TYPE=Release\n+    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n \n This will build the git binaries in contrib/buildsystems/out\n directory (our top-level .gitignore file knows to ignore contents of\n@@ -36,8 +34,8 @@ NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual St\n this option is ignored\n \n This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n-Run `make` to build Git on Linux/*BSD/MacOS.\n-Open git.sln on Windows and build Git.\n+Run `make -C contrib/buildsystems` to build Git on Linux/*BSD/MacOS.\n+Open contrib/buildsystems/git.sln on Windows and build Git.\n \n NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n to use another tool say `ninja` add this to the command line when configuring.\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466242","messageId":"patch-v3-02.12-7a21f4aa24c-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 02/12] cmake: update instructions for portable CMakeLists.txt","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:26Z","receivedAt":"2022-11-01T22:51:58Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The instructions for running CMake went back & forth between *nix,\nWindows and Visual Studio instructions Let's create headings and split\nthe existing instructions up into those new sections.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 66 +++++++++++++++++++++--------\n 1 file changed, 48 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 494da807c53..7bc123da315 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -4,7 +4,48 @@\n \n #[[\n \n-Instructions how to use this in Visual Studio:\n+== Overview ==\n+\n+The top-level Makefile is Git's primary build environment, and a lot\n+of things are missing (and probably always will be) from this CMake\n+alternative.\n+\n+The primary use-case for maintaining this CMake build recipe is to\n+have nicer IDE integration on Windows. To get Visual Studio-specific\n+instructions see \"== Visual Studio & Windows ==\" below.\n+\n+== Creating a build recipe ==\n+\n+To create the build recipe run:\n+\n+    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n+\n+For alternative \"-DCMAKE_BUILD_TYPE=<type>\" flags see instructions\n+under the \"== -DCMAKE_BUILD_TYPE=<type> ==\" heading below.\n+\n+== Building ==\n+\n+The \"cmake\" command creates a build file from this recipe. For Windows\n+Open contrib/buildsystems/git.sln and build Git. Or use the\n+\"msbuild\" command-line tool (see our own \".github/workflows/main.yml\"\n+for a real example):\n+\n+\tmsbuild git.sln\n+\n+On all other platforms running \"cmake\" will generate a Makefile; to\n+build with it run:\n+\n+\tmake -C contrib/buildsystems/out\n+\n+It's also possible to use other generators, e.g. Ninja has arguably\n+slightly better output. Add \"-G Ninja\" to the cmake command above,\n+then e.g.:\n+\n+\tninja -C contrib/buildsystems/out\n+\n+== Visual Studio & Windows ==\n+\n+To use this in Visual Studio:\n \n Open the worktree as a folder. Visual Studio 2019 and later will detect\n the CMake configuration automatically and set everything up for you,\n@@ -14,14 +55,15 @@ Note: Visual Studio also has the option of opening `CMakeLists.txt`\n directly; Using this option, Visual Studio will not find the source code,\n though, therefore the `File>Open>Folder...` option is preferred.\n \n-Instructions to run CMake manually:\n-\n-    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n-\n-This will build the git binaries in contrib/buildsystems/out\n+Following the instructions above will build the git binaries in the contrib/buildsystems/out\n directory (our top-level .gitignore file knows to ignore contents of\n this directory).\n \n+By default CMake will install vcpkg locally to your source tree on configuration,\n+to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n+\n+== -DCMAKE_BUILD_TYPE=<type> ==\n+\n Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding\n compiler flags\n Debug : -g\n@@ -32,18 +74,6 @@ empty(default) :\n \n NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n this option is ignored\n-\n-This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n-Run `make -C contrib/buildsystems` to build Git on Linux/*BSD/MacOS.\n-Open contrib/buildsystems/git.sln on Windows and build Git.\n-\n-NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n-to use another tool say `ninja` add this to the command line when configuring.\n-`-G Ninja`\n-\n-NOTE: By default CMake will install vcpkg locally to your source tree on configuration,\n-to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n-\n ]]\n cmake_minimum_required(VERSION 3.14)\n \n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466243","messageId":"patch-v3-03.12-3bfa873e792-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 03/12] cmake: don't copy chainlint.pl to build directory","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:27Z","receivedAt":"2022-11-01T22:52:01Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When [1] made this copy of \"chainlint.sed\" the script was invoked in\nthe test-lib.sh as:\n\n\t[...] sed -f \"$GIT_BUILD_DIR/t/chainlint.sed\" [...]\n\nBut when [2] replaced \"chainlint.sed\" with a \"chainlint.pl\" it also\nreplaced that \"$GIT_BUILD_DIR\" with \"$TEST_DIRECTORY\", invoking it as:\n\n\t\"$PERL_PATH\" \"$TEST_DIRECTORY/chainlint.pl\" \"$0\"\n\nSo this line could have been deleted in [2] but wasn't. Let's do that\nnow.\n\n1. 7f5397a07c6 (cmake: support for testing git when building out of\n   the source tree, 2020-06-26)\n2. 23a14f30166 (test-lib: replace chainlint.sed with chainlint.pl,\n   2022-09-01)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 7bc123da315..dd46ad25fb7 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1106,7 +1106,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n \t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)\n \tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n \tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n \tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466244","messageId":"patch-v3-04.12-ad551f53de9-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 04/12] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:28Z","receivedAt":"2022-11-01T22:52:11Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since the cmake file was made to run on *nix in [1] running the tests\nwith \"ctest\" broken, because we'd attempt to invoke our bin-wrappers/,\nbut they didn't have the executable bit.\n\nIn the best case, the \"t/test-lib.sh\" would be unable to find\n\"bin-wrappers/git\", and we'd fall back on\n\"GIT_EXEC_PATH=$GIT_BUILD_DIR\" using the fallback behavior added in\n[2]:\n\n\t$ ./t0001-init.sh\n\t<GIT_BUILD_DIR>/t/../contrib/buildsystems/out/bin-wrappers/git is not executable; using GIT_EXEC_PATH\n\nThis was recently somewhat swept under the rug in [3], as ctest would\nrun them with \"--no-bin-wrappers\". But still with [3], running e.g.:\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Debug &&\n\tmake -C contrib/buildsystems/out &&\n\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\" --output-on-failure\n\nFails around 20% of our testts on *nix. So even with [3] we'd fail any\ntest that needed to invoke one of our built shell, perl or Python\nscripts on *nix. E.g. t0012-help.sh would fail on a test that tried to\ninvoke \"git web--browse\". The equivalent of this (in the \"out\"\ndirectory) would happen:\n\n\t$ ./git --exec-path=$PWD web--browse\n\tgit: 'web--browse' is not a git command. See 'git --help'.\n\nWhich we can fix by \"chmod +x\"-ing the built \"git-web--browse\":\n\n\t$ chmod +x git-web--browse\n\t$ ./git --exec-path=$PWD web--browse\n\tusage: git web--browse [--browser=browser|--tool=browser] [--config=conf.var] url/file ...\n\nThe same goes for e.g. the \"git-p4\" tests, which would fail because\nour built \"git-p4\" wasn't executable, etc. There's also a few other\noutstanding issues, which will be fixed in subsequent commits.\n\nThis change should ideally use file(CHMOD ...), but the \"file(CHMOD\"\nfeature is much newer than our required cmake version[5].\n\nBefore this change:\n\n\t80% tests passed, 196 tests failed out of 977\n\nAfter:\n\n\t99% tests passed, 5 tests failed out of 977\n\nThe remaining failures will be addressed in subsequent commits.\n\nThere was a suggestion of using a function to abstract this away[6],\nwhich sounds good. But after spending too long trying to get all\ncombinations of \"${content}\" and ${content} (unqoted) in the function\nand its callers working I wasn't able to fix the quoting issues it\nintroduced.\n\nA lot of this is duplicated already, we can follow-up at some other\ntime with refactoring, and address any tricky quoting issues in\ncalling function with these parameters then.\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n3. 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n   runs, 2022-10-18)\n4. a30e4c531d9 (Merge branch 'ss/cmake-build', 2020-08-11)\n5. https://cmake.org/cmake/help/latest/command/file.html#chmod\n6. https://lore.kernel.org/git/0fda0e54-0432-7690-74a7-3d1a59923e0c@dunelm.org.uk/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex dd46ad25fb7..127a4a17853 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -864,6 +864,7 @@ foreach(script ${git_shell_scripts})\n \tstring(REPLACE \"@@PERL@@\" \"${PERL_PATH}\" content \"${content}\")\n \tstring(REPLACE \"@@PAGER_ENV@@\" \"LESS=FRX LV=-c\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n endforeach()\n \n #perl scripts\n@@ -879,12 +880,14 @@ foreach(script ${git_perl_scripts})\n \tstring(REPLACE \"#!/usr/bin/perl\" \"#!/usr/bin/perl\\n${perl_header}\\n\" content \"${content}\")\n \tstring(REPLACE \"@@GIT_VERSION@@\" \"${PROJECT_VERSION}\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n endforeach()\n \n #python script\n file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n+execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/git-p4)\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n@@ -1023,6 +1026,7 @@ foreach(script ${wrapper_scripts})\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"${script}${EXE_EXTENSION}\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/${script})\n endforeach()\n \n foreach(script ${wrapper_test_scripts})\n@@ -1030,12 +1034,14 @@ foreach(script ${wrapper_test_scripts})\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"t/helper/${script}${EXE_EXTENSION}\" content \"${content}\")\n \tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/${script})\n endforeach()\n \n file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n string(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n string(REPLACE \"@@PROG@@\" \"git-cvsserver\" content \"${content}\")\n file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})\n+execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver)\n \n #options for configuring test options\n option(PERL_TESTS \"Perform tests that use perl\" ON)\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466245","messageId":"patch-v3-05.12-5c7b64286ce-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 05/12] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:29Z","receivedAt":"2022-11-01T22:52:13Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When git is built and tested with cmake & ctest we usually do that\noutside of the top-level source directory. E.g.\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out\n\tmake -C contrib/buildsystems/out\n\tctest -j$(nproc) --test-dir contrib/buildsystems/out\n\nSince the test-lib.sh makes assumptions about the TEST_DIRECTORY being\nthe \"t\" subdirectory of the top-level \"$GIT_BUILD_DIR\", the cmake\nrecipe has needed to copy various assets to that\n\"contrib/buildsystems/out\" directory.\n\nBut we've only been doing this for the subsets of tests that run on\nWindows, and which have otherwise been covered by that CI target. The\nCI target builds (among other things) with \"-DPERL_TESTS=OFF\n-DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON\", see [1]. Furthermore, the\nCI isn't testing from the \"contrib/buildsystems/out\" directory,\ninstead it clobbers the top-level MAkefile.\n\nThere was a recent commit to fix a subset of these issues, see\n6a83b5f0810 (cmake: copy the merge tools for testing, 2022-10-18).\n\nLet's stop going for that approach, and instead teach the test-lib.sh\nthat there's such a thing as the \"$GIT_SOURCE_DIR\" distinct from the\n\"$GIT_BUILD_DIR\".\n\nJust as the \"$TEST_DIRECTORY\" always points to our actual \"t\"\ndirectory (not the \"[...]/out/t\" cmake creates), this new\n\"$GIT_SOURCE_DIR\" will always be the top-level source directory.\n\nWith this change we now pass 3/5 of the tests that we still had\nfailing with the fixes in the preceding commit.\n\n1. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt |  6 ------\n t/lib-gettext.sh                    |  2 +-\n t/lib-gitweb.sh                     |  2 +-\n t/t7609-mergetool--lib.sh           |  2 +-\n t/t9902-completion.sh               | 14 +++++++-------\n t/t9903-bash-prompt.sh              |  2 +-\n t/test-lib.sh                       |  8 +++++++-\n 7 files changed, 18 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 127a4a17853..26a93b7b2cf 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1111,12 +1111,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \t#Setting the build directory in test-lib.sh before running tests\n \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n-\t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n-\tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n-\tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\ndiff --git a/t/lib-gettext.sh b/t/lib-gettext.sh\nindex cc6bb2cdeaa..dcd6e9c3f75 100644\n--- a/t/lib-gettext.sh\n+++ b/t/lib-gettext.sh\n@@ -7,7 +7,7 @@\n . ./test-lib.sh\n \n GIT_TEXTDOMAINDIR=\"$GIT_BUILD_DIR/po/build/locale\"\n-GIT_PO_PATH=\"$GIT_BUILD_DIR/po\"\n+GIT_PO_PATH=\"$GIT_SOURCE_DIR/po\"\n export GIT_TEXTDOMAINDIR GIT_PO_PATH\n \n if test -n \"$GIT_TEST_INSTALLED\"\ndiff --git a/t/lib-gitweb.sh b/t/lib-gitweb.sh\nindex 1f32ca66ea5..6f68df247af 100644\n--- a/t/lib-gitweb.sh\n+++ b/t/lib-gitweb.sh\n@@ -49,7 +49,7 @@ EOF\n \t\terror \"Cannot find gitweb at $GITWEB_TEST_INSTALLED.\"\n \t\tsay \"# Testing $SCRIPT_NAME\"\n \telse # normal case, use source version of gitweb\n-\t\tSCRIPT_NAME=\"$GIT_BUILD_DIR/gitweb/gitweb.perl\"\n+\t\tSCRIPT_NAME=\"$GIT_SOURCE_DIR/gitweb/gitweb.perl\"\n \tfi\n \texport SCRIPT_NAME\n }\ndiff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh\nindex 8b1c3bd39f2..2090d12a489 100755\n--- a/t/t7609-mergetool--lib.sh\n+++ b/t/t7609-mergetool--lib.sh\n@@ -8,7 +8,7 @@ TEST_PASSES_SANITIZE_LEAK=true\n . ./test-lib.sh\n \n test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '\n-\t. \"$GIT_BUILD_DIR\"/mergetools/vimdiff &&\n+\t. \"$GIT_SOURCE_DIR\"/mergetools/vimdiff &&\n \trun_unit_tests\n '\n \ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 43de868b800..1bd4cae92fe 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -33,7 +33,7 @@ complete ()\n GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'\n GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\"\n \n # We don't need this function to actually join words or do anything special.\n # Also, it's cleaner to avoid touching bash's internal completion variables.\n@@ -2567,7 +2567,7 @@ test_expect_success 'sourcing the completion script clears cached commands' '\n \t(\n \t\t__git_compute_all_commands &&\n \t\tverbose test -n \"$__git_all_commands\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_all_commands\"\n \t)\n '\n@@ -2576,7 +2576,7 @@ test_expect_success 'sourcing the completion script clears cached merge strategi\n \t(\n \t\t__git_compute_merge_strategies &&\n \t\tverbose test -n \"$__git_merge_strategies\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_merge_strategies\"\n \t)\n '\n@@ -2587,7 +2587,7 @@ test_expect_success 'sourcing the completion script clears cached --options' '\n \t\tverbose test -n \"$__gitcomp_builtin_checkout\" &&\n \t\t__gitcomp_builtin notes_edit &&\n \t\tverbose test -n \"$__gitcomp_builtin_notes_edit\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_checkout\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_notes_edit\"\n \t)\n@@ -2599,7 +2599,7 @@ test_expect_success 'option aliases are not shown by default' '\n \n test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&\n \t\ttest_completion \"git clone --recurs\" <<-\\EOF\n \t\t--recurse-submodules Z\n@@ -2610,7 +2610,7 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \n test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n \n \t\t# Just mainporcelain, not plumbing commands\n@@ -2622,7 +2622,7 @@ test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_\n \n test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n \t\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex d459fae6551..06f0abfc294 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -10,7 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./lib-bash.sh\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-prompt.sh\"\n \n actual=\"$TRASH_DIRECTORY/actual\"\n c_red='\\\\[\\\\e[31m\\\\]'\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 6db377f68b8..36358811a0f 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -47,6 +47,10 @@ then\n \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n \texit 1\n fi\n+\n+# For CMake the top-level source directory is different from our build\n+# directory. With the top-level Makefile they're the same.\n+GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n@@ -1447,7 +1451,7 @@ then\n \t\tmake_valgrind_symlink $file\n \tdone\n \t# special-case the mergetools loadables\n-\tmake_symlink \"$GIT_BUILD_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n+\tmake_symlink \"$GIT_SOURCE_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n \tOLDIFS=$IFS\n \tIFS=:\n \tfor path in $PATH\n@@ -1500,6 +1504,8 @@ GIT_CONFIG_NOSYSTEM=1\n GIT_ATTR_NOSYSTEM=1\n GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\"\n export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES\n+MERGE_TOOLS_DIR=\"$GIT_SOURCE_DIR/mergetools\"\n+export MERGE_TOOLS_DIR\n \n if test -z \"$GIT_TEST_CMP\"\n then\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466246","messageId":"patch-v3-06.12-cba90650879-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 06/12] cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:30Z","receivedAt":"2022-11-01T22:52:16Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When we build with libpcre2 which cmake has supported since [1] we\nneed to set \"USE_LIBPCRE2='YesPlease'\" (or similar) in\n\"GIT-BUILD-OPTIONS\".\n\nWithout this e.g. t7810-grep.sh will fail, as it has tests that rely\non the behavior of !PCRE2. The reason this hasn't been noticed is that\nthe Windows CI doesn't have access to libpcre2.\n\nWith this the remaining two failures we had left after the preceding\nstep are resolved, but note that that test run didn't include the\ngit-p4 tests, which a subsequent commit will address).\n\n1. 80431510a2b (cmake: add pcre2 support, 2022-05-24)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 26a93b7b2cf..fc45004226a 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1091,6 +1091,9 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PYTHON_PATH='${PYTHON_PATH}'\\\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"TAR='${TAR}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_CURL='${NO_CURL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_EXPAT='${NO_EXPAT}'\\n\")\n+if(PCRE2_FOUND)\n+\tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"USE_LIBPCRE2='YesPlease'\\n\")\n+endif()\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PERL='${NO_PERL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PTHREADS='${NO_PTHREADS}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\\n\")\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466247","messageId":"patch-v3-07.12-bd7fb1eec24-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 07/12] test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:31Z","receivedAt":"2022-11-01T22:52:18Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Compliment the existing GIT_TEST_INSTALLED variable added in [1] with\none that allows for testing a git built in a directory that's not\n\"../\".\n\nInstead of \"test this installed git\" (\"GIT_TEST_INSTALLED\"), this new\n\"GIT_TEST_BUILD_DIR\" is a \"test this built directory over\nthere\". E.g. this will pass all tests:\n\n\tgit clone --depth=1 https://github.com/git/git.git git1\n\tcp -R git1 git2\n\tmake -C git1\n\t[apply this change to git2]\n\t(cd git2 && GIT_TEST_BUILD_DIR=\"$PWD/../git1\" make -C t prove)\n\nThis facility and file-based instructions to have the test suite use\nanother build directory[2] are mutually exclusive, but in a subsequent\ncommit we'll make CMake use this instead.\n\n1. 6720721e152 (test-lib.sh: Allow running the test suite against\n   installed git, 2009-03-16)\n2. 350a005e366 (cmake: avoid editing t/test-lib.sh, 2022-10-18)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/README      | 3 +++\n t/test-lib.sh | 5 ++++-\n 2 files changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/t/README b/t/README\nindex 979b2d4833d..fc0daef2e41 100644\n--- a/t/README\n+++ b/t/README\n@@ -231,6 +231,9 @@ override the location of the dashed-form subcommands (what\n GIT_EXEC_PATH would be used for during normal operation).\n GIT_TEST_EXEC_PATH defaults to `$GIT_TEST_INSTALLED/git --exec-path`.\n \n+Similar to GIT_TEST_INSTALLED, GIT_TEST_BUILD_DIR can be pointed to\n+another git.git checkout's build directory, to test its built binaries\n+against the tests in this checkout.\n \n Skipping Tests\n --------------\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 36358811a0f..388774a0aa0 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -51,7 +51,10 @@ fi\n # For CMake the top-level source directory is different from our build\n # directory. With the top-level Makefile they're the same.\n GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n-if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n+if test -n \"$GIT_TEST_BUILD_DIR\"\n+then\n+\tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n+elif test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n \t# On Windows, we must convert Windows paths lest they contain a colon\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466248","messageId":"patch-v3-08.12-fd3e6be5689-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 08/12] Makefile + cmake: use environment, not GIT-BUILD-DIR","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:32Z","receivedAt":"2022-11-01T22:52:21Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the method used to have building with \"cmake\" followed by\nrunning the tests manually work without creating inter-dependency issues with the Makefile.\n\nPer ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18) and\nthe surrounding discussion the goal of that change was to have\nbuilding with cmake and:\n\n\t(cd t && ./t0001-init.sh)\n\nWork, to do so we need some way to make the test-lib.sh aware that we\nhave a build in contrib/buildsystems/out. The downside of doing it via\nthe GIT-BUILD-DIR facility in ee9e66e4e76 is:\n\n- A \"remove this file while at it\" only fits into the Makefile\n  dependency graph if we \"FORCE\" a shell command to be run, so doing it\n  this way precludes speeding up the Makefile by e.g. making use of the\n  \"$(file)\" function (for which I've got follow-up patches).\n\n- If you build with make, then with cmake, and then e.g.:\n\n\tmake -C t prove\n\n  We'll run the tests against the cmake version of the tests, not the\n  \"make\" built ones. It's important to get any subtle interaction\n  between two conflicting build systems right.\n\nNow we'll instead:\n\n- Check if the top-level \"git\" exists, if not we'll look in\n  \"contrib/buildsystems/out/git\", and when running interactively inform\n  the user about the fallback being picked.\n\n\t$ ./t0001-init.sh\n\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n\tok 1 - plain\n\t[...]\n\n- This also makes things more obvious on the cmake side, because we'll\n  now use an environment variable to select the test environment, which\n  ctest it notes in its verbose output, e.g.:\n\n\t[...]\n\t2: Test command: /bin/sh \"/home/avar/g/git/contrib/buildsystems/../../t/t0001-init.sh\" \"--no-bin-wrappers\" \"--no-chain-lint\" \"-vx\"\n\t2: Working Directory: /home/avar/g/git/contrib/buildsystems/../../t\n\t2: Environment variables:\n\t2:  GIT_TEST_BUILD_DIR=/home/avar/g/git/contrib/buildsystems/out\n\t[...]\n\n   See [1] for the relevant cmake language references.\n\n- We don't support an arbitrary build directory outside of\n  \"contrib/buildsystems/out\". This is OK because the reason for doing\n  this part is to support the workflow documented in [2].\n\n  As [3] notes \"contrib/buildsystems/out\" isn't just the directory that\n  happens to be documented in \"contrib/buildsystems/CMakeLists.txt\", but\n  the one that VS will use when building git.\n\n1. https://cmake.org/cmake/help/latest/command/set_property.html\n   https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#test-properties\n   https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#cmake-language-lists\n1. f2f1250c47f (cmake (Windows): recommend using Visual Studio's\n   built-in CMake support, 2020-09-30)\n2. 3eccc7b99d4 (cmake: ignore files generated by CMake as run in\n   Visual Studio, 2020-09-25)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .gitignore                          |  1 -\n Makefile                            |  1 -\n contrib/buildsystems/CMakeLists.txt | 10 ++--------\n t/test-lib.sh                       | 16 ++++++++++++++--\n 4 files changed, 16 insertions(+), 12 deletions(-)\n\ndiff --git a/.gitignore b/.gitignore\nindex cb0231fb401..62720c6135d 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -1,5 +1,4 @@\n /fuzz_corpora\n-/GIT-BUILD-DIR\n /GIT-BUILD-OPTIONS\n /GIT-CFLAGS\n /GIT-LDFLAGS\ndiff --git a/Makefile b/Makefile\nindex 4927379184c..36802fe45eb 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -3045,7 +3045,6 @@ else\n \t@echo RUNTIME_PREFIX=\\'false\\' >>$@+\n endif\n \t@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi\n-\t@if test -f GIT-BUILD-DIR; then rm GIT-BUILD-DIR; fi\n \n ### Detect Python interpreter path changes\n ifndef NO_PYTHON\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex fc45004226a..f0de37b35a1 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1108,14 +1108,6 @@ if(USE_VCPKG)\n \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n endif()\n \n-#Make the tests work when building out of the source tree\n-get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n-if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n-\t#Setting the build directory in test-lib.sh before running tests\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n-\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n-endif()\n-\n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n \n #test\n@@ -1123,6 +1115,8 @@ foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n \t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n+\tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n+\t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n endforeach()\n \n # This test script takes an extremely long time and is known to time out even\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 388774a0aa0..ce319c9963e 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -51,12 +51,17 @@ fi\n # For CMake the top-level source directory is different from our build\n # directory. With the top-level Makefile they're the same.\n GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n+\n+GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=\n if test -n \"$GIT_TEST_BUILD_DIR\"\n then\n \tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n-elif test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n+elif ! test -x \"$GIT_BUILD_DIR/git\" &&\n+     test -x \"$GIT_BUILD_DIR/contrib/buildsystems/out/git\"\n then\n-\tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n+\tGIT_BUILD_DIR=\"$GIT_SOURCE_DIR/contrib/buildsystems/out\"\n+\tGIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=t\n+\n \t# On Windows, we must convert Windows paths lest they contain a colon\n \tcase \"$(uname -s)\" in\n \t*MINGW*)\n@@ -1637,6 +1642,13 @@ remove_trash_directory \"$TRASH_DIRECTORY\" || {\n \tBAIL_OUT 'cannot prepare test area'\n }\n \n+# Emitting this now because earlier we didn't have \"say\", but not in\n+# anything using lib-subtest.sh\n+if test -n \"$GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT\" && test -t 1\n+then\n+\tsay \"setup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\"\n+fi\n+\n remove_trash=t\n if test -z \"$TEST_NO_CREATE_REPO\"\n then\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466249","messageId":"patch-v3-09.12-8a660a2baa4-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 09/12] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:33Z","receivedAt":"2022-11-01T22:52:24Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The rationale for adding \"--no-bin-wrappers\" and \"--no-chain-lint\" in\n2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\nruns, 2022-10-18) was those options slowed down the tests considerably\non Windows.\n\nBut since f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\nand with the preceding commits cmake and ctest are not\nWindows-specific anymore.\n\nSo let's set those same options by default on Windows, but do so with\nthe set() facility. As noted in cmake's documentation[1] this\nintegrates nicely with e.g. cmake-gui.\n\nOn *nix we don't set any custom options. The change in 2ea1d8b5563\ndidn't discuss why Windows should have divergent defaults with \"cmake\"\nand \"make\", but such reasons presumably don't apply on *nix. I for one\nam happy with the same defaults as the tests have when running via the\nMakefile.\n\nWith the \"message()\" addition we'll emit this when running cmake:\n\n\tGenerating hook-list.h\n\t-- Using user-selected test options: -vixd\n\t-- Configuring done\n\t-- Generating done\n\t-- Build files have been written to: /home/avar/g/git/contrib/buildsystems/out\n\nUnfortunately cmake doesn't support a non-hacky way to pass variables\nto ctest without re-running cmake itself, so when re-running tests via\ncmake and wanting to change the test defaults we'll need:\n\n\tGIT_TEST_OPTS=-i cmake -S contrib/buildsystems -B contrib/buildsystems/out &&\n\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out -R t0071 --verbose\n\n1. https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 46 +++++++++++++++++++++++++++--\n 1 file changed, 44 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex f0de37b35a1..6a3240d4ffa 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -49,7 +49,7 @@ To use this in Visual Studio:\n \n Open the worktree as a folder. Visual Studio 2019 and later will detect\n the CMake configuration automatically and set everything up for you,\n-ready to build. You can then run the tests in `t/` via a regular Git Bash.\n+ready to build. See \"== Running the tests ==\" below for running the tests.\n \n Note: Visual Studio also has the option of opening `CMakeLists.txt`\n directly; Using this option, Visual Studio will not find the source code,\n@@ -74,6 +74,35 @@ empty(default) :\n \n NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n this option is ignored\n+\n+== Running the tests ==\n+\n+Once we've built in \"contrib/buildsystems/out\" the tests can be run at\n+the top-level (note: not the generated \"contrib/buildsystems/out/t/\"\n+drectory). If no top-level build is found (as created with the\n+Makefile) the t/test-lib.sh will discover the git in\n+\"contrib/buildsystems/out\" on e.g.:\n+\n+\t(cd t && ./t0001-init.sh)\n+\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n+\t[...]\n+\n+The tests can also be run with ctest, e.g. after building with \"cmake\"\n+and \"make\" or \"msbuild\" run, from the top-level e.g.:\n+\n+\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\"--output-on-failure\n+\n+Options can be passed by setting GIT_TEST_OPTIONS before invoking\n+cmake. E.g. on a Linux system with systemd the tests can be sped up by\n+using a ramdisk for the scratch files:\n+\n+\tGIT_TEST_OPTS=\"--root=/run/user/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n+\t[...]\n+\t-- Using user-selected test options: --root=/run/user/1001/ctest\n+\n+Then running the tests with \"ctest\" (here with --jobs=\"$(nproc)\"):\n+\n+\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out\n ]]\n cmake_minimum_required(VERSION 3.14)\n \n@@ -1110,10 +1139,23 @@ endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n \n+string(COMPARE NOTEQUAL \"$ENV{GIT_TEST_OPTS}\" \"\" HAVE_USER_GIT_TEST_OPTS)\n+if(HAVE_USER_GIT_TEST_OPTS)\n+\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n+\tmessage(STATUS \"Using user-selected test options: ${GIT_TEST_OPTS}\")\n+elseif(WIN32)\n+\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\")\n+\tmessage(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n+else()\n+\tset(GIT_TEST_OPTS \"\")\n+\tmessage(STATUS \"No custom test options selected, set e.g. GIT_TEST_OPTS=\\\"-vixd\\\"\")\n+endif()\n+separate_arguments(GIT_TEST_OPTS)\n+\n #test\n foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n-\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n+\t\tCOMMAND ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n \tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n \t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466250","messageId":"patch-v3-11.12-aad17d8f858-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 11/12] cmake: copy over git-p4.py for t983[56] perforce test","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:35Z","receivedAt":"2022-11-01T22:52:26Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] two git-p4 tests have relied on there being a \"git-p4.py\" in\nthe build directory, but the cmake recipe was not updated to account\nfor this. Let's copy the \"git-p4.py\" over.\n\nWe could also change the test to e.g. grab the built \"git-p4\" and\nalter its shebang, which would be friendly to GIT_TEST_INSTALLED, but\nlet's just do the bare minimum here to get cmake+ctest working without\naltering the test itself.\n\nThe reason this hasn't been caught by \"vs-build\" and \"vs-test\" is\nbecause those tests added in [2] invoke \"cmake\" with\n\"-DPYTHON_TESTS=OFF\", and therefore we'd skip this part of the git-p4\ntests before getting past the \"do we have python?\" check. Even if we\ngot past that the Windows CI wouldn't have a \"p4\" or \"p4d\" binary\ninstalled, so we'd skip the tests anyway.\n\nIn a subsequent commit we'll run \"cmake\" and \"ctest\" in CI with\n\"ubuntu-latest\", so we'll need this \"git-p4.py\" file.\n\n1. f7b5ff607fa (git-p4: improve encoding handling to support\n   inconsistent encodings, 2022-04-30)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex be5dce8ec69..2e299e933a6 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -917,6 +917,7 @@ file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/git-p4)\n+file(COPY ${CMAKE_SOURCE_DIR}/git-p4.py DESTINATION ${CMAKE_BINARY_DIR}/)\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466251","messageId":"patch-v3-10.12-966fec83b77-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 10/12] cmake: increase test timeout on Windows only","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:34Z","receivedAt":"2022-11-01T22:52:28Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Per c858750b41c (cmake: increase time-out for a long-running test,\n2022-10-18) the reason to set a custom timeout for\nt7112-reset-submodule.sh is Windows-specific. Let's only do that on\nWindows then.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 6a3240d4ffa..be5dce8ec69 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1161,8 +1161,10 @@ foreach(tsh ${test_scipts})\n \t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n endforeach()\n \n-# This test script takes an extremely long time and is known to time out even\n-# on fast machines because it requires in excess of one hour to run\n-set_tests_properties(\"${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh\" PROPERTIES TIMEOUT 4000)\n+if(WIN32)\n+\t# This test script takes an extremely long time and is known to time out even\n+\t# on fast machines because it requires in excess of one hour to run\n+\tset_tests_properties(\"${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh\" PROPERTIES TIMEOUT 4000)\n+endif()\n \n endif()#BUILD_TESTING\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466252","messageId":"patch-v3-12.12-c27f620dfa3-20221101T225022Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v3 12/12] CI: add a \"linux-cmake-test\" to run cmake & ctest on linux","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-01T22:51:36Z","receivedAt":"2022-11-01T22:52:52Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] the \"cmake\" build method should work properly on Linux, but\nas seen in preceding commits there were various bugs in it, which are\nhopefully now all fixed.\n\nTo ensure that it doesn't break again let's add a \"linux-cmake-ctest\"\ntarget to build and test \"cmake\" on Linux, in addition to that we'll\nalso run the tests with \"ctest\" instead of \"make\" or \"prove\", so we\ncan assert that testing with that method works..\n\nThis also stress tests running \"cmake\" (and \"ctest\") out of a build\ndirectory that isn't the top-level. The \"vs-build\" job uses \"cmake\"\nsince [2], but clobbers the top-level \"Makefile\" and builds in the\ntop-level directory.\n\nThat was the reason for why we didn't spot that various tests still\nrequired missing \"mergetools/*\" etc, which was fixed by using\n\"$GIT_SOURCE_DIR\" in a preceding commit.\n\nSince the \"ci/lib.sh\" already creates and exports a\nGIT_TEST_OPTS=\"...\" we'll pick that up in our CI, see the preceding\ncommit. Because we pass the \"--verbose-log -x\n--github-workflow-markup\" in the GitHub CI as a result the interaction\nwith \"handle_failed_tests\" here works correctly. I.e. on failure we'll\nhave saved \"t/test-results/*.{exit,out,markup}\" files relevant to the\nfailing test(s).\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .github/workflows/main.yml |  3 +++\n ci/run-build-and-tests.sh  | 13 +++++++++++--\n 2 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/.github/workflows/main.yml b/.github/workflows/main.yml\nindex bd6f75b8e0f..68c2e134646 100644\n--- a/.github/workflows/main.yml\n+++ b/.github/workflows/main.yml\n@@ -238,6 +238,9 @@ jobs:\n             os: ubuntu\n             cc_package: gcc-8\n             pool: ubuntu-latest\n+          - jobname: linux-cmake-ctest\n+            cc: gcc\n+            pool: ubuntu-latest\n           - jobname: osx-clang\n             cc: clang\n             pool: macos-latest\ndiff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh\nindex 8ebff425967..a3ae5ff3972 100755\n--- a/ci/run-build-and-tests.sh\n+++ b/ci/run-build-and-tests.sh\n@@ -45,10 +45,19 @@ pedantic)\n \t;;\n esac\n \n-group Build make\n+mc=\n+if test \"$jobname\" = \"linux-cmake-ctest\"\n+then\n+\tcb=contrib/buildsystems\n+\tgroup CMake cmake -S \"$cb\" -B \"$cb/out\"\n+\tmc=\"-C $cb/out\"\n+fi\n+\n+group Build make $mc\n+\n if test -n \"$run_tests\"\n then\n-\tgroup \"Run tests\" make test ||\n+\tgroup \"Run tests\" make $mc test ||\n \thandle_failed_tests\n fi\n check_unignored_build_artifacts\n-- \n2.38.0.1280.g8136eb6fab2\n\n"},{"id":"466255","messageId":"CAPig+cRA5-TS_FVpw=oRN3Ws0BBRDcTkXWsVuMnk4Z4d1uLF2g@mail.gmail.com","threadId":"58666","inReplyTo":"patch-v3-02.12-7a21f4aa24c-20221101T225022Z-avarab@gmail.com","subject":"Re: [PATCH v3 02/12] cmake: update instructions for portable CMakeLists.txt","fromName":"Eric Sunshine","fromEmail":"ericsunshine@gmail.com","sentAt":"2022-11-01T22:58:37Z","receivedAt":"2022-11-01T22:59:11Z","isPatch":true,"sender":{"key":"ericsunshine@gmail.com","avatar":null},"body":"On Tue, Nov 1, 2022 at 6:51 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n> The instructions for running CMake went back & forth between *nix,\n> Windows and Visual Studio instructions Let's create headings and split\n> the existing instructions up into those new sections.\n>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n> diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n> @@ -4,7 +4,48 @@\n> +== Building ==\n> +\n> +The \"cmake\" command creates a build file from this recipe. For Windows\n> +Open contrib/buildsystems/git.sln and build Git. Or use the\n\nI suspect you wanted: s/Windows Open contrib/Windows, open contrib/\n\n> +\"msbuild\" command-line tool (see our own \".github/workflows/main.yml\"\n> +for a real example):\n"},{"id":"466387","messageId":"eca36d20-8469-0e37-3af6-8a7a976df1a2@dunelm.org.uk","threadId":"58666","inReplyTo":"cover-v2-00.11-00000000000-20221027T032622Z-avarab@gmail.com","subject":"Re: [PATCH v2 00/11] cmake: document, fix on *nix, add CI","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-11-03T09:34:58Z","receivedAt":"2022-11-03T09:35:05Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 27/10/2022 04:26, Ævar Arnfjörð Bjarmason wrote:\n>    cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n> \n> I tried to use the suggested \"write_script\" function, but couldn't get\n> past cmake quoting issues. So the commit message is updated, but the\n> change is the same.\n\nThat's a shame - what was the issue? My suggestion was cut and pasted \nfrom \nhttps://github.com/phillipwood/git/commit/0bb195b00c3a5ff27ec66a5966d0a9d91a187738 \nI don't remember having any problems when I wrote it.\n\nBest Wishes\n\nPhillip\n"},{"id":"466389","messageId":"0999e43a-8f6e-bcc1-9f7d-f55b642b5ef4@dunelm.org.uk","threadId":"58666","inReplyTo":"patch-v3-01.12-028fa1436d8-20221101T225022Z-avarab@gmail.com","subject":"Re: [PATCH v3 01/12] cmake: don't \"mkdir -p\" and \"cd\" in build instructions","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-11-03T09:37:49Z","receivedAt":"2022-11-03T09:37:57Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 01/11/2022 22:51, Ævar Arnfjörð Bjarmason wrote:\n> Use the \"-S\" and -B\" flags instead of \"mkdir -p\" and \"cd\". The \"-p\"\n> flag to \"mkdir\" wasn't needed as \"contrib/buildsystems\" is tracked,\n> and the rest of this is now easier to copy/paste into a shell without\n> having one's directory changed.\n\nWhen was \"-B\" added? This feels like a personal preference rather than \nan objective improvement. Arguably changing into the build directory is \nactually better as ctest has to be run from there. It also appears that \nthese instructions have not been tested as the make invocation in wrong.\n\nBest Wishes\n\nPhillip\n\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>   contrib/buildsystems/CMakeLists.txt | 8 +++-----\n>   1 file changed, 3 insertions(+), 5 deletions(-)\n> \n> diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n> index 3957e4cf8cd..494da807c53 100644\n> --- a/contrib/buildsystems/CMakeLists.txt\n> +++ b/contrib/buildsystems/CMakeLists.txt\n> @@ -16,9 +16,7 @@ though, therefore the `File>Open>Folder...` option is preferred.\n>   \n>   Instructions to run CMake manually:\n>   \n> -    mkdir -p contrib/buildsystems/out\n> -    cd contrib/buildsystems/out\n> -    cmake ../ -DCMAKE_BUILD_TYPE=Release\n> +    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n>   \n>   This will build the git binaries in contrib/buildsystems/out\n>   directory (our top-level .gitignore file knows to ignore contents of\n> @@ -36,8 +34,8 @@ NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual St\n>   this option is ignored\n>   \n>   This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n> -Run `make` to build Git on Linux/*BSD/MacOS.\n> -Open git.sln on Windows and build Git.\n> +Run `make -C contrib/buildsystems` to build Git on Linux/*BSD/MacOS.\n> +Open contrib/buildsystems/git.sln on Windows and build Git.\n>   \n>   NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n>   to use another tool say `ninja` add this to the command line when configuring.\n"},{"id":"466390","messageId":"059cf6aa-d288-6584-4d48-90f831de5344@dunelm.org.uk","threadId":"58666","inReplyTo":"patch-v3-02.12-7a21f4aa24c-20221101T225022Z-avarab@gmail.com","subject":"Re: [PATCH v3 02/12] cmake: update instructions for portable CMakeLists.txt","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-11-03T09:42:33Z","receivedAt":"2022-11-03T09:42:40Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 01/11/2022 22:51, Ævar Arnfjörð Bjarmason wrote:\n> The instructions for running CMake went back & forth between *nix,\n> Windows and Visual Studio instructions Let's create headings and split\n> the existing instructions up into those new sections.\n> \n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>   contrib/buildsystems/CMakeLists.txt | 66 +++++++++++++++++++++--------\n>   1 file changed, 48 insertions(+), 18 deletions(-)\n> \n> diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n> index 494da807c53..7bc123da315 100644\n> --- a/contrib/buildsystems/CMakeLists.txt\n> +++ b/contrib/buildsystems/CMakeLists.txt\n> @@ -4,7 +4,48 @@\n>   \n>   #[[\n>   \n> -Instructions how to use this in Visual Studio:\n> +== Overview ==\n> +\n> +The top-level Makefile is Git's primary build environment, and a lot\n> +of things are missing (and probably always will be) from this CMake\n> +alternative.\n> +\n> +The primary use-case for maintaining this CMake build recipe is to\n> +have nicer IDE integration on Windows. To get Visual Studio-specific\n> +instructions see \"== Visual Studio & Windows ==\" below.\n\nIf that is the primary use-case (which I agree it is) then it perhaps we \nshould but the instructions for that use at the top of the document.\n\n> +\n> +== Creating a build recipe ==\n> +\n> +To create the build recipe run:\n> +\n> +    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n> +\n> +For alternative \"-DCMAKE_BUILD_TYPE=<type>\" flags see instructions\n> +under the \"== -DCMAKE_BUILD_TYPE=<type> ==\" heading below.\n\nRather than forcing the reader to jump back and forth, perhaps we could \ndocument -DCMAKE_BUILD_TYPE and -GNinja here.\n\nBest Wishes\n\nPhillip\n"},{"id":"466394","messageId":"4d6ff46f-afc1-62a6-923d-b793712a5276@dunelm.org.uk","threadId":"58666","inReplyTo":"patch-v3-09.12-8a660a2baa4-20221101T225022Z-avarab@gmail.com","subject":"Re: [PATCH v3 09/12] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-11-03T10:03:30Z","receivedAt":"2022-11-03T10:03:37Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 01/11/2022 22:51, Ævar Arnfjörð Bjarmason wrote:\n> The rationale for adding \"--no-bin-wrappers\" and \"--no-chain-lint\" in\n> 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n> runs, 2022-10-18) was those options slowed down the tests considerably\n> on Windows.\n> \n> But since f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n> and with the preceding commits cmake and ctest are not\n> Windows-specific anymore.\n> \n> So let's set those same options by default on Windows, but do so with\n> the set() facility. As noted in cmake's documentation[1] this\n> integrates nicely with e.g. cmake-gui.\n\nShouldn't there a documentation string for the variable if you want to \nsupport cmake-gui?\n\n> \n> On *nix we don't set any custom options. The change in 2ea1d8b5563\n> didn't discuss why Windows should have divergent defaults with \"cmake\"\n> and \"make\", but such reasons presumably don't apply on *nix. I for one\n> am happy with the same defaults as the tests have when running via the\n> Makefile.\n> \n> With the \"message()\" addition we'll emit this when running cmake:\n> \n> \tGenerating hook-list.h\n> \t-- Using user-selected test options: -vixd\n> \t-- Configuring done\n> \t-- Generating done\n> \t-- Build files have been written to: /home/avar/g/git/contrib/buildsystems/out\n> \n> Unfortunately cmake doesn't support a non-hacky way to pass variables\n> to ctest without re-running cmake itself, so when re-running tests via\n> cmake and wanting to change the test defaults we'll need:\n> \n> \tGIT_TEST_OPTS=-i cmake -S contrib/buildsystems -B contrib/buildsystems/out &&\n> \tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out -R t0071 --verbose\n\nRather than having to rerun cmake I think it would be nicer to use the \nshell to pass the test options when the tests are run so the user can \nset their preferred defaults when running cmake but override them with \nGIT_TEST_OPTIONS when running ctest as I showed previously.\n\n> 1. https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry\n> \n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>   contrib/buildsystems/CMakeLists.txt | 46 +++++++++++++++++++++++++++--\n>   1 file changed, 44 insertions(+), 2 deletions(-)\n> \n> diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\n> index f0de37b35a1..6a3240d4ffa 100644\n> --- a/contrib/buildsystems/CMakeLists.txt\n> +++ b/contrib/buildsystems/CMakeLists.txt\n> @@ -49,7 +49,7 @@ To use this in Visual Studio:\n>   \n>   Open the worktree as a folder. Visual Studio 2019 and later will detect\n>   the CMake configuration automatically and set everything up for you,\n> -ready to build. You can then run the tests in `t/` via a regular Git Bash.\n> +ready to build. See \"== Running the tests ==\" below for running the tests.\n>   \n>   Note: Visual Studio also has the option of opening `CMakeLists.txt`\n>   directly; Using this option, Visual Studio will not find the source code,\n> @@ -74,6 +74,35 @@ empty(default) :\n>   \n>   NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n>   this option is ignored\n> +\n> +== Running the tests ==\n> +\n> +Once we've built in \"contrib/buildsystems/out\" the tests can be run at\n> +the top-level (note: not the generated \"contrib/buildsystems/out/t/\"\n> +drectory). If no top-level build is found (as created with the\n> +Makefile) the t/test-lib.sh will discover the git in\n> +\"contrib/buildsystems/out\" on e.g.:\n> +\n> +\t(cd t && ./t0001-init.sh)\n> +\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n> +\t[...]\n> +\n> +The tests can also be run with ctest, e.g. after building with \"cmake\"\n> +and \"make\" or \"msbuild\" run, from the top-level e.g.:\n> +\n> +\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\"--output-on-failure\n\nCmakeLists.txt claims we only require v3.14 which does not appear to \nsupport --test-dir (see \nhttps://cmake.org/cmake/help/v3.14/manual/ctest.1.html)\n\n> +Options can be passed by setting GIT_TEST_OPTIONS before invoking\n> +cmake. E.g. on a Linux system with systemd the tests can be sped up by\n> +using a ramdisk for the scratch files:\n\nDoesn't the systemd wiki warn against using /run for things like this as \nto avoid running out of space. I thought our usual recommendation was to \nuse --root=/dev/shm\n\n> +\tGIT_TEST_OPTS=\"--root=/run/user/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n> +\t[...]\n> +\t-- Using user-selected test options: --root=/run/user/1001/ctest\n> +\n> +Then running the tests with \"ctest\" (here with --jobs=\"$(nproc)\"):\n\nI think it would be helpful to show setting --jobs at configure time as \nit makes running the tests simpler.\n\n> +\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out\n>   ]]\n>   cmake_minimum_required(VERSION 3.14)\n>   \n> @@ -1110,10 +1139,23 @@ endif()\n>   \n>   file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n>   \n> +string(COMPARE NOTEQUAL \"$ENV{GIT_TEST_OPTS}\" \"\" HAVE_USER_GIT_TEST_OPTS)\n> +if(HAVE_USER_GIT_TEST_OPTS)\n\nif (DEFINED ENV{GIT_TEST_OPTS}) ?\n\n> +\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n> +\tmessage(STATUS \"Using user-selected test options: ${GIT_TEST_OPTS}\")\n> +elseif(WIN32)\n> +\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\")\n> +\tmessage(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n> +else()\n> +\tset(GIT_TEST_OPTS \"\")\n\nI'd like to see us setting -vx here so users get debugging logs\n\n> +\tmessage(STATUS \"No custom test options selected, set e.g. GIT_TEST_OPTS=\\\"-vixd\\\"\")\n> +endif()\n> +separate_arguments(GIT_TEST_OPTS)\n\nWhat rules does this use for separating arguments?\n\nBest Wishes\n\nPhillip\n\n>   #test\n>   foreach(tsh ${test_scipts})\n>   \tadd_test(NAME ${tsh}\n> -\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n> +\t\tCOMMAND ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n>   \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n>   \tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n>   \t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n"},{"id":"466410","messageId":"221103.86a6581129.gmgdl@evledraar.gmail.com","threadId":"58666","inReplyTo":"4d6ff46f-afc1-62a6-923d-b793712a5276@dunelm.org.uk","subject":"Re: [PATCH v3 09/12] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T15:43:35Z","receivedAt":"2022-11-03T16:02:05Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Thu, Nov 03 2022, Phillip Wood wrote:\n\n> On 01/11/2022 22:51, Ævar Arnfjörð Bjarmason wrote:\n>> The rationale for adding \"--no-bin-wrappers\" and \"--no-chain-lint\" in\n>> 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n>> runs, 2022-10-18) was those options slowed down the tests considerably\n>> on Windows.\n>> But since f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n>> and with the preceding commits cmake and ctest are not\n>> Windows-specific anymore.\n>> So let's set those same options by default on Windows, but do so\n>> with\n>> the set() facility. As noted in cmake's documentation[1] this\n>> integrates nicely with e.g. cmake-gui.\n>\n> Shouldn't there a documentation string for the variable if you want to\n> support cmake-gui?\n\nYeah, I missed that. Now I've actually tested it locally with cmake-gui,\nand it works.\n\n>> On *nix we don't set any custom options. The change in 2ea1d8b5563\n>> didn't discuss why Windows should have divergent defaults with \"cmake\"\n>> and \"make\", but such reasons presumably don't apply on *nix. I for one\n>> am happy with the same defaults as the tests have when running via the\n>> Makefile.\n>> With the \"message()\" addition we'll emit this when running cmake:\n>> \tGenerating hook-list.h\n>> \t-- Using user-selected test options: -vixd\n>> \t-- Configuring done\n>> \t-- Generating done\n>> \t-- Build files have been written to: /home/avar/g/git/contrib/buildsystems/out\n>> Unfortunately cmake doesn't support a non-hacky way to pass\n>> variables\n>> to ctest without re-running cmake itself, so when re-running tests via\n>> cmake and wanting to change the test defaults we'll need:\n>> \tGIT_TEST_OPTS=-i cmake -S contrib/buildsystems -B\n>> contrib/buildsystems/out &&\n>> \tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out -R t0071 --verbose\n>\n> Rather than having to rerun cmake I think it would be nicer to use the\n> shell to pass the test options when the tests are run so the user can \n> set their preferred defaults when running cmake but override them with\n> GIT_TEST_OPTIONS when running ctest as I showed previously.\n\nYeah, I saw that, sorry about not directly addressing it. I tried it,\nbut in the end I think I'd rather narrow down the scope in this series.\n\nI.e. before it's hardcoded with no way to change it, after you can set\nit at build time.\n\ncmake's model of viewing the world seems to really dislike the notion of\ndynamically setting test options for whatever reason, it's a FAQ about\ncmake/ctest. Your sh -c workaround is clever, and there's similar\nworkarounds e.g. on stackoverflow.\n\nBut let's pursue that separately, and just go for the \"way cmake likes\nit\" in this series.\n\n>> 1. https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry\n>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>> ---\n>>   contrib/buildsystems/CMakeLists.txt | 46 +++++++++++++++++++++++++++--\n>>   1 file changed, 44 insertions(+), 2 deletions(-)\n>> diff --git a/contrib/buildsystems/CMakeLists.txt\n>> b/contrib/buildsystems/CMakeLists.txt\n>> index f0de37b35a1..6a3240d4ffa 100644\n>> --- a/contrib/buildsystems/CMakeLists.txt\n>> +++ b/contrib/buildsystems/CMakeLists.txt\n>> @@ -49,7 +49,7 @@ To use this in Visual Studio:\n>>     Open the worktree as a folder. Visual Studio 2019 and later will\n>> detect\n>>   the CMake configuration automatically and set everything up for you,\n>> -ready to build. You can then run the tests in `t/` via a regular Git Bash.\n>> +ready to build. See \"== Running the tests ==\" below for running the tests.\n>>     Note: Visual Studio also has the option of opening\n>> `CMakeLists.txt`\n>>   directly; Using this option, Visual Studio will not find the source code,\n>> @@ -74,6 +74,35 @@ empty(default) :\n>>     NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config\n>> generators like Visual Studio\n>>   this option is ignored\n>> +\n>> +== Running the tests ==\n>> +\n>> +Once we've built in \"contrib/buildsystems/out\" the tests can be run at\n>> +the top-level (note: not the generated \"contrib/buildsystems/out/t/\"\n>> +drectory). If no top-level build is found (as created with the\n>> +Makefile) the t/test-lib.sh will discover the git in\n>> +\"contrib/buildsystems/out\" on e.g.:\n>> +\n>> +\t(cd t && ./t0001-init.sh)\n>> +\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n>> +\t[...]\n>> +\n>> +The tests can also be run with ctest, e.g. after building with \"cmake\"\n>> +and \"make\" or \"msbuild\" run, from the top-level e.g.:\n>> +\n>> +\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\"--output-on-failure\n>\n> CmakeLists.txt claims we only require v3.14 which does not appear to\n> support --test-dir (see \n> https://cmake.org/cmake/help/v3.14/manual/ctest.1.html)\n\nThanks, I missed that, updated docs etc. as appropriate in the incoming\nre-roll.\n\n>> +Options can be passed by setting GIT_TEST_OPTIONS before invoking\n>> +cmake. E.g. on a Linux system with systemd the tests can be sped up by\n>> +using a ramdisk for the scratch files:\n>\n> Doesn't the systemd wiki warn against using /run for things like this\n> as to avoid running out of space. I thought our usual recommendation\n> was to use --root=/dev/shm\n\nUsed /dev/shm in the updated docs.\n\n>> +\tGIT_TEST_OPTS=\"--root=/run/user/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n>> +\t[...]\n>> +\t-- Using user-selected test options: --root=/run/user/1001/ctest\n>> +\n>> +Then running the tests with \"ctest\" (here with --jobs=\"$(nproc)\"):\n>\n> I think it would be helpful to show setting --jobs at configure time\n> as it makes running the tests simpler.\n\nmm, you mean turn it into a set(...) variable? Sounds useful, or ideally\ngrabbing some pre-set cmake idea of the parallelism.\n\nBut for now I'd like to just leave it as \"maybe try running this\",\nrather than integrate it into the whole cmake/ctest chain.\n\n>> +\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out\n>>   ]]\n>>   cmake_minimum_required(VERSION 3.14)\n>>   @@ -1110,10 +1139,23 @@ endif()\n>>     file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n>>   +string(COMPARE NOTEQUAL \"$ENV{GIT_TEST_OPTS}\" \"\"\n>> HAVE_USER_GIT_TEST_OPTS)\n>> +if(HAVE_USER_GIT_TEST_OPTS)\n>\n> if (DEFINED ENV{GIT_TEST_OPTS}) ?\n\nThanks! That's much better.\n\n>> +\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n>> +\tmessage(STATUS \"Using user-selected test options: ${GIT_TEST_OPTS}\")\n>> +elseif(WIN32)\n>> +\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\")\n>> +\tmessage(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n>> +else()\n>> +\tset(GIT_TEST_OPTS \"\")\n>\n> I'd like to see us setting -vx here so users get debugging logs\n\nI think it might make sense to do that by default, but let's consider\nthat separately, and if we're going to do that we should set that\ndefault for the t/Makefile (or t/test-lib.h), not just cmake.\n\nThe reason it has these settings now is because of Windows-specific\ntrade-offs in the already landed topic.\n\nBut since the topic of this series is to port it to run nicely on *nix I\ndon't see why we'd have it as a goal to have \"cmake\" / \"ctest\" behave\ndifferently than \"make\" or \"make test\".\n\nExcept of course cases where some inherent differente between the\ntoolchains suggests that we should.\n\nBut in this case I don't see why that's the case, if I run a full\n\"ctest\" run and have failures, I might wish I've got logs, but the same\ngoes for:\n\n     make test GIT_TEST_OPTS=\"--verbose-log -vx\"\n\n>> +\tmessage(STATUS \"No custom test options selected, set e.g. GIT_TEST_OPTS=\\\"-vixd\\\"\")\n>> +endif()\n>> +separate_arguments(GIT_TEST_OPTS)\n>\n> What rules does this use for separating arguments?\n\nBad ones :( I've updated the commit message accordingly, but kept this,\nI couldn't find some non-crappy way to e.g. handle spaces in parameters\non the cmake version we require.\n"},{"id":"466411","messageId":"221103.865yfw110a.gmgdl@evledraar.gmail.com","threadId":"58666","inReplyTo":"059cf6aa-d288-6584-4d48-90f831de5344@dunelm.org.uk","subject":"Re: [PATCH v3 02/12] cmake: update instructions for portable CMakeLists.txt","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:00:15Z","receivedAt":"2022-11-03T16:03:44Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Thu, Nov 03 2022, Phillip Wood wrote:\n\n> On 01/11/2022 22:51, Ævar Arnfjörð Bjarmason wrote:\n>> The instructions for running CMake went back & forth between *nix,\n>> Windows and Visual Studio instructions Let's create headings and split\n>> the existing instructions up into those new sections.\n>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>> ---\n>>   contrib/buildsystems/CMakeLists.txt | 66 +++++++++++++++++++++--------\n>>   1 file changed, 48 insertions(+), 18 deletions(-)\n>> diff --git a/contrib/buildsystems/CMakeLists.txt\n>> b/contrib/buildsystems/CMakeLists.txt\n>> index 494da807c53..7bc123da315 100644\n>> --- a/contrib/buildsystems/CMakeLists.txt\n>> +++ b/contrib/buildsystems/CMakeLists.txt\n>> @@ -4,7 +4,48 @@\n>>     #[[\n>>   -Instructions how to use this in Visual Studio:\n>> +== Overview ==\n>> +\n>> +The top-level Makefile is Git's primary build environment, and a lot\n>> +of things are missing (and probably always will be) from this CMake\n>> +alternative.\n>> +\n>> +The primary use-case for maintaining this CMake build recipe is to\n>> +have nicer IDE integration on Windows. To get Visual Studio-specific\n>> +instructions see \"== Visual Studio & Windows ==\" below.\n>\n> If that is the primary use-case (which I agree it is) then it perhaps\n> we should but the instructions for that use at the top of the\n> document.\n\nYes, I've tried to re-arrange it like that in the incoming v4.\n\n>> +\n>> +== Creating a build recipe ==\n>> +\n>> +To create the build recipe run:\n>> +\n>> +    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n>> +\n>> +For alternative \"-DCMAKE_BUILD_TYPE=<type>\" flags see instructions\n>> +under the \"== -DCMAKE_BUILD_TYPE=<type> ==\" heading below.\n>\n> Rather than forcing the reader to jump back and forth, perhaps we\n\n*nod*, changing...\n"},{"id":"466412","messageId":"patch-v4-02.14-dd934b0597d-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 02/14] cmake: use \"-S\" and \"-B\" to specify source and build directories","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:37:52Z","receivedAt":"2022-11-03T16:42:38Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Rather than the multi-line \"mkdir/cd/cmake\" recipe provide an\nequivalent one-liner using the \"-S\" and \"-B\" options, and then suggest building with \"make -C <build-dir>\".\n\nThe rest of these instructions discuss e.g. running tests from our\ntop-level \"t/\" directory, so it's more helpful to avoid changing the\nuser's current directory.\n\nThe \"-S\" and \"-B\" options were added in cmake v3.13.0, which is older\nthan the version we have a hard dependency on[1].\n\nAs an aside The \"-p\" flag to \"mkdir\" in the pre-image wasn't needed,\nas \"contrib/buildsystems\" is tracked\n\n1. 061c2240b1b (Introduce CMake support for configuring Git, 2020-06-12)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 0a75898ca9f..463f55e5516 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -16,9 +16,7 @@ though, therefore the `File>Open>Folder...` option is preferred.\n \n Instructions to run CMake manually:\n \n-    mkdir -p contrib/buildsystems/out\n-    cd contrib/buildsystems/out\n-    cmake ../ -DCMAKE_BUILD_TYPE=Release\n+    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n \n This will build the git binaries in contrib/buildsystems/out\n directory (our top-level .gitignore file knows to ignore contents of\n@@ -36,8 +34,8 @@ NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual St\n this option is ignored\n \n This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n-Run `make` to build Git on Linux/*BSD/MacOS.\n-Open git.sln on Windows and build Git.\n+Run `make -C contrib/buildsystems/out` to build Git on Linux/*BSD/MacOS.\n+Open contrib/buildsystems/git.sln on Windows and build Git.\n \n NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n to use another tool say `ninja` add this to the command line when configuring.\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466413","messageId":"patch-v4-05.14-eda1c1e95e5-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 05/14] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:37:55Z","receivedAt":"2022-11-03T16:42:41Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since the cmake file was made to run on *nix in [1] running the tests\nwith \"ctest\" broken, because we'd attempt to invoke our bin-wrappers/,\nbut they didn't have the executable bit.\n\nIn the best case, the \"t/test-lib.sh\" would be unable to find\n\"bin-wrappers/git\", and we'd fall back on\n\"GIT_EXEC_PATH=$GIT_BUILD_DIR\" using the fallback behavior added in\n[2]:\n\n\t$ ./t0001-init.sh\n\t<GIT_BUILD_DIR>/t/../contrib/buildsystems/out/bin-wrappers/git is not executable; using GIT_EXEC_PATH\n\nThis was recently somewhat swept under the rug in [3], as ctest would\nrun them with \"--no-bin-wrappers\". But still with [3], running e.g.:\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Debug &&\n\tmake -C contrib/buildsystems/out &&\n\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\" --output-on-failure\n\nFails around 20% of our tests on *nix. So even with [3] we'd fail any\ntest that needed to invoke one of our built shell, perl or Python\nscripts on *nix. E.g. t0012-help.sh would fail on a test that tried to\ninvoke \"git web--browse\". The equivalent of this (in the \"out\"\ndirectory) would happen:\n\n\t$ ./git --exec-path=$PWD web--browse\n\tgit: 'web--browse' is not a git command. See 'git --help'.\n\nWhich we can fix by \"chmod +x\"-ing the built \"git-web--browse\":\n\n\t$ chmod +x git-web--browse\n\t$ ./git --exec-path=$PWD web--browse\n\tusage: git web--browse [--browser=browser|--tool=browser] [--config=conf.var] url/file ...\n\nThe same goes for e.g. the \"git-p4\" tests, which would fail because\nour built \"git-p4\" wasn't executable, etc. There's also a few other\noutstanding issues, which will be fixed in subsequent commits.\n\nIdeally we'd use the file(CHMOD ...) form everywhere, but that syntax\nwas introduced in cmake 3.19[4], whereas we only require 3.14. Let's\nprovide a fallback behind a version check, so that we'll eventually be\nable to delete the \"else\" part. Both forms result in the same file\nmodes.\n\nBefore this change:\n\n\t80% tests passed, 196 tests failed out of 977\n\nAfter:\n\n\t99% tests passed, 5 tests failed out of 977\n\nThe remaining failures will be addressed in subsequent commits.\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n3. 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n   runs, 2022-10-18)\n4. https://cmake.org/cmake/help/latest/command/file.html#chmod\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n\nwrite script\n---\n contrib/buildsystems/CMakeLists.txt | 25 +++++++++++++++++++------\n 1 file changed, 19 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex a900aff9960..27c939641e0 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -840,6 +840,19 @@ add_custom_command(OUTPUT ${git_links} ${git_http_links}\n \t\tDEPENDS git git-remote-http)\n add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links})\n \n+function(write_script path content)\n+\tfile(WRITE ${path} ${content})\n+\n+\tif(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" VERSION_GREATER_EQUAL \"3.19\")\n+\t\tfile(CHMOD ${path} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)\n+\telse()\n+\t\texecute_process(COMMAND chmod +x ${path}\n+\t\t\t\tRESULT_VARIABLE CHILD_ERROR)\n+\t\tif(CHILD_ERROR)\n+\t\t\tmessage(FATAL_ERROR \"failed to chmod +x '${path}': '${CHILD_ERROR}'\")\n+\t\tendif()\n+\tendif()\n+endfunction()\n \n #creating required scripts\n set(SHELL_PATH /bin/sh)\n@@ -865,7 +878,7 @@ foreach(script ${git_shell_scripts})\n \tstring(REPLACE \"# @@BROKEN_PATH_FIX@@\" \"\" content \"${content}\")\n \tstring(REPLACE \"@@PERL@@\" \"${PERL_PATH}\" content \"${content}\")\n \tstring(REPLACE \"@@PAGER_ENV@@\" \"LESS=FRX LV=-c\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n endforeach()\n \n #perl scripts\n@@ -880,13 +893,13 @@ foreach(script ${git_perl_scripts})\n \tfile(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME)\n \tstring(REPLACE \"#!/usr/bin/perl\" \"#!/usr/bin/perl\\n${perl_header}\\n\" content \"${content}\")\n \tstring(REPLACE \"@@GIT_VERSION@@\" \"${PROJECT_VERSION}\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n endforeach()\n \n #python script\n file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n-file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n+write_script(${CMAKE_BINARY_DIR}/git-p4 \"${content}\")\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n@@ -1024,20 +1037,20 @@ foreach(script ${wrapper_scripts})\n \tfile(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"${script}${EXE_EXTENSION}\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/bin-wrappers/${script} \"${content}\")\n endforeach()\n \n foreach(script ${wrapper_test_scripts})\n \tfile(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"t/helper/${script}${EXE_EXTENSION}\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/bin-wrappers/${script} \"${content}\")\n endforeach()\n \n file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n string(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n string(REPLACE \"@@PROG@@\" \"git-cvsserver\" content \"${content}\")\n-file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})\n+write_script(${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver \"${content}\")\n \n #options for configuring test options\n option(PERL_TESTS \"Perform tests that use perl\" ON)\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466414","messageId":"patch-v4-04.14-0f0eb2a76c7-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 04/14] cmake: don't copy chainlint.pl to build directory","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:37:54Z","receivedAt":"2022-11-03T16:42:45Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When [1] made this copy of \"chainlint.sed\" the script was invoked in\nthe test-lib.sh as:\n\n\t[...] sed -f \"$GIT_BUILD_DIR/t/chainlint.sed\" [...]\n\nBut when [2] replaced \"chainlint.sed\" with a \"chainlint.pl\" it also\nreplaced that \"$GIT_BUILD_DIR\" with \"$TEST_DIRECTORY\", invoking it as:\n\n\t\"$PERL_PATH\" \"$TEST_DIRECTORY/chainlint.pl\" \"$0\"\n\nSo this line could have been deleted in [2] but wasn't. Let's do that\nnow.\n\n1. 7f5397a07c6 (cmake: support for testing git when building out of\n   the source tree, 2020-06-26)\n2. 23a14f30166 (test-lib: replace chainlint.sed with chainlint.pl,\n   2022-09-01)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 484b1988a7e..a900aff9960 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1108,7 +1108,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n \t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)\n \tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n \tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n \tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466415","messageId":"patch-v4-01.14-78dfc2a69b7-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 01/14] cmake: don't invoke msgfmt with --statistics","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:37:51Z","receivedAt":"2022-11-03T16:42:47Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"In 2f12b31b746 (Makefile: don't invoke msgfmt with --statistics,\n2021-12-17) I made the same change to our Makefile, let's follow-up\nand do the same here.\n\nFor \"cmake\" this is particularly nice with \"-G Ninja\", as before we'd\nemit ~40 lines of overflowed progress bar output, but now it's only\nthe one line of \"ninja\"'s progress bar.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 3957e4cf8cd..0a75898ca9f 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -897,7 +897,7 @@ if(MSGFMT_EXE)\n \tforeach(po ${po_files})\n \t\tfile(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES)\n \t\tadd_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo\n-\t\t\t\tCOMMAND ${MSGFMT_EXE} --check --statistics -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po)\n+\t\t\t\tCOMMAND ${MSGFMT_EXE} --check -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po)\n \t\tlist(APPEND po_gen ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo)\n \tendforeach()\n \tadd_custom_target(po-gen ALL DEPENDS ${po_gen})\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466416","messageId":"patch-v4-03.14-6f0eae7a02a-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 03/14] cmake: update instructions for portable CMakeLists.txt","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:37:53Z","receivedAt":"2022-11-03T16:42:49Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The instructions for running CMake went back & forth between *nix,\nWindows and Visual Studio instructions Let's create headings and split\nthe existing instructions up into those new sections.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 68 +++++++++++++++++++++--------\n 1 file changed, 50 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 463f55e5516..484b1988a7e 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -4,7 +4,31 @@\n \n #[[\n \n-Instructions how to use this in Visual Studio:\n+== Overview ==\n+\n+The top-level Makefile is Git's primary build environment, and a lot\n+of things are missing (and probably always will be) from this CMake\n+alternative.\n+\n+The primary use-case for maintaining this CMake build recipe is to\n+have nicer IDE integration on Windows.\n+\n+== Creating a build recipe ==\n+\n+The \"cmake\" command creates a build file from this recipe:\n+\n+    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n+\n+Running this will create files in the contrib/buildsystems/out\n+directory (our top-level .gitignore file knows to ignore contents of\n+this directory).\n+\n+See \"cmake options\" below for a discussion of\n+\"-DCMAKE_BUILD_TYPE=Release\" and other options to \"cmake\".\n+\n+== Building with Visual Visual Studio ==\n+\n+To use this in Visual Studio:\n \n Open the worktree as a folder. Visual Studio 2019 and later will detect\n the CMake configuration automatically and set everything up for you,\n@@ -14,13 +38,33 @@ Note: Visual Studio also has the option of opening `CMakeLists.txt`\n directly; Using this option, Visual Studio will not find the source code,\n though, therefore the `File>Open>Folder...` option is preferred.\n \n-Instructions to run CMake manually:\n+By default CMake will install vcpkg locally to your source tree on configuration,\n+to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n \n-    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n+== Building on Windows without Visual Studio ==\n \n-This will build the git binaries in contrib/buildsystems/out\n-directory (our top-level .gitignore file knows to ignore contents of\n-this directory).\n+Open contrib/buildsystems/git.sln and build Git. Or use the \"msbuild\"\n+command-line tool (see our own \".github/workflows/main.yml\" for a real\n+example):\n+\n+\tmsbuild git.sln\n+\n+== Building on *nix ==\n+\n+On all other platforms running \"cmake\" will generate a Makefile; to\n+build with it run:\n+\n+\tmake -C contrib/buildsystems/out\n+\n+It's also possible to use other generators, e.g. Ninja has arguably\n+slightly better output. Add \"-G Ninja\" to the cmake command above,\n+then:\n+\n+\tninja -C contrib/buildsystems/out\n+\n+== cmake options ==\n+\n+=== -DCMAKE_BUILD_TYPE=<type> ===\n \n Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding\n compiler flags\n@@ -32,18 +76,6 @@ empty(default) :\n \n NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n this option is ignored\n-\n-This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n-Run `make -C contrib/buildsystems/out` to build Git on Linux/*BSD/MacOS.\n-Open contrib/buildsystems/git.sln on Windows and build Git.\n-\n-NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n-to use another tool say `ninja` add this to the command line when configuring.\n-`-G Ninja`\n-\n-NOTE: By default CMake will install vcpkg locally to your source tree on configuration,\n-to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n-\n ]]\n cmake_minimum_required(VERSION 3.14)\n \n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466417","messageId":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com","subject":"[PATCH v4 00/14] cmake: document, fix on *nix, add CI","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:37:50Z","receivedAt":"2022-11-03T16:42:53Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This topic gets our tests from passing ~80% with ctest on *nix to\npassing 100%.\n\nSee passing CI job for \"cmake + ctest\" on Ubuntu at:\nhttps://github.com/avar/git/actions/runs/3387253536/jobs/5627772317\n\nSee\nhttp://lore.kernel.org/git/cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com\nfor v3.\n\nChanges since the v3:\n\n * A small \"while at it\" change in 1/14 to make the build output nicer\n   (particularly for \"ninja, as it's not verbose). It's just the\n   \"msgfmt without --statistics\" change we've got in the Makefile\n   already.\n\n * Discuss more about -S and -B in 2/14. It's supported by our cmake\n   version(s0.\n\n * Re-arranged the docs in 3/14 as Phillip Wood suggested.\n\n * Used Phillip's write_script(). I tested the emitted files\n   carefully, and they're the same. So something went wrong in my\n   testing before.\n\n * Use Phillip's file(CHMOD ...) if we have a new enough cmake\n   version, otherwise shell out to \"chmod +x\".\n\n * Use /dev/shm instead of /run/user/`id -u` in an exmaple, and other\n   small things noted in replies to v3.\n\n * A new 12/14 to do less Windows-specific stuff on *nix, we were\n   looking for \"sh\" in C:\\Program\\ Files on *nix...\n\n * The GIT_TEST_OPTS integration with cmake-gui now works.\n\n * Various small rewording/typo etc. changes to commit messages, see\n   range-diff below.\n\nÆvar Arnfjörð Bjarmason (14):\n  cmake: don't invoke msgfmt with --statistics\n  cmake: use \"-S\" and \"-B\" to specify source and build directories\n  cmake: update instructions for portable CMakeLists.txt\n  cmake: don't copy chainlint.pl to build directory\n  cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n  cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n  cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n  test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n  Makefile + cmake: use environment, not GIT-BUILD-DIR\n  cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n  cmake: increase test timeout on Windows only\n  cmake: only look for \"sh\" in \"C:/Program Files\" on Windows\n  cmake: copy over git-p4.py for t983[56] perforce test\n  CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n\n .github/workflows/main.yml          |   3 +\n .gitignore                          |   1 -\n Makefile                            |   1 -\n ci/run-build-and-tests.sh           |  13 +-\n contrib/buildsystems/CMakeLists.txt | 183 +++++++++++++++++++++-------\n t/README                            |   3 +\n t/lib-gettext.sh                    |   2 +-\n t/lib-gitweb.sh                     |   2 +-\n t/t7609-mergetool--lib.sh           |   2 +-\n t/t9902-completion.sh               |  14 +--\n t/t9903-bash-prompt.sh              |   2 +-\n t/test-lib.sh                       |  27 +++-\n 12 files changed, 188 insertions(+), 65 deletions(-)\n\nRange-diff against v3:\n -:  ----------- >  1:  78dfc2a69b7 cmake: don't invoke msgfmt with --statistics\n 1:  028fa1436d8 !  2:  dd934b0597d cmake: don't \"mkdir -p\" and \"cd\" in build instructions\n    @@ Metadata\n     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n      ## Commit message ##\n    -    cmake: don't \"mkdir -p\" and \"cd\" in build instructions\n    +    cmake: use \"-S\" and \"-B\" to specify source and build directories\n     \n    -    Use the \"-S\" and -B\" flags instead of \"mkdir -p\" and \"cd\". The \"-p\"\n    -    flag to \"mkdir\" wasn't needed as \"contrib/buildsystems\" is tracked,\n    -    and the rest of this is now easier to copy/paste into a shell without\n    -    having one's directory changed.\n    +    Rather than the multi-line \"mkdir/cd/cmake\" recipe provide an\n    +    equivalent one-liner using the \"-S\" and \"-B\" options, and then suggest building with \"make -C <build-dir>\".\n    +\n    +    The rest of these instructions discuss e.g. running tests from our\n    +    top-level \"t/\" directory, so it's more helpful to avoid changing the\n    +    user's current directory.\n    +\n    +    The \"-S\" and \"-B\" options were added in cmake v3.13.0, which is older\n    +    than the version we have a hard dependency on[1].\n    +\n    +    As an aside The \"-p\" flag to \"mkdir\" in the pre-image wasn't needed,\n    +    as \"contrib/buildsystems\" is tracked\n    +\n    +    1. 061c2240b1b (Introduce CMake support for configuring Git, 2020-06-12)\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n    @@ contrib/buildsystems/CMakeLists.txt: NOTE: -DCMAKE_BUILD_TYPE is optional. For m\n      This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n     -Run `make` to build Git on Linux/*BSD/MacOS.\n     -Open git.sln on Windows and build Git.\n    -+Run `make -C contrib/buildsystems` to build Git on Linux/*BSD/MacOS.\n    ++Run `make -C contrib/buildsystems/out` to build Git on Linux/*BSD/MacOS.\n     +Open contrib/buildsystems/git.sln on Windows and build Git.\n      \n      NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n 2:  7a21f4aa24c !  3:  6f0eae7a02a cmake: update instructions for portable CMakeLists.txt\n    @@ contrib/buildsystems/CMakeLists.txt\n     +alternative.\n     +\n     +The primary use-case for maintaining this CMake build recipe is to\n    -+have nicer IDE integration on Windows. To get Visual Studio-specific\n    -+instructions see \"== Visual Studio & Windows ==\" below.\n    ++have nicer IDE integration on Windows.\n     +\n     +== Creating a build recipe ==\n     +\n    -+To create the build recipe run:\n    ++The \"cmake\" command creates a build file from this recipe:\n     +\n     +    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n     +\n    -+For alternative \"-DCMAKE_BUILD_TYPE=<type>\" flags see instructions\n    -+under the \"== -DCMAKE_BUILD_TYPE=<type> ==\" heading below.\n    ++Running this will create files in the contrib/buildsystems/out\n    ++directory (our top-level .gitignore file knows to ignore contents of\n    ++this directory).\n     +\n    -+== Building ==\n    ++See \"cmake options\" below for a discussion of\n    ++\"-DCMAKE_BUILD_TYPE=Release\" and other options to \"cmake\".\n     +\n    -+The \"cmake\" command creates a build file from this recipe. For Windows\n    -+Open contrib/buildsystems/git.sln and build Git. Or use the\n    -+\"msbuild\" command-line tool (see our own \".github/workflows/main.yml\"\n    -+for a real example):\n    ++== Building with Visual Visual Studio ==\n    ++\n    ++To use this in Visual Studio:\n    + \n    + Open the worktree as a folder. Visual Studio 2019 and later will detect\n    + the CMake configuration automatically and set everything up for you,\n    +@@ contrib/buildsystems/CMakeLists.txt: Note: Visual Studio also has the option of opening `CMakeLists.txt`\n    + directly; Using this option, Visual Studio will not find the source code,\n    + though, therefore the `File>Open>Folder...` option is preferred.\n    + \n    +-Instructions to run CMake manually:\n    ++By default CMake will install vcpkg locally to your source tree on configuration,\n    ++to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n    + \n    +-    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n    ++== Building on Windows without Visual Studio ==\n    + \n    +-This will build the git binaries in contrib/buildsystems/out\n    +-directory (our top-level .gitignore file knows to ignore contents of\n    +-this directory).\n    ++Open contrib/buildsystems/git.sln and build Git. Or use the \"msbuild\"\n    ++command-line tool (see our own \".github/workflows/main.yml\" for a real\n    ++example):\n     +\n     +\tmsbuild git.sln\n     +\n    ++== Building on *nix ==\n    ++\n     +On all other platforms running \"cmake\" will generate a Makefile; to\n     +build with it run:\n     +\n    @@ contrib/buildsystems/CMakeLists.txt\n     +\n     +It's also possible to use other generators, e.g. Ninja has arguably\n     +slightly better output. Add \"-G Ninja\" to the cmake command above,\n    -+then e.g.:\n    ++then:\n     +\n     +\tninja -C contrib/buildsystems/out\n     +\n    -+== Visual Studio & Windows ==\n    ++== cmake options ==\n     +\n    -+To use this in Visual Studio:\n    ++=== -DCMAKE_BUILD_TYPE=<type> ===\n      \n    - Open the worktree as a folder. Visual Studio 2019 and later will detect\n    - the CMake configuration automatically and set everything up for you,\n    -@@ contrib/buildsystems/CMakeLists.txt: Note: Visual Studio also has the option of opening `CMakeLists.txt`\n    - directly; Using this option, Visual Studio will not find the source code,\n    - though, therefore the `File>Open>Folder...` option is preferred.\n    - \n    --Instructions to run CMake manually:\n    --\n    --    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n    --\n    --This will build the git binaries in contrib/buildsystems/out\n    -+Following the instructions above will build the git binaries in the contrib/buildsystems/out\n    - directory (our top-level .gitignore file knows to ignore contents of\n    - this directory).\n    - \n    -+By default CMake will install vcpkg locally to your source tree on configuration,\n    -+to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n    -+\n    -+== -DCMAKE_BUILD_TYPE=<type> ==\n    -+\n      Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding\n      compiler flags\n    - Debug : -g\n     @@ contrib/buildsystems/CMakeLists.txt: empty(default) :\n      \n      NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n      this option is ignored\n     -\n     -This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n    --Run `make -C contrib/buildsystems` to build Git on Linux/*BSD/MacOS.\n    +-Run `make -C contrib/buildsystems/out` to build Git on Linux/*BSD/MacOS.\n     -Open contrib/buildsystems/git.sln on Windows and build Git.\n     -\n     -NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n 3:  3bfa873e792 =  4:  0f0eb2a76c7 cmake: don't copy chainlint.pl to build directory\n 4:  ad551f53de9 !  5:  eda1c1e95e5 cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n    @@ Commit message\n                 make -C contrib/buildsystems/out &&\n                 ctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\" --output-on-failure\n     \n    -    Fails around 20% of our testts on *nix. So even with [3] we'd fail any\n    +    Fails around 20% of our tests on *nix. So even with [3] we'd fail any\n         test that needed to invoke one of our built shell, perl or Python\n         scripts on *nix. E.g. t0012-help.sh would fail on a test that tried to\n         invoke \"git web--browse\". The equivalent of this (in the \"out\"\n    @@ Commit message\n         our built \"git-p4\" wasn't executable, etc. There's also a few other\n         outstanding issues, which will be fixed in subsequent commits.\n     \n    -    This change should ideally use file(CHMOD ...), but the \"file(CHMOD\"\n    -    feature is much newer than our required cmake version[5].\n    +    Ideally we'd use the file(CHMOD ...) form everywhere, but that syntax\n    +    was introduced in cmake 3.19[4], whereas we only require 3.14. Let's\n    +    provide a fallback behind a version check, so that we'll eventually be\n    +    able to delete the \"else\" part. Both forms result in the same file\n    +    modes.\n     \n         Before this change:\n     \n    @@ Commit message\n     \n         The remaining failures will be addressed in subsequent commits.\n     \n    -    There was a suggestion of using a function to abstract this away[6],\n    -    which sounds good. But after spending too long trying to get all\n    -    combinations of \"${content}\" and ${content} (unqoted) in the function\n    -    and its callers working I wasn't able to fix the quoting issues it\n    -    introduced.\n    -\n    -    A lot of this is duplicated already, we can follow-up at some other\n    -    time with refactoring, and address any tricky quoting issues in\n    -    calling function with these parameters then.\n    -\n         1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n         2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n         3. 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n            runs, 2022-10-18)\n    -    4. a30e4c531d9 (Merge branch 'ss/cmake-build', 2020-08-11)\n    -    5. https://cmake.org/cmake/help/latest/command/file.html#chmod\n    -    6. https://lore.kernel.org/git/0fda0e54-0432-7690-74a7-3d1a59923e0c@dunelm.org.uk/\n    +    4. https://cmake.org/cmake/help/latest/command/file.html#chmod\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n    +    write script\n    +\n      ## contrib/buildsystems/CMakeLists.txt ##\n    +@@ contrib/buildsystems/CMakeLists.txt: add_custom_command(OUTPUT ${git_links} ${git_http_links}\n    + \t\tDEPENDS git git-remote-http)\n    + add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links})\n    + \n    ++function(write_script path content)\n    ++\tfile(WRITE ${path} ${content})\n    ++\n    ++\tif(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" VERSION_GREATER_EQUAL \"3.19\")\n    ++\t\tfile(CHMOD ${path} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)\n    ++\telse()\n    ++\t\texecute_process(COMMAND chmod +x ${path}\n    ++\t\t\t\tRESULT_VARIABLE CHILD_ERROR)\n    ++\t\tif(CHILD_ERROR)\n    ++\t\t\tmessage(FATAL_ERROR \"failed to chmod +x '${path}': '${CHILD_ERROR}'\")\n    ++\t\tendif()\n    ++\tendif()\n    ++endfunction()\n    + \n    + #creating required scripts\n    + set(SHELL_PATH /bin/sh)\n     @@ contrib/buildsystems/CMakeLists.txt: foreach(script ${git_shell_scripts})\n    + \tstring(REPLACE \"# @@BROKEN_PATH_FIX@@\" \"\" content \"${content}\")\n      \tstring(REPLACE \"@@PERL@@\" \"${PERL_PATH}\" content \"${content}\")\n      \tstring(REPLACE \"@@PAGER_ENV@@\" \"LESS=FRX LV=-c\" content \"${content}\")\n    - \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n    -+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n    +-\tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n    ++\twrite_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n      endforeach()\n      \n      #perl scripts\n     @@ contrib/buildsystems/CMakeLists.txt: foreach(script ${git_perl_scripts})\n    + \tfile(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME)\n      \tstring(REPLACE \"#!/usr/bin/perl\" \"#!/usr/bin/perl\\n${perl_header}\\n\" content \"${content}\")\n      \tstring(REPLACE \"@@GIT_VERSION@@\" \"${PROJECT_VERSION}\" content \"${content}\")\n    - \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n    -+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n    +-\tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n    ++\twrite_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n      endforeach()\n      \n      #python script\n      file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n      string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n    - file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n    -+execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/git-p4)\n    +-file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n    ++write_script(${CMAKE_BINARY_DIR}/git-p4 \"${content}\")\n      \n      #perl modules\n      file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n     @@ contrib/buildsystems/CMakeLists.txt: foreach(script ${wrapper_scripts})\n    + \tfile(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n      \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n      \tstring(REPLACE \"@@PROG@@\" \"${script}${EXE_EXTENSION}\" content \"${content}\")\n    - \tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n    -+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/${script})\n    +-\tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n    ++\twrite_script(${CMAKE_BINARY_DIR}/bin-wrappers/${script} \"${content}\")\n      endforeach()\n      \n      foreach(script ${wrapper_test_scripts})\n    -@@ contrib/buildsystems/CMakeLists.txt: foreach(script ${wrapper_test_scripts})\n    + \tfile(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n      \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n      \tstring(REPLACE \"@@PROG@@\" \"t/helper/${script}${EXE_EXTENSION}\" content \"${content}\")\n    - \tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n    -+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/${script})\n    +-\tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n    ++\twrite_script(${CMAKE_BINARY_DIR}/bin-wrappers/${script} \"${content}\")\n      endforeach()\n      \n      file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n      string(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n      string(REPLACE \"@@PROG@@\" \"git-cvsserver\" content \"${content}\")\n    - file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})\n    -+execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver)\n    +-file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})\n    ++write_script(${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver \"${content}\")\n      \n      #options for configuring test options\n      option(PERL_TESTS \"Perform tests that use perl\" ON)\n 5:  5c7b64286ce =  6:  6c254f8cb9f cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n 6:  cba90650879 =  7:  1685a58e13a cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n 7:  bd7fb1eec24 =  8:  87a2c77ee68 test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n 8:  fd3e6be5689 =  9:  6187ded42db Makefile + cmake: use environment, not GIT-BUILD-DIR\n 9:  8a660a2baa4 ! 10:  3ea4a61698e cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n    @@ Commit message\n         Windows-specific anymore.\n     \n         So let's set those same options by default on Windows, but do so with\n    -    the set() facility. As noted in cmake's documentation[1] this\n    -    integrates nicely with e.g. cmake-gui.\n    +    the set(... CACHE <type> <docstring>) facility. As noted in cmake's\n    +    documentation[1] this integrates nicely with e.g. cmake-gui.\n     \n         On *nix we don't set any custom options. The change in 2ea1d8b5563\n         didn't discuss why Windows should have divergent defaults with \"cmake\"\n    @@ Commit message\n                 GIT_TEST_OPTS=-i cmake -S contrib/buildsystems -B contrib/buildsystems/out &&\n                 ctest --jobs=$(nproc) --test-dir contrib/buildsystems/out -R t0071 --verbose\n     \n    +    The \"separate_arguments()\" here will do the right thing for arguments\n    +    that don't contain whitespace, so e.g. the path to --root=\"\" can't\n    +    have a space in it. There's supposedly a way to work around that with\n    +    separate_arguments(), but it requires features newer than our required\n    +    cmake version, so let's live with that edge case for now.\n    +\n         1. https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n    @@ contrib/buildsystems/CMakeLists.txt: empty(default) :\n     +The tests can also be run with ctest, e.g. after building with \"cmake\"\n     +and \"make\" or \"msbuild\" run, from the top-level e.g.:\n     +\n    ++\t# \"--test-dir\" is new in cmake v3.20, so \"(cd\n    ++\t# contrib/buildsystems/out && ctest ...)\" on older versions.\n     +\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\"--output-on-failure\n     +\n     +Options can be passed by setting GIT_TEST_OPTIONS before invoking\n     +cmake. E.g. on a Linux system with systemd the tests can be sped up by\n     +using a ramdisk for the scratch files:\n     +\n    -+\tGIT_TEST_OPTS=\"--root=/run/user/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n    ++\tGIT_TEST_OPTS=\"--root=/dev/shm/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n     +\t[...]\n    -+\t-- Using user-selected test options: --root=/run/user/1001/ctest\n    ++\t-- Using user-selected test options: --root=/dev/shm/<uid>/ctest\n     +\n     +Then running the tests with \"ctest\" (here with --jobs=\"$(nproc)\"):\n     +\n    @@ contrib/buildsystems/CMakeLists.txt: endif()\n      \n      file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n      \n    -+string(COMPARE NOTEQUAL \"$ENV{GIT_TEST_OPTS}\" \"\" HAVE_USER_GIT_TEST_OPTS)\n    -+if(HAVE_USER_GIT_TEST_OPTS)\n    -+\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n    ++if(DEFINED ENV{GIT_TEST_OPTS})\n    ++\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\"\n    ++\t\tCACHE STRING \"test options, see t/README\")\n     +\tmessage(STATUS \"Using user-selected test options: ${GIT_TEST_OPTS}\")\n     +elseif(WIN32)\n    -+\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\")\n    ++\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\"\n    ++\t\tCACHE STRING \"test options, see t/README\")\n     +\tmessage(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n     +else()\n    -+\tset(GIT_TEST_OPTS \"\")\n    ++\tset(GIT_TEST_OPTS \"\"\n    ++\t\tCACHE STRING \"test options, see t/README\")\n     +\tmessage(STATUS \"No custom test options selected, set e.g. GIT_TEST_OPTS=\\\"-vixd\\\"\")\n     +endif()\n     +separate_arguments(GIT_TEST_OPTS)\n10:  966fec83b77 = 11:  8ccf5c8c265 cmake: increase test timeout on Windows only\n -:  ----------- > 12:  7b1f10eb4c0 cmake: only look for \"sh\" in \"C:/Program Files\" on Windows\n11:  aad17d8f858 ! 13:  0699e398e89 cmake: copy over git-p4.py for t983[56] perforce test\n    @@ Commit message\n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n      ## contrib/buildsystems/CMakeLists.txt ##\n    -@@ contrib/buildsystems/CMakeLists.txt: file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n    +@@ contrib/buildsystems/CMakeLists.txt: endforeach()\n    + file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n      string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n    - file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n    - execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/git-p4)\n    + write_script(${CMAKE_BINARY_DIR}/git-p4 \"${content}\")\n     +file(COPY ${CMAKE_SOURCE_DIR}/git-p4.py DESTINATION ${CMAKE_BINARY_DIR}/)\n      \n      #perl modules\n12:  c27f620dfa3 = 14:  277028678c8 CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466418","messageId":"patch-v4-06.14-6c254f8cb9f-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 06/14] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:37:56Z","receivedAt":"2022-11-03T16:42:57Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When git is built and tested with cmake & ctest we usually do that\noutside of the top-level source directory. E.g.\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out\n\tmake -C contrib/buildsystems/out\n\tctest -j$(nproc) --test-dir contrib/buildsystems/out\n\nSince the test-lib.sh makes assumptions about the TEST_DIRECTORY being\nthe \"t\" subdirectory of the top-level \"$GIT_BUILD_DIR\", the cmake\nrecipe has needed to copy various assets to that\n\"contrib/buildsystems/out\" directory.\n\nBut we've only been doing this for the subsets of tests that run on\nWindows, and which have otherwise been covered by that CI target. The\nCI target builds (among other things) with \"-DPERL_TESTS=OFF\n-DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON\", see [1]. Furthermore, the\nCI isn't testing from the \"contrib/buildsystems/out\" directory,\ninstead it clobbers the top-level MAkefile.\n\nThere was a recent commit to fix a subset of these issues, see\n6a83b5f0810 (cmake: copy the merge tools for testing, 2022-10-18).\n\nLet's stop going for that approach, and instead teach the test-lib.sh\nthat there's such a thing as the \"$GIT_SOURCE_DIR\" distinct from the\n\"$GIT_BUILD_DIR\".\n\nJust as the \"$TEST_DIRECTORY\" always points to our actual \"t\"\ndirectory (not the \"[...]/out/t\" cmake creates), this new\n\"$GIT_SOURCE_DIR\" will always be the top-level source directory.\n\nWith this change we now pass 3/5 of the tests that we still had\nfailing with the fixes in the preceding commit.\n\n1. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt |  6 ------\n t/lib-gettext.sh                    |  2 +-\n t/lib-gitweb.sh                     |  2 +-\n t/t7609-mergetool--lib.sh           |  2 +-\n t/t9902-completion.sh               | 14 +++++++-------\n t/t9903-bash-prompt.sh              |  2 +-\n t/test-lib.sh                       |  8 +++++++-\n 7 files changed, 18 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 27c939641e0..812365e1dd8 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1120,12 +1120,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \t#Setting the build directory in test-lib.sh before running tests\n \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n-\t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n-\tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n-\tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\ndiff --git a/t/lib-gettext.sh b/t/lib-gettext.sh\nindex cc6bb2cdeaa..dcd6e9c3f75 100644\n--- a/t/lib-gettext.sh\n+++ b/t/lib-gettext.sh\n@@ -7,7 +7,7 @@\n . ./test-lib.sh\n \n GIT_TEXTDOMAINDIR=\"$GIT_BUILD_DIR/po/build/locale\"\n-GIT_PO_PATH=\"$GIT_BUILD_DIR/po\"\n+GIT_PO_PATH=\"$GIT_SOURCE_DIR/po\"\n export GIT_TEXTDOMAINDIR GIT_PO_PATH\n \n if test -n \"$GIT_TEST_INSTALLED\"\ndiff --git a/t/lib-gitweb.sh b/t/lib-gitweb.sh\nindex 1f32ca66ea5..6f68df247af 100644\n--- a/t/lib-gitweb.sh\n+++ b/t/lib-gitweb.sh\n@@ -49,7 +49,7 @@ EOF\n \t\terror \"Cannot find gitweb at $GITWEB_TEST_INSTALLED.\"\n \t\tsay \"# Testing $SCRIPT_NAME\"\n \telse # normal case, use source version of gitweb\n-\t\tSCRIPT_NAME=\"$GIT_BUILD_DIR/gitweb/gitweb.perl\"\n+\t\tSCRIPT_NAME=\"$GIT_SOURCE_DIR/gitweb/gitweb.perl\"\n \tfi\n \texport SCRIPT_NAME\n }\ndiff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh\nindex 8b1c3bd39f2..2090d12a489 100755\n--- a/t/t7609-mergetool--lib.sh\n+++ b/t/t7609-mergetool--lib.sh\n@@ -8,7 +8,7 @@ TEST_PASSES_SANITIZE_LEAK=true\n . ./test-lib.sh\n \n test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '\n-\t. \"$GIT_BUILD_DIR\"/mergetools/vimdiff &&\n+\t. \"$GIT_SOURCE_DIR\"/mergetools/vimdiff &&\n \trun_unit_tests\n '\n \ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 43de868b800..1bd4cae92fe 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -33,7 +33,7 @@ complete ()\n GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'\n GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\"\n \n # We don't need this function to actually join words or do anything special.\n # Also, it's cleaner to avoid touching bash's internal completion variables.\n@@ -2567,7 +2567,7 @@ test_expect_success 'sourcing the completion script clears cached commands' '\n \t(\n \t\t__git_compute_all_commands &&\n \t\tverbose test -n \"$__git_all_commands\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_all_commands\"\n \t)\n '\n@@ -2576,7 +2576,7 @@ test_expect_success 'sourcing the completion script clears cached merge strategi\n \t(\n \t\t__git_compute_merge_strategies &&\n \t\tverbose test -n \"$__git_merge_strategies\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_merge_strategies\"\n \t)\n '\n@@ -2587,7 +2587,7 @@ test_expect_success 'sourcing the completion script clears cached --options' '\n \t\tverbose test -n \"$__gitcomp_builtin_checkout\" &&\n \t\t__gitcomp_builtin notes_edit &&\n \t\tverbose test -n \"$__gitcomp_builtin_notes_edit\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_checkout\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_notes_edit\"\n \t)\n@@ -2599,7 +2599,7 @@ test_expect_success 'option aliases are not shown by default' '\n \n test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&\n \t\ttest_completion \"git clone --recurs\" <<-\\EOF\n \t\t--recurse-submodules Z\n@@ -2610,7 +2610,7 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \n test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n \n \t\t# Just mainporcelain, not plumbing commands\n@@ -2622,7 +2622,7 @@ test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_\n \n test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n \t\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex d459fae6551..06f0abfc294 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -10,7 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./lib-bash.sh\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-prompt.sh\"\n \n actual=\"$TRASH_DIRECTORY/actual\"\n c_red='\\\\[\\\\e[31m\\\\]'\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 6db377f68b8..36358811a0f 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -47,6 +47,10 @@ then\n \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n \texit 1\n fi\n+\n+# For CMake the top-level source directory is different from our build\n+# directory. With the top-level Makefile they're the same.\n+GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n@@ -1447,7 +1451,7 @@ then\n \t\tmake_valgrind_symlink $file\n \tdone\n \t# special-case the mergetools loadables\n-\tmake_symlink \"$GIT_BUILD_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n+\tmake_symlink \"$GIT_SOURCE_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n \tOLDIFS=$IFS\n \tIFS=:\n \tfor path in $PATH\n@@ -1500,6 +1504,8 @@ GIT_CONFIG_NOSYSTEM=1\n GIT_ATTR_NOSYSTEM=1\n GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\"\n export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES\n+MERGE_TOOLS_DIR=\"$GIT_SOURCE_DIR/mergetools\"\n+export MERGE_TOOLS_DIR\n \n if test -z \"$GIT_TEST_CMP\"\n then\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466419","messageId":"patch-v4-07.14-1685a58e13a-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 07/14] cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:37:57Z","receivedAt":"2022-11-03T16:42:59Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When we build with libpcre2 which cmake has supported since [1] we\nneed to set \"USE_LIBPCRE2='YesPlease'\" (or similar) in\n\"GIT-BUILD-OPTIONS\".\n\nWithout this e.g. t7810-grep.sh will fail, as it has tests that rely\non the behavior of !PCRE2. The reason this hasn't been noticed is that\nthe Windows CI doesn't have access to libpcre2.\n\nWith this the remaining two failures we had left after the preceding\nstep are resolved, but note that that test run didn't include the\ngit-p4 tests, which a subsequent commit will address).\n\n1. 80431510a2b (cmake: add pcre2 support, 2022-05-24)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 812365e1dd8..5c51840887e 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1100,6 +1100,9 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PYTHON_PATH='${PYTHON_PATH}'\\\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"TAR='${TAR}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_CURL='${NO_CURL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_EXPAT='${NO_EXPAT}'\\n\")\n+if(PCRE2_FOUND)\n+\tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"USE_LIBPCRE2='YesPlease'\\n\")\n+endif()\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PERL='${NO_PERL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PTHREADS='${NO_PTHREADS}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\\n\")\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466420","messageId":"patch-v4-13.14-0699e398e89-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 13/14] cmake: copy over git-p4.py for t983[56] perforce test","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:38:03Z","receivedAt":"2022-11-03T16:43:03Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] two git-p4 tests have relied on there being a \"git-p4.py\" in\nthe build directory, but the cmake recipe was not updated to account\nfor this. Let's copy the \"git-p4.py\" over.\n\nWe could also change the test to e.g. grab the built \"git-p4\" and\nalter its shebang, which would be friendly to GIT_TEST_INSTALLED, but\nlet's just do the bare minimum here to get cmake+ctest working without\naltering the test itself.\n\nThe reason this hasn't been caught by \"vs-build\" and \"vs-test\" is\nbecause those tests added in [2] invoke \"cmake\" with\n\"-DPYTHON_TESTS=OFF\", and therefore we'd skip this part of the git-p4\ntests before getting past the \"do we have python?\" check. Even if we\ngot past that the Windows CI wouldn't have a \"p4\" or \"p4d\" binary\ninstalled, so we'd skip the tests anyway.\n\nIn a subsequent commit we'll run \"cmake\" and \"ctest\" in CI with\n\"ubuntu-latest\", so we'll need this \"git-p4.py\" file.\n\n1. f7b5ff607fa (git-p4: improve encoding handling to support\n   inconsistent encodings, 2022-04-30)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 88723b971c6..de855d953a9 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -938,6 +938,7 @@ endforeach()\n file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n write_script(${CMAKE_BINARY_DIR}/git-p4 \"${content}\")\n+file(COPY ${CMAKE_SOURCE_DIR}/git-p4.py DESTINATION ${CMAKE_BINARY_DIR}/)\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466421","messageId":"patch-v4-09.14-6187ded42db-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 09/14] Makefile + cmake: use environment, not GIT-BUILD-DIR","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:37:59Z","receivedAt":"2022-11-03T16:43:06Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the method used to have building with \"cmake\" followed by\nrunning the tests manually work without creating inter-dependency issues with the Makefile.\n\nPer ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18) and\nthe surrounding discussion the goal of that change was to have\nbuilding with cmake and:\n\n\t(cd t && ./t0001-init.sh)\n\nWork, to do so we need some way to make the test-lib.sh aware that we\nhave a build in contrib/buildsystems/out. The downside of doing it via\nthe GIT-BUILD-DIR facility in ee9e66e4e76 is:\n\n- A \"remove this file while at it\" only fits into the Makefile\n  dependency graph if we \"FORCE\" a shell command to be run, so doing it\n  this way precludes speeding up the Makefile by e.g. making use of the\n  \"$(file)\" function (for which I've got follow-up patches).\n\n- If you build with make, then with cmake, and then e.g.:\n\n\tmake -C t prove\n\n  We'll run the tests against the cmake version of the tests, not the\n  \"make\" built ones. It's important to get any subtle interaction\n  between two conflicting build systems right.\n\nNow we'll instead:\n\n- Check if the top-level \"git\" exists, if not we'll look in\n  \"contrib/buildsystems/out/git\", and when running interactively inform\n  the user about the fallback being picked.\n\n\t$ ./t0001-init.sh\n\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n\tok 1 - plain\n\t[...]\n\n- This also makes things more obvious on the cmake side, because we'll\n  now use an environment variable to select the test environment, which\n  ctest it notes in its verbose output, e.g.:\n\n\t[...]\n\t2: Test command: /bin/sh \"/home/avar/g/git/contrib/buildsystems/../../t/t0001-init.sh\" \"--no-bin-wrappers\" \"--no-chain-lint\" \"-vx\"\n\t2: Working Directory: /home/avar/g/git/contrib/buildsystems/../../t\n\t2: Environment variables:\n\t2:  GIT_TEST_BUILD_DIR=/home/avar/g/git/contrib/buildsystems/out\n\t[...]\n\n   See [1] for the relevant cmake language references.\n\n- We don't support an arbitrary build directory outside of\n  \"contrib/buildsystems/out\". This is OK because the reason for doing\n  this part is to support the workflow documented in [2].\n\n  As [3] notes \"contrib/buildsystems/out\" isn't just the directory that\n  happens to be documented in \"contrib/buildsystems/CMakeLists.txt\", but\n  the one that VS will use when building git.\n\n1. https://cmake.org/cmake/help/latest/command/set_property.html\n   https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#test-properties\n   https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#cmake-language-lists\n1. f2f1250c47f (cmake (Windows): recommend using Visual Studio's\n   built-in CMake support, 2020-09-30)\n2. 3eccc7b99d4 (cmake: ignore files generated by CMake as run in\n   Visual Studio, 2020-09-25)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .gitignore                          |  1 -\n Makefile                            |  1 -\n contrib/buildsystems/CMakeLists.txt | 10 ++--------\n t/test-lib.sh                       | 16 ++++++++++++++--\n 4 files changed, 16 insertions(+), 12 deletions(-)\n\ndiff --git a/.gitignore b/.gitignore\nindex cb0231fb401..62720c6135d 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -1,5 +1,4 @@\n /fuzz_corpora\n-/GIT-BUILD-DIR\n /GIT-BUILD-OPTIONS\n /GIT-CFLAGS\n /GIT-LDFLAGS\ndiff --git a/Makefile b/Makefile\nindex 4927379184c..36802fe45eb 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -3045,7 +3045,6 @@ else\n \t@echo RUNTIME_PREFIX=\\'false\\' >>$@+\n endif\n \t@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi\n-\t@if test -f GIT-BUILD-DIR; then rm GIT-BUILD-DIR; fi\n \n ### Detect Python interpreter path changes\n ifndef NO_PYTHON\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 5c51840887e..b9759be4f72 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1117,14 +1117,6 @@ if(USE_VCPKG)\n \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n endif()\n \n-#Make the tests work when building out of the source tree\n-get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n-if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n-\t#Setting the build directory in test-lib.sh before running tests\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n-\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n-endif()\n-\n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n \n #test\n@@ -1132,6 +1124,8 @@ foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n \t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n+\tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n+\t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n endforeach()\n \n # This test script takes an extremely long time and is known to time out even\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 388774a0aa0..ce319c9963e 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -51,12 +51,17 @@ fi\n # For CMake the top-level source directory is different from our build\n # directory. With the top-level Makefile they're the same.\n GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n+\n+GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=\n if test -n \"$GIT_TEST_BUILD_DIR\"\n then\n \tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n-elif test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n+elif ! test -x \"$GIT_BUILD_DIR/git\" &&\n+     test -x \"$GIT_BUILD_DIR/contrib/buildsystems/out/git\"\n then\n-\tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n+\tGIT_BUILD_DIR=\"$GIT_SOURCE_DIR/contrib/buildsystems/out\"\n+\tGIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=t\n+\n \t# On Windows, we must convert Windows paths lest they contain a colon\n \tcase \"$(uname -s)\" in\n \t*MINGW*)\n@@ -1637,6 +1642,13 @@ remove_trash_directory \"$TRASH_DIRECTORY\" || {\n \tBAIL_OUT 'cannot prepare test area'\n }\n \n+# Emitting this now because earlier we didn't have \"say\", but not in\n+# anything using lib-subtest.sh\n+if test -n \"$GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT\" && test -t 1\n+then\n+\tsay \"setup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\"\n+fi\n+\n remove_trash=t\n if test -z \"$TEST_NO_CREATE_REPO\"\n then\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466422","messageId":"patch-v4-08.14-87a2c77ee68-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 08/14] test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:37:58Z","receivedAt":"2022-11-03T16:43:10Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Compliment the existing GIT_TEST_INSTALLED variable added in [1] with\none that allows for testing a git built in a directory that's not\n\"../\".\n\nInstead of \"test this installed git\" (\"GIT_TEST_INSTALLED\"), this new\n\"GIT_TEST_BUILD_DIR\" is a \"test this built directory over\nthere\". E.g. this will pass all tests:\n\n\tgit clone --depth=1 https://github.com/git/git.git git1\n\tcp -R git1 git2\n\tmake -C git1\n\t[apply this change to git2]\n\t(cd git2 && GIT_TEST_BUILD_DIR=\"$PWD/../git1\" make -C t prove)\n\nThis facility and file-based instructions to have the test suite use\nanother build directory[2] are mutually exclusive, but in a subsequent\ncommit we'll make CMake use this instead.\n\n1. 6720721e152 (test-lib.sh: Allow running the test suite against\n   installed git, 2009-03-16)\n2. 350a005e366 (cmake: avoid editing t/test-lib.sh, 2022-10-18)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/README      | 3 +++\n t/test-lib.sh | 5 ++++-\n 2 files changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/t/README b/t/README\nindex 979b2d4833d..fc0daef2e41 100644\n--- a/t/README\n+++ b/t/README\n@@ -231,6 +231,9 @@ override the location of the dashed-form subcommands (what\n GIT_EXEC_PATH would be used for during normal operation).\n GIT_TEST_EXEC_PATH defaults to `$GIT_TEST_INSTALLED/git --exec-path`.\n \n+Similar to GIT_TEST_INSTALLED, GIT_TEST_BUILD_DIR can be pointed to\n+another git.git checkout's build directory, to test its built binaries\n+against the tests in this checkout.\n \n Skipping Tests\n --------------\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 36358811a0f..388774a0aa0 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -51,7 +51,10 @@ fi\n # For CMake the top-level source directory is different from our build\n # directory. With the top-level Makefile they're the same.\n GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n-if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n+if test -n \"$GIT_TEST_BUILD_DIR\"\n+then\n+\tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n+elif test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n \t# On Windows, we must convert Windows paths lest they contain a colon\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466423","messageId":"patch-v4-11.14-8ccf5c8c265-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 11/14] cmake: increase test timeout on Windows only","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:38:01Z","receivedAt":"2022-11-03T16:43:13Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Per c858750b41c (cmake: increase time-out for a long-running test,\n2022-10-18) the reason to set a custom timeout for\nt7112-reset-submodule.sh is Windows-specific. Let's only do that on\nWindows then.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 4a832404da6..2b4e5a2f4b6 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1174,8 +1174,10 @@ foreach(tsh ${test_scipts})\n \t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n endforeach()\n \n-# This test script takes an extremely long time and is known to time out even\n-# on fast machines because it requires in excess of one hour to run\n-set_tests_properties(\"${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh\" PROPERTIES TIMEOUT 4000)\n+if(WIN32)\n+\t# This test script takes an extremely long time and is known to time out even\n+\t# on fast machines because it requires in excess of one hour to run\n+\tset_tests_properties(\"${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh\" PROPERTIES TIMEOUT 4000)\n+endif()\n \n endif()#BUILD_TESTING\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466424","messageId":"patch-v4-12.14-7b1f10eb4c0-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 12/14] cmake: only look for \"sh\" in \"C:/Program Files\" on Windows","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:38:02Z","receivedAt":"2022-11-03T16:43:16Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Guard the finding of \"SH_EXE\" in \"C:\\Program Files\" with a check for\nwhether we're on Windows.\n\nThis Windows-specific code was first added in [1], and later expanded\non [2], but since some of that was added this build recipe has been\nmade portable outside of Windows.\n\n1. 72b6eeb81b1 (cmake: do find Git for Windows' shell interpreter,\n   2020-09-28)\n2. 476e54b1c60 (cmake: support local installations of git,\n   2022-07-27).\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 15 +++++++++++----\n 1 file changed, 11 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 2b4e5a2f4b6..88723b971c6 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -138,10 +138,17 @@ if(USE_VCPKG)\n \tset(CMAKE_TOOLCHAIN_FILE ${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake CACHE STRING \"Vcpkg toolchain file\")\n endif()\n \n-find_program(SH_EXE sh PATHS \"C:/Program Files/Git/bin\" \"$ENV{LOCALAPPDATA}/Programs/Git/bin\")\n-if(NOT SH_EXE)\n-\tmessage(FATAL_ERROR \"sh: shell interpreter was not found in your path, please install one.\"\n-\t\t\t\"On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/\")\n+if(WIN32)\n+\tfind_program(SH_EXE sh PATHS \"C:/Program Files/Git/bin\" \"$ENV{LOCALAPPDATA}/Programs/Git/bin\")\n+\tif(NOT SH_EXE)\n+\t\tmessage(FATAL_ERROR \"sh: shell interpreter was not found in your path, please install one.\"\n+\t\t\t\t\"You can get it as part of 'Git for Windows' install at https://gitforwindows.org/\")\n+\tendif()\n+else()\n+\tfind_program(SH_EXE sh)\n+\tif(NOT SH_EXE)\n+\t\tmessage(FATAL_ERROR \"cannot find 'sh' in '$PATH'\")\n+\tendif()\n endif()\n \n #Create GIT-VERSION-FILE using GIT-VERSION-GEN\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466425","messageId":"patch-v4-14.14-277028678c8-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 14/14] CI: add a \"linux-cmake-test\" to run cmake & ctest on linux","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:38:04Z","receivedAt":"2022-11-03T16:43:17Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] the \"cmake\" build method should work properly on Linux, but\nas seen in preceding commits there were various bugs in it, which are\nhopefully now all fixed.\n\nTo ensure that it doesn't break again let's add a \"linux-cmake-ctest\"\ntarget to build and test \"cmake\" on Linux, in addition to that we'll\nalso run the tests with \"ctest\" instead of \"make\" or \"prove\", so we\ncan assert that testing with that method works..\n\nThis also stress tests running \"cmake\" (and \"ctest\") out of a build\ndirectory that isn't the top-level. The \"vs-build\" job uses \"cmake\"\nsince [2], but clobbers the top-level \"Makefile\" and builds in the\ntop-level directory.\n\nThat was the reason for why we didn't spot that various tests still\nrequired missing \"mergetools/*\" etc, which was fixed by using\n\"$GIT_SOURCE_DIR\" in a preceding commit.\n\nSince the \"ci/lib.sh\" already creates and exports a\nGIT_TEST_OPTS=\"...\" we'll pick that up in our CI, see the preceding\ncommit. Because we pass the \"--verbose-log -x\n--github-workflow-markup\" in the GitHub CI as a result the interaction\nwith \"handle_failed_tests\" here works correctly. I.e. on failure we'll\nhave saved \"t/test-results/*.{exit,out,markup}\" files relevant to the\nfailing test(s).\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .github/workflows/main.yml |  3 +++\n ci/run-build-and-tests.sh  | 13 +++++++++++--\n 2 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/.github/workflows/main.yml b/.github/workflows/main.yml\nindex bd6f75b8e0f..68c2e134646 100644\n--- a/.github/workflows/main.yml\n+++ b/.github/workflows/main.yml\n@@ -238,6 +238,9 @@ jobs:\n             os: ubuntu\n             cc_package: gcc-8\n             pool: ubuntu-latest\n+          - jobname: linux-cmake-ctest\n+            cc: gcc\n+            pool: ubuntu-latest\n           - jobname: osx-clang\n             cc: clang\n             pool: macos-latest\ndiff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh\nindex 8ebff425967..a3ae5ff3972 100755\n--- a/ci/run-build-and-tests.sh\n+++ b/ci/run-build-and-tests.sh\n@@ -45,10 +45,19 @@ pedantic)\n \t;;\n esac\n \n-group Build make\n+mc=\n+if test \"$jobname\" = \"linux-cmake-ctest\"\n+then\n+\tcb=contrib/buildsystems\n+\tgroup CMake cmake -S \"$cb\" -B \"$cb/out\"\n+\tmc=\"-C $cb/out\"\n+fi\n+\n+group Build make $mc\n+\n if test -n \"$run_tests\"\n then\n-\tgroup \"Run tests\" make test ||\n+\tgroup \"Run tests\" make $mc test ||\n \thandle_failed_tests\n fi\n check_unignored_build_artifacts\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466426","messageId":"patch-v4-10.14-3ea4a61698e-20221103T160255Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v4 10/14] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-03T16:38:00Z","receivedAt":"2022-11-03T16:43:21Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The rationale for adding \"--no-bin-wrappers\" and \"--no-chain-lint\" in\n2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\nruns, 2022-10-18) was those options slowed down the tests considerably\non Windows.\n\nBut since f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\nand with the preceding commits cmake and ctest are not\nWindows-specific anymore.\n\nSo let's set those same options by default on Windows, but do so with\nthe set(... CACHE <type> <docstring>) facility. As noted in cmake's\ndocumentation[1] this integrates nicely with e.g. cmake-gui.\n\nOn *nix we don't set any custom options. The change in 2ea1d8b5563\ndidn't discuss why Windows should have divergent defaults with \"cmake\"\nand \"make\", but such reasons presumably don't apply on *nix. I for one\nam happy with the same defaults as the tests have when running via the\nMakefile.\n\nWith the \"message()\" addition we'll emit this when running cmake:\n\n\tGenerating hook-list.h\n\t-- Using user-selected test options: -vixd\n\t-- Configuring done\n\t-- Generating done\n\t-- Build files have been written to: /home/avar/g/git/contrib/buildsystems/out\n\nUnfortunately cmake doesn't support a non-hacky way to pass variables\nto ctest without re-running cmake itself, so when re-running tests via\ncmake and wanting to change the test defaults we'll need:\n\n\tGIT_TEST_OPTS=-i cmake -S contrib/buildsystems -B contrib/buildsystems/out &&\n\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out -R t0071 --verbose\n\nThe \"separate_arguments()\" here will do the right thing for arguments\nthat don't contain whitespace, so e.g. the path to --root=\"\" can't\nhave a space in it. There's supposedly a way to work around that with\nseparate_arguments(), but it requires features newer than our required\ncmake version, so let's live with that edge case for now.\n\n1. https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 50 +++++++++++++++++++++++++++--\n 1 file changed, 48 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex b9759be4f72..4a832404da6 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -32,7 +32,7 @@ To use this in Visual Studio:\n \n Open the worktree as a folder. Visual Studio 2019 and later will detect\n the CMake configuration automatically and set everything up for you,\n-ready to build. You can then run the tests in `t/` via a regular Git Bash.\n+ready to build. See \"== Running the tests ==\" below for running the tests.\n \n Note: Visual Studio also has the option of opening `CMakeLists.txt`\n directly; Using this option, Visual Studio will not find the source code,\n@@ -76,6 +76,37 @@ empty(default) :\n \n NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n this option is ignored\n+\n+== Running the tests ==\n+\n+Once we've built in \"contrib/buildsystems/out\" the tests can be run at\n+the top-level (note: not the generated \"contrib/buildsystems/out/t/\"\n+drectory). If no top-level build is found (as created with the\n+Makefile) the t/test-lib.sh will discover the git in\n+\"contrib/buildsystems/out\" on e.g.:\n+\n+\t(cd t && ./t0001-init.sh)\n+\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n+\t[...]\n+\n+The tests can also be run with ctest, e.g. after building with \"cmake\"\n+and \"make\" or \"msbuild\" run, from the top-level e.g.:\n+\n+\t# \"--test-dir\" is new in cmake v3.20, so \"(cd\n+\t# contrib/buildsystems/out && ctest ...)\" on older versions.\n+\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\"--output-on-failure\n+\n+Options can be passed by setting GIT_TEST_OPTIONS before invoking\n+cmake. E.g. on a Linux system with systemd the tests can be sped up by\n+using a ramdisk for the scratch files:\n+\n+\tGIT_TEST_OPTS=\"--root=/dev/shm/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n+\t[...]\n+\t-- Using user-selected test options: --root=/dev/shm/<uid>/ctest\n+\n+Then running the tests with \"ctest\" (here with --jobs=\"$(nproc)\"):\n+\n+\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out\n ]]\n cmake_minimum_required(VERSION 3.14)\n \n@@ -1119,10 +1150,25 @@ endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n \n+if(DEFINED ENV{GIT_TEST_OPTS})\n+\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\"\n+\t\tCACHE STRING \"test options, see t/README\")\n+\tmessage(STATUS \"Using user-selected test options: ${GIT_TEST_OPTS}\")\n+elseif(WIN32)\n+\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\"\n+\t\tCACHE STRING \"test options, see t/README\")\n+\tmessage(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n+else()\n+\tset(GIT_TEST_OPTS \"\"\n+\t\tCACHE STRING \"test options, see t/README\")\n+\tmessage(STATUS \"No custom test options selected, set e.g. GIT_TEST_OPTS=\\\"-vixd\\\"\")\n+endif()\n+separate_arguments(GIT_TEST_OPTS)\n+\n #test\n foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n-\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n+\t\tCOMMAND ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n \tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n \t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n-- \n2.38.0.1451.g86b35f4140a\n\n"},{"id":"466568","messageId":"Y2Wt4SK1PX+kfL/G@nand.local","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"Re: [PATCH v4 00/14] cmake: document, fix on *nix, add CI","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-11-05T00:27:13Z","receivedAt":"2022-11-05T00:27:20Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Thu, Nov 03, 2022 at 05:37:50PM +0100, Ævar Arnfjörð Bjarmason wrote:\n> This topic gets our tests from passing ~80% with ctest on *nix to\n> passing 100%.\n>\n> See passing CI job for \"cmake + ctest\" on Ubuntu at:\n> https://github.com/avar/git/actions/runs/3387253536/jobs/5627772317\n>\n> See\n> http://lore.kernel.org/git/cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com\n> for v3.\n\nThanks, will queue.\n\nThanks,\nTaylor\n"},{"id":"466840","messageId":"920e1189-99c1-611e-1f0e-7cd33eebf49a@dunelm.org.uk","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"Re: [PATCH v4 00/14] cmake: document, fix on *nix, add CI","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-11-08T14:42:52Z","receivedAt":"2022-11-08T14:42:58Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 03/11/2022 16:37, Ævar Arnfjörð Bjarmason wrote:\n> This topic gets our tests from passing ~80% with ctest on *nix to\n> passing 100%.\n> \n> See passing CI job for \"cmake + ctest\" on Ubuntu at:\n> https://github.com/avar/git/actions/runs/3387253536/jobs/5627772317\n> \n> See\n> http://lore.kernel.org/git/cover-v3-00.12-00000000000-20221101T225022Z-avarab@gmail.com\n> for v3.\n> \n> Changes since the v3:\n> \n>   * A small \"while at it\" change in 1/14 to make the build output nicer\n>     (particularly for \"ninja, as it's not verbose). It's just the\n>     \"msgfmt without --statistics\" change we've got in the Makefile\n>     already.\n> \n>   * Discuss more about -S and -B in 2/14. It's supported by our cmake\n>     version(s0.\n\nThanks, looking the range-diff there seems to be an overlong line in the \ncommit message.\n\n>   * Re-arranged the docs in 3/14 as Phillip Wood suggested.\n\nI'm not really seeing that. I suggested putting the windows build \ninstructions at the top and inlining the -DCMAKE_BUILD_TYPE discussion \nbut looking at the range diff there are still forward references in the \ntext.\n\n>   * Used Phillip's write_script(). I tested the emitted files\n>     carefully, and they're the same. So something went wrong in my\n>     testing before.\n\nI'm glad that works for you now\n\n>   * Use Phillip's file(CHMOD ...) if we have a new enough cmake\n>     version, otherwise shell out to \"chmod +x\".\n\nKudos for the version test\n\n>   * Use /dev/shm instead of /run/user/`id -u` in an exmaple, and other\n>     small things noted in replies to v3.\n\nThe range-diff for patch 5 shows a reference to \"ctest --test-dir\" which \nis not supported by cmake 3.14 but I see that in patch 10 you provide \nalternative instructions for older versions. I would be simpler just to \nprovide a single recipe that works everywhere. I think you only need \n\"ctest --test-dir\" because you changed the build instructions to use \n\"cmake -B\"\n\nBest Wishes\n\nPhillip\n\n>   * A new 12/14 to do less Windows-specific stuff on *nix, we were\n>     looking for \"sh\" in C:\\Program\\ Files on *nix...\n> \n>   * The GIT_TEST_OPTS integration with cmake-gui now works.\n> \n>   * Various small rewording/typo etc. changes to commit messages, see\n>     range-diff below.\n> \n> Ævar Arnfjörð Bjarmason (14):\n>    cmake: don't invoke msgfmt with --statistics\n>    cmake: use \"-S\" and \"-B\" to specify source and build directories\n>    cmake: update instructions for portable CMakeLists.txt\n>    cmake: don't copy chainlint.pl to build directory\n>    cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n>    cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n>    cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n>    test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n>    Makefile + cmake: use environment, not GIT-BUILD-DIR\n>    cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n>    cmake: increase test timeout on Windows only\n>    cmake: only look for \"sh\" in \"C:/Program Files\" on Windows\n>    cmake: copy over git-p4.py for t983[56] perforce test\n>    CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n> \n>   .github/workflows/main.yml          |   3 +\n>   .gitignore                          |   1 -\n>   Makefile                            |   1 -\n>   ci/run-build-and-tests.sh           |  13 +-\n>   contrib/buildsystems/CMakeLists.txt | 183 +++++++++++++++++++++-------\n>   t/README                            |   3 +\n>   t/lib-gettext.sh                    |   2 +-\n>   t/lib-gitweb.sh                     |   2 +-\n>   t/t7609-mergetool--lib.sh           |   2 +-\n>   t/t9902-completion.sh               |  14 +--\n>   t/t9903-bash-prompt.sh              |   2 +-\n>   t/test-lib.sh                       |  27 +++-\n>   12 files changed, 188 insertions(+), 65 deletions(-)\n> \n> Range-diff against v3:\n>   -:  ----------- >  1:  78dfc2a69b7 cmake: don't invoke msgfmt with --statistics\n>   1:  028fa1436d8 !  2:  dd934b0597d cmake: don't \"mkdir -p\" and \"cd\" in build instructions\n>      @@ Metadata\n>       Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>       \n>        ## Commit message ##\n>      -    cmake: don't \"mkdir -p\" and \"cd\" in build instructions\n>      +    cmake: use \"-S\" and \"-B\" to specify source and build directories\n>       \n>      -    Use the \"-S\" and -B\" flags instead of \"mkdir -p\" and \"cd\". The \"-p\"\n>      -    flag to \"mkdir\" wasn't needed as \"contrib/buildsystems\" is tracked,\n>      -    and the rest of this is now easier to copy/paste into a shell without\n>      -    having one's directory changed.\n>      +    Rather than the multi-line \"mkdir/cd/cmake\" recipe provide an\n>      +    equivalent one-liner using the \"-S\" and \"-B\" options, and then suggest building with \"make -C <build-dir>\".\n>      +\n>      +    The rest of these instructions discuss e.g. running tests from our\n>      +    top-level \"t/\" directory, so it's more helpful to avoid changing the\n>      +    user's current directory.\n>      +\n>      +    The \"-S\" and \"-B\" options were added in cmake v3.13.0, which is older\n>      +    than the version we have a hard dependency on[1].\n>      +\n>      +    As an aside The \"-p\" flag to \"mkdir\" in the pre-image wasn't needed,\n>      +    as \"contrib/buildsystems\" is tracked\n>      +\n>      +    1. 061c2240b1b (Introduce CMake support for configuring Git, 2020-06-12)\n>       \n>           Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>       \n>      @@ contrib/buildsystems/CMakeLists.txt: NOTE: -DCMAKE_BUILD_TYPE is optional. For m\n>        This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n>       -Run `make` to build Git on Linux/*BSD/MacOS.\n>       -Open git.sln on Windows and build Git.\n>      -+Run `make -C contrib/buildsystems` to build Git on Linux/*BSD/MacOS.\n>      ++Run `make -C contrib/buildsystems/out` to build Git on Linux/*BSD/MacOS.\n>       +Open contrib/buildsystems/git.sln on Windows and build Git.\n>        \n>        NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n>   2:  7a21f4aa24c !  3:  6f0eae7a02a cmake: update instructions for portable CMakeLists.txt\n>      @@ contrib/buildsystems/CMakeLists.txt\n>       +alternative.\n>       +\n>       +The primary use-case for maintaining this CMake build recipe is to\n>      -+have nicer IDE integration on Windows. To get Visual Studio-specific\n>      -+instructions see \"== Visual Studio & Windows ==\" below.\n>      ++have nicer IDE integration on Windows.\n>       +\n>       +== Creating a build recipe ==\n>       +\n>      -+To create the build recipe run:\n>      ++The \"cmake\" command creates a build file from this recipe:\n>       +\n>       +    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n>       +\n>      -+For alternative \"-DCMAKE_BUILD_TYPE=<type>\" flags see instructions\n>      -+under the \"== -DCMAKE_BUILD_TYPE=<type> ==\" heading below.\n>      ++Running this will create files in the contrib/buildsystems/out\n>      ++directory (our top-level .gitignore file knows to ignore contents of\n>      ++this directory).\n>       +\n>      -+== Building ==\n>      ++See \"cmake options\" below for a discussion of\n>      ++\"-DCMAKE_BUILD_TYPE=Release\" and other options to \"cmake\".\n>       +\n>      -+The \"cmake\" command creates a build file from this recipe. For Windows\n>      -+Open contrib/buildsystems/git.sln and build Git. Or use the\n>      -+\"msbuild\" command-line tool (see our own \".github/workflows/main.yml\"\n>      -+for a real example):\n>      ++== Building with Visual Visual Studio ==\n>      ++\n>      ++To use this in Visual Studio:\n>      +\n>      + Open the worktree as a folder. Visual Studio 2019 and later will detect\n>      + the CMake configuration automatically and set everything up for you,\n>      +@@ contrib/buildsystems/CMakeLists.txt: Note: Visual Studio also has the option of opening `CMakeLists.txt`\n>      + directly; Using this option, Visual Studio will not find the source code,\n>      + though, therefore the `File>Open>Folder...` option is preferred.\n>      +\n>      +-Instructions to run CMake manually:\n>      ++By default CMake will install vcpkg locally to your source tree on configuration,\n>      ++to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n>      +\n>      +-    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n>      ++== Building on Windows without Visual Studio ==\n>      +\n>      +-This will build the git binaries in contrib/buildsystems/out\n>      +-directory (our top-level .gitignore file knows to ignore contents of\n>      +-this directory).\n>      ++Open contrib/buildsystems/git.sln and build Git. Or use the \"msbuild\"\n>      ++command-line tool (see our own \".github/workflows/main.yml\" for a real\n>      ++example):\n>       +\n>       +\tmsbuild git.sln\n>       +\n>      ++== Building on *nix ==\n>      ++\n>       +On all other platforms running \"cmake\" will generate a Makefile; to\n>       +build with it run:\n>       +\n>      @@ contrib/buildsystems/CMakeLists.txt\n>       +\n>       +It's also possible to use other generators, e.g. Ninja has arguably\n>       +slightly better output. Add \"-G Ninja\" to the cmake command above,\n>      -+then e.g.:\n>      ++then:\n>       +\n>       +\tninja -C contrib/buildsystems/out\n>       +\n>      -+== Visual Studio & Windows ==\n>      ++== cmake options ==\n>       +\n>      -+To use this in Visual Studio:\n>      ++=== -DCMAKE_BUILD_TYPE=<type> ===\n>        \n>      - Open the worktree as a folder. Visual Studio 2019 and later will detect\n>      - the CMake configuration automatically and set everything up for you,\n>      -@@ contrib/buildsystems/CMakeLists.txt: Note: Visual Studio also has the option of opening `CMakeLists.txt`\n>      - directly; Using this option, Visual Studio will not find the source code,\n>      - though, therefore the `File>Open>Folder...` option is preferred.\n>      -\n>      --Instructions to run CMake manually:\n>      --\n>      --    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n>      --\n>      --This will build the git binaries in contrib/buildsystems/out\n>      -+Following the instructions above will build the git binaries in the contrib/buildsystems/out\n>      - directory (our top-level .gitignore file knows to ignore contents of\n>      - this directory).\n>      -\n>      -+By default CMake will install vcpkg locally to your source tree on configuration,\n>      -+to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n>      -+\n>      -+== -DCMAKE_BUILD_TYPE=<type> ==\n>      -+\n>        Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding\n>        compiler flags\n>      - Debug : -g\n>       @@ contrib/buildsystems/CMakeLists.txt: empty(default) :\n>        \n>        NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n>        this option is ignored\n>       -\n>       -This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n>      --Run `make -C contrib/buildsystems` to build Git on Linux/*BSD/MacOS.\n>      +-Run `make -C contrib/buildsystems/out` to build Git on Linux/*BSD/MacOS.\n>       -Open contrib/buildsystems/git.sln on Windows and build Git.\n>       -\n>       -NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n>   3:  3bfa873e792 =  4:  0f0eb2a76c7 cmake: don't copy chainlint.pl to build directory\n>   4:  ad551f53de9 !  5:  eda1c1e95e5 cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n>      @@ Commit message\n>                   make -C contrib/buildsystems/out &&\n>                   ctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\" --output-on-failure\n>       \n>      -    Fails around 20% of our testts on *nix. So even with [3] we'd fail any\n>      +    Fails around 20% of our tests on *nix. So even with [3] we'd fail any\n>           test that needed to invoke one of our built shell, perl or Python\n>           scripts on *nix. E.g. t0012-help.sh would fail on a test that tried to\n>           invoke \"git web--browse\". The equivalent of this (in the \"out\"\n>      @@ Commit message\n>           our built \"git-p4\" wasn't executable, etc. There's also a few other\n>           outstanding issues, which will be fixed in subsequent commits.\n>       \n>      -    This change should ideally use file(CHMOD ...), but the \"file(CHMOD\"\n>      -    feature is much newer than our required cmake version[5].\n>      +    Ideally we'd use the file(CHMOD ...) form everywhere, but that syntax\n>      +    was introduced in cmake 3.19[4], whereas we only require 3.14. Let's\n>      +    provide a fallback behind a version check, so that we'll eventually be\n>      +    able to delete the \"else\" part. Both forms result in the same file\n>      +    modes.\n>       \n>           Before this change:\n>       \n>      @@ Commit message\n>       \n>           The remaining failures will be addressed in subsequent commits.\n>       \n>      -    There was a suggestion of using a function to abstract this away[6],\n>      -    which sounds good. But after spending too long trying to get all\n>      -    combinations of \"${content}\" and ${content} (unqoted) in the function\n>      -    and its callers working I wasn't able to fix the quoting issues it\n>      -    introduced.\n>      -\n>      -    A lot of this is duplicated already, we can follow-up at some other\n>      -    time with refactoring, and address any tricky quoting issues in\n>      -    calling function with these parameters then.\n>      -\n>           1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n>           2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n>           3. 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n>              runs, 2022-10-18)\n>      -    4. a30e4c531d9 (Merge branch 'ss/cmake-build', 2020-08-11)\n>      -    5. https://cmake.org/cmake/help/latest/command/file.html#chmod\n>      -    6. https://lore.kernel.org/git/0fda0e54-0432-7690-74a7-3d1a59923e0c@dunelm.org.uk/\n>      +    4. https://cmake.org/cmake/help/latest/command/file.html#chmod\n>       \n>           Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>       \n>      +    write script\n>      +\n>        ## contrib/buildsystems/CMakeLists.txt ##\n>      +@@ contrib/buildsystems/CMakeLists.txt: add_custom_command(OUTPUT ${git_links} ${git_http_links}\n>      + \t\tDEPENDS git git-remote-http)\n>      + add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links})\n>      +\n>      ++function(write_script path content)\n>      ++\tfile(WRITE ${path} ${content})\n>      ++\n>      ++\tif(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" VERSION_GREATER_EQUAL \"3.19\")\n>      ++\t\tfile(CHMOD ${path} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)\n>      ++\telse()\n>      ++\t\texecute_process(COMMAND chmod +x ${path}\n>      ++\t\t\t\tRESULT_VARIABLE CHILD_ERROR)\n>      ++\t\tif(CHILD_ERROR)\n>      ++\t\t\tmessage(FATAL_ERROR \"failed to chmod +x '${path}': '${CHILD_ERROR}'\")\n>      ++\t\tendif()\n>      ++\tendif()\n>      ++endfunction()\n>      +\n>      + #creating required scripts\n>      + set(SHELL_PATH /bin/sh)\n>       @@ contrib/buildsystems/CMakeLists.txt: foreach(script ${git_shell_scripts})\n>      + \tstring(REPLACE \"# @@BROKEN_PATH_FIX@@\" \"\" content \"${content}\")\n>        \tstring(REPLACE \"@@PERL@@\" \"${PERL_PATH}\" content \"${content}\")\n>        \tstring(REPLACE \"@@PAGER_ENV@@\" \"LESS=FRX LV=-c\" content \"${content}\")\n>      - \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n>      -+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n>      +-\tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n>      ++\twrite_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n>        endforeach()\n>        \n>        #perl scripts\n>       @@ contrib/buildsystems/CMakeLists.txt: foreach(script ${git_perl_scripts})\n>      + \tfile(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME)\n>        \tstring(REPLACE \"#!/usr/bin/perl\" \"#!/usr/bin/perl\\n${perl_header}\\n\" content \"${content}\")\n>        \tstring(REPLACE \"@@GIT_VERSION@@\" \"${PROJECT_VERSION}\" content \"${content}\")\n>      - \tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n>      -+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/${script})\n>      +-\tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n>      ++\twrite_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n>        endforeach()\n>        \n>        #python script\n>        file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n>        string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n>      - file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n>      -+execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/git-p4)\n>      +-file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n>      ++write_script(${CMAKE_BINARY_DIR}/git-p4 \"${content}\")\n>        \n>        #perl modules\n>        file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n>       @@ contrib/buildsystems/CMakeLists.txt: foreach(script ${wrapper_scripts})\n>      + \tfile(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n>        \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n>        \tstring(REPLACE \"@@PROG@@\" \"${script}${EXE_EXTENSION}\" content \"${content}\")\n>      - \tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n>      -+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/${script})\n>      +-\tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n>      ++\twrite_script(${CMAKE_BINARY_DIR}/bin-wrappers/${script} \"${content}\")\n>        endforeach()\n>        \n>        foreach(script ${wrapper_test_scripts})\n>      -@@ contrib/buildsystems/CMakeLists.txt: foreach(script ${wrapper_test_scripts})\n>      + \tfile(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n>        \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n>        \tstring(REPLACE \"@@PROG@@\" \"t/helper/${script}${EXE_EXTENSION}\" content \"${content}\")\n>      - \tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n>      -+\texecute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/${script})\n>      +-\tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n>      ++\twrite_script(${CMAKE_BINARY_DIR}/bin-wrappers/${script} \"${content}\")\n>        endforeach()\n>        \n>        file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n>        string(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n>        string(REPLACE \"@@PROG@@\" \"git-cvsserver\" content \"${content}\")\n>      - file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})\n>      -+execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver)\n>      +-file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})\n>      ++write_script(${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver \"${content}\")\n>        \n>        #options for configuring test options\n>        option(PERL_TESTS \"Perform tests that use perl\" ON)\n>   5:  5c7b64286ce =  6:  6c254f8cb9f cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n>   6:  cba90650879 =  7:  1685a58e13a cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n>   7:  bd7fb1eec24 =  8:  87a2c77ee68 test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n>   8:  fd3e6be5689 =  9:  6187ded42db Makefile + cmake: use environment, not GIT-BUILD-DIR\n>   9:  8a660a2baa4 ! 10:  3ea4a61698e cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n>      @@ Commit message\n>           Windows-specific anymore.\n>       \n>           So let's set those same options by default on Windows, but do so with\n>      -    the set() facility. As noted in cmake's documentation[1] this\n>      -    integrates nicely with e.g. cmake-gui.\n>      +    the set(... CACHE <type> <docstring>) facility. As noted in cmake's\n>      +    documentation[1] this integrates nicely with e.g. cmake-gui.\n>       \n>           On *nix we don't set any custom options. The change in 2ea1d8b5563\n>           didn't discuss why Windows should have divergent defaults with \"cmake\"\n>      @@ Commit message\n>                   GIT_TEST_OPTS=-i cmake -S contrib/buildsystems -B contrib/buildsystems/out &&\n>                   ctest --jobs=$(nproc) --test-dir contrib/buildsystems/out -R t0071 --verbose\n>       \n>      +    The \"separate_arguments()\" here will do the right thing for arguments\n>      +    that don't contain whitespace, so e.g. the path to --root=\"\" can't\n>      +    have a space in it. There's supposedly a way to work around that with\n>      +    separate_arguments(), but it requires features newer than our required\n>      +    cmake version, so let's live with that edge case for now.\n>      +\n>           1. https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry\n>       \n>           Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>      @@ contrib/buildsystems/CMakeLists.txt: empty(default) :\n>       +The tests can also be run with ctest, e.g. after building with \"cmake\"\n>       +and \"make\" or \"msbuild\" run, from the top-level e.g.:\n>       +\n>      ++\t# \"--test-dir\" is new in cmake v3.20, so \"(cd\n>      ++\t# contrib/buildsystems/out && ctest ...)\" on older versions.\n>       +\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\"--output-on-failure\n>       +\n>       +Options can be passed by setting GIT_TEST_OPTIONS before invoking\n>       +cmake. E.g. on a Linux system with systemd the tests can be sped up by\n>       +using a ramdisk for the scratch files:\n>       +\n>      -+\tGIT_TEST_OPTS=\"--root=/run/user/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n>      ++\tGIT_TEST_OPTS=\"--root=/dev/shm/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n>       +\t[...]\n>      -+\t-- Using user-selected test options: --root=/run/user/1001/ctest\n>      ++\t-- Using user-selected test options: --root=/dev/shm/<uid>/ctest\n>       +\n>       +Then running the tests with \"ctest\" (here with --jobs=\"$(nproc)\"):\n>       +\n>      @@ contrib/buildsystems/CMakeLists.txt: endif()\n>        \n>        file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n>        \n>      -+string(COMPARE NOTEQUAL \"$ENV{GIT_TEST_OPTS}\" \"\" HAVE_USER_GIT_TEST_OPTS)\n>      -+if(HAVE_USER_GIT_TEST_OPTS)\n>      -+\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\")\n>      ++if(DEFINED ENV{GIT_TEST_OPTS})\n>      ++\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\"\n>      ++\t\tCACHE STRING \"test options, see t/README\")\n>       +\tmessage(STATUS \"Using user-selected test options: ${GIT_TEST_OPTS}\")\n>       +elseif(WIN32)\n>      -+\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\")\n>      ++\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\"\n>      ++\t\tCACHE STRING \"test options, see t/README\")\n>       +\tmessage(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n>       +else()\n>      -+\tset(GIT_TEST_OPTS \"\")\n>      ++\tset(GIT_TEST_OPTS \"\"\n>      ++\t\tCACHE STRING \"test options, see t/README\")\n>       +\tmessage(STATUS \"No custom test options selected, set e.g. GIT_TEST_OPTS=\\\"-vixd\\\"\")\n>       +endif()\n>       +separate_arguments(GIT_TEST_OPTS)\n> 10:  966fec83b77 = 11:  8ccf5c8c265 cmake: increase test timeout on Windows only\n>   -:  ----------- > 12:  7b1f10eb4c0 cmake: only look for \"sh\" in \"C:/Program Files\" on Windows\n> 11:  aad17d8f858 ! 13:  0699e398e89 cmake: copy over git-p4.py for t983[56] perforce test\n>      @@ Commit message\n>           Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>       \n>        ## contrib/buildsystems/CMakeLists.txt ##\n>      -@@ contrib/buildsystems/CMakeLists.txt: file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n>      +@@ contrib/buildsystems/CMakeLists.txt: endforeach()\n>      + file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n>        string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n>      - file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n>      - execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/git-p4)\n>      + write_script(${CMAKE_BINARY_DIR}/git-p4 \"${content}\")\n>       +file(COPY ${CMAKE_SOURCE_DIR}/git-p4.py DESTINATION ${CMAKE_BINARY_DIR}/)\n>        \n>        #perl modules\n> 12:  c27f620dfa3 = 14:  277028678c8 CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n"},{"id":"468407","messageId":"patch-v5-01.15-7d83ff44c61-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 01/15] cmake: don't invoke msgfmt with --statistics","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:22Z","receivedAt":"2022-12-02T11:28:49Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"In 2f12b31b746 (Makefile: don't invoke msgfmt with --statistics,\n2021-12-17) I made the same change to our Makefile, let's follow-up\nand do the same here.\n\nFor \"cmake\" this is particularly nice with \"-G Ninja\", as before we'd\nemit ~40 lines of overflowed progress bar output, but now it's only\nthe one line of \"ninja\"'s progress bar.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 2f6e0197ffa..8f8b6f375f7 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -897,7 +897,7 @@ if(MSGFMT_EXE)\n \tforeach(po ${po_files})\n \t\tfile(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES)\n \t\tadd_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo\n-\t\t\t\tCOMMAND ${MSGFMT_EXE} --check --statistics -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po)\n+\t\t\t\tCOMMAND ${MSGFMT_EXE} --check -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po)\n \t\tlist(APPEND po_gen ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo)\n \tendforeach()\n \tadd_custom_target(po-gen ALL DEPENDS ${po_gen})\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468408","messageId":"patch-v5-03.15-5c4ba2425b6-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 03/15] cmake: update instructions for portable CMakeLists.txt","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:24Z","receivedAt":"2022-12-02T11:28:51Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The instructions for running CMake went back & forth between *nix,\nWindows and Visual Studio instructions Let's create headings and split\nthe existing instructions up into those new sections.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 68 +++++++++++++++++++++--------\n 1 file changed, 50 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 5b22a9b217f..80290edd72a 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -4,7 +4,31 @@\n \n #[[\n \n-Instructions how to use this in Visual Studio:\n+== Overview ==\n+\n+The top-level Makefile is Git's primary build environment, and a lot\n+of things are missing (and probably always will be) from this CMake\n+alternative.\n+\n+The primary use-case for maintaining this CMake build recipe is to\n+have nicer IDE integration on Windows.\n+\n+== Creating a build recipe ==\n+\n+The \"cmake\" command creates a build file from this recipe:\n+\n+    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n+\n+Running this will create files in the contrib/buildsystems/out\n+directory (our top-level .gitignore file knows to ignore contents of\n+this directory).\n+\n+See \"cmake options\" below for a discussion of\n+\"-DCMAKE_BUILD_TYPE=Release\" and other options to \"cmake\".\n+\n+== Building with Visual Visual Studio ==\n+\n+To use this in Visual Studio:\n \n Open the worktree as a folder. Visual Studio 2019 and later will detect\n the CMake configuration automatically and set everything up for you,\n@@ -14,13 +38,33 @@ Note: Visual Studio also has the option of opening `CMakeLists.txt`\n directly; Using this option, Visual Studio will not find the source code,\n though, therefore the `File>Open>Folder...` option is preferred.\n \n-Instructions to run CMake manually:\n+By default CMake will install vcpkg locally to your source tree on configuration,\n+to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n \n-    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n+== Building on Windows without Visual Studio ==\n \n-This will build the git binaries in contrib/buildsystems/out\n-directory (our top-level .gitignore file knows to ignore contents of\n-this directory).\n+Open contrib/buildsystems/git.sln and build Git. Or use the \"msbuild\"\n+command-line tool (see our own \".github/workflows/main.yml\" for a real\n+example):\n+\n+\tmsbuild git.sln\n+\n+== Building on *nix ==\n+\n+On all other platforms running \"cmake\" will generate a Makefile; to\n+build with it run:\n+\n+\tmake -C contrib/buildsystems/out\n+\n+It's also possible to use other generators, e.g. Ninja has arguably\n+slightly better output. Add \"-G Ninja\" to the cmake command above,\n+then:\n+\n+\tninja -C contrib/buildsystems/out\n+\n+== cmake options ==\n+\n+=== -DCMAKE_BUILD_TYPE=<type> ===\n \n Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding\n compiler flags\n@@ -32,18 +76,6 @@ empty(default) :\n \n NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n this option is ignored\n-\n-This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n-Run `make -C contrib/buildsystems/out` to build Git on Linux/*BSD/MacOS.\n-Open contrib/buildsystems/git.sln on Windows and build Git.\n-\n-NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n-to use another tool say `ninja` add this to the command line when configuring.\n-`-G Ninja`\n-\n-NOTE: By default CMake will install vcpkg locally to your source tree on configuration,\n-to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n-\n ]]\n cmake_minimum_required(VERSION 3.14)\n \n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468409","messageId":"patch-v5-02.15-314c5e40cff-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 02/15] cmake: use \"-S\" and \"-B\" to specify source and build directories","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:23Z","receivedAt":"2022-12-02T11:28:52Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Rather than the multi-line \"mkdir/cd/cmake\" recipe provide an\nequivalent one-liner using the \"-S\" and \"-B\" options, and then suggest building with \"make -C <build-dir>\".\n\nThe rest of these instructions discuss e.g. running tests from our\ntop-level \"t/\" directory, so it's more helpful to avoid changing the\nuser's current directory.\n\nThe \"-S\" and \"-B\" options were added in cmake v3.13.0, which is older\nthan the version we have a hard dependency on[1].\n\nAs an aside The \"-p\" flag to \"mkdir\" in the pre-image wasn't needed,\nas \"contrib/buildsystems\" is tracked\n\n1. 061c2240b1b (Introduce CMake support for configuring Git, 2020-06-12)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 8f8b6f375f7..5b22a9b217f 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -16,9 +16,7 @@ though, therefore the `File>Open>Folder...` option is preferred.\n \n Instructions to run CMake manually:\n \n-    mkdir -p contrib/buildsystems/out\n-    cd contrib/buildsystems/out\n-    cmake ../ -DCMAKE_BUILD_TYPE=Release\n+    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n \n This will build the git binaries in contrib/buildsystems/out\n directory (our top-level .gitignore file knows to ignore contents of\n@@ -36,8 +34,8 @@ NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual St\n this option is ignored\n \n This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n-Run `make` to build Git on Linux/*BSD/MacOS.\n-Open git.sln on Windows and build Git.\n+Run `make -C contrib/buildsystems/out` to build Git on Linux/*BSD/MacOS.\n+Open contrib/buildsystems/git.sln on Windows and build Git.\n \n NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n to use another tool say `ninja` add this to the command line when configuring.\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468410","messageId":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com","subject":"[PATCH v5 00/15] cmake: document, fix on *nix, add CI","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:21Z","receivedAt":"2022-12-02T11:29:04Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This topic gets our tests from passing ~80% with ctest on *nix to\npassing 100%.\n\nSee passing CI job for \"cmake + ctest\" on Ubuntu at:\nhttps://github.com/avar/git/actions/runs/3598398023\n\nSee\nhttps://lore.kernel.org/git/cover-v4-00.14-00000000000-20221103T160255Z-avarab@gmail.com/\nfor the v4.\n\nThe v4 of this is in \"next\", but expected to be ejected & re-queued\nper [1].\n\nChanges since v4.\n\n* Rebased on master. Junio: I think the merge you had for main.yml was\n  a mismerge, i.e. the new job here wanted \"ubuntu-latest\". Per\n  0178420b9ca (github-actions: run gcc-8 on ubuntu-20.04 image,\n  2022-11-25) only the gcc-8 jobs want to pin the version.\n\n  In practice that merge resolution was harmless, as the job ran just\n  fine on ubuntu-20.04.\n\n* Per the discussion starting at [2] this v5 doesn't remove the\n  GIT-BUILD-DIR file, but if we have it and build directory built\n  with \"make\" we'll prefer the \"make\" one.\n\n  This supports the use-case of running the tests discovering the\n  \"cmake\" build directory using the same mechanism as before, while\n  fixing the edge cases where the two will trip over one\n  another. E.g. a \"make git\" after a \"cmake\" still running the tests\n  with the \"cmake\".\n\n* There are other behavior differences to fix what I consider bugs in\n  the existing behavior, but that new behavior is guarded by a\n  \"GIT_CTEST_SETS_BUILD_DIR\" variable. On Windows it's \"ON\" by default\n  (the old behavior), elsewhere it's \"OFF\".\n\n  As the test suite wasn't close to running succesfully before this\n  the non-Windows users should benefit from the new behavior, but it\n  is different. So Windows users get old semantics, unless they'd like\n  to opt-in.\n\n  The resulting behavior differences are the following (table taken\n  from 10/15):\n\n\t|---+----+-----|\n\t|   | ON | OFF |\n\t|---+----+-----|\n\t| A | N  | Y   |\n\t| B | N  | Y   |\n\t| C | Y  | Y   |\n\t| D | Y  | N   |\n\t| E | N  | Y   |\n\t|---+----+-----|\n\tA. Can manually run tests before ctest?\n\tB. Manually run tests point to latest cmake build?...\n\tC. Manually run tests point to latest \"ctest\"'d build?\n        D. \"git\" picked at ctest start time?\n        E. \"git\" picked at test start time?\n\n1. https://lore.kernel.org/git/xmqq5yeuspam.fsf@gitster.g/\n2. https://lore.kernel.org/git/544fff8a-7d56-57a1-00a3-d1a9302e227c@dunelm.org.uk/\n\nBranch & passing CI at\nhttps://github.com/avar/git/tree/avar/cmake-test-path-5\n\nÆvar Arnfjörð Bjarmason (15):\n  cmake: don't invoke msgfmt with --statistics\n  cmake: use \"-S\" and \"-B\" to specify source and build directories\n  cmake: update instructions for portable CMakeLists.txt\n  cmake: don't copy chainlint.pl to build directory\n  cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n  cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n  cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n  Makefile + test-lib.sh: don't prefer cmake-built to make-built git\n  test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n  cmake: optionally be able to run tests before \"ctest\"\n  cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n  cmake: increase test timeout on Windows only\n  cmake: only look for \"sh\" in \"C:/Program Files\" on Windows\n  cmake: copy over git-p4.py for t983[56] perforce test\n  CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n\n .github/workflows/main.yml          |   3 +\n Makefile                            |   1 -\n ci/run-build-and-tests.sh           |  13 +-\n contrib/buildsystems/CMakeLists.txt | 211 ++++++++++++++++++++++------\n t/README                            |   3 +\n t/lib-gettext.sh                    |   2 +-\n t/lib-gitweb.sh                     |   2 +-\n t/t7609-mergetool--lib.sh           |   2 +-\n t/t9902-completion.sh               |  14 +-\n t/t9903-bash-prompt.sh              |   2 +-\n t/test-lib.sh                       |  19 ++-\n 11 files changed, 211 insertions(+), 61 deletions(-)\n\nRange-diff against v4:\n 1:  78dfc2a69b7 =  1:  7d83ff44c61 cmake: don't invoke msgfmt with --statistics\n 2:  dd934b0597d =  2:  314c5e40cff cmake: use \"-S\" and \"-B\" to specify source and build directories\n 3:  6f0eae7a02a =  3:  5c4ba2425b6 cmake: update instructions for portable CMakeLists.txt\n 4:  0f0eb2a76c7 =  4:  e86245ffbab cmake: don't copy chainlint.pl to build directory\n 5:  eda1c1e95e5 =  5:  435452314fa cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n 6:  6c254f8cb9f =  6:  7ee341245a8 cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n 7:  1685a58e13a =  7:  49645cb1643 cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n -:  ----------- >  8:  9e10cd5bd8a Makefile + test-lib.sh: don't prefer cmake-built to make-built git\n 8:  87a2c77ee68 !  9:  df5aea35bbd test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n    @@ Commit message\n                 (cd git2 && GIT_TEST_BUILD_DIR=\"$PWD/../git1\" make -C t prove)\n     \n         This facility and file-based instructions to have the test suite use\n    -    another build directory[2] are mutually exclusive, but in a subsequent\n    -    commit we'll make CMake use this instead.\n    +    another build directory[2] are mutually exclusive. In a subsequent\n    +    commit we'll make CMake and CTest optionally prefer this method.\n     \n         1. 6720721e152 (test-lib.sh: Allow running the test suite against\n            installed git, 2009-03-16)\n    @@ t/README: override the location of the dashed-form subcommands (what\n      --------------\n     \n      ## t/test-lib.sh ##\n    -@@ t/test-lib.sh: fi\n    - # For CMake the top-level source directory is different from our build\n    - # directory. With the top-level Makefile they're the same.\n    - GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n    --if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n    -+if test -n \"$GIT_TEST_BUILD_DIR\"\n    -+then\n    -+\tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n    -+elif test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n    +@@ t/test-lib.sh: if test ! -x \"$GIT_BUILD_DIR/git\" &&\n    + \ttest -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n      then\n      \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n    ++elif test -n \"$GIT_TEST_BUILD_DIR\"\n    ++then\n    ++\tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n    ++fi\n    ++\n    ++if test \"$GIT_SOURCE_DIR\" != \"$GIT_BUILD_DIR\"\n    ++then\n      \t# On Windows, we must convert Windows paths lest they contain a colon\n    + \tcase \"$(uname -s)\" in\n    + \t*MINGW*)\n 9:  6187ded42db ! 10:  529e18f7f72 Makefile + cmake: use environment, not GIT-BUILD-DIR\n    @@ Metadata\n     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n      ## Commit message ##\n    -    Makefile + cmake: use environment, not GIT-BUILD-DIR\n    +    cmake: optionally be able to run tests before \"ctest\"\n     \n    -    Change the method used to have building with \"cmake\" followed by\n    -    running the tests manually work without creating inter-dependency issues with the Makefile.\n    +    Since [1] the \"cmake\" build has had support for running the tests\n    +    manually from the \"t/\" directory once we've built with \"cmake\", but\n    +    only after a one-off run of \"ctest\".\n     \n    -    Per ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18) and\n    -    the surrounding discussion the goal of that change was to have\n    -    building with cmake and:\n    +    I.e. we create the build recipe via \"cmake\" and build with\n    +    e.g. \"make\", but after doing so would get:\n     \n    -            (cd t && ./t0001-init.sh)\n    +            $ (cd t && ./t0071-sort.sh)\n    +            error: GIT-BUILD-OPTIONS missing (has Git been built?).\n     \n    -    Work, to do so we need some way to make the test-lib.sh aware that we\n    -    have a build in contrib/buildsystems/out. The downside of doing it via\n    -    the GIT-BUILD-DIR facility in ee9e66e4e76 is:\n    +    The recently added amendment to this of using a \"GIT-BUILD-DIR\"[2]\n    +    didn't change these semantics. After we did a one-off run of \"ctest\"\n    +    we'd be able to run the tests without \"ctest\":\n     \n    -    - A \"remove this file while at it\" only fits into the Makefile\n    -      dependency graph if we \"FORCE\" a shell command to be run, so doing it\n    -      this way precludes speeding up the Makefile by e.g. making use of the\n    -      \"$(file)\" function (for which I've got follow-up patches).\n    -\n    -    - If you build with make, then with cmake, and then e.g.:\n    -\n    -            make -C t prove\n    -\n    -      We'll run the tests against the cmake version of the tests, not the\n    -      \"make\" built ones. It's important to get any subtle interaction\n    -      between two conflicting build systems right.\n    -\n    -    Now we'll instead:\n    -\n    -    - Check if the top-level \"git\" exists, if not we'll look in\n    -      \"contrib/buildsystems/out/git\", and when running interactively inform\n    -      the user about the fallback being picked.\n    -\n    -            $ ./t0001-init.sh\n    -            setup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n    -            ok 1 - plain\n    +            $ ctest --test-dir contrib/buildsystems/out -R t0071\n                 [...]\n    -\n    -    - This also makes things more obvious on the cmake side, because we'll\n    -      now use an environment variable to select the test environment, which\n    -      ctest it notes in its verbose output, e.g.:\n    -\n    -            [...]\n    -            2: Test command: /bin/sh \"/home/avar/g/git/contrib/buildsystems/../../t/t0001-init.sh\" \"--no-bin-wrappers\" \"--no-chain-lint\" \"-vx\"\n    -            2: Working Directory: /home/avar/g/git/contrib/buildsystems/../../t\n    -            2: Environment variables:\n    -            2:  GIT_TEST_BUILD_DIR=/home/avar/g/git/contrib/buildsystems/out\n    +            100% tests passed, 0 tests failed out of 1\n                 [...]\n    -\n    -       See [1] for the relevant cmake language references.\n    -\n    -    - We don't support an arbitrary build directory outside of\n    -      \"contrib/buildsystems/out\". This is OK because the reason for doing\n    -      this part is to support the workflow documented in [2].\n    -\n    -      As [3] notes \"contrib/buildsystems/out\" isn't just the directory that\n    -      happens to be documented in \"contrib/buildsystems/CMakeLists.txt\", but\n    -      the one that VS will use when building git.\n    -\n    -    1. https://cmake.org/cmake/help/latest/command/set_property.html\n    -       https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#test-properties\n    -       https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#cmake-language-lists\n    -    1. f2f1250c47f (cmake (Windows): recommend using Visual Studio's\n    -       built-in CMake support, 2020-09-30)\n    -    2. 3eccc7b99d4 (cmake: ignore files generated by CMake as run in\n    -       Visual Studio, 2020-09-25)\n    +            $ (cd t && ./t0071-sort.sh)\n    +            ok 1 - DEFINE_LIST_SORT_DEBUG\n    +            # passed all 1 test(s)\n    +            1..1\n    +\n    +    This change optionally closes that gap, and allows for more sensible\n    +    behavior. Due to concerns about existing MS Visual Studio users\n    +    relying on some of these edge cases this is being made optional, with\n    +    the default of the new \"GIT_CTEST_SETS_BUILD_DIR\" being \"ON\" on\n    +    Windows (i.e. the old behavior), and \"OFF\" elsewhere.\n    +\n    +    The resulting behavior differences are the following:\n    +\n    +            |---+----+-----|\n    +            |   | ON | OFF |\n    +            |---+----+-----|\n    +            | A | N  | Y   |\n    +            | B | N  | Y   |\n    +            | C | Y  | Y   |\n    +            | D | Y  | N   |\n    +            | E | N  | Y   |\n    +            |---+----+-----|\n    +            A. Can manually run tests before ctest?\n    +            B. Manually run tests point to latest cmake build?...\n    +            C. Manually run tests point to latest \"ctest\"'d build?\n    +            D. \"git\" picked at ctest start time?\n    +            E. \"git\" picked at test start time?\n    +\n    +    On \"D\" and \"E\": Because GIT_CTEST_SETS_BUILD_DIR=ON relies on the\n    +    global \"GIT-BUILD-DIR\" when using \"ctest\" it cannot be used to run\n    +    concurrent tests for two different builds from the same source\n    +    directory.\n    +\n    +    But as noted in [3] existing users using Visual Studio may be relying\n    +    on some of these edge cases, so let's make this optional on Windows,\n    +    but switch the default to this new discover method on other platforms.\n    +\n    +    1. 7f5397a07c6 (cmake: support for testing git when building out of\n    +       the source tree, 2020-06-26)\n    +    2. ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18)\n    +    3. https://lore.kernel.org/git/663b93ef-0c89-a5f6-1069-b4be97915d20@dunelm.org.uk/\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n    - ## .gitignore ##\n    -@@\n    - /fuzz_corpora\n    --/GIT-BUILD-DIR\n    - /GIT-BUILD-OPTIONS\n    - /GIT-CFLAGS\n    - /GIT-LDFLAGS\n    -\n    - ## Makefile ##\n    -@@ Makefile: else\n    - \t@echo RUNTIME_PREFIX=\\'false\\' >>$@+\n    - endif\n    - \t@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi\n    --\t@if test -f GIT-BUILD-DIR; then rm GIT-BUILD-DIR; fi\n    - \n    - ### Detect Python interpreter path changes\n    - ifndef NO_PYTHON\n    -\n      ## contrib/buildsystems/CMakeLists.txt ##\n     @@ contrib/buildsystems/CMakeLists.txt: if(USE_VCPKG)\n      \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n    @@ contrib/buildsystems/CMakeLists.txt: if(USE_VCPKG)\n     -\t#Setting the build directory in test-lib.sh before running tests\n     -\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n     -\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n    --endif()\n    --\n    - file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n    ++set(GIT_CTEST_SETS_BUILD_DIR_DOC \"find cmake build dir via ctest-set GIT-BUILD-DIR?\")\n    ++if(DEFINED ENV{GIT_CTEST_SETS_BUILD_DIR})\n    ++\tset(GIT_CTEST_SETS_BUILD_DIR \"$ENV{GIT_CTEST_SETS_BUILD_DIR}\"\n    ++\t\tCACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n    ++elseif(WIN32)\n    ++\tset(GIT_CTEST_SETS_BUILD_DIR \"ON\" CACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n    ++else()\n    ++\tset(GIT_CTEST_SETS_BUILD_DIR \"OFF\" CACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n    ++endif()\n    ++if(GIT_CTEST_SETS_BUILD_DIR)\n    ++\tmessage(STATUS \"Enabling manual runs of t/* tests once ctest writes CMAKE-BUILD-DIR\")\n    ++else()\n    ++\tmessage(STATUS \"Enabling manual runs of t/* tests via cmake build dir discovery\")\n    ++endif()\n    ++\n    ++# When using GIT_CTEST_SETS_BUILD_DIR, running the tests from the \"t/\"\n    ++# directory will only work once \"ctest\" has been run, as we write to\n    ++# \"GIT-BUILD-DIR\" from the optional \"ctest\" invocation following the\n    ++# \"cmake\"\n    ++if(GIT_CTEST_SETS_BUILD_DIR)\n    ++\tget_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n    ++\tif(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n    ++\t\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n    ++\t\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n    ++\tendif()\n    ++else()\n    ++\tfile(WRITE \"${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR\" \"${CMAKE_BINARY_DIR}\")\n    + endif()\n      \n    - #test\n    + file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n     @@ contrib/buildsystems/CMakeLists.txt: foreach(tsh ${test_scipts})\n      \tadd_test(NAME ${tsh}\n      \t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n      \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n    ++if(NOT GIT_CTEST_SETS_BUILD_DIR)\n     +\tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n    ++\t\tGIT_TEST_PREFER_BUILD_DIR_ENV=\"Yes, ignore GIT-BUILD-DIR\"\n     +\t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n    ++endif()\n      endforeach()\n      \n      # This test script takes an extremely long time and is known to time out even\n    @@ t/test-lib.sh: fi\n      # For CMake the top-level source directory is different from our build\n      # directory. With the top-level Makefile they're the same.\n      GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n    -+\n    -+GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=\n    - if test -n \"$GIT_TEST_BUILD_DIR\"\n    - then\n    - \tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n    --elif test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n    -+elif ! test -x \"$GIT_BUILD_DIR/git\" &&\n    -+     test -x \"$GIT_BUILD_DIR/contrib/buildsystems/out/git\"\n    - then\n    --\tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n    -+\tGIT_BUILD_DIR=\"$GIT_SOURCE_DIR/contrib/buildsystems/out\"\n    -+\tGIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT=t\n    -+\n    - \t# On Windows, we must convert Windows paths lest they contain a colon\n    - \tcase \"$(uname -s)\" in\n    - \t*MINGW*)\n    -@@ t/test-lib.sh: remove_trash_directory \"$TRASH_DIRECTORY\" || {\n    - \tBAIL_OUT 'cannot prepare test area'\n    - }\n    - \n    -+# Emitting this now because earlier we didn't have \"say\", but not in\n    -+# anything using lib-subtest.sh\n    -+if test -n \"$GIT_AUTO_CONTRIB_BUILDSYSTEMS_OUT\" && test -t 1\n    -+then\n    -+\tsay \"setup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\"\n    -+fi\n    -+\n    - remove_trash=t\n    - if test -z \"$TEST_NO_CREATE_REPO\"\n    +-if test ! -x \"$GIT_BUILD_DIR/git\" &&\n    ++if test -z \"$GIT_TEST_PREFER_BUILD_DIR_ENV\" &&\n    ++\ttest ! -x \"$GIT_BUILD_DIR/git\" &&\n    + \ttest -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n      then\n    + \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n10:  3ea4a61698e ! 11:  a5dd4fa1d00 cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n    @@ contrib/buildsystems/CMakeLists.txt: endif()\n     -\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n     +\t\tCOMMAND ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n      \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n    + if(NOT GIT_CTEST_SETS_BUILD_DIR)\n      \tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n    - \t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n11:  8ccf5c8c265 ! 12:  c9d550b8558 cmake: increase test timeout on Windows only\n    @@ Commit message\n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n      ## contrib/buildsystems/CMakeLists.txt ##\n    -@@ contrib/buildsystems/CMakeLists.txt: foreach(tsh ${test_scipts})\n    - \t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n    +@@ contrib/buildsystems/CMakeLists.txt: if(NOT GIT_CTEST_SETS_BUILD_DIR)\n    + endif()\n      endforeach()\n      \n     -# This test script takes an extremely long time and is known to time out even\n12:  7b1f10eb4c0 = 13:  7a5dd684d40 cmake: only look for \"sh\" in \"C:/Program Files\" on Windows\n13:  0699e398e89 = 14:  c9c895bb794 cmake: copy over git-p4.py for t983[56] perforce test\n14:  277028678c8 ! 15:  a6f343b6221 CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n    @@ Commit message\n     \n      ## .github/workflows/main.yml ##\n     @@ .github/workflows/main.yml: jobs:\n    -             os: ubuntu\n    +             cc: gcc\n                  cc_package: gcc-8\n    -             pool: ubuntu-latest\n    +             pool: ubuntu-20.04\n     +          - jobname: linux-cmake-ctest\n     +            cc: gcc\n     +            pool: ubuntu-latest\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468411","messageId":"patch-v5-04.15-e86245ffbab-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 04/15] cmake: don't copy chainlint.pl to build directory","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:25Z","receivedAt":"2022-12-02T11:29:05Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When [1] made this copy of \"chainlint.sed\" the script was invoked in\nthe test-lib.sh as:\n\n\t[...] sed -f \"$GIT_BUILD_DIR/t/chainlint.sed\" [...]\n\nBut when [2] replaced \"chainlint.sed\" with a \"chainlint.pl\" it also\nreplaced that \"$GIT_BUILD_DIR\" with \"$TEST_DIRECTORY\", invoking it as:\n\n\t\"$PERL_PATH\" \"$TEST_DIRECTORY/chainlint.pl\" \"$0\"\n\nSo this line could have been deleted in [2] but wasn't. Let's do that\nnow.\n\n1. 7f5397a07c6 (cmake: support for testing git when building out of\n   the source tree, 2020-06-26)\n2. 23a14f30166 (test-lib: replace chainlint.sed with chainlint.pl,\n   2022-09-01)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 80290edd72a..c641e9349c9 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1106,7 +1106,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n \t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)\n \tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n \tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n \tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468412","messageId":"patch-v5-05.15-435452314fa-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 05/15] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:26Z","receivedAt":"2022-12-02T11:29:09Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since the cmake file was made to run on *nix in [1] running the tests\nwith \"ctest\" broken, because we'd attempt to invoke our bin-wrappers/,\nbut they didn't have the executable bit.\n\nIn the best case, the \"t/test-lib.sh\" would be unable to find\n\"bin-wrappers/git\", and we'd fall back on\n\"GIT_EXEC_PATH=$GIT_BUILD_DIR\" using the fallback behavior added in\n[2]:\n\n\t$ ./t0001-init.sh\n\t<GIT_BUILD_DIR>/t/../contrib/buildsystems/out/bin-wrappers/git is not executable; using GIT_EXEC_PATH\n\nThis was recently somewhat swept under the rug in [3], as ctest would\nrun them with \"--no-bin-wrappers\". But still with [3], running e.g.:\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Debug &&\n\tmake -C contrib/buildsystems/out &&\n\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\" --output-on-failure\n\nFails around 20% of our tests on *nix. So even with [3] we'd fail any\ntest that needed to invoke one of our built shell, perl or Python\nscripts on *nix. E.g. t0012-help.sh would fail on a test that tried to\ninvoke \"git web--browse\". The equivalent of this (in the \"out\"\ndirectory) would happen:\n\n\t$ ./git --exec-path=$PWD web--browse\n\tgit: 'web--browse' is not a git command. See 'git --help'.\n\nWhich we can fix by \"chmod +x\"-ing the built \"git-web--browse\":\n\n\t$ chmod +x git-web--browse\n\t$ ./git --exec-path=$PWD web--browse\n\tusage: git web--browse [--browser=browser|--tool=browser] [--config=conf.var] url/file ...\n\nThe same goes for e.g. the \"git-p4\" tests, which would fail because\nour built \"git-p4\" wasn't executable, etc. There's also a few other\noutstanding issues, which will be fixed in subsequent commits.\n\nIdeally we'd use the file(CHMOD ...) form everywhere, but that syntax\nwas introduced in cmake 3.19[4], whereas we only require 3.14. Let's\nprovide a fallback behind a version check, so that we'll eventually be\nable to delete the \"else\" part. Both forms result in the same file\nmodes.\n\nBefore this change:\n\n\t80% tests passed, 196 tests failed out of 977\n\nAfter:\n\n\t99% tests passed, 5 tests failed out of 977\n\nThe remaining failures will be addressed in subsequent commits.\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n3. 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n   runs, 2022-10-18)\n4. https://cmake.org/cmake/help/latest/command/file.html#chmod\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n\nwrite script\n---\n contrib/buildsystems/CMakeLists.txt | 25 +++++++++++++++++++------\n 1 file changed, 19 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex c641e9349c9..2248b755b3b 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -840,6 +840,19 @@ add_custom_command(OUTPUT ${git_links} ${git_http_links}\n \t\tDEPENDS git git-remote-http)\n add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links})\n \n+function(write_script path content)\n+\tfile(WRITE ${path} ${content})\n+\n+\tif(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" VERSION_GREATER_EQUAL \"3.19\")\n+\t\tfile(CHMOD ${path} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)\n+\telse()\n+\t\texecute_process(COMMAND chmod +x ${path}\n+\t\t\t\tRESULT_VARIABLE CHILD_ERROR)\n+\t\tif(CHILD_ERROR)\n+\t\t\tmessage(FATAL_ERROR \"failed to chmod +x '${path}': '${CHILD_ERROR}'\")\n+\t\tendif()\n+\tendif()\n+endfunction()\n \n #creating required scripts\n set(SHELL_PATH /bin/sh)\n@@ -865,7 +878,7 @@ foreach(script ${git_shell_scripts})\n \tstring(REPLACE \"# @@BROKEN_PATH_FIX@@\" \"\" content \"${content}\")\n \tstring(REPLACE \"@@PERL@@\" \"${PERL_PATH}\" content \"${content}\")\n \tstring(REPLACE \"@@PAGER_ENV@@\" \"LESS=FRX LV=-c\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n endforeach()\n \n #perl scripts\n@@ -880,13 +893,13 @@ foreach(script ${git_perl_scripts})\n \tfile(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME)\n \tstring(REPLACE \"#!/usr/bin/perl\" \"#!/usr/bin/perl\\n${perl_header}\\n\" content \"${content}\")\n \tstring(REPLACE \"@@GIT_VERSION@@\" \"${PROJECT_VERSION}\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n endforeach()\n \n #python script\n file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n-file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n+write_script(${CMAKE_BINARY_DIR}/git-p4 \"${content}\")\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n@@ -1024,20 +1037,20 @@ foreach(script ${wrapper_scripts})\n \tfile(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"${script}${EXE_EXTENSION}\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/bin-wrappers/${script} \"${content}\")\n endforeach()\n \n foreach(script ${wrapper_test_scripts})\n \tfile(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"t/helper/${script}${EXE_EXTENSION}\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/bin-wrappers/${script} \"${content}\")\n endforeach()\n \n file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n string(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n string(REPLACE \"@@PROG@@\" \"git-cvsserver\" content \"${content}\")\n-file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})\n+write_script(${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver \"${content}\")\n \n #options for configuring test options\n option(PERL_TESTS \"Perform tests that use perl\" ON)\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468413","messageId":"patch-v5-07.15-49645cb1643-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 07/15] cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:28Z","receivedAt":"2022-12-02T11:29:12Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When we build with libpcre2 which cmake has supported since [1] we\nneed to set \"USE_LIBPCRE2='YesPlease'\" (or similar) in\n\"GIT-BUILD-OPTIONS\".\n\nWithout this e.g. t7810-grep.sh will fail, as it has tests that rely\non the behavior of !PCRE2. The reason this hasn't been noticed is that\nthe Windows CI doesn't have access to libpcre2.\n\nWith this the remaining two failures we had left after the preceding\nstep are resolved, but note that that test run didn't include the\ngit-p4 tests, which a subsequent commit will address).\n\n1. 80431510a2b (cmake: add pcre2 support, 2022-05-24)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 73b060a0385..5b3fb93120d 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1099,6 +1099,9 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PYTHON_PATH='${PYTHON_PATH}'\\\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"TAR='${TAR}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_CURL='${NO_CURL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_EXPAT='${NO_EXPAT}'\\n\")\n+if(PCRE2_FOUND)\n+\tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"USE_LIBPCRE2='YesPlease'\\n\")\n+endif()\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PERL='${NO_PERL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PTHREADS='${NO_PTHREADS}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\\n\")\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468414","messageId":"patch-v5-06.15-7ee341245a8-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 06/15] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:27Z","receivedAt":"2022-12-02T11:29:13Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When git is built and tested with cmake & ctest we usually do that\noutside of the top-level source directory. E.g.\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out\n\tmake -C contrib/buildsystems/out\n\tctest -j$(nproc) --test-dir contrib/buildsystems/out\n\nSince the test-lib.sh makes assumptions about the TEST_DIRECTORY being\nthe \"t\" subdirectory of the top-level \"$GIT_BUILD_DIR\", the cmake\nrecipe has needed to copy various assets to that\n\"contrib/buildsystems/out\" directory.\n\nBut we've only been doing this for the subsets of tests that run on\nWindows, and which have otherwise been covered by that CI target. The\nCI target builds (among other things) with \"-DPERL_TESTS=OFF\n-DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON\", see [1]. Furthermore, the\nCI isn't testing from the \"contrib/buildsystems/out\" directory,\ninstead it clobbers the top-level MAkefile.\n\nThere was a recent commit to fix a subset of these issues, see\n6a83b5f0810 (cmake: copy the merge tools for testing, 2022-10-18).\n\nLet's stop going for that approach, and instead teach the test-lib.sh\nthat there's such a thing as the \"$GIT_SOURCE_DIR\" distinct from the\n\"$GIT_BUILD_DIR\".\n\nJust as the \"$TEST_DIRECTORY\" always points to our actual \"t\"\ndirectory (not the \"[...]/out/t\" cmake creates), this new\n\"$GIT_SOURCE_DIR\" will always be the top-level source directory.\n\nWith this change we now pass 3/5 of the tests that we still had\nfailing with the fixes in the preceding commit.\n\n1. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt |  6 ------\n t/lib-gettext.sh                    |  2 +-\n t/lib-gitweb.sh                     |  2 +-\n t/t7609-mergetool--lib.sh           |  2 +-\n t/t9902-completion.sh               | 14 +++++++-------\n t/t9903-bash-prompt.sh              |  2 +-\n t/test-lib.sh                       |  8 +++++++-\n 7 files changed, 18 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 2248b755b3b..73b060a0385 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1118,12 +1118,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \t#Setting the build directory in test-lib.sh before running tests\n \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n-\t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n-\tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n-\tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\ndiff --git a/t/lib-gettext.sh b/t/lib-gettext.sh\nindex cc6bb2cdeaa..dcd6e9c3f75 100644\n--- a/t/lib-gettext.sh\n+++ b/t/lib-gettext.sh\n@@ -7,7 +7,7 @@\n . ./test-lib.sh\n \n GIT_TEXTDOMAINDIR=\"$GIT_BUILD_DIR/po/build/locale\"\n-GIT_PO_PATH=\"$GIT_BUILD_DIR/po\"\n+GIT_PO_PATH=\"$GIT_SOURCE_DIR/po\"\n export GIT_TEXTDOMAINDIR GIT_PO_PATH\n \n if test -n \"$GIT_TEST_INSTALLED\"\ndiff --git a/t/lib-gitweb.sh b/t/lib-gitweb.sh\nindex 1f32ca66ea5..6f68df247af 100644\n--- a/t/lib-gitweb.sh\n+++ b/t/lib-gitweb.sh\n@@ -49,7 +49,7 @@ EOF\n \t\terror \"Cannot find gitweb at $GITWEB_TEST_INSTALLED.\"\n \t\tsay \"# Testing $SCRIPT_NAME\"\n \telse # normal case, use source version of gitweb\n-\t\tSCRIPT_NAME=\"$GIT_BUILD_DIR/gitweb/gitweb.perl\"\n+\t\tSCRIPT_NAME=\"$GIT_SOURCE_DIR/gitweb/gitweb.perl\"\n \tfi\n \texport SCRIPT_NAME\n }\ndiff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh\nindex 8b1c3bd39f2..2090d12a489 100755\n--- a/t/t7609-mergetool--lib.sh\n+++ b/t/t7609-mergetool--lib.sh\n@@ -8,7 +8,7 @@ TEST_PASSES_SANITIZE_LEAK=true\n . ./test-lib.sh\n \n test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '\n-\t. \"$GIT_BUILD_DIR\"/mergetools/vimdiff &&\n+\t. \"$GIT_SOURCE_DIR\"/mergetools/vimdiff &&\n \trun_unit_tests\n '\n \ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 43de868b800..1bd4cae92fe 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -33,7 +33,7 @@ complete ()\n GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'\n GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\"\n \n # We don't need this function to actually join words or do anything special.\n # Also, it's cleaner to avoid touching bash's internal completion variables.\n@@ -2567,7 +2567,7 @@ test_expect_success 'sourcing the completion script clears cached commands' '\n \t(\n \t\t__git_compute_all_commands &&\n \t\tverbose test -n \"$__git_all_commands\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_all_commands\"\n \t)\n '\n@@ -2576,7 +2576,7 @@ test_expect_success 'sourcing the completion script clears cached merge strategi\n \t(\n \t\t__git_compute_merge_strategies &&\n \t\tverbose test -n \"$__git_merge_strategies\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_merge_strategies\"\n \t)\n '\n@@ -2587,7 +2587,7 @@ test_expect_success 'sourcing the completion script clears cached --options' '\n \t\tverbose test -n \"$__gitcomp_builtin_checkout\" &&\n \t\t__gitcomp_builtin notes_edit &&\n \t\tverbose test -n \"$__gitcomp_builtin_notes_edit\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_checkout\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_notes_edit\"\n \t)\n@@ -2599,7 +2599,7 @@ test_expect_success 'option aliases are not shown by default' '\n \n test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&\n \t\ttest_completion \"git clone --recurs\" <<-\\EOF\n \t\t--recurse-submodules Z\n@@ -2610,7 +2610,7 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \n test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n \n \t\t# Just mainporcelain, not plumbing commands\n@@ -2622,7 +2622,7 @@ test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_\n \n test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n \t\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex d459fae6551..06f0abfc294 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -10,7 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./lib-bash.sh\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-prompt.sh\"\n \n actual=\"$TRASH_DIRECTORY/actual\"\n c_red='\\\\[\\\\e[31m\\\\]'\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 6db377f68b8..36358811a0f 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -47,6 +47,10 @@ then\n \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n \texit 1\n fi\n+\n+# For CMake the top-level source directory is different from our build\n+# directory. With the top-level Makefile they're the same.\n+GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n@@ -1447,7 +1451,7 @@ then\n \t\tmake_valgrind_symlink $file\n \tdone\n \t# special-case the mergetools loadables\n-\tmake_symlink \"$GIT_BUILD_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n+\tmake_symlink \"$GIT_SOURCE_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n \tOLDIFS=$IFS\n \tIFS=:\n \tfor path in $PATH\n@@ -1500,6 +1504,8 @@ GIT_CONFIG_NOSYSTEM=1\n GIT_ATTR_NOSYSTEM=1\n GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\"\n export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES\n+MERGE_TOOLS_DIR=\"$GIT_SOURCE_DIR/mergetools\"\n+export MERGE_TOOLS_DIR\n \n if test -z \"$GIT_TEST_CMP\"\n then\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468415","messageId":"patch-v5-08.15-9e10cd5bd8a-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 08/15] Makefile + test-lib.sh: don't prefer cmake-built to make-built git","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:29Z","receivedAt":"2022-12-02T11:29:29Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Per ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18) and\nthe surrounding discussion the goal of that change was to have\nbuilding with cmake and:\n\n\t(cd t && ./t0001-init.sh)\n\nWork, to do so we need some way to make the test-lib.sh aware that we\nhave a build in contrib/buildsystems/out. The downside of doing it via\nthe GIT-BUILD-DIR facility in ee9e66e4e76 is:\n\n- A \"remove this file while at it\" only fits into the Makefile\n  dependency graph if we \"FORCE\" a shell command to be run, so doing it\n  this way precludes speeding up the Makefile by e.g. making use of the\n  \"$(file)\" function (for which I've got follow-up patches).\n\n- If you build with make, then with cmake, and then e.g.:\n\n\tmake -C t prove\n\n  We'll run the tests against the cmake version of the tests, not the\n  \"make\" built ones. It's important to get any subtle interaction\n  between two conflicting build systems right.\n\nNow we'll instead check if the top-level \"git\" exists, and only if it\ndoesn't look for the one built by cmake. This ensures that we'll pick\nit up as required when the user is using CMake, without being subject\nto the odd interaction of flip-flopping between the two\nenvironments.\n\nIt also means that we can remove the rule to remove the\n\"GIT-BUILD-DIR\", if we get to creating \"GIT-BUILD-OPTIONS\" in the\ntop-level git. That's because now when building with both \"make\" and\n\"cmake\" we will always prefer the former for running the tests, so\nthere's no need to remove the \"GIT-BUILD-DIR\" file to resolve the\nconflicts between the two.\n\nIn practice users are building with either \"make\" or \"cmake\", and not\nmixing the two, but in a subsequent change we'll provide an out for\nthat \"make\"-preferring selection behavior, by having \"ctest\" runs\nalways prefer the \"cmake\" built one.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Makefile      | 1 -\n t/test-lib.sh | 3 ++-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex b258fdbed86..c602ce57e64 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -3150,7 +3150,6 @@ else\n \t@echo RUNTIME_PREFIX=\\'false\\' >>$@+\n endif\n \t@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi\n-\t@if test -f GIT-BUILD-DIR; then rm GIT-BUILD-DIR; fi\n \n ### Detect Python interpreter path changes\n ifndef NO_PYTHON\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 36358811a0f..c7d55ff0796 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -51,7 +51,8 @@ fi\n # For CMake the top-level source directory is different from our build\n # directory. With the top-level Makefile they're the same.\n GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n-if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n+if test ! -x \"$GIT_BUILD_DIR/git\" &&\n+\ttest -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n \t# On Windows, we must convert Windows paths lest they contain a colon\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468416","messageId":"patch-v5-09.15-df5aea35bbd-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 09/15] test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:30Z","receivedAt":"2022-12-02T11:29:33Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Compliment the existing GIT_TEST_INSTALLED variable added in [1] with\none that allows for testing a git built in a directory that's not\n\"../\".\n\nInstead of \"test this installed git\" (\"GIT_TEST_INSTALLED\"), this new\n\"GIT_TEST_BUILD_DIR\" is a \"test this built directory over\nthere\". E.g. this will pass all tests:\n\n\tgit clone --depth=1 https://github.com/git/git.git git1\n\tcp -R git1 git2\n\tmake -C git1\n\t[apply this change to git2]\n\t(cd git2 && GIT_TEST_BUILD_DIR=\"$PWD/../git1\" make -C t prove)\n\nThis facility and file-based instructions to have the test suite use\nanother build directory[2] are mutually exclusive. In a subsequent\ncommit we'll make CMake and CTest optionally prefer this method.\n\n1. 6720721e152 (test-lib.sh: Allow running the test suite against\n   installed git, 2009-03-16)\n2. 350a005e366 (cmake: avoid editing t/test-lib.sh, 2022-10-18)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/README      | 3 +++\n t/test-lib.sh | 7 +++++++\n 2 files changed, 10 insertions(+)\n\ndiff --git a/t/README b/t/README\nindex 979b2d4833d..fc0daef2e41 100644\n--- a/t/README\n+++ b/t/README\n@@ -231,6 +231,9 @@ override the location of the dashed-form subcommands (what\n GIT_EXEC_PATH would be used for during normal operation).\n GIT_TEST_EXEC_PATH defaults to `$GIT_TEST_INSTALLED/git --exec-path`.\n \n+Similar to GIT_TEST_INSTALLED, GIT_TEST_BUILD_DIR can be pointed to\n+another git.git checkout's build directory, to test its built binaries\n+against the tests in this checkout.\n \n Skipping Tests\n --------------\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex c7d55ff0796..a1b5c7c6ce1 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -55,6 +55,13 @@ if test ! -x \"$GIT_BUILD_DIR/git\" &&\n \ttest -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n+elif test -n \"$GIT_TEST_BUILD_DIR\"\n+then\n+\tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n+fi\n+\n+if test \"$GIT_SOURCE_DIR\" != \"$GIT_BUILD_DIR\"\n+then\n \t# On Windows, we must convert Windows paths lest they contain a colon\n \tcase \"$(uname -s)\" in\n \t*MINGW*)\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468417","messageId":"patch-v5-10.15-529e18f7f72-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 10/15] cmake: optionally be able to run tests before \"ctest\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:31Z","receivedAt":"2022-12-02T11:29:48Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] the \"cmake\" build has had support for running the tests\nmanually from the \"t/\" directory once we've built with \"cmake\", but\nonly after a one-off run of \"ctest\".\n\nI.e. we create the build recipe via \"cmake\" and build with\ne.g. \"make\", but after doing so would get:\n\n\t$ (cd t && ./t0071-sort.sh)\n\terror: GIT-BUILD-OPTIONS missing (has Git been built?).\n\nThe recently added amendment to this of using a \"GIT-BUILD-DIR\"[2]\ndidn't change these semantics. After we did a one-off run of \"ctest\"\nwe'd be able to run the tests without \"ctest\":\n\n\t$ ctest --test-dir contrib/buildsystems/out -R t0071\n\t[...]\n\t100% tests passed, 0 tests failed out of 1\n\t[...]\n\t$ (cd t && ./t0071-sort.sh)\n\tok 1 - DEFINE_LIST_SORT_DEBUG\n\t# passed all 1 test(s)\n\t1..1\n\nThis change optionally closes that gap, and allows for more sensible\nbehavior. Due to concerns about existing MS Visual Studio users\nrelying on some of these edge cases this is being made optional, with\nthe default of the new \"GIT_CTEST_SETS_BUILD_DIR\" being \"ON\" on\nWindows (i.e. the old behavior), and \"OFF\" elsewhere.\n\nThe resulting behavior differences are the following:\n\n\t|---+----+-----|\n\t|   | ON | OFF |\n\t|---+----+-----|\n\t| A | N  | Y   |\n\t| B | N  | Y   |\n\t| C | Y  | Y   |\n\t| D | Y  | N   |\n\t| E | N  | Y   |\n\t|---+----+-----|\n\tA. Can manually run tests before ctest?\n\tB. Manually run tests point to latest cmake build?...\n\tC. Manually run tests point to latest \"ctest\"'d build?\n        D. \"git\" picked at ctest start time?\n        E. \"git\" picked at test start time?\n\nOn \"D\" and \"E\": Because GIT_CTEST_SETS_BUILD_DIR=ON relies on the\nglobal \"GIT-BUILD-DIR\" when using \"ctest\" it cannot be used to run\nconcurrent tests for two different builds from the same source\ndirectory.\n\nBut as noted in [3] existing users using Visual Studio may be relying\non some of these edge cases, so let's make this optional on Windows,\nbut switch the default to this new discover method on other platforms.\n\n1. 7f5397a07c6 (cmake: support for testing git when building out of\n   the source tree, 2020-06-26)\n2. ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18)\n3. https://lore.kernel.org/git/663b93ef-0c89-a5f6-1069-b4be97915d20@dunelm.org.uk/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 38 ++++++++++++++++++++++++-----\n t/test-lib.sh                       |  3 ++-\n 2 files changed, 34 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 5b3fb93120d..866bdc1914a 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1115,12 +1115,33 @@ if(USE_VCPKG)\n \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n endif()\n \n-#Make the tests work when building out of the source tree\n-get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n-if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n-\t#Setting the build directory in test-lib.sh before running tests\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n-\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n+set(GIT_CTEST_SETS_BUILD_DIR_DOC \"find cmake build dir via ctest-set GIT-BUILD-DIR?\")\n+if(DEFINED ENV{GIT_CTEST_SETS_BUILD_DIR})\n+\tset(GIT_CTEST_SETS_BUILD_DIR \"$ENV{GIT_CTEST_SETS_BUILD_DIR}\"\n+\t\tCACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n+elseif(WIN32)\n+\tset(GIT_CTEST_SETS_BUILD_DIR \"ON\" CACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n+else()\n+\tset(GIT_CTEST_SETS_BUILD_DIR \"OFF\" CACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n+endif()\n+if(GIT_CTEST_SETS_BUILD_DIR)\n+\tmessage(STATUS \"Enabling manual runs of t/* tests once ctest writes CMAKE-BUILD-DIR\")\n+else()\n+\tmessage(STATUS \"Enabling manual runs of t/* tests via cmake build dir discovery\")\n+endif()\n+\n+# When using GIT_CTEST_SETS_BUILD_DIR, running the tests from the \"t/\"\n+# directory will only work once \"ctest\" has been run, as we write to\n+# \"GIT-BUILD-DIR\" from the optional \"ctest\" invocation following the\n+# \"cmake\"\n+if(GIT_CTEST_SETS_BUILD_DIR)\n+\tget_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n+\tif(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n+\t\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n+\t\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n+\tendif()\n+else()\n+\tfile(WRITE \"${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR\" \"${CMAKE_BINARY_DIR}\")\n endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n@@ -1130,6 +1151,11 @@ foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n \t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n+if(NOT GIT_CTEST_SETS_BUILD_DIR)\n+\tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n+\t\tGIT_TEST_PREFER_BUILD_DIR_ENV=\"Yes, ignore GIT-BUILD-DIR\"\n+\t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n+endif()\n endforeach()\n \n # This test script takes an extremely long time and is known to time out even\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex a1b5c7c6ce1..36a9a32db05 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -51,7 +51,8 @@ fi\n # For CMake the top-level source directory is different from our build\n # directory. With the top-level Makefile they're the same.\n GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n-if test ! -x \"$GIT_BUILD_DIR/git\" &&\n+if test -z \"$GIT_TEST_PREFER_BUILD_DIR_ENV\" &&\n+\ttest ! -x \"$GIT_BUILD_DIR/git\" &&\n \ttest -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468418","messageId":"patch-v5-11.15-a5dd4fa1d00-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 11/15] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:32Z","receivedAt":"2022-12-02T11:29:49Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The rationale for adding \"--no-bin-wrappers\" and \"--no-chain-lint\" in\n2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\nruns, 2022-10-18) was those options slowed down the tests considerably\non Windows.\n\nBut since f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\nand with the preceding commits cmake and ctest are not\nWindows-specific anymore.\n\nSo let's set those same options by default on Windows, but do so with\nthe set(... CACHE <type> <docstring>) facility. As noted in cmake's\ndocumentation[1] this integrates nicely with e.g. cmake-gui.\n\nOn *nix we don't set any custom options. The change in 2ea1d8b5563\ndidn't discuss why Windows should have divergent defaults with \"cmake\"\nand \"make\", but such reasons presumably don't apply on *nix. I for one\nam happy with the same defaults as the tests have when running via the\nMakefile.\n\nWith the \"message()\" addition we'll emit this when running cmake:\n\n\tGenerating hook-list.h\n\t-- Using user-selected test options: -vixd\n\t-- Configuring done\n\t-- Generating done\n\t-- Build files have been written to: /home/avar/g/git/contrib/buildsystems/out\n\nUnfortunately cmake doesn't support a non-hacky way to pass variables\nto ctest without re-running cmake itself, so when re-running tests via\ncmake and wanting to change the test defaults we'll need:\n\n\tGIT_TEST_OPTS=-i cmake -S contrib/buildsystems -B contrib/buildsystems/out &&\n\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out -R t0071 --verbose\n\nThe \"separate_arguments()\" here will do the right thing for arguments\nthat don't contain whitespace, so e.g. the path to --root=\"\" can't\nhave a space in it. There's supposedly a way to work around that with\nseparate_arguments(), but it requires features newer than our required\ncmake version, so let's live with that edge case for now.\n\n1. https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 50 +++++++++++++++++++++++++++--\n 1 file changed, 48 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 866bdc1914a..cfe8126d939 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -32,7 +32,7 @@ To use this in Visual Studio:\n \n Open the worktree as a folder. Visual Studio 2019 and later will detect\n the CMake configuration automatically and set everything up for you,\n-ready to build. You can then run the tests in `t/` via a regular Git Bash.\n+ready to build. See \"== Running the tests ==\" below for running the tests.\n \n Note: Visual Studio also has the option of opening `CMakeLists.txt`\n directly; Using this option, Visual Studio will not find the source code,\n@@ -76,6 +76,37 @@ empty(default) :\n \n NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n this option is ignored\n+\n+== Running the tests ==\n+\n+Once we've built in \"contrib/buildsystems/out\" the tests can be run at\n+the top-level (note: not the generated \"contrib/buildsystems/out/t/\"\n+drectory). If no top-level build is found (as created with the\n+Makefile) the t/test-lib.sh will discover the git in\n+\"contrib/buildsystems/out\" on e.g.:\n+\n+\t(cd t && ./t0001-init.sh)\n+\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n+\t[...]\n+\n+The tests can also be run with ctest, e.g. after building with \"cmake\"\n+and \"make\" or \"msbuild\" run, from the top-level e.g.:\n+\n+\t# \"--test-dir\" is new in cmake v3.20, so \"(cd\n+\t# contrib/buildsystems/out && ctest ...)\" on older versions.\n+\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\"--output-on-failure\n+\n+Options can be passed by setting GIT_TEST_OPTIONS before invoking\n+cmake. E.g. on a Linux system with systemd the tests can be sped up by\n+using a ramdisk for the scratch files:\n+\n+\tGIT_TEST_OPTS=\"--root=/dev/shm/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n+\t[...]\n+\t-- Using user-selected test options: --root=/dev/shm/<uid>/ctest\n+\n+Then running the tests with \"ctest\" (here with --jobs=\"$(nproc)\"):\n+\n+\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out\n ]]\n cmake_minimum_required(VERSION 3.14)\n \n@@ -1146,10 +1177,25 @@ endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n \n+if(DEFINED ENV{GIT_TEST_OPTS})\n+\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\"\n+\t\tCACHE STRING \"test options, see t/README\")\n+\tmessage(STATUS \"Using user-selected test options: ${GIT_TEST_OPTS}\")\n+elseif(WIN32)\n+\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\"\n+\t\tCACHE STRING \"test options, see t/README\")\n+\tmessage(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n+else()\n+\tset(GIT_TEST_OPTS \"\"\n+\t\tCACHE STRING \"test options, see t/README\")\n+\tmessage(STATUS \"No custom test options selected, set e.g. GIT_TEST_OPTS=\\\"-vixd\\\"\")\n+endif()\n+separate_arguments(GIT_TEST_OPTS)\n+\n #test\n foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n-\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n+\t\tCOMMAND ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n if(NOT GIT_CTEST_SETS_BUILD_DIR)\n \tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468419","messageId":"patch-v5-12.15-c9d550b8558-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 12/15] cmake: increase test timeout on Windows only","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:33Z","receivedAt":"2022-12-02T11:29:53Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Per c858750b41c (cmake: increase time-out for a long-running test,\n2022-10-18) the reason to set a custom timeout for\nt7112-reset-submodule.sh is Windows-specific. Let's only do that on\nWindows then.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex cfe8126d939..712caffe8f1 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1204,8 +1204,10 @@ if(NOT GIT_CTEST_SETS_BUILD_DIR)\n endif()\n endforeach()\n \n-# This test script takes an extremely long time and is known to time out even\n-# on fast machines because it requires in excess of one hour to run\n-set_tests_properties(\"${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh\" PROPERTIES TIMEOUT 4000)\n+if(WIN32)\n+\t# This test script takes an extremely long time and is known to time out even\n+\t# on fast machines because it requires in excess of one hour to run\n+\tset_tests_properties(\"${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh\" PROPERTIES TIMEOUT 4000)\n+endif()\n \n endif()#BUILD_TESTING\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468420","messageId":"patch-v5-13.15-7a5dd684d40-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 13/15] cmake: only look for \"sh\" in \"C:/Program Files\" on Windows","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:34Z","receivedAt":"2022-12-02T11:29:55Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Guard the finding of \"SH_EXE\" in \"C:\\Program Files\" with a check for\nwhether we're on Windows.\n\nThis Windows-specific code was first added in [1], and later expanded\non [2], but since some of that was added this build recipe has been\nmade portable outside of Windows.\n\n1. 72b6eeb81b1 (cmake: do find Git for Windows' shell interpreter,\n   2020-09-28)\n2. 476e54b1c60 (cmake: support local installations of git,\n   2022-07-27).\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 15 +++++++++++----\n 1 file changed, 11 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 712caffe8f1..da47d9c8397 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -138,10 +138,17 @@ if(USE_VCPKG)\n \tset(CMAKE_TOOLCHAIN_FILE ${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake CACHE STRING \"Vcpkg toolchain file\")\n endif()\n \n-find_program(SH_EXE sh PATHS \"C:/Program Files/Git/bin\" \"$ENV{LOCALAPPDATA}/Programs/Git/bin\")\n-if(NOT SH_EXE)\n-\tmessage(FATAL_ERROR \"sh: shell interpreter was not found in your path, please install one.\"\n-\t\t\t\"On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/\")\n+if(WIN32)\n+\tfind_program(SH_EXE sh PATHS \"C:/Program Files/Git/bin\" \"$ENV{LOCALAPPDATA}/Programs/Git/bin\")\n+\tif(NOT SH_EXE)\n+\t\tmessage(FATAL_ERROR \"sh: shell interpreter was not found in your path, please install one.\"\n+\t\t\t\t\"You can get it as part of 'Git for Windows' install at https://gitforwindows.org/\")\n+\tendif()\n+else()\n+\tfind_program(SH_EXE sh)\n+\tif(NOT SH_EXE)\n+\t\tmessage(FATAL_ERROR \"cannot find 'sh' in '$PATH'\")\n+\tendif()\n endif()\n \n #Create GIT-VERSION-FILE using GIT-VERSION-GEN\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468421","messageId":"patch-v5-14.15-c9c895bb794-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 14/15] cmake: copy over git-p4.py for t983[56] perforce test","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:35Z","receivedAt":"2022-12-02T11:29:59Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] two git-p4 tests have relied on there being a \"git-p4.py\" in\nthe build directory, but the cmake recipe was not updated to account\nfor this. Let's copy the \"git-p4.py\" over.\n\nWe could also change the test to e.g. grab the built \"git-p4\" and\nalter its shebang, which would be friendly to GIT_TEST_INSTALLED, but\nlet's just do the bare minimum here to get cmake+ctest working without\naltering the test itself.\n\nThe reason this hasn't been caught by \"vs-build\" and \"vs-test\" is\nbecause those tests added in [2] invoke \"cmake\" with\n\"-DPYTHON_TESTS=OFF\", and therefore we'd skip this part of the git-p4\ntests before getting past the \"do we have python?\" check. Even if we\ngot past that the Windows CI wouldn't have a \"p4\" or \"p4d\" binary\ninstalled, so we'd skip the tests anyway.\n\nIn a subsequent commit we'll run \"cmake\" and \"ctest\" in CI with\n\"ubuntu-latest\", so we'll need this \"git-p4.py\" file.\n\n1. f7b5ff607fa (git-p4: improve encoding handling to support\n   inconsistent encodings, 2022-04-30)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex da47d9c8397..d989e534377 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -938,6 +938,7 @@ endforeach()\n file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n write_script(${CMAKE_BINARY_DIR}/git-p4 \"${content}\")\n+file(COPY ${CMAKE_SOURCE_DIR}/git-p4.py DESTINATION ${CMAKE_BINARY_DIR}/)\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468422","messageId":"patch-v5-15.15-a6f343b6221-20221202T110947Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v5 15/15] CI: add a \"linux-cmake-test\" to run cmake & ctest on linux","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-02T11:28:36Z","receivedAt":"2022-12-02T11:30:00Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] the \"cmake\" build method should work properly on Linux, but\nas seen in preceding commits there were various bugs in it, which are\nhopefully now all fixed.\n\nTo ensure that it doesn't break again let's add a \"linux-cmake-ctest\"\ntarget to build and test \"cmake\" on Linux, in addition to that we'll\nalso run the tests with \"ctest\" instead of \"make\" or \"prove\", so we\ncan assert that testing with that method works..\n\nThis also stress tests running \"cmake\" (and \"ctest\") out of a build\ndirectory that isn't the top-level. The \"vs-build\" job uses \"cmake\"\nsince [2], but clobbers the top-level \"Makefile\" and builds in the\ntop-level directory.\n\nThat was the reason for why we didn't spot that various tests still\nrequired missing \"mergetools/*\" etc, which was fixed by using\n\"$GIT_SOURCE_DIR\" in a preceding commit.\n\nSince the \"ci/lib.sh\" already creates and exports a\nGIT_TEST_OPTS=\"...\" we'll pick that up in our CI, see the preceding\ncommit. Because we pass the \"--verbose-log -x\n--github-workflow-markup\" in the GitHub CI as a result the interaction\nwith \"handle_failed_tests\" here works correctly. I.e. on failure we'll\nhave saved \"t/test-results/*.{exit,out,markup}\" files relevant to the\nfailing test(s).\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .github/workflows/main.yml |  3 +++\n ci/run-build-and-tests.sh  | 13 +++++++++++--\n 2 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/.github/workflows/main.yml b/.github/workflows/main.yml\nindex 9afacfa0b33..3657ba66c5e 100644\n--- a/.github/workflows/main.yml\n+++ b/.github/workflows/main.yml\n@@ -236,6 +236,9 @@ jobs:\n             cc: gcc\n             cc_package: gcc-8\n             pool: ubuntu-20.04\n+          - jobname: linux-cmake-ctest\n+            cc: gcc\n+            pool: ubuntu-latest\n           - jobname: osx-clang\n             cc: clang\n             pool: macos-latest\ndiff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh\nindex 8ebff425967..a3ae5ff3972 100755\n--- a/ci/run-build-and-tests.sh\n+++ b/ci/run-build-and-tests.sh\n@@ -45,10 +45,19 @@ pedantic)\n \t;;\n esac\n \n-group Build make\n+mc=\n+if test \"$jobname\" = \"linux-cmake-ctest\"\n+then\n+\tcb=contrib/buildsystems\n+\tgroup CMake cmake -S \"$cb\" -B \"$cb/out\"\n+\tmc=\"-C $cb/out\"\n+fi\n+\n+group Build make $mc\n+\n if test -n \"$run_tests\"\n then\n-\tgroup \"Run tests\" make test ||\n+\tgroup \"Run tests\" make $mc test ||\n \thandle_failed_tests\n fi\n check_unignored_build_artifacts\n-- \n2.39.0.rc1.981.gf846af54b4b\n\n"},{"id":"468481","messageId":"CAPig+cQRFtFWesYgaBfeqbP4Nax+-335W9at6uPgvCdtX_CPSQ@mail.gmail.com","threadId":"58666","inReplyTo":"patch-v5-02.15-314c5e40cff-20221202T110947Z-avarab@gmail.com","subject":"Re: [PATCH v5 02/15] cmake: use \"-S\" and \"-B\" to specify source and build directories","fromName":"Eric Sunshine","fromEmail":"ericsunshine@gmail.com","sentAt":"2022-12-03T05:14:59Z","receivedAt":"2022-12-03T05:15:15Z","isPatch":true,"sender":{"key":"ericsunshine@gmail.com","avatar":null},"body":"On Fri, Dec 2, 2022 at 6:28 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n> Rather than the multi-line \"mkdir/cd/cmake\" recipe provide an\n> equivalent one-liner using the \"-S\" and \"-B\" options, and then suggest building with \"make -C <build-dir>\".\n>\n> The rest of these instructions discuss e.g. running tests from our\n> top-level \"t/\" directory, so it's more helpful to avoid changing the\n> user's current directory.\n>\n> The \"-S\" and \"-B\" options were added in cmake v3.13.0, which is older\n> than the version we have a hard dependency on[1].\n>\n> As an aside The \"-p\" flag to \"mkdir\" in the pre-image wasn't needed,\n> as \"contrib/buildsystems\" is tracked\n\ns/aside The/aside, the/\n\n> 1. 061c2240b1b (Introduce CMake support for configuring Git, 2020-06-12)\n>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n"},{"id":"468482","messageId":"CAPig+cTYjzEvMqMMBnaVBaZzfctxiWQXJE+CqV6kJyXbyijgdQ@mail.gmail.com","threadId":"58666","inReplyTo":"patch-v5-09.15-df5aea35bbd-20221202T110947Z-avarab@gmail.com","subject":"Re: [PATCH v5 09/15] test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"","fromName":"Eric Sunshine","fromEmail":"ericsunshine@gmail.com","sentAt":"2022-12-03T05:22:48Z","receivedAt":"2022-12-03T05:26:16Z","isPatch":true,"sender":{"key":"ericsunshine@gmail.com","avatar":null},"body":"On Fri, Dec 2, 2022 at 6:28 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n> Compliment the existing GIT_TEST_INSTALLED variable added in [1] with\n> one that allows for testing a git built in a directory that's not\n> \"../\".\n\ns/Compliment/Complement/\n\n> Instead of \"test this installed git\" (\"GIT_TEST_INSTALLED\"), this new\n> \"GIT_TEST_BUILD_DIR\" is a \"test this built directory over\n> there\". E.g. this will pass all tests:\n>\n>         git clone --depth=1 https://github.com/git/git.git git1\n>         cp -R git1 git2\n>         make -C git1\n>         [apply this change to git2]\n>         (cd git2 && GIT_TEST_BUILD_DIR=\"$PWD/../git1\" make -C t prove)\n>\n> This facility and file-based instructions to have the test suite use\n> another build directory[2] are mutually exclusive. In a subsequent\n> commit we'll make CMake and CTest optionally prefer this method.\n>\n> 1. 6720721e152 (test-lib.sh: Allow running the test suite against\n>    installed git, 2009-03-16)\n> 2. 350a005e366 (cmake: avoid editing t/test-lib.sh, 2022-10-18)\n>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n"},{"id":"468483","messageId":"CAPig+cTQu6E4-sLac_WEMJ6NMWCVDenOj1iNdfPib_WociXhXQ@mail.gmail.com","threadId":"58666","inReplyTo":"patch-v5-11.15-a5dd4fa1d00-20221202T110947Z-avarab@gmail.com","subject":"Re: [PATCH v5 11/15] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults","fromName":"Eric Sunshine","fromEmail":"ericsunshine@gmail.com","sentAt":"2022-12-03T05:38:28Z","receivedAt":"2022-12-03T05:38:43Z","isPatch":true,"sender":{"key":"ericsunshine@gmail.com","avatar":null},"body":"On Fri, Dec 2, 2022 at 6:28 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n> +       message(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n\ns/Windowns/Windows/\n"},{"id":"468484","messageId":"CAPig+cQNiidJz0dW+FwkdCVtk4uKA8d-thEz=0spKS+uSfS1fQ@mail.gmail.com","threadId":"58666","inReplyTo":"patch-v5-15.15-a6f343b6221-20221202T110947Z-avarab@gmail.com","subject":"Re: [PATCH v5 15/15] CI: add a \"linux-cmake-test\" to run cmake & ctest on linux","fromName":"Eric Sunshine","fromEmail":"ericsunshine@gmail.com","sentAt":"2022-12-03T05:47:52Z","receivedAt":"2022-12-03T05:48:09Z","isPatch":true,"sender":{"key":"ericsunshine@gmail.com","avatar":null},"body":"On Fri, Dec 2, 2022 at 6:28 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n> Since [1] the \"cmake\" build method should work properly on Linux, but\n> as seen in preceding commits there were various bugs in it, which are\n> hopefully now all fixed.\n>\n> To ensure that it doesn't break again let's add a \"linux-cmake-ctest\"\n> target to build and test \"cmake\" on Linux, in addition to that we'll\n> also run the tests with \"ctest\" instead of \"make\" or \"prove\", so we\n> can assert that testing with that method works..\n\ns/\\.\\.$/./\n\n> This also stress tests running \"cmake\" (and \"ctest\") out of a build\n> directory that isn't the top-level. The \"vs-build\" job uses \"cmake\"\n> since [2], but clobbers the top-level \"Makefile\" and builds in the\n> top-level directory.\n>\n> That was the reason for why we didn't spot that various tests still\n> required missing \"mergetools/*\" etc, which was fixed by using\n> \"$GIT_SOURCE_DIR\" in a preceding commit.\n>\n> Since the \"ci/lib.sh\" already creates and exports a\n> GIT_TEST_OPTS=\"...\" we'll pick that up in our CI, see the preceding\n\nProbably want: s/CI,/CI;/\n\n> commit. Because we pass the \"--verbose-log -x\n> --github-workflow-markup\" in the GitHub CI as a result the interaction\n> with \"handle_failed_tests\" here works correctly. I.e. on failure we'll\n> have saved \"t/test-results/*.{exit,out,markup}\" files relevant to the\n> failing test(s).\n>\n> 1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n> 2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n>    job, 2020-06-26)\n>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n"},{"id":"468491","messageId":"221203.86h6yceioj.gmgdl@evledraar.gmail.com","threadId":"58666","inReplyTo":"CAPig+cTQu6E4-sLac_WEMJ6NMWCVDenOj1iNdfPib_WociXhXQ@mail.gmail.com","subject":"Re: [PATCH v5 11/15] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-03T13:10:54Z","receivedAt":"2022-12-03T13:11:15Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sat, Dec 03 2022, Eric Sunshine wrote:\n\n> On Fri, Dec 2, 2022 at 6:28 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n>> +       message(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n>\n> s/Windowns/Windows/\n\nThanks, the rest of this is just typos, but maybe this one's a Freudian slip :)\n"},{"id":"468492","messageId":"CAPig+cQjEyr1yvufqX8gf-YS8RgEzZQbpQvSn9GuNDWAt8Z8Sw@mail.gmail.com","threadId":"58666","inReplyTo":"221203.86h6yceioj.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH v5 11/15] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults","fromName":"Eric Sunshine","fromEmail":"ericsunshine@gmail.com","sentAt":"2022-12-03T16:58:51Z","receivedAt":"2022-12-03T16:59:09Z","isPatch":true,"sender":{"key":"ericsunshine@gmail.com","avatar":null},"body":"On Sat, Dec 3, 2022 at 8:11 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n> On Sat, Dec 03 2022, Eric Sunshine wrote:\n> > On Fri, Dec 2, 2022 at 6:28 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n> >> +       message(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n> >\n> > s/Windowns/Windows/\n>\n> Thanks, the rest of this is just typos, but maybe this one's a Freudian slip :)\n\nI had the same thought and nearly said so.\n"},{"id":"468582","messageId":"patch-v6-01.15-fc190b379cd-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 01/15] cmake: don't invoke msgfmt with --statistics","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:08:59Z","receivedAt":"2022-12-06T02:09:35Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"In [1] I made the same change to our Makefile, let's follow-up and do\nthe same here.\n\nFor \"cmake\" this is particularly nice with \"-G Ninja\", as before we'd\nemit ~40 lines of overflowed progress bar output, but now it's only\nthe one line of \"ninja\"'s progress bar.\n\n1. 2f12b31b746 (Makefile: don't invoke msgfmt with --statistics,\n   2021-12-17)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 2f6e0197ffa..8f8b6f375f7 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -897,7 +897,7 @@ if(MSGFMT_EXE)\n \tforeach(po ${po_files})\n \t\tfile(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES)\n \t\tadd_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo\n-\t\t\t\tCOMMAND ${MSGFMT_EXE} --check --statistics -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po)\n+\t\t\t\tCOMMAND ${MSGFMT_EXE} --check -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po)\n \t\tlist(APPEND po_gen ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo)\n \tendforeach()\n \tadd_custom_target(po-gen ALL DEPENDS ${po_gen})\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468583","messageId":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com","subject":"[PATCH v6 00/15] cmake: document, fix on *nix, add CI","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:08:58Z","receivedAt":"2022-12-06T02:09:37Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This topic gets our tests from passing ~80% with ctest on *nix to\npassing 100%.\n\nSee passing CI job for \"cmake + ctest\" on Ubuntu at:\nhttps://github.com/avar/git/actions/runs/3625189647\n\nSee\nhttps://lore.kernel.org/git/cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com/\nfor the v5.\n\nChanges since v5:\n\n* Typo/grammar etc. fixes noted by Eric.\n* Phillip reported the \"chmod\" fallback no working on Windows. I\n  couldn't reproduce that, but running it was always redundant there\n  we'll now skip doing that on Windows.\n* Adjust 15/15 to fold into an existing \"case\" statement, rather than\n  adding a new \"if\" statement.\n\nFor this v6 I experimented with changing the \"win+VS build|test\" job\nbuild in \"contrib/buildsystems/out\" rather than at the top-level[1]. I\nleft those changes out here, but doing so makes that a lot simpler, as\nit no longer needs to rely on the Makefile to tell it what cmake might\nhave built.\n\nBut even without including that here, those changes should give more\nconfidence in these changes, i.e. they show that our CI's \"msbuild\"\ndoesn't require the \"cmake\" to build things at the top-level.\n\n1. https://github.com/avar/git/tree/avar/cmake-test-path-no-make-for-windows-ci\n\nÆvar Arnfjörð Bjarmason (15):\n  cmake: don't invoke msgfmt with --statistics\n  cmake: use \"-S\" and \"-B\" to specify source and build directories\n  cmake: update instructions for portable CMakeLists.txt\n  cmake: don't copy chainlint.pl to build directory\n  cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n  cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n  cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n  Makefile + test-lib.sh: don't prefer cmake-built to make-built git\n  test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n  cmake: optionally be able to run tests before \"ctest\"\n  cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n  cmake: increase test timeout on Windows only\n  cmake: only look for \"sh\" in \"C:/Program Files\" on Windows\n  cmake: copy over git-p4.py for t983[56] perforce test\n  CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n\n .github/workflows/main.yml          |   3 +\n Makefile                            |   1 -\n ci/run-build-and-tests.sh           |  11 +-\n contrib/buildsystems/CMakeLists.txt | 213 ++++++++++++++++++++++------\n t/README                            |   3 +\n t/lib-gettext.sh                    |   2 +-\n t/lib-gitweb.sh                     |   2 +-\n t/t7609-mergetool--lib.sh           |   2 +-\n t/t9902-completion.sh               |  14 +-\n t/t9903-bash-prompt.sh              |   2 +-\n t/test-lib.sh                       |  19 ++-\n 11 files changed, 211 insertions(+), 61 deletions(-)\n\nRange-diff against v5:\n 1:  7d83ff44c61 !  1:  fc190b379cd cmake: don't invoke msgfmt with --statistics\n    @@ Metadata\n      ## Commit message ##\n         cmake: don't invoke msgfmt with --statistics\n     \n    -    In 2f12b31b746 (Makefile: don't invoke msgfmt with --statistics,\n    -    2021-12-17) I made the same change to our Makefile, let's follow-up\n    -    and do the same here.\n    +    In [1] I made the same change to our Makefile, let's follow-up and do\n    +    the same here.\n     \n         For \"cmake\" this is particularly nice with \"-G Ninja\", as before we'd\n         emit ~40 lines of overflowed progress bar output, but now it's only\n         the one line of \"ninja\"'s progress bar.\n     \n    +    1. 2f12b31b746 (Makefile: don't invoke msgfmt with --statistics,\n    +       2021-12-17)\n    +\n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n      ## contrib/buildsystems/CMakeLists.txt ##\n 2:  314c5e40cff !  2:  1a11aa233a3 cmake: use \"-S\" and \"-B\" to specify source and build directories\n    @@ Commit message\n         The \"-S\" and \"-B\" options were added in cmake v3.13.0, which is older\n         than the version we have a hard dependency on[1].\n     \n    -    As an aside The \"-p\" flag to \"mkdir\" in the pre-image wasn't needed,\n    +    As an aside, the \"-p\" flag to \"mkdir\" in the pre-image wasn't needed,\n         as \"contrib/buildsystems\" is tracked\n     \n         1. 061c2240b1b (Introduce CMake support for configuring Git, 2020-06-12)\n 3:  5c4ba2425b6 =  3:  b9ddb5db1d3 cmake: update instructions for portable CMakeLists.txt\n 4:  e86245ffbab =  4:  7b7850c00ee cmake: don't copy chainlint.pl to build directory\n 5:  435452314fa !  5:  82ecb797915 cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n    @@ Commit message\n     \n         The remaining failures will be addressed in subsequent commits.\n     \n    +    As this isn't needed on Windows let's skip this there. There's also an\n    +    unconfirmed (it works in CI) report[5] that invoking the \"chmod\"\n    +    command fails in some scenarios.\n    +\n         1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n         2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n         3. 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n            runs, 2022-10-18)\n         4. https://cmake.org/cmake/help/latest/command/file.html#chmod\n    +    5. https://lore.kernel.org/git/87f22a55-ee84-2f76-7b9b-924a97f44f89@dunelm.org.uk/\n     \n         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n     \n    @@ contrib/buildsystems/CMakeLists.txt: add_custom_command(OUTPUT ${git_links} ${gi\n     +function(write_script path content)\n     +\tfile(WRITE ${path} ${content})\n     +\n    -+\tif(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" VERSION_GREATER_EQUAL \"3.19\")\n    ++\tif(WIN32)\n    ++\t\tmessage(TRACE \"skipping chmod +x '${path}' on Windows\")\n    ++\telseif(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" VERSION_GREATER_EQUAL \"3.19\")\n     +\t\tfile(CHMOD ${path} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)\n     +\telse()\n     +\t\texecute_process(COMMAND chmod +x ${path}\n 6:  7ee341245a8 =  6:  1f326944a07 cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n 7:  49645cb1643 =  7:  973c8038f54 cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n 8:  9e10cd5bd8a =  8:  b8448c7a8a6 Makefile + test-lib.sh: don't prefer cmake-built to make-built git\n 9:  df5aea35bbd !  9:  5135e40969e test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n    @@ Metadata\n      ## Commit message ##\n         test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n     \n    -    Compliment the existing GIT_TEST_INSTALLED variable added in [1] with\n    +    Complement the existing GIT_TEST_INSTALLED variable added in [1] with\n         one that allows for testing a git built in a directory that's not\n         \"../\".\n     \n10:  529e18f7f72 ! 10:  65204463730 cmake: optionally be able to run tests before \"ctest\"\n    @@ contrib/buildsystems/CMakeLists.txt: if(USE_VCPKG)\n     +\tset(GIT_CTEST_SETS_BUILD_DIR \"OFF\" CACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n     +endif()\n     +if(GIT_CTEST_SETS_BUILD_DIR)\n    -+\tmessage(STATUS \"Enabling manual runs of t/* tests once ctest writes CMAKE-BUILD-DIR\")\n    ++\tmessage(STATUS \"Have GIT_CTEST_SETS_BUILD_DIR=ON. Need a 'ctest' run to write GIT-BUILD-DIR\")\n     +else()\n    -+\tmessage(STATUS \"Enabling manual runs of t/* tests via cmake build dir discovery\")\n    ++\tmessage(STATUS \"Have GIT_CTEST_SETS_BUILD_DIR=OFF. Wrote out a GIT-BUILD-DIR, no 'ctest' required\")\n     +endif()\n     +\n     +# When using GIT_CTEST_SETS_BUILD_DIR, running the tests from the \"t/\"\n11:  a5dd4fa1d00 ! 11:  e25992b16f1 cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n    @@ contrib/buildsystems/CMakeLists.txt: endif()\n     +elseif(WIN32)\n     +\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\"\n     +\t\tCACHE STRING \"test options, see t/README\")\n    -+\tmessage(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n    ++\tmessage(STATUS \"Using Windows-specific default test options: ${GIT_TEST_OPTS}\")\n     +else()\n     +\tset(GIT_TEST_OPTS \"\"\n     +\t\tCACHE STRING \"test options, see t/README\")\n12:  c9d550b8558 = 12:  4905ce5321d cmake: increase test timeout on Windows only\n13:  7a5dd684d40 = 13:  6c6b530965d cmake: only look for \"sh\" in \"C:/Program Files\" on Windows\n14:  c9c895bb794 = 14:  563f1b9b045 cmake: copy over git-p4.py for t983[56] perforce test\n15:  a6f343b6221 ! 15:  917a884eb65 CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n    @@ Commit message\n         To ensure that it doesn't break again let's add a \"linux-cmake-ctest\"\n         target to build and test \"cmake\" on Linux, in addition to that we'll\n         also run the tests with \"ctest\" instead of \"make\" or \"prove\", so we\n    -    can assert that testing with that method works..\n    +    can assert that testing with that method works.\n     \n         This also stress tests running \"cmake\" (and \"ctest\") out of a build\n         directory that isn't the top-level. The \"vs-build\" job uses \"cmake\"\n    @@ Commit message\n         \"$GIT_SOURCE_DIR\" in a preceding commit.\n     \n         Since the \"ci/lib.sh\" already creates and exports a\n    -    GIT_TEST_OPTS=\"...\" we'll pick that up in our CI, see the preceding\n    +    GIT_TEST_OPTS=\"...\" we'll pick that up in our CI; see the preceding\n         commit. Because we pass the \"--verbose-log -x\n         --github-workflow-markup\" in the GitHub CI as a result the interaction\n         with \"handle_failed_tests\" here works correctly. I.e. on failure we'll\n    @@ .github/workflows/main.yml: jobs:\n                  pool: macos-latest\n     \n      ## ci/run-build-and-tests.sh ##\n    -@@ ci/run-build-and-tests.sh: pedantic)\n    - \t;;\n    - esac\n    +@@ ci/run-build-and-tests.sh: esac\n    + \n    + run_tests=t\n      \n    --group Build make\n     +mc=\n    -+if test \"$jobname\" = \"linux-cmake-ctest\"\n    -+then\n    + case \"$jobname\" in\n    + linux-gcc)\n    + \texport GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n    +@@ ci/run-build-and-tests.sh: pedantic)\n    + \texport DEVOPTS=pedantic\n    + \trun_tests=\n    + \t;;\n    ++linux-cmake-ctest)\n     +\tcb=contrib/buildsystems\n     +\tgroup CMake cmake -S \"$cb\" -B \"$cb/out\"\n     +\tmc=\"-C $cb/out\"\n    -+fi\n    -+\n    ++\t;;\n    + esac\n    + \n    +-group Build make\n     +group Build make $mc\n     +\n      if test -n \"$run_tests\"\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468584","messageId":"patch-v6-02.15-1a11aa233a3-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 02/15] cmake: use \"-S\" and \"-B\" to specify source and build directories","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:00Z","receivedAt":"2022-12-06T02:09:39Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Rather than the multi-line \"mkdir/cd/cmake\" recipe provide an\nequivalent one-liner using the \"-S\" and \"-B\" options, and then suggest building with \"make -C <build-dir>\".\n\nThe rest of these instructions discuss e.g. running tests from our\ntop-level \"t/\" directory, so it's more helpful to avoid changing the\nuser's current directory.\n\nThe \"-S\" and \"-B\" options were added in cmake v3.13.0, which is older\nthan the version we have a hard dependency on[1].\n\nAs an aside, the \"-p\" flag to \"mkdir\" in the pre-image wasn't needed,\nas \"contrib/buildsystems\" is tracked\n\n1. 061c2240b1b (Introduce CMake support for configuring Git, 2020-06-12)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 8f8b6f375f7..5b22a9b217f 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -16,9 +16,7 @@ though, therefore the `File>Open>Folder...` option is preferred.\n \n Instructions to run CMake manually:\n \n-    mkdir -p contrib/buildsystems/out\n-    cd contrib/buildsystems/out\n-    cmake ../ -DCMAKE_BUILD_TYPE=Release\n+    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n \n This will build the git binaries in contrib/buildsystems/out\n directory (our top-level .gitignore file knows to ignore contents of\n@@ -36,8 +34,8 @@ NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual St\n this option is ignored\n \n This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n-Run `make` to build Git on Linux/*BSD/MacOS.\n-Open git.sln on Windows and build Git.\n+Run `make -C contrib/buildsystems/out` to build Git on Linux/*BSD/MacOS.\n+Open contrib/buildsystems/git.sln on Windows and build Git.\n \n NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n to use another tool say `ninja` add this to the command line when configuring.\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468585","messageId":"patch-v6-04.15-7b7850c00ee-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 04/15] cmake: don't copy chainlint.pl to build directory","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:02Z","receivedAt":"2022-12-06T02:09:40Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When [1] made this copy of \"chainlint.sed\" the script was invoked in\nthe test-lib.sh as:\n\n\t[...] sed -f \"$GIT_BUILD_DIR/t/chainlint.sed\" [...]\n\nBut when [2] replaced \"chainlint.sed\" with a \"chainlint.pl\" it also\nreplaced that \"$GIT_BUILD_DIR\" with \"$TEST_DIRECTORY\", invoking it as:\n\n\t\"$PERL_PATH\" \"$TEST_DIRECTORY/chainlint.pl\" \"$0\"\n\nSo this line could have been deleted in [2] but wasn't. Let's do that\nnow.\n\n1. 7f5397a07c6 (cmake: support for testing git when building out of\n   the source tree, 2020-06-26)\n2. 23a14f30166 (test-lib: replace chainlint.sed with chainlint.pl,\n   2022-09-01)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 80290edd72a..c641e9349c9 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1106,7 +1106,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n \t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)\n \tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n \tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n \tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468586","messageId":"patch-v6-03.15-b9ddb5db1d3-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 03/15] cmake: update instructions for portable CMakeLists.txt","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:01Z","receivedAt":"2022-12-06T02:09:42Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The instructions for running CMake went back & forth between *nix,\nWindows and Visual Studio instructions Let's create headings and split\nthe existing instructions up into those new sections.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 68 +++++++++++++++++++++--------\n 1 file changed, 50 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 5b22a9b217f..80290edd72a 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -4,7 +4,31 @@\n \n #[[\n \n-Instructions how to use this in Visual Studio:\n+== Overview ==\n+\n+The top-level Makefile is Git's primary build environment, and a lot\n+of things are missing (and probably always will be) from this CMake\n+alternative.\n+\n+The primary use-case for maintaining this CMake build recipe is to\n+have nicer IDE integration on Windows.\n+\n+== Creating a build recipe ==\n+\n+The \"cmake\" command creates a build file from this recipe:\n+\n+    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n+\n+Running this will create files in the contrib/buildsystems/out\n+directory (our top-level .gitignore file knows to ignore contents of\n+this directory).\n+\n+See \"cmake options\" below for a discussion of\n+\"-DCMAKE_BUILD_TYPE=Release\" and other options to \"cmake\".\n+\n+== Building with Visual Visual Studio ==\n+\n+To use this in Visual Studio:\n \n Open the worktree as a folder. Visual Studio 2019 and later will detect\n the CMake configuration automatically and set everything up for you,\n@@ -14,13 +38,33 @@ Note: Visual Studio also has the option of opening `CMakeLists.txt`\n directly; Using this option, Visual Studio will not find the source code,\n though, therefore the `File>Open>Folder...` option is preferred.\n \n-Instructions to run CMake manually:\n+By default CMake will install vcpkg locally to your source tree on configuration,\n+to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n \n-    cmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Release\n+== Building on Windows without Visual Studio ==\n \n-This will build the git binaries in contrib/buildsystems/out\n-directory (our top-level .gitignore file knows to ignore contents of\n-this directory).\n+Open contrib/buildsystems/git.sln and build Git. Or use the \"msbuild\"\n+command-line tool (see our own \".github/workflows/main.yml\" for a real\n+example):\n+\n+\tmsbuild git.sln\n+\n+== Building on *nix ==\n+\n+On all other platforms running \"cmake\" will generate a Makefile; to\n+build with it run:\n+\n+\tmake -C contrib/buildsystems/out\n+\n+It's also possible to use other generators, e.g. Ninja has arguably\n+slightly better output. Add \"-G Ninja\" to the cmake command above,\n+then:\n+\n+\tninja -C contrib/buildsystems/out\n+\n+== cmake options ==\n+\n+=== -DCMAKE_BUILD_TYPE=<type> ===\n \n Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding\n compiler flags\n@@ -32,18 +76,6 @@ empty(default) :\n \n NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n this option is ignored\n-\n-This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.\n-Run `make -C contrib/buildsystems/out` to build Git on Linux/*BSD/MacOS.\n-Open contrib/buildsystems/git.sln on Windows and build Git.\n-\n-NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,\n-to use another tool say `ninja` add this to the command line when configuring.\n-`-G Ninja`\n-\n-NOTE: By default CMake will install vcpkg locally to your source tree on configuration,\n-to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.\n-\n ]]\n cmake_minimum_required(VERSION 3.14)\n \n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468587","messageId":"patch-v6-05.15-82ecb797915-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 05/15] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:03Z","receivedAt":"2022-12-06T02:09:51Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since the cmake file was made to run on *nix in [1] running the tests\nwith \"ctest\" broken, because we'd attempt to invoke our bin-wrappers/,\nbut they didn't have the executable bit.\n\nIn the best case, the \"t/test-lib.sh\" would be unable to find\n\"bin-wrappers/git\", and we'd fall back on\n\"GIT_EXEC_PATH=$GIT_BUILD_DIR\" using the fallback behavior added in\n[2]:\n\n\t$ ./t0001-init.sh\n\t<GIT_BUILD_DIR>/t/../contrib/buildsystems/out/bin-wrappers/git is not executable; using GIT_EXEC_PATH\n\nThis was recently somewhat swept under the rug in [3], as ctest would\nrun them with \"--no-bin-wrappers\". But still with [3], running e.g.:\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out -DCMAKE_BUILD_TYPE=Debug &&\n\tmake -C contrib/buildsystems/out &&\n\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\" --output-on-failure\n\nFails around 20% of our tests on *nix. So even with [3] we'd fail any\ntest that needed to invoke one of our built shell, perl or Python\nscripts on *nix. E.g. t0012-help.sh would fail on a test that tried to\ninvoke \"git web--browse\". The equivalent of this (in the \"out\"\ndirectory) would happen:\n\n\t$ ./git --exec-path=$PWD web--browse\n\tgit: 'web--browse' is not a git command. See 'git --help'.\n\nWhich we can fix by \"chmod +x\"-ing the built \"git-web--browse\":\n\n\t$ chmod +x git-web--browse\n\t$ ./git --exec-path=$PWD web--browse\n\tusage: git web--browse [--browser=browser|--tool=browser] [--config=conf.var] url/file ...\n\nThe same goes for e.g. the \"git-p4\" tests, which would fail because\nour built \"git-p4\" wasn't executable, etc. There's also a few other\noutstanding issues, which will be fixed in subsequent commits.\n\nIdeally we'd use the file(CHMOD ...) form everywhere, but that syntax\nwas introduced in cmake 3.19[4], whereas we only require 3.14. Let's\nprovide a fallback behind a version check, so that we'll eventually be\nable to delete the \"else\" part. Both forms result in the same file\nmodes.\n\nBefore this change:\n\n\t80% tests passed, 196 tests failed out of 977\n\nAfter:\n\n\t99% tests passed, 5 tests failed out of 977\n\nThe remaining failures will be addressed in subsequent commits.\n\nAs this isn't needed on Windows let's skip this there. There's also an\nunconfirmed (it works in CI) report[5] that invoking the \"chmod\"\ncommand fails in some scenarios.\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n3. 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n   runs, 2022-10-18)\n4. https://cmake.org/cmake/help/latest/command/file.html#chmod\n5. https://lore.kernel.org/git/87f22a55-ee84-2f76-7b9b-924a97f44f89@dunelm.org.uk/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n\nwrite script\n---\n contrib/buildsystems/CMakeLists.txt | 27 +++++++++++++++++++++------\n 1 file changed, 21 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex c641e9349c9..7a2c3681e0d 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -840,6 +840,21 @@ add_custom_command(OUTPUT ${git_links} ${git_http_links}\n \t\tDEPENDS git git-remote-http)\n add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links})\n \n+function(write_script path content)\n+\tfile(WRITE ${path} ${content})\n+\n+\tif(WIN32)\n+\t\tmessage(TRACE \"skipping chmod +x '${path}' on Windows\")\n+\telseif(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" VERSION_GREATER_EQUAL \"3.19\")\n+\t\tfile(CHMOD ${path} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)\n+\telse()\n+\t\texecute_process(COMMAND chmod +x ${path}\n+\t\t\t\tRESULT_VARIABLE CHILD_ERROR)\n+\t\tif(CHILD_ERROR)\n+\t\t\tmessage(FATAL_ERROR \"failed to chmod +x '${path}': '${CHILD_ERROR}'\")\n+\t\tendif()\n+\tendif()\n+endfunction()\n \n #creating required scripts\n set(SHELL_PATH /bin/sh)\n@@ -865,7 +880,7 @@ foreach(script ${git_shell_scripts})\n \tstring(REPLACE \"# @@BROKEN_PATH_FIX@@\" \"\" content \"${content}\")\n \tstring(REPLACE \"@@PERL@@\" \"${PERL_PATH}\" content \"${content}\")\n \tstring(REPLACE \"@@PAGER_ENV@@\" \"LESS=FRX LV=-c\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n endforeach()\n \n #perl scripts\n@@ -880,13 +895,13 @@ foreach(script ${git_perl_scripts})\n \tfile(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME)\n \tstring(REPLACE \"#!/usr/bin/perl\" \"#!/usr/bin/perl\\n${perl_header}\\n\" content \"${content}\")\n \tstring(REPLACE \"@@GIT_VERSION@@\" \"${PROJECT_VERSION}\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/${script} \"${content}\")\n endforeach()\n \n #python script\n file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n-file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})\n+write_script(${CMAKE_BINARY_DIR}/git-p4 \"${content}\")\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n@@ -1024,20 +1039,20 @@ foreach(script ${wrapper_scripts})\n \tfile(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"${script}${EXE_EXTENSION}\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/bin-wrappers/${script} \"${content}\")\n endforeach()\n \n foreach(script ${wrapper_test_scripts})\n \tfile(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n \tstring(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n \tstring(REPLACE \"@@PROG@@\" \"t/helper/${script}${EXE_EXTENSION}\" content \"${content}\")\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})\n+\twrite_script(${CMAKE_BINARY_DIR}/bin-wrappers/${script} \"${content}\")\n endforeach()\n \n file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)\n string(REPLACE \"@@BUILD_DIR@@\" \"${CMAKE_BINARY_DIR}\" content \"${content}\")\n string(REPLACE \"@@PROG@@\" \"git-cvsserver\" content \"${content}\")\n-file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})\n+write_script(${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver \"${content}\")\n \n #options for configuring test options\n option(PERL_TESTS \"Perform tests that use perl\" ON)\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468588","messageId":"patch-v6-06.15-1f326944a07-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 06/15] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:04Z","receivedAt":"2022-12-06T02:09:55Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When git is built and tested with cmake & ctest we usually do that\noutside of the top-level source directory. E.g.\n\n\tcmake -S contrib/buildsystems -B contrib/buildsystems/out\n\tmake -C contrib/buildsystems/out\n\tctest -j$(nproc) --test-dir contrib/buildsystems/out\n\nSince the test-lib.sh makes assumptions about the TEST_DIRECTORY being\nthe \"t\" subdirectory of the top-level \"$GIT_BUILD_DIR\", the cmake\nrecipe has needed to copy various assets to that\n\"contrib/buildsystems/out\" directory.\n\nBut we've only been doing this for the subsets of tests that run on\nWindows, and which have otherwise been covered by that CI target. The\nCI target builds (among other things) with \"-DPERL_TESTS=OFF\n-DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON\", see [1]. Furthermore, the\nCI isn't testing from the \"contrib/buildsystems/out\" directory,\ninstead it clobbers the top-level MAkefile.\n\nThere was a recent commit to fix a subset of these issues, see\n6a83b5f0810 (cmake: copy the merge tools for testing, 2022-10-18).\n\nLet's stop going for that approach, and instead teach the test-lib.sh\nthat there's such a thing as the \"$GIT_SOURCE_DIR\" distinct from the\n\"$GIT_BUILD_DIR\".\n\nJust as the \"$TEST_DIRECTORY\" always points to our actual \"t\"\ndirectory (not the \"[...]/out/t\" cmake creates), this new\n\"$GIT_SOURCE_DIR\" will always be the top-level source directory.\n\nWith this change we now pass 3/5 of the tests that we still had\nfailing with the fixes in the preceding commit.\n\n1. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt |  6 ------\n t/lib-gettext.sh                    |  2 +-\n t/lib-gitweb.sh                     |  2 +-\n t/t7609-mergetool--lib.sh           |  2 +-\n t/t9902-completion.sh               | 14 +++++++-------\n t/t9903-bash-prompt.sh              |  2 +-\n t/test-lib.sh                       |  8 +++++++-\n 7 files changed, 18 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 7a2c3681e0d..ad47430f9be 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1120,12 +1120,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n \t#Setting the build directory in test-lib.sh before running tests\n \tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n \t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n-\t#misc copies\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)\n-\tfile(GLOB mergetools \"${CMAKE_SOURCE_DIR}/mergetools/*\")\n-\tfile(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n-\tfile(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)\n endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\ndiff --git a/t/lib-gettext.sh b/t/lib-gettext.sh\nindex cc6bb2cdeaa..dcd6e9c3f75 100644\n--- a/t/lib-gettext.sh\n+++ b/t/lib-gettext.sh\n@@ -7,7 +7,7 @@\n . ./test-lib.sh\n \n GIT_TEXTDOMAINDIR=\"$GIT_BUILD_DIR/po/build/locale\"\n-GIT_PO_PATH=\"$GIT_BUILD_DIR/po\"\n+GIT_PO_PATH=\"$GIT_SOURCE_DIR/po\"\n export GIT_TEXTDOMAINDIR GIT_PO_PATH\n \n if test -n \"$GIT_TEST_INSTALLED\"\ndiff --git a/t/lib-gitweb.sh b/t/lib-gitweb.sh\nindex 1f32ca66ea5..6f68df247af 100644\n--- a/t/lib-gitweb.sh\n+++ b/t/lib-gitweb.sh\n@@ -49,7 +49,7 @@ EOF\n \t\terror \"Cannot find gitweb at $GITWEB_TEST_INSTALLED.\"\n \t\tsay \"# Testing $SCRIPT_NAME\"\n \telse # normal case, use source version of gitweb\n-\t\tSCRIPT_NAME=\"$GIT_BUILD_DIR/gitweb/gitweb.perl\"\n+\t\tSCRIPT_NAME=\"$GIT_SOURCE_DIR/gitweb/gitweb.perl\"\n \tfi\n \texport SCRIPT_NAME\n }\ndiff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh\nindex 8b1c3bd39f2..2090d12a489 100755\n--- a/t/t7609-mergetool--lib.sh\n+++ b/t/t7609-mergetool--lib.sh\n@@ -8,7 +8,7 @@ TEST_PASSES_SANITIZE_LEAK=true\n . ./test-lib.sh\n \n test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '\n-\t. \"$GIT_BUILD_DIR\"/mergetools/vimdiff &&\n+\t. \"$GIT_SOURCE_DIR\"/mergetools/vimdiff &&\n \trun_unit_tests\n '\n \ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 43de868b800..1bd4cae92fe 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -33,7 +33,7 @@ complete ()\n GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'\n GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\"\n \n # We don't need this function to actually join words or do anything special.\n # Also, it's cleaner to avoid touching bash's internal completion variables.\n@@ -2567,7 +2567,7 @@ test_expect_success 'sourcing the completion script clears cached commands' '\n \t(\n \t\t__git_compute_all_commands &&\n \t\tverbose test -n \"$__git_all_commands\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_all_commands\"\n \t)\n '\n@@ -2576,7 +2576,7 @@ test_expect_success 'sourcing the completion script clears cached merge strategi\n \t(\n \t\t__git_compute_merge_strategies &&\n \t\tverbose test -n \"$__git_merge_strategies\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__git_merge_strategies\"\n \t)\n '\n@@ -2587,7 +2587,7 @@ test_expect_success 'sourcing the completion script clears cached --options' '\n \t\tverbose test -n \"$__gitcomp_builtin_checkout\" &&\n \t\t__gitcomp_builtin notes_edit &&\n \t\tverbose test -n \"$__gitcomp_builtin_notes_edit\" &&\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_checkout\" &&\n \t\tverbose test -z \"$__gitcomp_builtin_notes_edit\"\n \t)\n@@ -2599,7 +2599,7 @@ test_expect_success 'option aliases are not shown by default' '\n \n test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&\n \t\ttest_completion \"git clone --recurs\" <<-\\EOF\n \t\t--recurse-submodules Z\n@@ -2610,7 +2610,7 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '\n \n test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\n \n \t\t# Just mainporcelain, not plumbing commands\n@@ -2622,7 +2622,7 @@ test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_\n \n test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '\n \t(\n-\t\t. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\" &&\n+\t\t. \"$GIT_SOURCE_DIR/contrib/completion/git-completion.bash\" &&\n \t\tGIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&\n \t\texport GIT_COMPLETION_SHOW_ALL_COMMANDS &&\n \t\tsane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex d459fae6551..06f0abfc294 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -10,7 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./lib-bash.sh\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+. \"$GIT_SOURCE_DIR/contrib/completion/git-prompt.sh\"\n \n actual=\"$TRASH_DIRECTORY/actual\"\n c_red='\\\\[\\\\e[31m\\\\]'\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 6db377f68b8..36358811a0f 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -47,6 +47,10 @@ then\n \techo \"PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?\" >&2\n \texit 1\n fi\n+\n+# For CMake the top-level source directory is different from our build\n+# directory. With the top-level Makefile they're the same.\n+GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n@@ -1447,7 +1451,7 @@ then\n \t\tmake_valgrind_symlink $file\n \tdone\n \t# special-case the mergetools loadables\n-\tmake_symlink \"$GIT_BUILD_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n+\tmake_symlink \"$GIT_SOURCE_DIR\"/mergetools \"$GIT_VALGRIND/bin/mergetools\"\n \tOLDIFS=$IFS\n \tIFS=:\n \tfor path in $PATH\n@@ -1500,6 +1504,8 @@ GIT_CONFIG_NOSYSTEM=1\n GIT_ATTR_NOSYSTEM=1\n GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\"\n export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES\n+MERGE_TOOLS_DIR=\"$GIT_SOURCE_DIR/mergetools\"\n+export MERGE_TOOLS_DIR\n \n if test -z \"$GIT_TEST_CMP\"\n then\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468589","messageId":"patch-v6-07.15-973c8038f54-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 07/15] cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:05Z","receivedAt":"2022-12-06T02:09:57Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"When we build with libpcre2 which cmake has supported since [1] we\nneed to set \"USE_LIBPCRE2='YesPlease'\" (or similar) in\n\"GIT-BUILD-OPTIONS\".\n\nWithout this e.g. t7810-grep.sh will fail, as it has tests that rely\non the behavior of !PCRE2. The reason this hasn't been noticed is that\nthe Windows CI doesn't have access to libpcre2.\n\nWith this the remaining two failures we had left after the preceding\nstep are resolved, but note that that test run didn't include the\ngit-p4 tests, which a subsequent commit will address).\n\n1. 80431510a2b (cmake: add pcre2 support, 2022-05-24)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex ad47430f9be..2d66d471acb 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1101,6 +1101,9 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PYTHON_PATH='${PYTHON_PATH}'\\\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"TAR='${TAR}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_CURL='${NO_CURL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_EXPAT='${NO_EXPAT}'\\n\")\n+if(PCRE2_FOUND)\n+\tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"USE_LIBPCRE2='YesPlease'\\n\")\n+endif()\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PERL='${NO_PERL}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_PTHREADS='${NO_PTHREADS}'\\n\")\n file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\\n\")\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468590","messageId":"patch-v6-08.15-b8448c7a8a6-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 08/15] Makefile + test-lib.sh: don't prefer cmake-built to make-built git","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:06Z","receivedAt":"2022-12-06T02:09:58Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Per ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18) and\nthe surrounding discussion the goal of that change was to have\nbuilding with cmake and:\n\n\t(cd t && ./t0001-init.sh)\n\nWork, to do so we need some way to make the test-lib.sh aware that we\nhave a build in contrib/buildsystems/out. The downside of doing it via\nthe GIT-BUILD-DIR facility in ee9e66e4e76 is:\n\n- A \"remove this file while at it\" only fits into the Makefile\n  dependency graph if we \"FORCE\" a shell command to be run, so doing it\n  this way precludes speeding up the Makefile by e.g. making use of the\n  \"$(file)\" function (for which I've got follow-up patches).\n\n- If you build with make, then with cmake, and then e.g.:\n\n\tmake -C t prove\n\n  We'll run the tests against the cmake version of the tests, not the\n  \"make\" built ones. It's important to get any subtle interaction\n  between two conflicting build systems right.\n\nNow we'll instead check if the top-level \"git\" exists, and only if it\ndoesn't look for the one built by cmake. This ensures that we'll pick\nit up as required when the user is using CMake, without being subject\nto the odd interaction of flip-flopping between the two\nenvironments.\n\nIt also means that we can remove the rule to remove the\n\"GIT-BUILD-DIR\", if we get to creating \"GIT-BUILD-OPTIONS\" in the\ntop-level git. That's because now when building with both \"make\" and\n\"cmake\" we will always prefer the former for running the tests, so\nthere's no need to remove the \"GIT-BUILD-DIR\" file to resolve the\nconflicts between the two.\n\nIn practice users are building with either \"make\" or \"cmake\", and not\nmixing the two, but in a subsequent change we'll provide an out for\nthat \"make\"-preferring selection behavior, by having \"ctest\" runs\nalways prefer the \"cmake\" built one.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Makefile      | 1 -\n t/test-lib.sh | 3 ++-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex b258fdbed86..c602ce57e64 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -3150,7 +3150,6 @@ else\n \t@echo RUNTIME_PREFIX=\\'false\\' >>$@+\n endif\n \t@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi\n-\t@if test -f GIT-BUILD-DIR; then rm GIT-BUILD-DIR; fi\n \n ### Detect Python interpreter path changes\n ifndef NO_PYTHON\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 36358811a0f..c7d55ff0796 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -51,7 +51,8 @@ fi\n # For CMake the top-level source directory is different from our build\n # directory. With the top-level Makefile they're the same.\n GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n-if test -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n+if test ! -x \"$GIT_BUILD_DIR/git\" &&\n+\ttest -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n \t# On Windows, we must convert Windows paths lest they contain a colon\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468591","messageId":"patch-v6-09.15-5135e40969e-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 09/15] test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:07Z","receivedAt":"2022-12-06T02:10:09Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Complement the existing GIT_TEST_INSTALLED variable added in [1] with\none that allows for testing a git built in a directory that's not\n\"../\".\n\nInstead of \"test this installed git\" (\"GIT_TEST_INSTALLED\"), this new\n\"GIT_TEST_BUILD_DIR\" is a \"test this built directory over\nthere\". E.g. this will pass all tests:\n\n\tgit clone --depth=1 https://github.com/git/git.git git1\n\tcp -R git1 git2\n\tmake -C git1\n\t[apply this change to git2]\n\t(cd git2 && GIT_TEST_BUILD_DIR=\"$PWD/../git1\" make -C t prove)\n\nThis facility and file-based instructions to have the test suite use\nanother build directory[2] are mutually exclusive. In a subsequent\ncommit we'll make CMake and CTest optionally prefer this method.\n\n1. 6720721e152 (test-lib.sh: Allow running the test suite against\n   installed git, 2009-03-16)\n2. 350a005e366 (cmake: avoid editing t/test-lib.sh, 2022-10-18)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/README      | 3 +++\n t/test-lib.sh | 7 +++++++\n 2 files changed, 10 insertions(+)\n\ndiff --git a/t/README b/t/README\nindex 979b2d4833d..fc0daef2e41 100644\n--- a/t/README\n+++ b/t/README\n@@ -231,6 +231,9 @@ override the location of the dashed-form subcommands (what\n GIT_EXEC_PATH would be used for during normal operation).\n GIT_TEST_EXEC_PATH defaults to `$GIT_TEST_INSTALLED/git --exec-path`.\n \n+Similar to GIT_TEST_INSTALLED, GIT_TEST_BUILD_DIR can be pointed to\n+another git.git checkout's build directory, to test its built binaries\n+against the tests in this checkout.\n \n Skipping Tests\n --------------\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex c7d55ff0796..a1b5c7c6ce1 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -55,6 +55,13 @@ if test ! -x \"$GIT_BUILD_DIR/git\" &&\n \ttest -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n+elif test -n \"$GIT_TEST_BUILD_DIR\"\n+then\n+\tGIT_BUILD_DIR=\"$GIT_TEST_BUILD_DIR\"\n+fi\n+\n+if test \"$GIT_SOURCE_DIR\" != \"$GIT_BUILD_DIR\"\n+then\n \t# On Windows, we must convert Windows paths lest they contain a colon\n \tcase \"$(uname -s)\" in\n \t*MINGW*)\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468592","messageId":"patch-v6-10.15-65204463730-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 10/15] cmake: optionally be able to run tests before \"ctest\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:08Z","receivedAt":"2022-12-06T02:10:17Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] the \"cmake\" build has had support for running the tests\nmanually from the \"t/\" directory once we've built with \"cmake\", but\nonly after a one-off run of \"ctest\".\n\nI.e. we create the build recipe via \"cmake\" and build with\ne.g. \"make\", but after doing so would get:\n\n\t$ (cd t && ./t0071-sort.sh)\n\terror: GIT-BUILD-OPTIONS missing (has Git been built?).\n\nThe recently added amendment to this of using a \"GIT-BUILD-DIR\"[2]\ndidn't change these semantics. After we did a one-off run of \"ctest\"\nwe'd be able to run the tests without \"ctest\":\n\n\t$ ctest --test-dir contrib/buildsystems/out -R t0071\n\t[...]\n\t100% tests passed, 0 tests failed out of 1\n\t[...]\n\t$ (cd t && ./t0071-sort.sh)\n\tok 1 - DEFINE_LIST_SORT_DEBUG\n\t# passed all 1 test(s)\n\t1..1\n\nThis change optionally closes that gap, and allows for more sensible\nbehavior. Due to concerns about existing MS Visual Studio users\nrelying on some of these edge cases this is being made optional, with\nthe default of the new \"GIT_CTEST_SETS_BUILD_DIR\" being \"ON\" on\nWindows (i.e. the old behavior), and \"OFF\" elsewhere.\n\nThe resulting behavior differences are the following:\n\n\t|---+----+-----|\n\t|   | ON | OFF |\n\t|---+----+-----|\n\t| A | N  | Y   |\n\t| B | N  | Y   |\n\t| C | Y  | Y   |\n\t| D | Y  | N   |\n\t| E | N  | Y   |\n\t|---+----+-----|\n\tA. Can manually run tests before ctest?\n\tB. Manually run tests point to latest cmake build?...\n\tC. Manually run tests point to latest \"ctest\"'d build?\n        D. \"git\" picked at ctest start time?\n        E. \"git\" picked at test start time?\n\nOn \"D\" and \"E\": Because GIT_CTEST_SETS_BUILD_DIR=ON relies on the\nglobal \"GIT-BUILD-DIR\" when using \"ctest\" it cannot be used to run\nconcurrent tests for two different builds from the same source\ndirectory.\n\nBut as noted in [3] existing users using Visual Studio may be relying\non some of these edge cases, so let's make this optional on Windows,\nbut switch the default to this new discover method on other platforms.\n\n1. 7f5397a07c6 (cmake: support for testing git when building out of\n   the source tree, 2020-06-26)\n2. ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18)\n3. https://lore.kernel.org/git/663b93ef-0c89-a5f6-1069-b4be97915d20@dunelm.org.uk/\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 38 ++++++++++++++++++++++++-----\n t/test-lib.sh                       |  3 ++-\n 2 files changed, 34 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 2d66d471acb..385e4e9d772 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1117,12 +1117,33 @@ if(USE_VCPKG)\n \tfile(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS \"PATH=\\\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\\\"\\n\")\n endif()\n \n-#Make the tests work when building out of the source tree\n-get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n-if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n-\t#Setting the build directory in test-lib.sh before running tests\n-\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n-\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n+set(GIT_CTEST_SETS_BUILD_DIR_DOC \"find cmake build dir via ctest-set GIT-BUILD-DIR?\")\n+if(DEFINED ENV{GIT_CTEST_SETS_BUILD_DIR})\n+\tset(GIT_CTEST_SETS_BUILD_DIR \"$ENV{GIT_CTEST_SETS_BUILD_DIR}\"\n+\t\tCACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n+elseif(WIN32)\n+\tset(GIT_CTEST_SETS_BUILD_DIR \"ON\" CACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n+else()\n+\tset(GIT_CTEST_SETS_BUILD_DIR \"OFF\" CACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n+endif()\n+if(GIT_CTEST_SETS_BUILD_DIR)\n+\tmessage(STATUS \"Have GIT_CTEST_SETS_BUILD_DIR=ON. Need a 'ctest' run to write GIT-BUILD-DIR\")\n+else()\n+\tmessage(STATUS \"Have GIT_CTEST_SETS_BUILD_DIR=OFF. Wrote out a GIT-BUILD-DIR, no 'ctest' required\")\n+endif()\n+\n+# When using GIT_CTEST_SETS_BUILD_DIR, running the tests from the \"t/\"\n+# directory will only work once \"ctest\" has been run, as we write to\n+# \"GIT-BUILD-DIR\" from the optional \"ctest\" invocation following the\n+# \"cmake\"\n+if(GIT_CTEST_SETS_BUILD_DIR)\n+\tget_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)\n+\tif(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})\n+\t\tfile(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake\n+\t\t\t\"file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \\\"${CMAKE_BINARY_DIR}\\\")\")\n+\tendif()\n+else()\n+\tfile(WRITE \"${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR\" \"${CMAKE_BINARY_DIR}\")\n endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n@@ -1132,6 +1153,11 @@ foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n \t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n+if(NOT GIT_CTEST_SETS_BUILD_DIR)\n+\tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n+\t\tGIT_TEST_PREFER_BUILD_DIR_ENV=\"Yes, ignore GIT-BUILD-DIR\"\n+\t\tGIT_TEST_BUILD_DIR=${CMAKE_BINARY_DIR})\n+endif()\n endforeach()\n \n # This test script takes an extremely long time and is known to time out even\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex a1b5c7c6ce1..36a9a32db05 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -51,7 +51,8 @@ fi\n # For CMake the top-level source directory is different from our build\n # directory. With the top-level Makefile they're the same.\n GIT_SOURCE_DIR=\"$GIT_BUILD_DIR\"\n-if test ! -x \"$GIT_BUILD_DIR/git\" &&\n+if test -z \"$GIT_TEST_PREFER_BUILD_DIR_ENV\" &&\n+\ttest ! -x \"$GIT_BUILD_DIR/git\" &&\n \ttest -f \"$GIT_BUILD_DIR/GIT-BUILD-DIR\"\n then\n \tGIT_BUILD_DIR=\"$(cat \"$GIT_BUILD_DIR/GIT-BUILD-DIR\")\" || exit 1\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468593","messageId":"patch-v6-11.15-e25992b16f1-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 11/15] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:09Z","receivedAt":"2022-12-06T02:10:21Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"The rationale for adding \"--no-bin-wrappers\" and \"--no-chain-lint\" in\n2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\nruns, 2022-10-18) was those options slowed down the tests considerably\non Windows.\n\nBut since f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\nand with the preceding commits cmake and ctest are not\nWindows-specific anymore.\n\nSo let's set those same options by default on Windows, but do so with\nthe set(... CACHE <type> <docstring>) facility. As noted in cmake's\ndocumentation[1] this integrates nicely with e.g. cmake-gui.\n\nOn *nix we don't set any custom options. The change in 2ea1d8b5563\ndidn't discuss why Windows should have divergent defaults with \"cmake\"\nand \"make\", but such reasons presumably don't apply on *nix. I for one\nam happy with the same defaults as the tests have when running via the\nMakefile.\n\nWith the \"message()\" addition we'll emit this when running cmake:\n\n\tGenerating hook-list.h\n\t-- Using user-selected test options: -vixd\n\t-- Configuring done\n\t-- Generating done\n\t-- Build files have been written to: /home/avar/g/git/contrib/buildsystems/out\n\nUnfortunately cmake doesn't support a non-hacky way to pass variables\nto ctest without re-running cmake itself, so when re-running tests via\ncmake and wanting to change the test defaults we'll need:\n\n\tGIT_TEST_OPTS=-i cmake -S contrib/buildsystems -B contrib/buildsystems/out &&\n\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out -R t0071 --verbose\n\nThe \"separate_arguments()\" here will do the right thing for arguments\nthat don't contain whitespace, so e.g. the path to --root=\"\" can't\nhave a space in it. There's supposedly a way to work around that with\nseparate_arguments(), but it requires features newer than our required\ncmake version, so let's live with that edge case for now.\n\n1. https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 50 +++++++++++++++++++++++++++--\n 1 file changed, 48 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 385e4e9d772..034ab2c879a 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -32,7 +32,7 @@ To use this in Visual Studio:\n \n Open the worktree as a folder. Visual Studio 2019 and later will detect\n the CMake configuration automatically and set everything up for you,\n-ready to build. You can then run the tests in `t/` via a regular Git Bash.\n+ready to build. See \"== Running the tests ==\" below for running the tests.\n \n Note: Visual Studio also has the option of opening `CMakeLists.txt`\n directly; Using this option, Visual Studio will not find the source code,\n@@ -76,6 +76,37 @@ empty(default) :\n \n NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio\n this option is ignored\n+\n+== Running the tests ==\n+\n+Once we've built in \"contrib/buildsystems/out\" the tests can be run at\n+the top-level (note: not the generated \"contrib/buildsystems/out/t/\"\n+drectory). If no top-level build is found (as created with the\n+Makefile) the t/test-lib.sh will discover the git in\n+\"contrib/buildsystems/out\" on e.g.:\n+\n+\t(cd t && ./t0001-init.sh)\n+\tsetup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git\n+\t[...]\n+\n+The tests can also be run with ctest, e.g. after building with \"cmake\"\n+and \"make\" or \"msbuild\" run, from the top-level e.g.:\n+\n+\t# \"--test-dir\" is new in cmake v3.20, so \"(cd\n+\t# contrib/buildsystems/out && ctest ...)\" on older versions.\n+\tctest --test-dir contrib/buildsystems/out --jobs=\"$(nproc)\"--output-on-failure\n+\n+Options can be passed by setting GIT_TEST_OPTIONS before invoking\n+cmake. E.g. on a Linux system with systemd the tests can be sped up by\n+using a ramdisk for the scratch files:\n+\n+\tGIT_TEST_OPTS=\"--root=/dev/shm/$(id -u)/ctest\" cmake -S contrib/buildsystems -B contrib/buildsystems/out\n+\t[...]\n+\t-- Using user-selected test options: --root=/dev/shm/<uid>/ctest\n+\n+Then running the tests with \"ctest\" (here with --jobs=\"$(nproc)\"):\n+\n+\tctest --jobs=$(nproc) --test-dir contrib/buildsystems/out\n ]]\n cmake_minimum_required(VERSION 3.14)\n \n@@ -1148,10 +1179,25 @@ endif()\n \n file(GLOB test_scipts \"${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh\")\n \n+if(DEFINED ENV{GIT_TEST_OPTS})\n+\tset(GIT_TEST_OPTS \"$ENV{GIT_TEST_OPTS}\"\n+\t\tCACHE STRING \"test options, see t/README\")\n+\tmessage(STATUS \"Using user-selected test options: ${GIT_TEST_OPTS}\")\n+elseif(WIN32)\n+\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\"\n+\t\tCACHE STRING \"test options, see t/README\")\n+\tmessage(STATUS \"Using Windows-specific default test options: ${GIT_TEST_OPTS}\")\n+else()\n+\tset(GIT_TEST_OPTS \"\"\n+\t\tCACHE STRING \"test options, see t/README\")\n+\tmessage(STATUS \"No custom test options selected, set e.g. GIT_TEST_OPTS=\\\"-vixd\\\"\")\n+endif()\n+separate_arguments(GIT_TEST_OPTS)\n+\n #test\n foreach(tsh ${test_scipts})\n \tadd_test(NAME ${tsh}\n-\t\tCOMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx\n+\t\tCOMMAND ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}\n \t\tWORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)\n if(NOT GIT_CTEST_SETS_BUILD_DIR)\n \tset_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468594","messageId":"patch-v6-12.15-4905ce5321d-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 12/15] cmake: increase test timeout on Windows only","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:10Z","receivedAt":"2022-12-06T02:10:23Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Per c858750b41c (cmake: increase time-out for a long-running test,\n2022-10-18) the reason to set a custom timeout for\nt7112-reset-submodule.sh is Windows-specific. Let's only do that on\nWindows then.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 034ab2c879a..139498c5d5b 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -1206,8 +1206,10 @@ if(NOT GIT_CTEST_SETS_BUILD_DIR)\n endif()\n endforeach()\n \n-# This test script takes an extremely long time and is known to time out even\n-# on fast machines because it requires in excess of one hour to run\n-set_tests_properties(\"${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh\" PROPERTIES TIMEOUT 4000)\n+if(WIN32)\n+\t# This test script takes an extremely long time and is known to time out even\n+\t# on fast machines because it requires in excess of one hour to run\n+\tset_tests_properties(\"${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh\" PROPERTIES TIMEOUT 4000)\n+endif()\n \n endif()#BUILD_TESTING\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468595","messageId":"patch-v6-14.15-563f1b9b045-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 14/15] cmake: copy over git-p4.py for t983[56] perforce test","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:12Z","receivedAt":"2022-12-06T02:10:36Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] two git-p4 tests have relied on there being a \"git-p4.py\" in\nthe build directory, but the cmake recipe was not updated to account\nfor this. Let's copy the \"git-p4.py\" over.\n\nWe could also change the test to e.g. grab the built \"git-p4\" and\nalter its shebang, which would be friendly to GIT_TEST_INSTALLED, but\nlet's just do the bare minimum here to get cmake+ctest working without\naltering the test itself.\n\nThe reason this hasn't been caught by \"vs-build\" and \"vs-test\" is\nbecause those tests added in [2] invoke \"cmake\" with\n\"-DPYTHON_TESTS=OFF\", and therefore we'd skip this part of the git-p4\ntests before getting past the \"do we have python?\" check. Even if we\ngot past that the Windows CI wouldn't have a \"p4\" or \"p4d\" binary\ninstalled, so we'd skip the tests anyway.\n\nIn a subsequent commit we'll run \"cmake\" and \"ctest\" in CI with\n\"ubuntu-latest\", so we'll need this \"git-p4.py\" file.\n\n1. f7b5ff607fa (git-p4: improve encoding handling to support\n   inconsistent encodings, 2022-04-30)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 9e3e46c93f5..b1b1f327e95 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -940,6 +940,7 @@ endforeach()\n file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)\n string(REPLACE \"#!/usr/bin/env python\" \"#!/usr/bin/python\" content \"${content}\")\n write_script(${CMAKE_BINARY_DIR}/git-p4 \"${content}\")\n+file(COPY ${CMAKE_SOURCE_DIR}/git-p4.py DESTINATION ${CMAKE_BINARY_DIR}/)\n \n #perl modules\n file(GLOB_RECURSE perl_modules \"${CMAKE_SOURCE_DIR}/perl/*.pm\")\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468596","messageId":"patch-v6-13.15-6c6b530965d-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 13/15] cmake: only look for \"sh\" in \"C:/Program Files\" on Windows","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:11Z","receivedAt":"2022-12-06T02:10:38Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Guard the finding of \"SH_EXE\" in \"C:\\Program Files\" with a check for\nwhether we're on Windows.\n\nThis Windows-specific code was first added in [1], and later expanded\non [2], but since some of that was added this build recipe has been\nmade portable outside of Windows.\n\n1. 72b6eeb81b1 (cmake: do find Git for Windows' shell interpreter,\n   2020-09-28)\n2. 476e54b1c60 (cmake: support local installations of git,\n   2022-07-27).\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n contrib/buildsystems/CMakeLists.txt | 15 +++++++++++----\n 1 file changed, 11 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt\nindex 139498c5d5b..9e3e46c93f5 100644\n--- a/contrib/buildsystems/CMakeLists.txt\n+++ b/contrib/buildsystems/CMakeLists.txt\n@@ -138,10 +138,17 @@ if(USE_VCPKG)\n \tset(CMAKE_TOOLCHAIN_FILE ${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake CACHE STRING \"Vcpkg toolchain file\")\n endif()\n \n-find_program(SH_EXE sh PATHS \"C:/Program Files/Git/bin\" \"$ENV{LOCALAPPDATA}/Programs/Git/bin\")\n-if(NOT SH_EXE)\n-\tmessage(FATAL_ERROR \"sh: shell interpreter was not found in your path, please install one.\"\n-\t\t\t\"On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/\")\n+if(WIN32)\n+\tfind_program(SH_EXE sh PATHS \"C:/Program Files/Git/bin\" \"$ENV{LOCALAPPDATA}/Programs/Git/bin\")\n+\tif(NOT SH_EXE)\n+\t\tmessage(FATAL_ERROR \"sh: shell interpreter was not found in your path, please install one.\"\n+\t\t\t\t\"You can get it as part of 'Git for Windows' install at https://gitforwindows.org/\")\n+\tendif()\n+else()\n+\tfind_program(SH_EXE sh)\n+\tif(NOT SH_EXE)\n+\t\tmessage(FATAL_ERROR \"cannot find 'sh' in '$PATH'\")\n+\tendif()\n endif()\n \n #Create GIT-VERSION-FILE using GIT-VERSION-GEN\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468597","messageId":"patch-v6-15.15-917a884eb65-20221206T001617Z-avarab@gmail.com","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"[PATCH v6 15/15] CI: add a \"linux-cmake-test\" to run cmake & ctest on linux","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-06T02:09:13Z","receivedAt":"2022-12-06T02:10:39Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Since [1] the \"cmake\" build method should work properly on Linux, but\nas seen in preceding commits there were various bugs in it, which are\nhopefully now all fixed.\n\nTo ensure that it doesn't break again let's add a \"linux-cmake-ctest\"\ntarget to build and test \"cmake\" on Linux, in addition to that we'll\nalso run the tests with \"ctest\" instead of \"make\" or \"prove\", so we\ncan assert that testing with that method works.\n\nThis also stress tests running \"cmake\" (and \"ctest\") out of a build\ndirectory that isn't the top-level. The \"vs-build\" job uses \"cmake\"\nsince [2], but clobbers the top-level \"Makefile\" and builds in the\ntop-level directory.\n\nThat was the reason for why we didn't spot that various tests still\nrequired missing \"mergetools/*\" etc, which was fixed by using\n\"$GIT_SOURCE_DIR\" in a preceding commit.\n\nSince the \"ci/lib.sh\" already creates and exports a\nGIT_TEST_OPTS=\"...\" we'll pick that up in our CI; see the preceding\ncommit. Because we pass the \"--verbose-log -x\n--github-workflow-markup\" in the GitHub CI as a result the interaction\nwith \"handle_failed_tests\" here works correctly. I.e. on failure we'll\nhave saved \"t/test-results/*.{exit,out,markup}\" files relevant to the\nfailing test(s).\n\n1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n2. 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build\n   job, 2020-06-26)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .github/workflows/main.yml |  3 +++\n ci/run-build-and-tests.sh  | 11 +++++++++--\n 2 files changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/.github/workflows/main.yml b/.github/workflows/main.yml\nindex 9afacfa0b33..3657ba66c5e 100644\n--- a/.github/workflows/main.yml\n+++ b/.github/workflows/main.yml\n@@ -236,6 +236,9 @@ jobs:\n             cc: gcc\n             cc_package: gcc-8\n             pool: ubuntu-20.04\n+          - jobname: linux-cmake-ctest\n+            cc: gcc\n+            pool: ubuntu-latest\n           - jobname: osx-clang\n             cc: clang\n             pool: macos-latest\ndiff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh\nindex 8ebff425967..339962bc7c1 100755\n--- a/ci/run-build-and-tests.sh\n+++ b/ci/run-build-and-tests.sh\n@@ -12,6 +12,7 @@ esac\n \n run_tests=t\n \n+mc=\n case \"$jobname\" in\n linux-gcc)\n \texport GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n@@ -43,12 +44,18 @@ pedantic)\n \texport DEVOPTS=pedantic\n \trun_tests=\n \t;;\n+linux-cmake-ctest)\n+\tcb=contrib/buildsystems\n+\tgroup CMake cmake -S \"$cb\" -B \"$cb/out\"\n+\tmc=\"-C $cb/out\"\n+\t;;\n esac\n \n-group Build make\n+group Build make $mc\n+\n if test -n \"$run_tests\"\n then\n-\tgroup \"Run tests\" make test ||\n+\tgroup \"Run tests\" make $mc test ||\n \thandle_failed_tests\n fi\n check_unignored_build_artifacts\n-- \n2.39.0.rc1.1006.gb4c675778ba\n\n"},{"id":"468722","messageId":"b56d6f29-b22f-f64a-82b3-e7217c0e720d@dunelm.org.uk","threadId":"58666","inReplyTo":"cover-v6-00.15-00000000000-20221206T001617Z-avarab@gmail.com","subject":"Re: [PATCH v6 00/15] cmake: document, fix on *nix, add CI","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-12-07T15:09:17Z","receivedAt":"2022-12-07T15:09:26Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Ævar\n\nOn 06/12/2022 02:08, Ævar Arnfjörð Bjarmason wrote:\n> This topic gets our tests from passing ~80% with ctest on *nix to\n> passing 100%.\n> \n> See passing CI job for \"cmake + ctest\" on Ubuntu at:\n> https://github.com/avar/git/actions/runs/3625189647\n> \n> See\n> https://lore.kernel.org/git/cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com/\n> for the v5.\n> \n> Changes since v5:\n> \n> * Typo/grammar etc. fixes noted by Eric.\n> * Phillip reported the \"chmod\" fallback no working on Windows. I\n>    couldn't reproduce that, but running it was always redundant there\n>    we'll now skip doing that on Windows.\n\nI suspect the issue is that \"chmod\" is not in %path% (i.e. $PATH in \nposix shell speak) when CMake is run from visual studio (the mingw stuff \nis only available when running \"sh\" by default to prevent name clashes \nwith the windows find command etc.) but is added to $PATH in the CI \nafter installing the git-for-windows sdk.\n\n> * Adjust 15/15 to fold into an existing \"case\" statement, rather than\n>    adding a new \"if\" statement.\n> \n> For this v6 I experimented with changing the \"win+VS build|test\" job\n> build in \"contrib/buildsystems/out\" rather than at the top-level[1]. I\n> left those changes out here, but doing so makes that a lot simpler, as\n> it no longer needs to rely on the Makefile to tell it what cmake might\n> have built.\n\nLong term I think that is a good direction for the CI job. The CI job is \nnot a good simulation of running CMake from Visual Studio. That does not \nnormally matter but has been a problem for this series. Ideally it would \nrun the test with CTest as well, I'm not sure how much work that would be.\n\n> But even without including that here, those changes should give more\n> confidence in these changes, i.e. they show that our CI's \"msbuild\"\n> doesn't require the \"cmake\" to build things at the top-level.\n> \n> 1. https://github.com/avar/git/tree/avar/cmake-test-path-no-make-for-windows-ci\n> \n> Ævar Arnfjörð Bjarmason (15):\n>    cmake: don't invoke msgfmt with --statistics\n>    cmake: use \"-S\" and \"-B\" to specify source and build directories\n>    cmake: update instructions for portable CMakeLists.txt\n>    cmake: don't copy chainlint.pl to build directory\n>    cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n>    cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n>    cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n>    Makefile + test-lib.sh: don't prefer cmake-built to make-built git\n\nAs far as I can see this changes test-lib.sh to prefer the make-built \ngit if it exists even after running cmake and ctest. Ideally we'd test \nthe most recent build.\n\nBest Wishes\n\nPhillip\n\n>    test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n>    cmake: optionally be able to run tests before \"ctest\"\n>    cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n>    cmake: increase test timeout on Windows only\n>    cmake: only look for \"sh\" in \"C:/Program Files\" on Windows\n>    cmake: copy over git-p4.py for t983[56] perforce test\n>    CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n> \n>   .github/workflows/main.yml          |   3 +\n>   Makefile                            |   1 -\n>   ci/run-build-and-tests.sh           |  11 +-\n>   contrib/buildsystems/CMakeLists.txt | 213 ++++++++++++++++++++++------\n>   t/README                            |   3 +\n>   t/lib-gettext.sh                    |   2 +-\n>   t/lib-gitweb.sh                     |   2 +-\n>   t/t7609-mergetool--lib.sh           |   2 +-\n>   t/t9902-completion.sh               |  14 +-\n>   t/t9903-bash-prompt.sh              |   2 +-\n>   t/test-lib.sh                       |  19 ++-\n>   11 files changed, 211 insertions(+), 61 deletions(-)\n> \n> Range-diff against v5:\n>   1:  7d83ff44c61 !  1:  fc190b379cd cmake: don't invoke msgfmt with --statistics\n>      @@ Metadata\n>        ## Commit message ##\n>           cmake: don't invoke msgfmt with --statistics\n>       \n>      -    In 2f12b31b746 (Makefile: don't invoke msgfmt with --statistics,\n>      -    2021-12-17) I made the same change to our Makefile, let's follow-up\n>      -    and do the same here.\n>      +    In [1] I made the same change to our Makefile, let's follow-up and do\n>      +    the same here.\n>       \n>           For \"cmake\" this is particularly nice with \"-G Ninja\", as before we'd\n>           emit ~40 lines of overflowed progress bar output, but now it's only\n>           the one line of \"ninja\"'s progress bar.\n>       \n>      +    1. 2f12b31b746 (Makefile: don't invoke msgfmt with --statistics,\n>      +       2021-12-17)\n>      +\n>           Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>       \n>        ## contrib/buildsystems/CMakeLists.txt ##\n>   2:  314c5e40cff !  2:  1a11aa233a3 cmake: use \"-S\" and \"-B\" to specify source and build directories\n>      @@ Commit message\n>           The \"-S\" and \"-B\" options were added in cmake v3.13.0, which is older\n>           than the version we have a hard dependency on[1].\n>       \n>      -    As an aside The \"-p\" flag to \"mkdir\" in the pre-image wasn't needed,\n>      +    As an aside, the \"-p\" flag to \"mkdir\" in the pre-image wasn't needed,\n>           as \"contrib/buildsystems\" is tracked\n>       \n>           1. 061c2240b1b (Introduce CMake support for configuring Git, 2020-06-12)\n>   3:  5c4ba2425b6 =  3:  b9ddb5db1d3 cmake: update instructions for portable CMakeLists.txt\n>   4:  e86245ffbab =  4:  7b7850c00ee cmake: don't copy chainlint.pl to build directory\n>   5:  435452314fa !  5:  82ecb797915 cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n>      @@ Commit message\n>       \n>           The remaining failures will be addressed in subsequent commits.\n>       \n>      +    As this isn't needed on Windows let's skip this there. There's also an\n>      +    unconfirmed (it works in CI) report[5] that invoking the \"chmod\"\n>      +    command fails in some scenarios.\n>      +\n>           1. f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)\n>           2. e4597aae659 (run test suite without dashed git-commands in PATH, 2009-12-02)\n>           3. 2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest\n>              runs, 2022-10-18)\n>           4. https://cmake.org/cmake/help/latest/command/file.html#chmod\n>      +    5. https://lore.kernel.org/git/87f22a55-ee84-2f76-7b9b-924a97f44f89@dunelm.org.uk/\n>       \n>           Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>       \n>      @@ contrib/buildsystems/CMakeLists.txt: add_custom_command(OUTPUT ${git_links} ${gi\n>       +function(write_script path content)\n>       +\tfile(WRITE ${path} ${content})\n>       +\n>      -+\tif(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" VERSION_GREATER_EQUAL \"3.19\")\n>      ++\tif(WIN32)\n>      ++\t\tmessage(TRACE \"skipping chmod +x '${path}' on Windows\")\n>      ++\telseif(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" VERSION_GREATER_EQUAL \"3.19\")\n>       +\t\tfile(CHMOD ${path} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)\n>       +\telse()\n>       +\t\texecute_process(COMMAND chmod +x ${path}\n>   6:  7ee341245a8 =  6:  1f326944a07 cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n>   7:  49645cb1643 =  7:  973c8038f54 cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n>   8:  9e10cd5bd8a =  8:  b8448c7a8a6 Makefile + test-lib.sh: don't prefer cmake-built to make-built git\n>   9:  df5aea35bbd !  9:  5135e40969e test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n>      @@ Metadata\n>        ## Commit message ##\n>           test-lib.sh: support a \"GIT_TEST_BUILD_DIR\"\n>       \n>      -    Compliment the existing GIT_TEST_INSTALLED variable added in [1] with\n>      +    Complement the existing GIT_TEST_INSTALLED variable added in [1] with\n>           one that allows for testing a git built in a directory that's not\n>           \"../\".\n>       \n> 10:  529e18f7f72 ! 10:  65204463730 cmake: optionally be able to run tests before \"ctest\"\n>      @@ contrib/buildsystems/CMakeLists.txt: if(USE_VCPKG)\n>       +\tset(GIT_CTEST_SETS_BUILD_DIR \"OFF\" CACHE BOOL GIT_CTEST_SETS_BUILD_DIR_DOC)\n>       +endif()\n>       +if(GIT_CTEST_SETS_BUILD_DIR)\n>      -+\tmessage(STATUS \"Enabling manual runs of t/* tests once ctest writes CMAKE-BUILD-DIR\")\n>      ++\tmessage(STATUS \"Have GIT_CTEST_SETS_BUILD_DIR=ON. Need a 'ctest' run to write GIT-BUILD-DIR\")\n>       +else()\n>      -+\tmessage(STATUS \"Enabling manual runs of t/* tests via cmake build dir discovery\")\n>      ++\tmessage(STATUS \"Have GIT_CTEST_SETS_BUILD_DIR=OFF. Wrote out a GIT-BUILD-DIR, no 'ctest' required\")\n>       +endif()\n>       +\n>       +# When using GIT_CTEST_SETS_BUILD_DIR, running the tests from the \"t/\"\n> 11:  a5dd4fa1d00 ! 11:  e25992b16f1 cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults\n>      @@ contrib/buildsystems/CMakeLists.txt: endif()\n>       +elseif(WIN32)\n>       +\tset(GIT_TEST_OPTS \"--no-bin-wrappers --no-chain-lint -vx\"\n>       +\t\tCACHE STRING \"test options, see t/README\")\n>      -+\tmessage(STATUS \"Using Windowns-specific default test options: ${GIT_TEST_OPTS}\")\n>      ++\tmessage(STATUS \"Using Windows-specific default test options: ${GIT_TEST_OPTS}\")\n>       +else()\n>       +\tset(GIT_TEST_OPTS \"\"\n>       +\t\tCACHE STRING \"test options, see t/README\")\n> 12:  c9d550b8558 = 12:  4905ce5321d cmake: increase test timeout on Windows only\n> 13:  7a5dd684d40 = 13:  6c6b530965d cmake: only look for \"sh\" in \"C:/Program Files\" on Windows\n> 14:  c9c895bb794 = 14:  563f1b9b045 cmake: copy over git-p4.py for t983[56] perforce test\n> 15:  a6f343b6221 ! 15:  917a884eb65 CI: add a \"linux-cmake-test\" to run cmake & ctest on linux\n>      @@ Commit message\n>           To ensure that it doesn't break again let's add a \"linux-cmake-ctest\"\n>           target to build and test \"cmake\" on Linux, in addition to that we'll\n>           also run the tests with \"ctest\" instead of \"make\" or \"prove\", so we\n>      -    can assert that testing with that method works..\n>      +    can assert that testing with that method works.\n>       \n>           This also stress tests running \"cmake\" (and \"ctest\") out of a build\n>           directory that isn't the top-level. The \"vs-build\" job uses \"cmake\"\n>      @@ Commit message\n>           \"$GIT_SOURCE_DIR\" in a preceding commit.\n>       \n>           Since the \"ci/lib.sh\" already creates and exports a\n>      -    GIT_TEST_OPTS=\"...\" we'll pick that up in our CI, see the preceding\n>      +    GIT_TEST_OPTS=\"...\" we'll pick that up in our CI; see the preceding\n>           commit. Because we pass the \"--verbose-log -x\n>           --github-workflow-markup\" in the GitHub CI as a result the interaction\n>           with \"handle_failed_tests\" here works correctly. I.e. on failure we'll\n>      @@ .github/workflows/main.yml: jobs:\n>                    pool: macos-latest\n>       \n>        ## ci/run-build-and-tests.sh ##\n>      -@@ ci/run-build-and-tests.sh: pedantic)\n>      - \t;;\n>      - esac\n>      +@@ ci/run-build-and-tests.sh: esac\n>      +\n>      + run_tests=t\n>        \n>      --group Build make\n>       +mc=\n>      -+if test \"$jobname\" = \"linux-cmake-ctest\"\n>      -+then\n>      + case \"$jobname\" in\n>      + linux-gcc)\n>      + \texport GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n>      +@@ ci/run-build-and-tests.sh: pedantic)\n>      + \texport DEVOPTS=pedantic\n>      + \trun_tests=\n>      + \t;;\n>      ++linux-cmake-ctest)\n>       +\tcb=contrib/buildsystems\n>       +\tgroup CMake cmake -S \"$cb\" -B \"$cb/out\"\n>       +\tmc=\"-C $cb/out\"\n>      -+fi\n>      -+\n>      ++\t;;\n>      + esac\n>      +\n>      +-group Build make\n>       +group Build make $mc\n>       +\n>        if test -n \"$run_tests\"\n"},{"id":"468759","messageId":"221208.865yem91ya.gmgdl@evledraar.gmail.com","threadId":"58666","inReplyTo":"b56d6f29-b22f-f64a-82b3-e7217c0e720d@dunelm.org.uk","subject":"Re: [PATCH v6 00/15] cmake: document, fix on *nix, add CI","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-08T00:06:07Z","receivedAt":"2022-12-08T00:25:07Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Wed, Dec 07 2022, Phillip Wood wrote:\n\n> Hi Ævar\n>\n> On 06/12/2022 02:08, Ævar Arnfjörð Bjarmason wrote:\n>> This topic gets our tests from passing ~80% with ctest on *nix to\n>> passing 100%.\n>> See passing CI job for \"cmake + ctest\" on Ubuntu at:\n>> https://github.com/avar/git/actions/runs/3625189647\n>> See\n>> https://lore.kernel.org/git/cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com/\n>> for the v5.\n>> Changes since v5:\n>> * Typo/grammar etc. fixes noted by Eric.\n>> * Phillip reported the \"chmod\" fallback no working on Windows. I\n>>    couldn't reproduce that, but running it was always redundant there\n>>    we'll now skip doing that on Windows.\n>\n> I suspect the issue is that \"chmod\" is not in %path% (i.e. $PATH in\n> posix shell speak) when CMake is run from visual studio (the mingw\n> stuff is only available when running \"sh\" by default to prevent name\n> clashes with the windows find command etc.) but is added to $PATH in\n> the CI after installing the git-for-windows sdk.\n\nMaybe, presumably the \"sh\" then sets the $PATH, because we do run\nshellscripts at the top-level that expect to find the binutils,\ne.g. \"sed\" and the like, which presumably are in the same location as\n\"chmod\".\n\nBut in any case this v6 avoids the issue entirely.\n\n>> * Adjust 15/15 to fold into an existing \"case\" statement, rather than\n>>    adding a new \"if\" statement.\n>> For this v6 I experimented with changing the \"win+VS build|test\" job\n>> build in \"contrib/buildsystems/out\" rather than at the top-level[1]. I\n>> left those changes out here, but doing so makes that a lot simpler, as\n>> it no longer needs to rely on the Makefile to tell it what cmake might\n>> have built.\n>\n> Long term I think that is a good direction for the CI job. The CI job\n> is not a good simulation of running CMake from Visual Studio.\n\nYes, I just didn't want to make this series even larger, but I can\nsubmit that after.\n\n> That does not normally matter but has been a problem for this\n> series. Ideally it would run the test with CTest as well, I'm not sure\n> how much work that would be.\n\nIn principle trivial, I did try, but it seems the Windows image doesn't\nhave \"ctest\", but does have \"cmake\" (unlike the Ubuntu image).\n\n(Or come to think of it, maybe it does and I tried \"ctest\" and not\n\"ctest.exe\". I can't remember)\n\nOther than that it should just work, and the \"linux-cmake-ctest\" CI job\nadded by this series already does a run with \"ctest\".\n\n>> But even without including that here, those changes should give more\n>> confidence in these changes, i.e. they show that our CI's \"msbuild\"\n>> doesn't require the \"cmake\" to build things at the top-level.\n>> 1. https://github.com/avar/git/tree/avar/cmake-test-path-no-make-for-windows-ci\n>> Ævar Arnfjörð Bjarmason (15):\n>>    cmake: don't invoke msgfmt with --statistics\n>>    cmake: use \"-S\" and \"-B\" to specify source and build directories\n>>    cmake: update instructions for portable CMakeLists.txt\n>>    cmake: don't copy chainlint.pl to build directory\n>>    cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4\n>>    cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable\n>>    cmake: set \"USE_LIBPCRE2\" in \"GIT-BUILD-OPTIONS\" for test-lib.sh\n>>    Makefile + test-lib.sh: don't prefer cmake-built to make-built git\n>\n> As far as I can see this changes test-lib.sh to prefer the make-built\n> git if it exists even after running cmake and ctest. Ideally we'd test \n> the most recent build.\n\nIdeally, but as summarized in the v5 CL this already isn't the case on\n\"master\". I.e. you can e.g. build with cmake, then \"make git\", then your\ntests will use the cmake (older) git, not your newly built one with\n\"make\".\n\nI think the only sane state of affairs here is what this series changes\nit to.\n\nIf we have a top-level \"git\" we should always prefer it, as \"make\" is\nour primary build system, and it would be impractical to plug all the\ngaps and intercept the \"latest git\" in all places.\n\nBut more importantly, isn't this concern entirely academic?\n\nWe can imagine scenarios where you build with both, but the VS users\nthat are the primary audience of the cmake recipe aren't going to also\nbuild with \"make\", they're just building with \"cmake\" and \"msbuild\".\n\nSo I don't think this will impact anyone in practice.\n\nEven you have both a \"make\" and \"cmake\" build in play the \"make test\"\nand \"ctest\" will always select the \"make\" and \"cmake\" built one,\nrespectively.\n\nThe only case where we need to pick one is if you run a test manually by\ncd-ing to \"t\" and invoking a shellscript.\n\nYou also brought up a concern about multiple builds in\ncontrib/buildsystems/ in a previous iteration. With the way this series\nleaves it that'll actually work in some sensible way. I.e. your \"ctest\"\nrun for a \"prod\" build run won't switch to a new git that you built\nmidway through the run, as it would on \"master\".\n\n"}]}