diff mbox series

[RFC,20/21] t: allow overriding build dir

Message ID c5ae59ce905512aaf4d02d744da90eea982eb065.1727881164.git.ps@pks.im (mailing list archive)
State Superseded
Headers show
Series Modernize the build system | expand

Commit Message

Patrick Steinhardt Oct. 2, 2024, 3:16 p.m. UTC
Our "test-lib.sh" assumes that our build directory is the parent
directory of "t/". While true when using our Makefile, it's not when
using build systems that support out-of-tree builds.

Allow such build systems to override the location of the build directory
with an environment variable.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/test-lib.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Phillip Wood Oct. 8, 2024, 2:04 p.m. UTC | #1
Hi Patrick

On 02/10/2024 16:16, Patrick Steinhardt wrote:
> Our "test-lib.sh" assumes that our build directory is the parent
> directory of "t/". While true when using our Makefile, it's not when
> using build systems that support out-of-tree builds.
> 
> Allow such build systems to override the location of the build directory
> with an environment variable.

ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18) added 
support for reading the "real" build directory from 
"$GIT_BUILD_DIR/GIT-BUILD-DIR". Using an environment variable is fine 
when running the tests from the build system but it is a pain to have to 
set it when running them manually.

Best Wishes

Phillip

> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>   t/test-lib.sh | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index e36a21ddf7..6f862621af 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -35,7 +35,7 @@ else
>   	# needing to exist.
>   	TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1
>   fi
> -GIT_BUILD_DIR="${TEST_DIRECTORY%/t}"
> +GIT_BUILD_DIR="${GIT_BUILD_DIR:-${TEST_DIRECTORY%/t}}"
>   if test "$TEST_DIRECTORY" = "$GIT_BUILD_DIR"
>   then
>   	echo "PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?" >&2
> @@ -514,6 +514,7 @@ unset VISUAL EMAIL LANGUAGE $("$PERL_PATH" -e '
>   		PERF_
>   		CURL_VERBOSE
>   		TRACE_CURL
> +		BUILD_DIR
>   	));
>   	my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
>   	print join("\n", @vars);
Patrick Steinhardt Oct. 8, 2024, 2:23 p.m. UTC | #2
On Tue, Oct 08, 2024 at 03:04:33PM +0100, Phillip Wood wrote:
> Hi Patrick
> 
> On 02/10/2024 16:16, Patrick Steinhardt wrote:
> > Our "test-lib.sh" assumes that our build directory is the parent
> > directory of "t/". While true when using our Makefile, it's not when
> > using build systems that support out-of-tree builds.
> > 
> > Allow such build systems to override the location of the build directory
> > with an environment variable.
> 
> ee9e66e4e76 (cmake: avoid editing t/test-lib.sh, 2022-10-18) added support
> for reading the "real" build directory from "$GIT_BUILD_DIR/GIT-BUILD-DIR".
> Using an environment variable is fine when running the tests from the build
> system but it is a pain to have to set it when running them manually.

That doesn't quite solve the problem though, because "$GIT_BUILD_DIR"
points to the _source_ directory as noted in the mentioned commit. So
the resulting build is still not fully self-contained. So I don't
currently see another way than to introduce a separate environment
variable.

Patrick
diff mbox series

Patch

diff --git a/t/test-lib.sh b/t/test-lib.sh
index e36a21ddf7..6f862621af 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -35,7 +35,7 @@  else
 	# needing to exist.
 	TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1
 fi
-GIT_BUILD_DIR="${TEST_DIRECTORY%/t}"
+GIT_BUILD_DIR="${GIT_BUILD_DIR:-${TEST_DIRECTORY%/t}}"
 if test "$TEST_DIRECTORY" = "$GIT_BUILD_DIR"
 then
 	echo "PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?" >&2
@@ -514,6 +514,7 @@  unset VISUAL EMAIL LANGUAGE $("$PERL_PATH" -e '
 		PERF_
 		CURL_VERBOSE
 		TRACE_CURL
+		BUILD_DIR
 	));
 	my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
 	print join("\n", @vars);