From 65f48c7002d919464d4e141177fbe203c99d93b5 Mon Sep 17 00:00:00 2001 From: Arseny Sher Date: Sat, 21 Oct 2023 22:47:20 +0300 Subject: [PATCH] Make targets to run pgindent on core and neon extension. --- .gitignore | 3 +++ Makefile | 38 ++++++++++++++++++++++++++++++++++++++ pgxn/neon/Makefile | 11 +++++++++++ 3 files changed, 52 insertions(+) diff --git a/.gitignore b/.gitignore index f1afdee599..c5fc121ac2 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ test_output/ *.o *.so *.Po + +# pgindent typedef lists +*.list diff --git a/Makefile b/Makefile index 89acbe564a..004ca3fbcf 100644 --- a/Makefile +++ b/Makefile @@ -260,6 +260,44 @@ distclean: fmt: ./pre-commit.py --fix-inplace +postgres-%-pg-bsd-indent: postgres-% + +@echo "Compiling pg_bsd_indent" + $(MAKE) -C $(POSTGRES_INSTALL_DIR)/build/$*/src/tools/pg_bsd_indent/ + +# Create typedef list for the core. Note that generally it should be combined with +# buildfarm one to cover platform specific stuff. +# https://wiki.postgresql.org/wiki/Running_pgindent_on_non-core_code_or_development_code +postgres-%-typedefs.list: postgres-% + $(ROOT_PROJECT_DIR)/vendor/postgres-$*/src/tools/find_typedef $(POSTGRES_INSTALL_DIR)/$*/bin > $@ + +# Indent postgres. See src/tools/pgindent/README for details. +.PHONY: postgres-%-pgindent +postgres-%-pgindent: postgres-%-pg-bsd-indent postgres-%-typedefs.list + +@echo merge with buildfarm typedef to cover all platforms + +@echo note: I first tried to download from pgbuildfarm.org, but for unclear reason e.g. \ + REL_16_STABLE list misses PGSemaphoreData + # wget -q -O - "http://www.pgbuildfarm.org/cgi-bin/typedefs.pl?branch=REL_16_STABLE" |\ + # cat - postgres-$*-typedefs.list | sort | uniq > postgres-$*-typedefs-full.list + cat $(ROOT_PROJECT_DIR)/vendor/postgres-$*/src/tools/pgindent/typedefs.list |\ + cat - postgres-$*-typedefs.list | sort | uniq > postgres-$*-typedefs-full.list + +@echo note: you might want to run it on selected files/dirs instead. + INDENT=$(POSTGRES_INSTALL_DIR)/build/$*/src/tools/pg_bsd_indent/pg_bsd_indent \ + $(ROOT_PROJECT_DIR)/vendor/postgres-$*/src/tools/pgindent/pgindent --typedefs postgres-$*-typedefs-full.list \ + $(ROOT_PROJECT_DIR)/vendor/postgres-$*/src/ \ + --excludes $(ROOT_PROJECT_DIR)/vendor/postgres-$*/src/tools/pgindent/exclude_file_patterns + rm -f pg*.BAK + +# Indent pxgn/neon. +.PHONY: pgindent +neon-pgindent: postgres-v16-pg-bsd-indent neon-pg-ext-v16 + $(MAKE) PG_CONFIG=$(POSTGRES_INSTALL_DIR)/v16/bin/pg_config CFLAGS='$(PG_CFLAGS) $(COPT)' \ + FIND_TYPEDEF=$(ROOT_PROJECT_DIR)/vendor/postgres-v16/src/tools/find_typedef \ + INDENT=$(POSTGRES_INSTALL_DIR)/build/v16/src/tools/pg_bsd_indent/pg_bsd_indent \ + PGINDENT_SCRIPT=$(ROOT_PROJECT_DIR)/vendor/postgres-v16/src/tools/pgindent/pgindent \ + -C $(POSTGRES_INSTALL_DIR)/build/neon-v16 \ + -f $(ROOT_PROJECT_DIR)/pgxn/neon/Makefile pgindent + + .PHONY: setup-pre-commit-hook setup-pre-commit-hook: ln -s -f $(ROOT_PROJECT_DIR)/pre-commit.py .git/hooks/pre-commit diff --git a/pgxn/neon/Makefile b/pgxn/neon/Makefile index 7fc99523db..466e346e46 100644 --- a/pgxn/neon/Makefile +++ b/pgxn/neon/Makefile @@ -41,6 +41,17 @@ libwalproposer.a: $(WALPROP_OBJS) rm -f $@ $(AR) $(AROPT) $@ $^ +# needs vars: +# FIND_TYPEDEF pointing to find_typedef +# INDENT pointing to pg_bsd_indent +# PGINDENT_SCRIPT pointing to pgindent (be careful with PGINDENT var name: +# pgindent will pick it up as pg_bsd_indent path). +.PHONY: pgindent +pgindent: + +@ echo top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) srcdir=$(srcdir) + $(FIND_TYPEDEF) . > neon.typedefs + INDENT=$(INDENT) $(PGINDENT_SCRIPT) --typedefs neon.typedefs $(srcdir)/*.c $(srcdir)/*.h + PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS)