Skip to content

Commit 18bef14

Browse files
mkindahlCommitfest Bot
authored and
Commitfest Bot
committed
Add meson build for coccicheck
This commit adds a run target `coccicheck` to meson build files. Since ninja does not accept parameters the same way make does, there are three run targets defined---"coccicheck-patch", "coccicheck-report", and "coccicheck-context"---that you can use to generate a patch, get a report, and get the context respectively. For example, to patch the tree from the "build" subdirectory created by the meson run: ninja coccicheck-patch | patch -d .. -p1
1 parent c1f7155 commit 18bef14

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

meson.build

+30
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ missing = find_program('config/missing', native: true)
348348
cp = find_program('cp', required: false, native: true)
349349
xmllint_bin = find_program(get_option('XMLLINT'), native: true, required: false)
350350
xsltproc_bin = find_program(get_option('XSLTPROC'), native: true, required: false)
351+
spatch = find_program(get_option('SPATCH'), native: true, required: false)
351352

352353
bison_flags = []
353354
if bison.found()
@@ -1649,6 +1650,34 @@ else
16491650
endif
16501651

16511652

1653+
###############################################################
1654+
# Option: Coccinelle checks
1655+
###############################################################
1656+
1657+
coccicheck_opt = get_option('coccicheck')
1658+
coccicheck_dep = not_found_dep
1659+
if not coccicheck_opt.disabled()
1660+
if spatch.found()
1661+
coccicheck_dep = declare_dependency()
1662+
elif coccicheck_opt.enabled()
1663+
error('missing required tools (spatch needed) for Coccinelle checks')
1664+
endif
1665+
endif
1666+
1667+
if coccicheck_opt.enabled()
1668+
coccicheck_modes = ['context', 'report', 'patch']
1669+
foreach mode : coccicheck_modes
1670+
run_target('coccicheck-' + mode,
1671+
command: [python, files('src/tools/coccicheck.py'),
1672+
'--mode', mode,
1673+
'--spatch', spatch,
1674+
'--patchdir', '@SOURCE_ROOT@',
1675+
'@SOURCE_ROOT@/cocci/**/*.cocci',
1676+
'@SOURCE_ROOT@/src',
1677+
'@SOURCE_ROOT@/contrib',
1678+
])
1679+
endforeach
1680+
endif
16521681

16531682
###############################################################
16541683
# Compiler tests
@@ -3866,6 +3895,7 @@ if meson.version().version_compare('>=0.57')
38663895
{
38673896
'bison': '@0@ @1@'.format(bison.full_path(), bison_version),
38683897
'dtrace': dtrace,
3898+
'spatch': spatch,
38693899
'flex': '@0@ @1@'.format(flex.full_path(), flex_version),
38703900
},
38713901
section: 'Programs',

meson_options.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ option('cassert', type: 'boolean', value: false,
4343
option('tap_tests', type: 'feature', value: 'auto',
4444
description: 'Enable TAP tests')
4545

46+
option('coccicheck', type: 'feature', value: 'auto',
47+
description: 'Enable Coccinelle checks')
48+
4649
option('injection_points', type: 'boolean', value: false,
4750
description: 'Enable injection points')
4851

@@ -52,7 +55,6 @@ option('PG_TEST_EXTRA', type: 'string', value: '',
5255
option('PG_GIT_REVISION', type: 'string', value: 'HEAD',
5356
description: 'git revision to be packaged by pgdist target')
5457

55-
5658
# Compilation options
5759

5860
option('extra_include_dirs', type: 'array', value: [],
@@ -198,6 +200,9 @@ option('PYTHON', type: 'array', value: ['python3', 'python'],
198200
option('SED', type: 'string', value: 'gsed',
199201
description: 'Path to sed binary')
200202

203+
option('SPATCH', type: 'string', value: 'spatch',
204+
description: 'Path to spatch binary, used for SmPL patches')
205+
201206
option('STRIP', type: 'string', value: 'strip',
202207
description: 'Path to strip binary, used for PGXS emulation')
203208

src/makefiles/meson.build

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pgxs_kv = {
5757
'enable_injection_points': get_option('injection_points') ? 'yes' : 'no',
5858
'enable_tap_tests': tap_tests_enabled ? 'yes' : 'no',
5959
'enable_debug': get_option('debug') ? 'yes' : 'no',
60+
'enable_coccicheck': spatch.found() ? 'yes' : 'no',
6061
'enable_coverage': 'no',
6162
'enable_dtrace': dtrace.found() ? 'yes' : 'no',
6263

@@ -151,6 +152,7 @@ pgxs_bins = {
151152
'TAR': tar,
152153
'ZSTD': program_zstd,
153154
'DTRACE': dtrace,
155+
'SPATCH': spatch,
154156
}
155157

156158
pgxs_empty = [
@@ -166,6 +168,10 @@ pgxs_empty = [
166168
'DBTOEPUB',
167169
'FOP',
168170

171+
# Coccinelle is not supported by pgxs
172+
'SPATCH',
173+
'SPFLAGS',
174+
169175
# supporting coverage for pgxs-in-meson build doesn't seem worth it
170176
'GENHTML',
171177
'LCOV',

0 commit comments

Comments
 (0)