From 87e05a46fba366e03df6c8b1fe7bd2b0a1ef560a Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio Date: Tue, 3 Mar 2026 23:46:52 +0100 Subject: [PATCH v2 2/7] pgindent: Try to find pg_bsd_indent binary in common locations To run pgindent you need to to have the right version of pg_bsd_indent in your PATH, or specify it manually. This is a bit of a hassle, especially for newcomers or when working on backbranches. So this chnages pgindent to search for a pg_bsd_indent that's built from the current sources, both in-tree (for in-tree autoconf builds) and in a build directory (for meson or autoconf vpath builds). --- src/tools/pgindent/pgindent | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent index ccc5db4b205..6570726381c 100755 --- a/src/tools/pgindent/pgindent +++ b/src/tools/pgindent/pgindent @@ -56,11 +56,34 @@ usage("Cannot use --commit with command line file list") # dir, then default location $typedefs_file ||= $ENV{PGTYPEDEFS}; -# get indent location for environment or default -$indent ||= $ENV{PGINDENT} || $ENV{INDENT} || "pg_bsd_indent"; - my $sourcedir = locate_sourcedir(); +# get indent location: command line wins, then environment, then try to find +# a compiled pg_bsd_indent in the source tree, then fall back to PATH. +$indent ||= $ENV{PGINDENT} || $ENV{INDENT}; +if (!$indent && $sourcedir) +{ + my $srcroot = "$sourcedir/../../.."; + my $bsd_indent_subdir = "src/tools/pg_bsd_indent/pg_bsd_indent"; + + # Look for pg_bsd_indent: first in-tree (autoconf in-tree build), + # then in a "build" directory (meson or autoconf vpath), + # then any "build*" directory. + foreach my $candidate ( + "$srcroot/$bsd_indent_subdir", + glob("$srcroot/build/$bsd_indent_subdir"), + glob("$srcroot/build*/$bsd_indent_subdir")) + { + if (-x $candidate) + { + $indent = $candidate; + last; + } + } +} +$indent ||= "pg_bsd_indent"; + + # if it's the base of a postgres tree, we will exclude the files # postgres wants excluded if ($sourcedir) -- 2.53.0