Skip to content

Commit ca50aa7

Browse files
mkindahlCommitfest Bot
authored andcommitted
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
1 parent 39f1c34 commit ca50aa7

File tree

4 files changed

+132
-7
lines changed

4 files changed

+132
-7
lines changed

configure

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 @@ enable_coverage
779779
GENHTML
780780
LCOV
781781
GCOV
782+
enable_coccicheck
783+
SPFLAGS
784+
SPATCH
782785
enable_debug
783786
enable_rpath
784787
default_port
@@ -846,6 +849,7 @@ with_pgport
846849
enable_rpath
847850
enable_debug
848851
enable_profiling
852+
enable_coccicheck
849853
enable_coverage
850854
enable_dtrace
851855
enable_tap_tests
@@ -1547,6 +1551,7 @@ Optional Features:
15471551
executables
15481552
--enable-debug build with debugging symbols (-g)
15491553
--enable-profiling build with profiling enabled
1554+
--enable-coccicheck enable Coccinelle checks (requires spatch)
15501555
--enable-coverage build with coverage testing instrumentation
15511556
--enable-dtrace build with DTrace support
15521557
--enable-tap-tests enable TAP tests (requires Perl and IPC::Run)
@@ -3347,6 +3352,91 @@ fi
33473352

33483353

33493354

3355+
#
3356+
# --enable-coccicheck enables Coccinelle check target "coccicheck"
3357+
#
3358+
3359+
3360+
# Check whether --enable-coccicheck was given.
3361+
if test "${enable_coccicheck+set}" = set; then :
3362+
enableval=$enable_coccicheck;
3363+
case $enableval in
3364+
yes)
3365+
if test -z "$SPATCH"; then
3366+
for ac_prog in spatch
3367+
do
3368+
# Extract the first word of "$ac_prog", so it can be a program name with args.
3369+
set dummy $ac_prog; ac_word=$2
3370+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
3371+
$as_echo_n "checking for $ac_word... " >&6; }
3372+
if ${ac_cv_path_SPATCH+:} false; then :
3373+
$as_echo_n "(cached) " >&6
3374+
else
3375+
case $SPATCH in
3376+
[\\/]* | ?:[\\/]*)
3377+
ac_cv_path_SPATCH="$SPATCH" # Let the user override the test with a path.
3378+
;;
3379+
*)
3380+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
3381+
for as_dir in $PATH
3382+
do
3383+
IFS=$as_save_IFS
3384+
test -z "$as_dir" && as_dir=.
3385+
for ac_exec_ext in '' $ac_executable_extensions; do
3386+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
3387+
ac_cv_path_SPATCH="$as_dir/$ac_word$ac_exec_ext"
3388+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
3389+
break 2
3390+
fi
3391+
done
3392+
done
3393+
IFS=$as_save_IFS
3394+
3395+
;;
3396+
esac
3397+
fi
3398+
SPATCH=$ac_cv_path_SPATCH
3399+
if test -n "$SPATCH"; then
3400+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $SPATCH" >&5
3401+
$as_echo "$SPATCH" >&6; }
3402+
else
3403+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
3404+
$as_echo "no" >&6; }
3405+
fi
3406+
3407+
3408+
test -n "$SPATCH" && break
3409+
done
3410+
3411+
else
3412+
# Report the value of SPATCH in configure's output in all cases.
3413+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SPATCH" >&5
3414+
$as_echo_n "checking for SPATCH... " >&6; }
3415+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $SPATCH" >&5
3416+
$as_echo "$SPATCH" >&6; }
3417+
fi
3418+
3419+
if test -z "$SPATCH"; then
3420+
as_fn_error $? "spatch not found" "$LINENO" 5
3421+
fi
3422+
3423+
;;
3424+
no)
3425+
:
3426+
;;
3427+
*)
3428+
as_fn_error $? "no argument expected for --enable-coccicheck option" "$LINENO" 5
3429+
;;
3430+
esac
3431+
3432+
else
3433+
enable_coccicheck=no
3434+
3435+
fi
3436+
3437+
3438+
3439+
33503440
#
33513441
# --enable-coverage enables generation of code coverage metrics with gcov
33523442
#
@@ -15173,7 +15263,7 @@ else
1517315263
We can't simply define LARGE_OFF_T to be 9223372036854775807,
1517415264
since some C++ compilers masquerading as C compilers
1517515265
incorrectly reject 9223372036854775807. */
15176-
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
15266+
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
1517715267
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
1517815268
&& LARGE_OFF_T % 2147483647 == 1)
1517915269
? 1 : -1];
@@ -15219,7 +15309,7 @@ else
1521915309
We can't simply define LARGE_OFF_T to be 9223372036854775807,
1522015310
since some C++ compilers masquerading as C compilers
1522115311
incorrectly reject 9223372036854775807. */
15222-
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
15312+
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
1522315313
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
1522415314
&& LARGE_OFF_T % 2147483647 == 1)
1522515315
? 1 : -1];
@@ -15243,7 +15333,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
1524315333
We can't simply define LARGE_OFF_T to be 9223372036854775807,
1524415334
since some C++ compilers masquerading as C compilers
1524515335
incorrectly reject 9223372036854775807. */
15246-
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
15336+
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
1524715337
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
1524815338
&& LARGE_OFF_T % 2147483647 == 1)
1524915339
? 1 : -1];
@@ -15288,7 +15378,7 @@ else
1528815378
We can't simply define LARGE_OFF_T to be 9223372036854775807,
1528915379
since some C++ compilers masquerading as C compilers
1529015380
incorrectly reject 9223372036854775807. */
15291-
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
15381+
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
1529215382
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
1529315383
&& LARGE_OFF_T % 2147483647 == 1)
1529415384
? 1 : -1];
@@ -15312,7 +15402,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
1531215402
We can't simply define LARGE_OFF_T to be 9223372036854775807,
1531315403
since some C++ compilers masquerading as C compilers
1531415404
incorrectly reject 9223372036854775807. */
15315-
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
15405+
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
1531615406
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
1531715407
&& LARGE_OFF_T % 2147483647 == 1)
1531815408
? 1 : -1];

configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ AC_SUBST(enable_debug)
193193
PGAC_ARG_BOOL(enable, profiling, no,
194194
[build with profiling enabled ])
195195

196+
#
197+
# --enable-coccicheck enables Coccinelle check target "coccicheck"
198+
#
199+
PGAC_ARG_BOOL(enable, coccicheck, no,
200+
[enable Coccinelle checks (requires spatch)],
201+
[PGAC_PATH_PROGS(SPATCH, spatch)
202+
if test -z "$SPATCH"; then
203+
AC_MSG_ERROR([spatch not found])
204+
fi
205+
AC_SUBST(SPFLAGS)])
206+
AC_SUBST(enable_coccicheck)
207+
196208
#
197209
# --enable-coverage enables generation of code coverage metrics with gcov
198210
#

src/Makefile.global.in

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020
# Meta configuration
2121

22-
standard_targets = all install installdirs uninstall clean distclean coverage check checkprep installcheck init-po update-po
22+
standard_targets = all install installdirs uninstall clean distclean coccicheck coverage check checkprep installcheck init-po update-po
2323
# these targets should recurse even into subdirectories not being built:
2424
standard_always_targets = clean distclean
2525

@@ -208,6 +208,7 @@ enable_rpath = @enable_rpath@
208208
enable_nls = @enable_nls@
209209
enable_debug = @enable_debug@
210210
enable_dtrace = @enable_dtrace@
211+
enable_coccicheck = @enable_coccicheck@
211212
enable_coverage = @enable_coverage@
212213
enable_injection_points = @enable_injection_points@
213214
enable_tap_tests = @enable_tap_tests@
@@ -389,7 +390,7 @@ CLDR_VERSION = 47
389390
# If a particular subdirectory knows this isn't needed in itself or its
390391
# children, it can set NO_GENERATED_HEADERS.
391392

392-
all install check installcheck: submake-generated-headers
393+
all install check installcheck coccicheck: submake-generated-headers
393394

394395
.PHONY: submake-generated-headers
395396

@@ -538,6 +539,11 @@ FOP = @FOP@
538539
XMLLINT = @XMLLINT@
539540
XSLTPROC = @XSLTPROC@
540541

542+
# Coccinelle
543+
544+
SPATCH = @SPATCH@
545+
SPFLAGS = @SPFLAGS@
546+
541547
# Code coverage
542548

543549
GCOV = @GCOV@
@@ -1005,6 +1011,20 @@ endif # nls.mk
10051011
endif # enable_nls
10061012

10071013

1014+
##########################################################################
1015+
#
1016+
# Coccinelle checks
1017+
#
1018+
1019+
ifeq ($(enable_coccicheck), yes)
1020+
coccicheck_py = $(top_srcdir)/src/tools/coccicheck.py
1021+
coccicheck = SPATCH=$(SPATCH) SPFLAGS=$(SPFLAGS) $(PYTHON) $(coccicheck_py)
1022+
1023+
.PHONY: coccicheck
1024+
coccicheck:
1025+
$(coccicheck) --mode=$(MODE) 'cocci/**/*.cocci' $(top_srcdir)
1026+
endif # enable_coccicheck
1027+
10081028
##########################################################################
10091029
#
10101030
# Coverage

src/makefiles/pgxs.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ endif
9595
ifeq ($(FLEX),)
9696
FLEX = flex
9797
endif
98+
ifeq ($(SPATCH),)
99+
SPATCH = spatch
100+
endif
98101

99102
endif # PGXS
100103

0 commit comments

Comments
 (0)