Hi, On 2023-05-25 13:05:57 -0400, Tom Lane wrote: > Andres Freund <and...@anarazel.de> writes: > > On 2023-05-25 09:09:45 -0400, Tom Lane wrote: > >> Peter Eisentraut <pe...@eisentraut.org> writes: > >>> Why does pgindent require that pg_bsd_indent be installed in the path? > > > Isn't the situation actually *easier* in VPATH builds? There's no build > > artifacts in the source tree, so you can just invoke the pg_bsd_indent built > > in the build directory against the source tree, without any problems? > > Well, if you know where the build directory is, sure.
I'm imaginging adding make / meson targets 'indent-tree' and 'indent-head' or such. Obviously the buildsystem knows where the source dir is, and you'd invoke it in the build dir, so it'd know all that'd need to be known. Attached is a prototype adding such meson targets. It's easier with a parameter telling pgindent where the source tree is, so I addeded that too (likely would need to be cleaned up some). > Since pg_bsd_indent > changes so seldom, keeping it in your PATH is at least as easy as any > other solution, IMO. > > Another reason why I like to do it that way is that it supports running > pgindent on files that aren't in the source tree at all, which suits > some old habits of mine. > But, as I said before, I'm open to adding support for other scenarios > as long as we don't remove that one. I can't imagine that we'd remove support for doing so... Greetings, Andres Freund
>From 2ae58700a37a0a9f1c5cad527e89bd00fc586858 Mon Sep 17 00:00:00 2001 From: Andres Freund <and...@anarazel.de> Date: Sat, 27 May 2023 11:38:27 -0700 Subject: [PATCH v1] add meson target to run pgindent Author: Reviewed-By: Discussion: https://postgr.es/m/ Backpatch: --- meson.build | 12 ++++++++++++ src/tools/pgindent/pgindent | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 16b2e866462..1c7ed9c87f9 100644 --- a/meson.build +++ b/meson.build @@ -3005,7 +3005,19 @@ run_target('install-test-files', depends: testprep_targets, ) +indent_base = [perl, files('src/tools/pgindent/pgindent'), + '--indent', pg_bsd_indent.full_path(), + '--sourcetree=@SOURCE_ROOT@'] +run_target('indent-head', + command: indent_base + ['--commit=HEAD'], + depends: pg_bsd_indent +) + +run_target('indent-tree', + command: indent_base + ['.'], + depends: pg_bsd_indent +) ############################################################### # Test prep diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent index bce63d95daf..08b0c95814f 100755 --- a/src/tools/pgindent/pgindent +++ b/src/tools/pgindent/pgindent @@ -23,7 +23,7 @@ my $devnull = File::Spec->devnull; my ($typedefs_file, $typedef_str, @excludes, $indent, $build, $show_diff, - $silent_diff, $help, @commits,); + $silent_diff, $sourcetree, $help, @commits,); $help = 0; @@ -35,7 +35,8 @@ my %options = ( "excludes=s" => \@excludes, "indent=s" => \$indent, "show-diff" => \$show_diff, - "silent-diff" => \$silent_diff,); + "silent-diff" => \$silent_diff, + "sourcetree=s" => \$sourcetree); GetOptions(%options) || usage("bad command line argument"); usage() if $help; @@ -53,6 +54,13 @@ $typedefs_file ||= $ENV{PGTYPEDEFS}; # get indent location for environment or default $indent ||= $ENV{PGINDENT} || $ENV{INDENT} || "pg_bsd_indent"; +# When invoked from the build directory, change into source tree, otherwise +# the heuristics in locate_sourcedir() don't work. +if (defined $sourcetree) +{ + chdir $sourcetree; +} + my $sourcedir = locate_sourcedir(); # if it's the base of a postgres tree, we will exclude the files -- 2.37.1.188.g71a8fab31b