Since I started using meson regularly, I have put the build directory
under the source directory, which appears to be the recommended
convention. See for example
https://mesonbuild.com/Quick-guide.html#compiling-a-meson-project
Then, if I also want to create a build directory using configure/make in
parallel to that (for example, to test the makefiles, if adding new
source files), then prep_buildtree is a bit stupid about that. It
processes all directories under the top-level source directory,
including existing other build trees, and so it makes a copy of existing
build trees under the new build tree. This isn't actually harmful, but
it seems pretty stupid, and it also makes prep_buildtree slower and
slower the more build trees you have.
I have never been much of a vpath user before meson, so I don't have
much experience with it, but I suspect that it was previously the
convention to have the build tree outside of the source tree, in which
case this wouldn't have been a problem.
To fix this, I first tried to devise a way to detect whether a given
directory is a build directory. But that seemed pretty complicated.
Instead, I chose the simpler solution that we just enumerate the source
subdirectories that we know about (config, contrib, doc, src). That way
we can also remove the special handling to exclude the .git directory
and make the find command a bit simpler.
See the attached patch.
Maybe people can try this with their local workflows to make sure it
still works for them, but I don't expect any particular problems, other
than perhaps some shell or find command portability issues. Note, this
only runs if you do a vpath configure/make build, not an in-tree
configure/make build, and of course not if you use meson.
From b9800a40d4f6e8c9339fd2ef91d058a1196ebc51 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 9 Jul 2025 15:45:01 +0200
Subject: [PATCH] Improve prep_buildtree
When prep_buildtree is used to prepare a build tree when the source
directory already contains another build tree, then it will produce
the directory structure of the first build tree in the second one.
For example, if there is
postgresql/
postgresql/build1/
and a new build tree postgresql/build2/ is prepared, then this will
produce
postgresql/build2/build1/
because it just copies all subdirectories of the source tree. This is
not harmful, but it's pretty stupid and can be confusing, and it slows
down prep_buildtree when there are many build trees.
When prep_buildtree was first created, it was more common for the
build tree to be outside the source tree, in which case this is not a
problem. But now with the arrival of meson, it appears to be more
common (and also the way it is documented in the PostgreSQL
documentation) to have the build tree inside the source tree. (To be
clear: This change does not affect meson at all. But it would be an
issue for example if you have a meson build tree and a configure build
tree under the same source tree.)
To fix this, change the "find" command to process only those top-level
directories that we know about (namely config, contrib, doc, src). (I
alternatively looked for ways to ignore directories that looked like
build directories, but that seemed extremely complicated.) With that,
we can also remove the code that ignores directories related to
source-control management.
In passing, also remove the workaround for handling prebuilt docs,
since that has been obsolete since commit 54fac0e5050.
---
config/prep_buildtree | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/config/prep_buildtree b/config/prep_buildtree
index a0eabd3dee2..509553fdac8 100644
--- a/config/prep_buildtree
+++ b/config/prep_buildtree
@@ -22,18 +22,14 @@ sourcetree=`cd $1 && pwd`
buildtree=`cd ${2:-'.'} && pwd`
-# We must not auto-create the subdirectories holding built documentation.
-# If we did, it would interfere with installation of prebuilt docs from
-# the source tree, if a VPATH build is done from a distribution tarball.
-# See bug #5595.
-for item in `find "$sourcetree" -type d \( \( -name CVS -prune \) -o \( -name
.git -prune \) -o -print \) | grep -v "$sourcetree/doc/src/sgml/\+"`; do
+for item in `find "$sourcetree"/config "$sourcetree"/contrib "$sourcetree"/doc
"$sourcetree"/src -type d -print`; do
subdir=`expr "$item" : "$sourcetree\(.*\)"`
if test ! -d "$buildtree/$subdir"; then
mkdir -p "$buildtree/$subdir" || exit 1
fi
done
-for item in `find "$sourcetree" -name Makefile -print -o -name GNUmakefile
-print | grep -v "$sourcetree/doc/src/sgml/images/"`; do
+for item in `find "$sourcetree"/config "$sourcetree"/contrib "$sourcetree"/doc
"$sourcetree"/src -name Makefile -print -o -name GNUmakefile -print`; do
filename=`expr "$item" : "$sourcetree\(.*\)"`
if test ! -f "${item}.in"; then
if cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then : ; else
--
2.50.1