git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Phillip Wood" <phillip.wood123@gmail.com>,
	"Victoria Dye" <vdye@github.com>,
	"Eric Sunshine" <ericsunshine@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v5 11/15] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults
Date: Fri,  2 Dec 2022 12:28:32 +0100	[thread overview]
Message-ID: <patch-v5-11.15-a5dd4fa1d00-20221202T110947Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v5-00.15-00000000000-20221202T110947Z-avarab@gmail.com>

The rationale for adding "--no-bin-wrappers" and "--no-chain-lint" in
2ea1d8b5563 (cmake: make it easier to diagnose regressions in CTest
runs, 2022-10-18) was those options slowed down the tests considerably
on Windows.

But since f31b6244950 (Merge branch 'yw/cmake-updates', 2022-06-07)
and with the preceding commits cmake and ctest are not
Windows-specific anymore.

So let's set those same options by default on Windows, but do so with
the set(... CACHE <type> <docstring>) facility. As noted in cmake's
documentation[1] this integrates nicely with e.g. cmake-gui.

On *nix we don't set any custom options. The change in 2ea1d8b5563
didn't discuss why Windows should have divergent defaults with "cmake"
and "make", but such reasons presumably don't apply on *nix. I for one
am happy with the same defaults as the tests have when running via the
Makefile.

With the "message()" addition we'll emit this when running cmake:

	Generating hook-list.h
	-- Using user-selected test options: -vixd
	-- Configuring done
	-- Generating done
	-- Build files have been written to: /home/avar/g/git/contrib/buildsystems/out

Unfortunately cmake doesn't support a non-hacky way to pass variables
to ctest without re-running cmake itself, so when re-running tests via
cmake and wanting to change the test defaults we'll need:

	GIT_TEST_OPTS=-i cmake -S contrib/buildsystems -B contrib/buildsystems/out &&
	ctest --jobs=$(nproc) --test-dir contrib/buildsystems/out -R t0071 --verbose

The "separate_arguments()" here will do the right thing for arguments
that don't contain whitespace, so e.g. the path to --root="" can't
have a space in it. There's supposedly a way to work around that with
separate_arguments(), but it requires features newer than our required
cmake version, so let's live with that edge case for now.

1. https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 contrib/buildsystems/CMakeLists.txt | 50 +++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 2 deletions(-)

diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index 866bdc1914a..cfe8126d939 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -32,7 +32,7 @@ To use this in Visual Studio:
 
 Open the worktree as a folder. Visual Studio 2019 and later will detect
 the CMake configuration automatically and set everything up for you,
-ready to build. You can then run the tests in `t/` via a regular Git Bash.
+ready to build. See "== Running the tests ==" below for running the tests.
 
 Note: Visual Studio also has the option of opening `CMakeLists.txt`
 directly; Using this option, Visual Studio will not find the source code,
@@ -76,6 +76,37 @@ empty(default) :
 
 NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio
 this option is ignored
+
+== Running the tests ==
+
+Once we've built in "contrib/buildsystems/out" the tests can be run at
+the top-level (note: not the generated "contrib/buildsystems/out/t/"
+drectory). If no top-level build is found (as created with the
+Makefile) the t/test-lib.sh will discover the git in
+"contrib/buildsystems/out" on e.g.:
+
+	(cd t && ./t0001-init.sh)
+	setup: had no ../git, but found & used cmake built git in ../contrib/buildsystems/out/git
+	[...]
+
+The tests can also be run with ctest, e.g. after building with "cmake"
+and "make" or "msbuild" run, from the top-level e.g.:
+
+	# "--test-dir" is new in cmake v3.20, so "(cd
+	# contrib/buildsystems/out && ctest ...)" on older versions.
+	ctest --test-dir contrib/buildsystems/out --jobs="$(nproc)"--output-on-failure
+
+Options can be passed by setting GIT_TEST_OPTIONS before invoking
+cmake. E.g. on a Linux system with systemd the tests can be sped up by
+using a ramdisk for the scratch files:
+
+	GIT_TEST_OPTS="--root=/dev/shm/$(id -u)/ctest" cmake -S contrib/buildsystems -B contrib/buildsystems/out
+	[...]
+	-- Using user-selected test options: --root=/dev/shm/<uid>/ctest
+
+Then running the tests with "ctest" (here with --jobs="$(nproc)"):
+
+	ctest --jobs=$(nproc) --test-dir contrib/buildsystems/out
 ]]
 cmake_minimum_required(VERSION 3.14)
 
@@ -1146,10 +1177,25 @@ endif()
 
 file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
 
+if(DEFINED ENV{GIT_TEST_OPTS})
+	set(GIT_TEST_OPTS "$ENV{GIT_TEST_OPTS}"
+		CACHE STRING "test options, see t/README")
+	message(STATUS "Using user-selected test options: ${GIT_TEST_OPTS}")
+elseif(WIN32)
+	set(GIT_TEST_OPTS "--no-bin-wrappers --no-chain-lint -vx"
+		CACHE STRING "test options, see t/README")
+	message(STATUS "Using Windowns-specific default test options: ${GIT_TEST_OPTS}")
+else()
+	set(GIT_TEST_OPTS ""
+		CACHE STRING "test options, see t/README")
+	message(STATUS "No custom test options selected, set e.g. GIT_TEST_OPTS=\"-vixd\"")
+endif()
+separate_arguments(GIT_TEST_OPTS)
+
 #test
 foreach(tsh ${test_scipts})
 	add_test(NAME ${tsh}
-		COMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx
+		COMMAND ${SH_EXE} ${tsh} ${GIT_TEST_OPTS}
 		WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)
 if(NOT GIT_CTEST_SETS_BUILD_DIR)
 	set_property(TEST ${tsh} APPEND PROPERTY ENVIRONMENT
-- 
2.39.0.rc1.981.gf846af54b4b


  parent reply	other threads:[~2022-12-02 11:30 UTC|newest]

Thread overview: 113+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21  9:44 [PATCH 0/9] cmake: fix *nix & general issues, no test-lib.sh editing, ctest in CI Ævar Arnfjörð Bjarmason
2022-10-21  9:44 ` [PATCH 1/9] cmake: don't copy chainlint.pl to build directory Ævar Arnfjörð Bjarmason
2022-10-21  9:44 ` [PATCH 2/9] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4 Ævar Arnfjörð Bjarmason
2022-10-21 14:18   ` Phillip Wood
2022-10-21 14:43     ` Ævar Arnfjörð Bjarmason
2022-10-21  9:44 ` [PATCH 3/9] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable Ævar Arnfjörð Bjarmason
2022-10-21  9:44 ` [PATCH 4/9] cmake: set "USE_LIBPCRE2" in "GIT-BUILD-OPTIONS" for test-lib.sh Ævar Arnfjörð Bjarmason
2022-10-21  9:44 ` [PATCH 5/9] test-lib.sh: support a "GIT_TEST_BUILD_DIR" Ævar Arnfjörð Bjarmason
2022-10-21  9:44 ` [PATCH 6/9] cmake: use GIT_TEST_BUILD_DIR instead of editing hack Ævar Arnfjörð Bjarmason
2022-10-21 14:18   ` Phillip Wood
2022-10-21 14:43     ` Ævar Arnfjörð Bjarmason
2022-10-25 13:29       ` Phillip Wood
2022-10-21  9:44 ` [PATCH 7/9] cmake: support using GIT_TEST_OPTS from the environment Ævar Arnfjörð Bjarmason
2022-10-21 14:18   ` Phillip Wood
2022-10-21 15:45     ` Ævar Arnfjörð Bjarmason
2022-10-25 13:38       ` Phillip Wood
2022-10-25 20:18         ` Ævar Arnfjörð Bjarmason
2022-10-21  9:44 ` [PATCH 8/9] cmake: copy over git-p4.py for t983[56] perforce test Ævar Arnfjörð Bjarmason
2022-10-21  9:44 ` [PATCH 9/9] CI: add a "linux-cmake-test" to run cmake & ctest on linux Ævar Arnfjörð Bjarmason
2022-10-21 10:29 ` [PATCH 0/9] cmake: fix *nix & general issues, no test-lib.sh editing, ctest in CI Johannes Schindelin
2022-10-21 14:27 ` Phillip Wood
2022-10-21 15:55   ` Ævar Arnfjörð Bjarmason
2022-10-25 13:22     ` Phillip Wood
2022-10-27  3:26 ` [PATCH v2 00/11] cmake: document, fix on *nix, add CI Ævar Arnfjörð Bjarmason
2022-10-27  3:26   ` [PATCH v2 01/11] cmake: don't "mkdir -p" and "cd" in build instructions Ævar Arnfjörð Bjarmason
2022-10-27  3:26   ` [PATCH v2 02/11] cmake: update instructions for portable CMakeLists.txt Ævar Arnfjörð Bjarmason
2022-10-27  3:35     ` Eric Sunshine
2022-10-27  3:26   ` [PATCH v2 03/11] cmake: don't copy chainlint.pl to build directory Ævar Arnfjörð Bjarmason
2022-10-27  3:26   ` [PATCH v2 04/11] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4 Ævar Arnfjörð Bjarmason
2022-10-27  3:26   ` [PATCH v2 05/11] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable Ævar Arnfjörð Bjarmason
2022-10-27  3:26   ` [PATCH v2 06/11] cmake: set "USE_LIBPCRE2" in "GIT-BUILD-OPTIONS" for test-lib.sh Ævar Arnfjörð Bjarmason
2022-10-27  3:26   ` [PATCH v2 07/11] test-lib.sh: support a "GIT_TEST_BUILD_DIR" Ævar Arnfjörð Bjarmason
2022-10-27  3:26   ` [PATCH v2 08/11] Makefile + cmake: use environment, not GIT-BUILD-DIR Ævar Arnfjörð Bjarmason
2022-10-27  3:26   ` [PATCH v2 09/11] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults Ævar Arnfjörð Bjarmason
2022-10-27  3:26   ` [PATCH v2 10/11] cmake: copy over git-p4.py for t983[56] perforce test Ævar Arnfjörð Bjarmason
2022-10-27  3:26   ` [PATCH v2 11/11] CI: add a "linux-cmake-test" to run cmake & ctest on linux Ævar Arnfjörð Bjarmason
2022-11-01 22:51   ` [PATCH v3 00/12] cmake: document, fix on *nix, add CI Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 01/12] cmake: don't "mkdir -p" and "cd" in build instructions Ævar Arnfjörð Bjarmason
2022-11-03  9:37       ` Phillip Wood
2022-11-01 22:51     ` [PATCH v3 02/12] cmake: update instructions for portable CMakeLists.txt Ævar Arnfjörð Bjarmason
2022-11-01 22:58       ` Eric Sunshine
2022-11-03  9:42       ` Phillip Wood
2022-11-03 16:00         ` Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 03/12] cmake: don't copy chainlint.pl to build directory Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 04/12] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4 Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 05/12] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 06/12] cmake: set "USE_LIBPCRE2" in "GIT-BUILD-OPTIONS" for test-lib.sh Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 07/12] test-lib.sh: support a "GIT_TEST_BUILD_DIR" Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 08/12] Makefile + cmake: use environment, not GIT-BUILD-DIR Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 09/12] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults Ævar Arnfjörð Bjarmason
2022-11-03 10:03       ` Phillip Wood
2022-11-03 15:43         ` Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 10/12] cmake: increase test timeout on Windows only Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 11/12] cmake: copy over git-p4.py for t983[56] perforce test Ævar Arnfjörð Bjarmason
2022-11-01 22:51     ` [PATCH v3 12/12] CI: add a "linux-cmake-test" to run cmake & ctest on linux Ævar Arnfjörð Bjarmason
2022-11-03 16:37     ` [PATCH v4 00/14] cmake: document, fix on *nix, add CI Ævar Arnfjörð Bjarmason
2022-11-03 16:37       ` [PATCH v4 01/14] cmake: don't invoke msgfmt with --statistics Ævar Arnfjörð Bjarmason
2022-11-03 16:37       ` [PATCH v4 02/14] cmake: use "-S" and "-B" to specify source and build directories Ævar Arnfjörð Bjarmason
2022-11-03 16:37       ` [PATCH v4 03/14] cmake: update instructions for portable CMakeLists.txt Ævar Arnfjörð Bjarmason
2022-11-03 16:37       ` [PATCH v4 04/14] cmake: don't copy chainlint.pl to build directory Ævar Arnfjörð Bjarmason
2022-11-03 16:37       ` [PATCH v4 05/14] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4 Ævar Arnfjörð Bjarmason
2022-11-03 16:37       ` [PATCH v4 06/14] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable Ævar Arnfjörð Bjarmason
2022-11-03 16:37       ` [PATCH v4 07/14] cmake: set "USE_LIBPCRE2" in "GIT-BUILD-OPTIONS" for test-lib.sh Ævar Arnfjörð Bjarmason
2022-11-03 16:37       ` [PATCH v4 08/14] test-lib.sh: support a "GIT_TEST_BUILD_DIR" Ævar Arnfjörð Bjarmason
2022-11-03 16:37       ` [PATCH v4 09/14] Makefile + cmake: use environment, not GIT-BUILD-DIR Ævar Arnfjörð Bjarmason
2022-11-03 16:38       ` [PATCH v4 10/14] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults Ævar Arnfjörð Bjarmason
2022-11-03 16:38       ` [PATCH v4 11/14] cmake: increase test timeout on Windows only Ævar Arnfjörð Bjarmason
2022-11-03 16:38       ` [PATCH v4 12/14] cmake: only look for "sh" in "C:/Program Files" on Windows Ævar Arnfjörð Bjarmason
2022-11-03 16:38       ` [PATCH v4 13/14] cmake: copy over git-p4.py for t983[56] perforce test Ævar Arnfjörð Bjarmason
2022-11-03 16:38       ` [PATCH v4 14/14] CI: add a "linux-cmake-test" to run cmake & ctest on linux Ævar Arnfjörð Bjarmason
2022-11-05  0:27       ` [PATCH v4 00/14] cmake: document, fix on *nix, add CI Taylor Blau
2022-11-08 14:42       ` Phillip Wood
2022-12-02 11:28       ` [PATCH v5 00/15] " Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 01/15] cmake: don't invoke msgfmt with --statistics Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 02/15] cmake: use "-S" and "-B" to specify source and build directories Ævar Arnfjörð Bjarmason
2022-12-03  5:14           ` Eric Sunshine
2022-12-02 11:28         ` [PATCH v5 03/15] cmake: update instructions for portable CMakeLists.txt Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 04/15] cmake: don't copy chainlint.pl to build directory Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 05/15] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4 Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 06/15] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 07/15] cmake: set "USE_LIBPCRE2" in "GIT-BUILD-OPTIONS" for test-lib.sh Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 08/15] Makefile + test-lib.sh: don't prefer cmake-built to make-built git Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 09/15] test-lib.sh: support a "GIT_TEST_BUILD_DIR" Ævar Arnfjörð Bjarmason
2022-12-03  5:22           ` Eric Sunshine
2022-12-02 11:28         ` [PATCH v5 10/15] cmake: optionally be able to run tests before "ctest" Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` Ævar Arnfjörð Bjarmason [this message]
2022-12-03  5:38           ` [PATCH v5 11/15] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults Eric Sunshine
2022-12-03 13:10             ` Ævar Arnfjörð Bjarmason
2022-12-03 16:58               ` Eric Sunshine
2022-12-02 11:28         ` [PATCH v5 12/15] cmake: increase test timeout on Windows only Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 13/15] cmake: only look for "sh" in "C:/Program Files" on Windows Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 14/15] cmake: copy over git-p4.py for t983[56] perforce test Ævar Arnfjörð Bjarmason
2022-12-02 11:28         ` [PATCH v5 15/15] CI: add a "linux-cmake-test" to run cmake & ctest on linux Ævar Arnfjörð Bjarmason
2022-12-03  5:47           ` Eric Sunshine
2022-12-06  2:08         ` [PATCH v6 00/15] cmake: document, fix on *nix, add CI Ævar Arnfjörð Bjarmason
2022-12-06  2:08           ` [PATCH v6 01/15] cmake: don't invoke msgfmt with --statistics Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 02/15] cmake: use "-S" and "-B" to specify source and build directories Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 03/15] cmake: update instructions for portable CMakeLists.txt Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 04/15] cmake: don't copy chainlint.pl to build directory Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 05/15] cmake: chmod +x the bin-wrappers/* & SCRIPT_{SH,PERL} & git-p4 Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 06/15] cmake & test-lib.sh: add a $GIT_SOURCE_DIR variable Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 07/15] cmake: set "USE_LIBPCRE2" in "GIT-BUILD-OPTIONS" for test-lib.sh Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 08/15] Makefile + test-lib.sh: don't prefer cmake-built to make-built git Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 09/15] test-lib.sh: support a "GIT_TEST_BUILD_DIR" Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 10/15] cmake: optionally be able to run tests before "ctest" Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 11/15] cmake: support GIT_TEST_OPTS, abstract away WIN32 defaults Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 12/15] cmake: increase test timeout on Windows only Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 13/15] cmake: only look for "sh" in "C:/Program Files" on Windows Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 14/15] cmake: copy over git-p4.py for t983[56] perforce test Ævar Arnfjörð Bjarmason
2022-12-06  2:09           ` [PATCH v6 15/15] CI: add a "linux-cmake-test" to run cmake & ctest on linux Ævar Arnfjörð Bjarmason
2022-12-07 15:09           ` [PATCH v6 00/15] cmake: document, fix on *nix, add CI Phillip Wood
2022-12-08  0:06             ` Ævar Arnfjörð Bjarmason
2022-11-03  9:34   ` [PATCH v2 00/11] " Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=patch-v5-11.15-a5dd4fa1d00-20221202T110947Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=ericsunshine@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood123@gmail.com \
    --cc=vdye@github.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).