This tries to make running formatting a lot easier for committers, but primarily for new contributors. You can not format the files by simply running one of the folowing:
make format ninja -C build format My primary goal is to introduce Python formatting too (using ruff), and integrate that in a similar manner. Right now we don't have many Python files, but hopefully the pytest patch gets merged soonish and then we'll get more and more Python files. So I'd like to get autoformatting out of the gate. But even without that, these rules should make it simpler to run the current formatters: Running pgindent is still not trivial for new users. You need to add our pg_bsd_indent to PATH. And if you use meson to build you have to manually specify src/ and contrib/ instead of ./ because otherwise pgindent will try to format files in the build directory. Running pgperltidy is even more complicated because you need to install a specific version of perltidy. Recently we started erroring when that version was not the one we expect.
From aaca6b3d2a0454183599d8f5f0d342d339b8a1a0 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio <[email protected]> Date: Wed, 31 Dec 2025 10:36:30 +0100 Subject: [PATCH v1 1/3] Add "format" target for make and ninja Running pgindent manually requires putting pg_bsd_indent in your path. This allows formatting the sources without having to do that. In follow on commits this will introduce more tools to these targets, like perltidy. --- GNUmakefile.in | 6 +++++- doc/src/sgml/targets-meson.txt | 1 + meson.build | 10 ++++++++++ src/tools/pgindent/README | 18 ++++++++++++++---- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/GNUmakefile.in b/GNUmakefile.in index cf6e759486e..65c2dffba4e 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -134,4 +134,8 @@ headerscheck: submake-generated-headers cpluspluscheck: submake-generated-headers $(top_srcdir)/src/tools/pginclude/headerscheck --cplusplus $(top_srcdir) $(abs_top_builddir) -.PHONY: dist distcheck docs install-docs world check-world install-world installcheck-world headerscheck cpluspluscheck +format: submake-libpgport + @$(MAKE) -C $(top_builddir)/src/tools/pg_bsd_indent + $(PERL) $(top_srcdir)/src/tools/pgindent/pgindent --indent=$(top_builddir)/src/tools/pg_bsd_indent/pg_bsd_indent --typedefs=$(top_srcdir)/src/tools/pgindent/typedefs.list --excludes=$(top_srcdir)/src/tools/pgindent/exclude_file_patterns $(top_srcdir)/src $(top_srcdir)/contrib + +.PHONY: dist distcheck docs install-docs world check-world install-world installcheck-world headerscheck cpluspluscheck format diff --git a/doc/src/sgml/targets-meson.txt b/doc/src/sgml/targets-meson.txt index d0021a5eb10..b9486b9fba0 100644 --- a/doc/src/sgml/targets-meson.txt +++ b/doc/src/sgml/targets-meson.txt @@ -14,6 +14,7 @@ Code Targets: pl Build procedural languages Developer Targets: + format Run pgindent on C source files reformat-dat-files Rewrite catalog data files into standard format expand-dat-files Expand all data files to include defaults update-unicode Update unicode data to new version diff --git a/meson.build b/meson.build index ec08cd49056..585925ecebc 100644 --- a/meson.build +++ b/meson.build @@ -3837,6 +3837,16 @@ run_target('help', ] ) +run_target('format', + command: [perl, files('src/tools/pgindent/pgindent'), + '--indent', pg_bsd_indent, + '--typedefs', files('src/tools/pgindent/typedefs.list'), + '--excludes', files('src/tools/pgindent/exclude_file_patterns'), + meson.project_source_root() / 'src', + meson.project_source_root() / 'contrib'], + depends: [pg_bsd_indent], +) + ############################################################### diff --git a/src/tools/pgindent/README b/src/tools/pgindent/README index b6cd4c6f6b7..17b65c29c7d 100644 --- a/src/tools/pgindent/README +++ b/src/tools/pgindent/README @@ -11,9 +11,11 @@ http://adpgtech.blogspot.com/2015/05/running-pgindent-on-non-core-code-or.html PREREQUISITES: -1) Install pg_bsd_indent in your PATH. Its source code is in the - sibling directory src/tools/pg_bsd_indent; see the directions - in that directory's README file. +1) Install pg_bsd_indent in your PATH. If you use the "ninja format" + or "make format" build targets, they will build pg_bsd_indent for you, + so this step can be skipped. Otherwise, its source code is in the + sibling directory src/tools/pg_bsd_indent; see the directions in that + directory's README file. 2) Install perltidy. Please be sure it is version 20230309 (older and newer versions make different formatting choices, and we want consistency). @@ -31,7 +33,15 @@ DOING THE INDENT RUN BEFORE A NORMAL COMMIT: 1) Change directory to the top of the source tree. -2) Run pgindent on the C files: +2) Run pgindent on the C files. With Meson: + + ninja -C build format + + Or with make: + + make format + + Or directly: src/tools/pgindent/pgindent . base-commit: 915711c8a4e60f606a8417ad033cea5385364c07 -- 2.52.0
From 9e67f9b81db96b140f250d84c2168ed311ab38b7 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio <[email protected]> Date: Wed, 31 Dec 2025 11:07:58 +0100 Subject: [PATCH v1 2/3] Allow running pgperltidy from any directory pgperltidy was assuming it was run from the root directory of the source tree. This makes it agnostic to that. --- src/tools/pgindent/pgperltidy | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tools/pgindent/pgperltidy b/src/tools/pgindent/pgperltidy index 87838d6bde3..75c99a84709 100755 --- a/src/tools/pgindent/pgperltidy +++ b/src/tools/pgindent/pgperltidy @@ -4,6 +4,10 @@ set -e +# Determine the directory where this script is located +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +TOOLS_DIR=$(dirname "$SCRIPT_DIR") + # set this to override default perltidy program: PERLTIDY=${PERLTIDY:-perltidy} @@ -13,6 +17,6 @@ if ! $PERLTIDY -v | grep -q $PERLTIDY_VERSION; then exit 1 fi -. src/tools/perlcheck/find_perl_files +. "$TOOLS_DIR/perlcheck/find_perl_files" -find_perl_files "$@" | xargs $PERLTIDY --profile=src/tools/pgindent/perltidyrc +find_perl_files "$@" | xargs $PERLTIDY --profile="$SCRIPT_DIR/perltidyrc" -- 2.52.0
From e46791c4daeb4e149c29ca68d3dd4f05a4160c13 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio <[email protected]> Date: Wed, 31 Dec 2025 11:07:26 +0100 Subject: [PATCH v1 3/3] Add pgpertidy to "format" target During "./configure" and "meson setup" perltidy will now be detected, and the version will be compared to the exact version that we require. If it's the correct version the format target will now also start indenting perl files using pgindent. This also introduces format-c and format-perl targets for a bit more tighter controls on what is getting formatted. Finally, pgperltidy will now automatically configure PERL5LIB to make it possible to use local-lib installations of pgperltidy. This makes it easier to have multiple pgperltidy versions installed next to eachother for different Postgres versions. --- GNUmakefile.in | 12 ++++- configure | 91 +++++++++++++++++++++++++++++++++ configure.ac | 36 +++++++++++++ doc/src/sgml/targets-meson.txt | 4 +- meson.build | 50 +++++++++++++++++- meson_options.txt | 3 ++ src/Makefile.global.in | 2 + src/makefiles/meson.build | 1 + src/tools/pgindent/README | 63 +++++++++++++++-------- src/tools/pgindent/meson_format | 34 ++++++++++++ src/tools/pgindent/pgperltidy | 14 ++++- 11 files changed, 284 insertions(+), 26 deletions(-) create mode 100755 src/tools/pgindent/meson_format diff --git a/GNUmakefile.in b/GNUmakefile.in index 65c2dffba4e..2442fa454d7 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -134,8 +134,16 @@ headerscheck: submake-generated-headers cpluspluscheck: submake-generated-headers $(top_srcdir)/src/tools/pginclude/headerscheck --cplusplus $(top_srcdir) $(abs_top_builddir) -format: submake-libpgport +format-c: submake-libpgport @$(MAKE) -C $(top_builddir)/src/tools/pg_bsd_indent $(PERL) $(top_srcdir)/src/tools/pgindent/pgindent --indent=$(top_builddir)/src/tools/pg_bsd_indent/pg_bsd_indent --typedefs=$(top_srcdir)/src/tools/pgindent/typedefs.list --excludes=$(top_srcdir)/src/tools/pgindent/exclude_file_patterns $(top_srcdir)/src $(top_srcdir)/contrib -.PHONY: dist distcheck docs install-docs world check-world install-world installcheck-world headerscheck cpluspluscheck format +format-perl: + PERLTIDY="$(PERLTIDY)" $(top_srcdir)/src/tools/pgindent/pgperltidy $(top_srcdir) + +format: format-c +ifneq ($(PERLTIDY),) +format: format-perl +endif + +.PHONY: dist distcheck docs install-docs world check-world install-world installcheck-world headerscheck cpluspluscheck format format-c format-perl diff --git a/configure b/configure index f203f9d528b..c0ec13aa3a9 100755 --- a/configure +++ b/configure @@ -630,6 +630,7 @@ vpath_build PG_SYSROOT PG_VERSION_NUM LDFLAGS_EX_BE +PERLTIDY PROVE DBTOEPUB FOP @@ -19197,6 +19198,96 @@ $as_echo "$modulestderr" >&6; } fi fi +# Look for perltidy (optional, for the format target) +# Must be version 20230309 for consistent formatting +PERLTIDY_VERSION_REQ=20230309 +if test -n "$PERLTIDY"; then + # User explicitly specified PERLTIDY + # For local-lib installations, set PERL5LIB to find modules + pgac_perltidy_perl5lib="" + case "$PERLTIDY" in + /*) + pgac_perltidy_base=`dirname "\`dirname \"$PERLTIDY\"\`"` + if test -d "$pgac_perltidy_base/lib/perl5"; then + pgac_perltidy_perl5lib="$pgac_perltidy_base/lib/perl5" + fi + ;; + esac + if test -n "$pgac_perltidy_perl5lib"; then + pgac_perltidy_version=`PERL5LIB="$pgac_perltidy_perl5lib" $PERLTIDY -v 2>/dev/null | sed -n 's/.*v\([0-9]*\).*/\1/p'` + else + pgac_perltidy_version=`$PERLTIDY -v 2>/dev/null | sed -n 's/.*v\([0-9]*\).*/\1/p'` + fi + if test "$pgac_perltidy_version" != "$PERLTIDY_VERSION_REQ"; then + as_fn_error $? "perltidy version $PERLTIDY_VERSION_REQ is required, but $PERLTIDY is version $pgac_perltidy_version" "$LINENO" 5 + fi +else + # Look for perltidy in PATH + if test -z "$PERLTIDY"; then + for ac_prog in perltidy +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_PERLTIDY+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $PERLTIDY in + [\\/]* | ?:[\\/]*) + ac_cv_path_PERLTIDY="$PERLTIDY" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_PERLTIDY="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +PERLTIDY=$ac_cv_path_PERLTIDY +if test -n "$PERLTIDY"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PERLTIDY" >&5 +$as_echo "$PERLTIDY" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$PERLTIDY" && break +done + +else + # Report the value of PERLTIDY in configure's output in all cases. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for PERLTIDY" >&5 +$as_echo_n "checking for PERLTIDY... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PERLTIDY" >&5 +$as_echo "$PERLTIDY" >&6; } +fi + + if test -n "$PERLTIDY"; then + pgac_perltidy_version=`$PERLTIDY -v 2>/dev/null | sed -n 's/.*v\([0-9]*\).*/\1/p'` + if test "$pgac_perltidy_version" != "$PERLTIDY_VERSION_REQ"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: perltidy version $PERLTIDY_VERSION_REQ is required for format-perl target, but found version $pgac_perltidy_version; disabling" >&5 +$as_echo "$as_me: WARNING: perltidy version $PERLTIDY_VERSION_REQ is required for format-perl target, but found version $pgac_perltidy_version; disabling" >&2;} + PERLTIDY="" + fi + fi +fi + + # If compiler will take -Wl,--as-needed (or various platform-specific # spellings thereof) then add that to LDFLAGS. This is much easier than # trying to filter LIBS to the minimum for each executable. diff --git a/configure.ac b/configure.ac index ec38ddefa36..da5261a4485 100644 --- a/configure.ac +++ b/configure.ac @@ -2408,6 +2408,42 @@ if test "$enable_tap_tests" = yes; then fi fi +# Look for perltidy (optional, for the format target) +# Must be version 20230309 for consistent formatting +PERLTIDY_VERSION_REQ=20230309 +if test -n "$PERLTIDY"; then + # User explicitly specified PERLTIDY + # For local-lib installations, set PERL5LIB to find modules + pgac_perltidy_perl5lib="" + case "$PERLTIDY" in + /*) + pgac_perltidy_base=`dirname "\`dirname \"$PERLTIDY\"\`"` + if test -d "$pgac_perltidy_base/lib/perl5"; then + pgac_perltidy_perl5lib="$pgac_perltidy_base/lib/perl5" + fi + ;; + esac + if test -n "$pgac_perltidy_perl5lib"; then + pgac_perltidy_version=`PERL5LIB="$pgac_perltidy_perl5lib" $PERLTIDY -v 2>/dev/null | sed -n 's/.*v\([[0-9]]*\).*/\1/p'` + else + pgac_perltidy_version=`$PERLTIDY -v 2>/dev/null | sed -n 's/.*v\([[0-9]]*\).*/\1/p'` + fi + if test "$pgac_perltidy_version" != "$PERLTIDY_VERSION_REQ"; then + AC_MSG_ERROR([perltidy version $PERLTIDY_VERSION_REQ is required, but $PERLTIDY is version $pgac_perltidy_version]) + fi +else + # Look for perltidy in PATH + PGAC_PATH_PROGS(PERLTIDY, perltidy) + if test -n "$PERLTIDY"; then + pgac_perltidy_version=`$PERLTIDY -v 2>/dev/null | sed -n 's/.*v\([[0-9]]*\).*/\1/p'` + if test "$pgac_perltidy_version" != "$PERLTIDY_VERSION_REQ"; then + AC_MSG_WARN([perltidy version $PERLTIDY_VERSION_REQ is required for format-perl target, but found version $pgac_perltidy_version; disabling]) + PERLTIDY="" + fi + fi +fi +AC_SUBST(PERLTIDY) + # If compiler will take -Wl,--as-needed (or various platform-specific # spellings thereof) then add that to LDFLAGS. This is much easier than # trying to filter LIBS to the minimum for each executable. diff --git a/doc/src/sgml/targets-meson.txt b/doc/src/sgml/targets-meson.txt index b9486b9fba0..391c759fde7 100644 --- a/doc/src/sgml/targets-meson.txt +++ b/doc/src/sgml/targets-meson.txt @@ -14,7 +14,9 @@ Code Targets: pl Build procedural languages Developer Targets: - format Run pgindent on C source files + format Run pgindent and perltidy on source files + format-c Run pgindent on C source files + format-perl Run perltidy on Perl source files reformat-dat-files Rewrite catalog data files into standard format expand-dat-files Expand all data files to include defaults update-unicode Update unicode data to new version diff --git a/meson.build b/meson.build index 585925ecebc..ee7d899f0d6 100644 --- a/meson.build +++ b/meson.build @@ -374,6 +374,39 @@ if flex.found() flex_version = flex_version_c.stdout().split(' ')[1].split('\n')[0] endif flex_wrapper = files('src/tools/pgflex') + +# perltidy is optional, but must be the correct version if specified +perltidy_version_req = '20230309' +perltidy_opt = get_option('PERLTIDY') +perltidy_prog = find_program(perltidy_opt, native: true, required: false) +perltidy_env = {} +if perltidy_prog.found() + # For local-lib installations, we need to set PERL5LIB to find modules + perltidy_path = perltidy_prog.full_path() + if perltidy_path.startswith('/') + perltidy_base = fs.parent(fs.parent(perltidy_path)) + perltidy_lib = perltidy_base / 'lib' / 'perl5' + if fs.is_dir(perltidy_lib) + perltidy_env = {'PERL5LIB': perltidy_lib} + endif + endif + + perltidy_version_c = run_command(perltidy_prog, '-v', check: false, env: perltidy_env) + if perltidy_version_c.returncode() == 0 and perltidy_version_c.stdout().contains(perltidy_version_req) + perltidy = perltidy_prog + perltidy_env += {'PERLTIDY': perltidy.full_path()} + elif perltidy_opt != 'perltidy' + # User explicitly specified a perltidy, but it's the wrong version + error('perltidy version @0@ is required, but @1@ is a different version'.format( + perltidy_version_req, perltidy_prog.full_path())) + else + # Found perltidy but wrong version - just disable it + perltidy = disabler() + perltidy_env = {} + endif +else + perltidy = disabler() +endif flex_cmd = [python, flex_wrapper, '--builddir', '@BUILD_ROOT@', '--srcdir', '@SOURCE_ROOT@', @@ -3837,7 +3870,7 @@ run_target('help', ] ) -run_target('format', +run_target('format-c', command: [perl, files('src/tools/pgindent/pgindent'), '--indent', pg_bsd_indent, '--typedefs', files('src/tools/pgindent/typedefs.list'), @@ -3847,6 +3880,21 @@ run_target('format', depends: [pg_bsd_indent], ) +run_target('format-perl', + command: [files('src/tools/pgindent/pgperltidy'), + meson.project_source_root()], + env: perltidy_env, +) + +format_env = {'PGINDENT': pg_bsd_indent.full_path()} +format_env += perltidy_env + +run_target('format', + command: [files('src/tools/pgindent/meson_format'), meson.project_source_root()], + depends: [pg_bsd_indent], + env: format_env, +) + ############################################################### diff --git a/meson_options.txt b/meson_options.txt index 06bf5627d3c..22cd2305cba 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -192,6 +192,9 @@ option('OPENSSL', type: 'string', value: 'openssl', option('PERL', type: 'string', value: 'perl', description: 'Path to perl binary') +option('PERLTIDY', type: 'string', value: 'perltidy', + description: 'Path to perltidy binary') + option('PROVE', type: 'string', value: 'prove', description: 'Path to prove binary') diff --git a/src/Makefile.global.in b/src/Makefile.global.in index 371cd7eba2c..e1c13477bf1 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -452,6 +452,8 @@ checkprep: $(if $(EXTRA_INSTALL),for extra in $(EXTRA_INSTALL); do $(MAKE) -C '$(top_builddir)'/$$extra DESTDIR='$(abs_top_builddir)'/tmp_install install || exit; done) PROVE = @PROVE@ +PERLTIDY = @PERLTIDY@ + # There are common routines in src/test/perl, and some test suites have # extra perl modules in their own directory. PG_PROVE_FLAGS = -I $(top_srcdir)/src/test/perl/ -I $(srcdir) diff --git a/src/makefiles/meson.build b/src/makefiles/meson.build index c6edf14ec44..3380cdcd6cc 100644 --- a/src/makefiles/meson.build +++ b/src/makefiles/meson.build @@ -144,6 +144,7 @@ pgxs_bins = { 'LZ4': program_lz4, 'OPENSSL': openssl, 'PERL': perl, + 'PERLTIDY': perltidy, 'PROVE': prove, 'PYTHON': python, 'TAR': tar, diff --git a/src/tools/pgindent/README b/src/tools/pgindent/README index 17b65c29c7d..c531f284351 100644 --- a/src/tools/pgindent/README +++ b/src/tools/pgindent/README @@ -17,23 +17,40 @@ PREREQUISITES: sibling directory src/tools/pg_bsd_indent; see the directions in that directory's README file. -2) Install perltidy. Please be sure it is version 20230309 (older and newer - versions make different formatting choices, and we want consistency). - You can get the correct version from - https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/ - To install, follow the usual install process for a Perl module - ("man perlmodinstall" explains it). Or, if you have cpan installed, - this should work: - cpan SHANCOCK/Perl-Tidy-20230309.tar.gz - Or if you have cpanm installed, you can just use: - cpanm https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/Perl-Tidy-20230309.tar.gz +2) Install perltidy version 20230309 (older and newer versions make + different formatting choices, and we want consistency). You can get + this specific version from CPAN: + + wget https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/Perl-Tidy-20230309.tar.gz + + To install system-wide, follow the usual process for a Perl module + ("man perlmodinstall" explains it), or use cpan/cpanm: + + cpanm Perl-Tidy-20230309.tar.gz + + Alternatively, you can install perltidy to a local directory using + cpanm's local-lib feature: + + cpanm -l $HOME/perltidy-20230309 Perl-Tidy-20230309.tar.gz + + Then configure with (for meson): + + meson setup build -DPERLTIDY=$HOME/perltidy-20230309/bin/perltidy + + Or for autoconf: + + ./configure PERLTIDY=$HOME/perltidy-20230309/bin/perltidy + + If perltidy is found in PATH but is the wrong version, it will be + ignored. If you explicitly specify a PERLTIDY path with the wrong + version, configuration will fail with an error. DOING THE INDENT RUN BEFORE A NORMAL COMMIT: 1) Change directory to the top of the source tree. -2) Run pgindent on the C files. With Meson: +2) Run the formatting tools. With Meson: ninja -C build format @@ -41,9 +58,17 @@ DOING THE INDENT RUN BEFORE A NORMAL COMMIT: make format - Or directly: + This formats both C files (with pgindent) and Perl files (with perltidy). + Perl formatting is only performed if perltidy version 20230309 was found + during "meson setup" or "./configure". To format only C or only Perl: + + ninja -C build format-c # or: make format-c + ninja -C build format-perl # or: make format-perl + + Or run the tools directly: src/tools/pgindent/pgindent . + src/tools/pgindent/pgperltidy . If any files generate errors, restore their original versions with "git checkout", and see below for cleanup ideas. @@ -84,26 +109,22 @@ AT LEAST ONCE PER RELEASE CYCLE: (See https://buildfarm.postgresql.org/cgi-bin/typedefs.pl?show_list for a full list of typedef files, if you want to indent some back branch.) -2) Run pgindent as above. - -3) Indent the Perl code using perltidy: +2) Run pgindent and perltidy as above (step 2 under "DOING THE INDENT RUN"). + If perltidy is not configured, run it directly: src/tools/pgindent/pgperltidy . - If you want to use some perltidy version that's not in your PATH, - first set the PERLTIDY environment variable to point to it. - -4) Reformat the bootstrap catalog data files: +3) Reformat the bootstrap catalog data files: ./configure # "make" will not work in an unconfigured tree cd src/include/catalog make reformat-dat-files cd ../../.. -5) When you're done, "git commit" everything including the typedefs.list file +4) When you're done, "git commit" everything including the typedefs.list file you used. -6) Add the newly created commit(s) to the .git-blame-ignore-revs file so +5) Add the newly created commit(s) to the .git-blame-ignore-revs file so that "git blame" ignores the commits (for anybody that has opted-in to using the ignore file). Follow the instructions that appear at the top of the .git-blame-ignore-revs file. diff --git a/src/tools/pgindent/meson_format b/src/tools/pgindent/meson_format new file mode 100755 index 00000000000..69e70bb4221 --- /dev/null +++ b/src/tools/pgindent/meson_format @@ -0,0 +1,34 @@ +#!/bin/sh + +# src/tools/pgindent/meson_format +# Runs both pgindent (C) and pgperltidy (Perl) formatting +# +# Environment variables: +# PGINDENT - path to pg_bsd_indent (required) +# PERLTIDY - path to perltidy (optional, skips Perl formatting if not set) +# +# Arguments: source directory to format + +set -e + +if [ $# -ne 1 ]; then + echo "Usage: $0 <source_directory>" >&2 + exit 1 +fi + +SRCDIR="$1" + +# Determine the directory where this script is located +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) + +# Run pgindent for C files +"$SCRIPT_DIR/pgindent" \ + --indent="$PGINDENT" \ + --typedefs="$SCRIPT_DIR/typedefs.list" \ + --excludes="$SCRIPT_DIR/exclude_file_patterns" \ + "$SRCDIR/src" "$SRCDIR/contrib" + +# Run pgperltidy for Perl files only if PERLTIDY is set +if [ -n "$PERLTIDY" ]; then + "$SCRIPT_DIR/pgperltidy" "$SRCDIR" +fi diff --git a/src/tools/pgindent/pgperltidy b/src/tools/pgindent/pgperltidy index 75c99a84709..3931a79bda2 100755 --- a/src/tools/pgindent/pgperltidy +++ b/src/tools/pgindent/pgperltidy @@ -11,9 +11,21 @@ TOOLS_DIR=$(dirname "$SCRIPT_DIR") # set this to override default perltidy program: PERLTIDY=${PERLTIDY:-perltidy} +# If PERLTIDY is an absolute path, set PERL5LIB to find local-lib modules +case "$PERLTIDY" in + /*) + perltidy_dir=$(dirname "$PERLTIDY") + perltidy_base=$(dirname "$perltidy_dir") + if [ -d "$perltidy_base/lib/perl5" ]; then + PERL5LIB="$perltidy_base/lib/perl5${PERL5LIB:+:$PERL5LIB}" + export PERL5LIB + fi + ;; +esac + PERLTIDY_VERSION=20230309 if ! $PERLTIDY -v | grep -q $PERLTIDY_VERSION; then - echo "You do not appear to have $PERLTIDY version $PERLTIDY_VERSION installed on your system." >&2 + echo "You do not appear to have $PERLTIDY version $PERLTIDY_VERSION installed on your system. See src/tools/pgindent/README on how to install it." >&2 exit 1 fi -- 2.52.0
