Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b524e3c

Browse files
JelteFCommitfest Bot
authored andcommitted
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).
1 parent 8dca943 commit b524e3c

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

src/tools/pgindent/pgindent

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,33 @@ usage("Cannot use --commit with command line file list")
8383
# dir, then default location
8484
$typedefs_file ||= $ENV{PGTYPEDEFS};
8585

86-
# get indent location for environment or default
87-
$indent ||= $ENV{PGINDENT} || $ENV{INDENT} || "pg_bsd_indent";
88-
8986
my $sourcedir = locate_sourcedir();
9087

88+
# get indent location: command line wins, then environment, then try to find
89+
# a compiled pg_bsd_indent in the source tree, then fall back to PATH.
90+
$indent ||= $ENV{PGINDENT} || $ENV{INDENT};
91+
if (!$indent && $sourcedir)
92+
{
93+
my $srcroot = "$sourcedir/../../..";
94+
my $bsd_indent_subdir = "src/tools/pg_bsd_indent/pg_bsd_indent";
95+
96+
# Look for pg_bsd_indent: first in-tree (autoconf in-tree build),
97+
# then in a "build" directory (meson or autoconf vpath),
98+
# then any "build*" directory.
99+
foreach my $candidate (
100+
"$srcroot/$bsd_indent_subdir",
101+
"$srcroot/build/$bsd_indent_subdir",
102+
glob("$srcroot/build*/$bsd_indent_subdir"))
103+
{
104+
if (-x $candidate)
105+
{
106+
$indent = $candidate;
107+
last;
108+
}
109+
}
110+
}
111+
$indent ||= "pg_bsd_indent";
112+
91113
# if it's the base of a postgres tree, we will exclude the files
92114
# postgres wants excluded
93115
if ($sourcedir)

0 commit comments

Comments
 (0)