Skip to content

Commit 23a1a84

Browse files
mkindahlCommitfest Bot
authored andcommitted
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 ca50aa7 commit 23a1a84

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

meson.build

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ missing = find_program('config/missing', native: true)
350350
cp = find_program('cp', required: false, native: true)
351351
xmllint_bin = find_program(get_option('XMLLINT'), native: true, required: false)
352352
xsltproc_bin = find_program(get_option('XSLTPROC'), native: true, required: false)
353+
spatch = find_program(get_option('SPATCH'), native: true, required: false)
353354

354355
bison_flags = []
355356
if bison.found()
@@ -1725,6 +1726,34 @@ else
17251726
endif
17261727

17271728

1729+
###############################################################
1730+
# Option: Coccinelle checks
1731+
###############################################################
1732+
1733+
coccicheck_opt = get_option('coccicheck')
1734+
coccicheck_dep = not_found_dep
1735+
if not coccicheck_opt.disabled()
1736+
if spatch.found()
1737+
coccicheck_dep = declare_dependency()
1738+
elif coccicheck_opt.enabled()
1739+
error('missing required tools (spatch needed) for Coccinelle checks')
1740+
endif
1741+
endif
1742+
1743+
if coccicheck_opt.enabled()
1744+
coccicheck_modes = ['context', 'report', 'patch']
1745+
foreach mode : coccicheck_modes
1746+
run_target('coccicheck-' + mode,
1747+
command: [python, files('src/tools/coccicheck.py'),
1748+
'--mode', mode,
1749+
'--spatch', spatch,
1750+
'--patchdir', '@SOURCE_ROOT@',
1751+
'@SOURCE_ROOT@/cocci/**/*.cocci',
1752+
'@SOURCE_ROOT@/src',
1753+
'@SOURCE_ROOT@/contrib',
1754+
])
1755+
endforeach
1756+
endif
17281757

17291758
###############################################################
17301759
# Compiler tests
@@ -3951,6 +3980,7 @@ summary(
39513980
{
39523981
'bison': '@0@ @1@'.format(bison.full_path(), bison_version),
39533982
'dtrace': dtrace,
3983+
'spatch': spatch,
39543984
'flex': '@0@ @1@'.format(flex.full_path(), flex_version),
39553985
},
39563986
section: 'Programs',

meson_options.txt

Lines changed: 6 additions & 1 deletion
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: [],
@@ -201,6 +203,9 @@ option('PYTHON', type: 'array', value: ['python3', 'python'],
201203
option('SED', type: 'string', value: 'gsed',
202204
description: 'Path to sed binary')
203205

206+
option('SPATCH', type: 'string', value: 'spatch',
207+
description: 'Path to spatch binary, used for SmPL patches')
208+
204209
option('STRIP', type: 'string', value: 'strip',
205210
description: 'Path to strip binary, used for PGXS emulation')
206211

src/makefiles/meson.build

Lines changed: 6 additions & 0 deletions
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

@@ -149,6 +150,7 @@ pgxs_bins = {
149150
'TAR': tar,
150151
'ZSTD': program_zstd,
151152
'DTRACE': dtrace,
153+
'SPATCH': spatch,
152154
}
153155

154156
pgxs_empty = [
@@ -164,6 +166,10 @@ pgxs_empty = [
164166
'DBTOEPUB',
165167
'FOP',
166168

169+
# Coccinelle is not supported by pgxs
170+
'SPATCH',
171+
'SPFLAGS',
172+
167173
# supporting coverage for pgxs-in-meson build doesn't seem worth it
168174
'GENHTML',
169175
'LCOV',

0 commit comments

Comments
 (0)