Missed the patch in the previous mail. Please ignore. This second patch adds support for coccicheck to configure.ac and related files (in particular Makefile.global.in). At this point, I have deliberately not added support for pgxs so extensions cannot use coccicheck through the PostgreSQL installation.
The semantic patches are expected to live in cocci/ directory under the root and the patch uses the pattern cocci/**/*.cocci to find all semantic patches. Right now there are no subdirectories for the semantic patches, but this might be something we want to add. The coccicheck target is used in the same way as for the Linux kernel, that is, to generate a patch with all changes suggested by the semantic patches, you type: make coccicheck MODE=patch Linux as support for a few more variables: V to set the verbosity, J to use multiple jobs for processing the semantic patches, M to select a different directory to apply the semantic patches to, and COCCI to use a single specific semantic patch rather than all available. I have not added support for this right now, but if you think this is valuable, it should be straightforward to add. -- Best wishes, Mats Kindahl, Timescale
From ada5652e97eba8e66a6bd9da8d29483608c048ae Mon Sep 17 00:00:00 2001 From: Mats Kindahl <m...@kindahl.net> Date: Mon, 30 Dec 2024 19:58:07 +0100 Subject: Create coccicheck target for autoconf This adds a coccicheck target for the autoconf-based build system. The coccicheck target accepts one parameter MODE, which can be either "patch", "report", or "context". The "patch" mode will generate a patch that can be applied to the source tree, the "report" mode will generate a list of file locations with information about what can be changed, and the "context" mode will just highlight the line that will be affected by the semantic patch. The following will generate a patch and apply it to the source code tree: make coccicheck MODE=patch | patch -p1 --- configure | 100 ++++++++++++++++++++++++++++++++++++++--- configure.ac | 12 +++++ src/Makefile.global.in | 22 ++++++++- src/makefiles/pgxs.mk | 3 ++ 4 files changed, 131 insertions(+), 6 deletions(-) diff --git a/configure b/configure index 518c33b73a9..32c7633a2c5 100755 --- a/configure +++ b/configure @@ -769,6 +769,9 @@ enable_coverage GENHTML LCOV GCOV +enable_coccicheck +SPFLAGS +SPATCH enable_debug enable_rpath default_port @@ -836,6 +839,7 @@ with_pgport enable_rpath enable_debug enable_profiling +enable_coccicheck enable_coverage enable_dtrace enable_tap_tests @@ -1528,6 +1532,7 @@ Optional Features: executables --enable-debug build with debugging symbols (-g) --enable-profiling build with profiling enabled + --enable-coccicheck enable Coccinelle checks (requires spatch) --enable-coverage build with coverage testing instrumentation --enable-dtrace build with DTrace support --enable-tap-tests enable TAP tests (requires Perl and IPC::Run) @@ -3319,6 +3324,91 @@ fi +# +# --enable-coccicheck enables Coccinelle check target "coccicheck" +# + + +# Check whether --enable-coccicheck was given. +if test "${enable_coccicheck+set}" = set; then : + enableval=$enable_coccicheck; + case $enableval in + yes) + if test -z "$SPATCH"; then + for ac_prog in spatch +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_SPATCH+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $SPATCH in + [\\/]* | ?:[\\/]*) + ac_cv_path_SPATCH="$SPATCH" # 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_SPATCH="$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 +SPATCH=$ac_cv_path_SPATCH +if test -n "$SPATCH"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SPATCH" >&5 +$as_echo "$SPATCH" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$SPATCH" && break +done + +else + # Report the value of SPATCH in configure's output in all cases. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SPATCH" >&5 +$as_echo_n "checking for SPATCH... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SPATCH" >&5 +$as_echo "$SPATCH" >&6; } +fi + +if test -z "$SPATCH"; then + as_fn_error $? "spatch not found" "$LINENO" 5 +fi + + ;; + no) + : + ;; + *) + as_fn_error $? "no argument expected for --enable-coccicheck option" "$LINENO" 5 + ;; + esac + +else + enable_coccicheck=no + +fi + + + + # # --enable-coverage enables generation of code coverage metrics with gcov # @@ -14776,7 +14866,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -14822,7 +14912,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -14846,7 +14936,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -14891,7 +14981,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -14915,7 +15005,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; diff --git a/configure.ac b/configure.ac index 247ae97fa4c..41f94e0fb7b 100644 --- a/configure.ac +++ b/configure.ac @@ -199,6 +199,18 @@ AC_SUBST(enable_debug) PGAC_ARG_BOOL(enable, profiling, no, [build with profiling enabled ]) +# +# --enable-coccicheck enables Coccinelle check target "coccicheck" +# +PGAC_ARG_BOOL(enable, coccicheck, no, + [enable Coccinelle checks (requires spatch)], +[PGAC_PATH_PROGS(SPATCH, spatch) +if test -z "$SPATCH"; then + AC_MSG_ERROR([spatch not found]) +fi +AC_SUBST(SPFLAGS)]) +AC_SUBST(enable_coccicheck) + # # --enable-coverage enables generation of code coverage metrics with gcov # diff --git a/src/Makefile.global.in b/src/Makefile.global.in index eac3d001211..00053943a1e 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -19,7 +19,7 @@ # # Meta configuration -standard_targets = all install installdirs uninstall clean distclean coverage check checkprep installcheck init-po update-po +standard_targets = all install installdirs uninstall clean distclean coccicheck coverage check checkprep installcheck init-po update-po # these targets should recurse even into subdirectories not being built: standard_always_targets = clean distclean @@ -200,6 +200,7 @@ enable_rpath = @enable_rpath@ enable_nls = @enable_nls@ enable_debug = @enable_debug@ enable_dtrace = @enable_dtrace@ +enable_coccicheck = @enable_coccicheck@ enable_coverage = @enable_coverage@ enable_injection_points = @enable_injection_points@ enable_tap_tests = @enable_tap_tests@ @@ -520,6 +521,11 @@ FOP = @FOP@ XMLLINT = @XMLLINT@ XSLTPROC = @XSLTPROC@ +# Coccinelle + +SPATCH = @SPATCH@ +SPFLAGS = @SPFLAGS@ + # Code coverage GCOV = @GCOV@ @@ -991,6 +997,20 @@ endif # nls.mk endif # enable_nls +########################################################################## +# +# Coccinelle checks +# + +ifeq ($(enable_coccicheck), yes) +coccicheck_py = $(top_srcdir)/src/tools/coccicheck.py +coccicheck = SPATCH=$(SPATCH) SPFLAGS=$(SPFLAGS) $(PYTHON) $(coccicheck_py) + +.PHONY: coccicheck +coccicheck: + $(coccicheck) --mode=$(MODE) 'cocci/**/*.cocci' $(top_srcdir) +endif # enable_coccicheck + ########################################################################## # # Coverage diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk index 0de3737e789..144459dccd2 100644 --- a/src/makefiles/pgxs.mk +++ b/src/makefiles/pgxs.mk @@ -95,6 +95,9 @@ endif ifeq ($(FLEX),) FLEX = flex endif +ifeq ($(SPATCH),) +SPATCH = spatch +endif endif # PGXS -- 2.43.0