Skip to content

Commit 0c2aa5b

Browse files
committed
meson: add syntax-check
This changes the approach used with autotools where it was separate make target. With meson it will be part of the `meson test` target but can be disabled using --no-suite syntax-check or we can run only syntax-check by using --suite syntax-check. Signed-off-by: Pavel Hrdina <[email protected]> Reviewed-by: Peter Krempa <[email protected]> Reviewed-by: Neal Gompa <[email protected]>
1 parent 13c9063 commit 0c2aa5b

File tree

5 files changed

+90
-31
lines changed

5 files changed

+90
-31
lines changed

build-aux/Makefile.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# define variables
2+
3+
top_srcdir = @top_srcdir@
4+
top_builddir = @top_builddir@
5+
FLAKE8 = @flake8_path@
6+
RUNUTF8 = @runutf8@
7+
8+
# include syntax-check.mk file
9+
include $(top_srcdir)/build-aux/syntax-check.mk
File renamed without changes.

build-aux/meson.build

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
syntax_check_conf = configuration_data()
2+
syntax_check_conf.set('top_srcdir', meson.source_root())
3+
syntax_check_conf.set('top_builddir', meson.build_root())
4+
5+
flake8_path = ''
6+
if flake8_prog.found()
7+
flake8_path = flake8_prog.path()
8+
endif
9+
syntax_check_conf.set('flake8_path', flake8_path)
10+
syntax_check_conf.set('runutf8', ' '.join(runutf8))
11+
12+
configure_file(
13+
input: 'Makefile.in',
14+
output: '@BASENAME@',
15+
configuration: syntax_check_conf,
16+
)
17+
18+
if host_machine.system() == 'freebsd'
19+
make_prog = find_program('gmake')
20+
else
21+
make_prog = find_program('make')
22+
endif
23+
24+
rc = run_command(
25+
'sed', '-n',
26+
's/^\\(sc_[a-zA-Z0-9_-]*\\):.*/\\1/p',
27+
meson.current_source_dir() / 'syntax-check.mk',
28+
check: true,
29+
)
30+
31+
sc_tests = rc.stdout().strip().split()
32+
33+
34+
# Skip syntax-check if not building from git because we get the list of files
35+
# to check using git commands and it fails if we are not in git repository.
36+
if git
37+
foreach target : sc_tests
38+
test(
39+
target,
40+
make_prog,
41+
args: [ '-C', meson.current_build_dir(), target ],
42+
depends: [
43+
potfiles_dep,
44+
],
45+
suite: 'syntax-check',
46+
)
47+
endforeach
48+
endif

build-aux/syntax-check.mk

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# This is reported not to work with make-3.79.1
2323
# ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
24-
ME := $(_build-aux)/syntax-check.mk
24+
ME := build-aux/syntax-check.mk
2525

2626
# These variables ought to be defined through the configure.ac section
2727
# of the module description. But some packages import this file directly,
@@ -42,29 +42,29 @@ _equal = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
4242
GIT = git
4343
VC = $(GIT)
4444

45-
VC_LIST = $(srcdir)/$(_build-aux)/vc-list-files -C $(srcdir)
45+
VC_LIST = $(top_srcdir)/build-aux/vc-list-files -C $(top_srcdir)
4646

4747
# You can override this variable in syntax-check.mk to set your own regexp
4848
# matching files to ignore.
4949
VC_LIST_ALWAYS_EXCLUDE_REGEX ?= ^$$
5050

5151
# This is to preprocess robustly the output of $(VC_LIST), so that even
52-
# when $(srcdir) is a pathological name like "....", the leading sed command
52+
# when $(top_srcdir) is a pathological name like "....", the leading sed command
5353
# removes only the intended prefix.
54-
_dot_escaped_srcdir = $(subst .,\.,$(srcdir))
55-
_dot_escaped_builddir = $(subst .,\.,$(builddir))
54+
_dot_escaped_srcdir = $(subst .,\.,$(top_srcdir))
55+
_dot_escaped_builddir = $(subst .,\.,$(top_builddir))
5656

57-
# Post-process $(VC_LIST) output, prepending $(srcdir)/, but only
58-
# when $(srcdir) is not ".".
59-
ifeq ($(srcdir),.)
57+
# Post-process $(VC_LIST) output, prepending $(top_srcdir)/, but only
58+
# when $(top_srcdir) is not ".".
59+
ifeq ($(top_srcdir),.)
6060
_prepend_srcdir_prefix =
6161
else
62-
_prepend_srcdir_prefix = | $(SED) 's|^|$(srcdir)/|'
62+
_prepend_srcdir_prefix = | $(SED) 's|^|$(top_srcdir)/|'
6363
endif
6464

6565
# In order to be able to consistently filter "."-relative names,
66-
# (i.e., with no $(srcdir) prefix), this definition is careful to
67-
# remove any $(srcdir) prefix, and to restore what it removes.
66+
# (i.e., with no $(top_srcdir) prefix), this definition is careful to
67+
# remove any $(top_srcdir) prefix, and to restore what it removes.
6868
_sc_excl = \
6969
$(or $(exclude_file_name_regexp--$@),^$$)
7070
VC_LIST_EXCEPT = \
@@ -84,11 +84,11 @@ export LC_ALL = C
8484
## Sanity checks. ##
8585
## --------------- ##
8686

87-
_cfg_mk := $(wildcard $(srcdir)/$(_build-aux)/syntax-check.mk)
87+
_cfg_mk := $(wildcard $(top_srcdir)/build-aux/syntax-check.mk)
8888

8989
# Collect the names of rules starting with 'sc_'.
9090
syntax-check-rules := $(sort $(shell $(SED) -n \
91-
's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(srcdir)/$(ME) $(_cfg_mk)))
91+
's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(top_srcdir)/$(ME) $(_cfg_mk)))
9292
.PHONY: $(syntax-check-rules)
9393

9494
ifeq ($(shell $(VC_LIST) >/dev/null 2>&1; echo $$?),0)
@@ -333,11 +333,11 @@ sc_flags_debug:
333333
# than d). The existence of long long, and of documentation about
334334
# flags, makes the regex in the third test slightly harder.
335335
sc_flags_usage:
336-
@test "$$(cat $(srcdir)/include/libvirt/libvirt-domain.h \
337-
$(srcdir)/include/libvirt/virterror.h \
338-
$(srcdir)/include/libvirt/libvirt-qemu.h \
339-
$(srcdir)/include/libvirt/libvirt-lxc.h \
340-
$(srcdir)/include/libvirt/libvirt-admin.h \
336+
@test "$$(cat $(top_srcdir)/include/libvirt/libvirt-domain.h \
337+
$(top_srcdir)/include/libvirt/virterror.h \
338+
$(top_srcdir)/include/libvirt/libvirt-qemu.h \
339+
$(top_srcdir)/include/libvirt/libvirt-lxc.h \
340+
$(top_srcdir)/include/libvirt/libvirt-admin.h \
341341
| $(GREP) -c '\(long\|unsigned\) flags')" != 4 && \
342342
{ echo '$(ME): new API should use "unsigned int flags"' 1>&2; \
343343
exit 1; } || :
@@ -496,7 +496,7 @@ sc_prohibit_PATH_MAX:
496496
halt='dynamically allocate paths, do not use PATH_MAX' \
497497
$(_sc_search_regexp)
498498

499-
include $(srcdir)/Makefile.nonreentrant
499+
include $(top_srcdir)/build-aux/Makefile.nonreentrant
500500
sc_prohibit_nonreentrant:
501501
@prohibit="\\<(${NON_REENTRANT_RE}) *\\(" \
502502
halt="use re-entrant functions (usually ending with _r)" \
@@ -833,7 +833,7 @@ sc_prohibit_gettext_markup:
833833

834834
# Our code is divided into modular subdirectories for a reason, and
835835
# lower-level code must not include higher-level headers.
836-
cross_dirs=$(patsubst $(srcdir)/src/%.,%,$(wildcard $(srcdir)/src/*/.))
836+
cross_dirs=$(patsubst $(top_srcdir)/src/%.,%,$(wildcard $(top_srcdir)/src/*/.))
837837
cross_dirs_re=($(subst / ,/|,$(cross_dirs)))
838838
mid_dirs=access|admin|conf|cpu|locking|logging|rpc|security
839839
sc_prohibit_cross_inclusion:
@@ -1177,7 +1177,7 @@ sc_prohibit_dirent_d_type:
11771177
# grep-E-style regexp selecting the files to check. For in_vc_files,
11781178
# the regexp is used to select matching files from the list of all
11791179
# version-controlled files; for in_files, it's from the names printed
1180-
# by "find $(srcdir)". When neither is specified, use all files that
1180+
# by "find $(top_srcdir)". When neither is specified, use all files that
11811181
# are under version control.
11821182
#
11831183
# containing | non_containing
@@ -1249,7 +1249,7 @@ define _sc_search_regexp
12491249
\
12501250
: Filter by file name; \
12511251
if test -n "$$in_files"; then \
1252-
files=$$(find $(srcdir) | $(GREP) -E "$$in_files" \
1252+
files=$$(find $(top_srcdir) | $(GREP) -E "$$in_files" \
12531253
| $(GREP) -Ev '$(_sc_excl)'); \
12541254
else \
12551255
files=$$($(VC_LIST_EXCEPT)); \
@@ -1293,7 +1293,7 @@ sc_avoid_if_before_free:
12931293
@$(VC_LIST_EXCEPT) \
12941294
| $(GREP) -v useless-if-before-free \
12951295
| xargs \
1296-
$(srcdir)/$(_build-aux)/useless-if-before-free \
1296+
$(top_srcdir)/build-aux/useless-if-before-free \
12971297
$(useless_free_options) \
12981298
&& { printf '$(ME): found useless "if"' \
12991299
' before "free" above\n' 1>&2; \
@@ -1781,9 +1781,6 @@ sc_const_long_option:
17811781
halt='add "const" to the above declarations' \
17821782
$(_sc_search_regexp)
17831783
1784-
gen_source_files:
1785-
$(MAKE) -C src generated-sources
1786-
17871784
fix_po_file_diag = \
17881785
'you have changed the set of files with translatable diagnostics;\n\
17891786
apply the above patch\n'
@@ -1805,26 +1802,26 @@ perl_translatable_files_list_ = \
18051802
18061803
# Verify that all source files using _() (more specifically, files that
18071804
# match $(_gl_translatable_string_re)) are listed in po/POTFILES.in.
1808-
po_file ?= $(srcdir)/po/POTFILES.in
1805+
po_file ?= $(top_srcdir)/po/POTFILES.in
18091806
18101807
# List of additional files that we want to pick up in our POTFILES.in
18111808
# This is all generated files for RPC code.
18121809
generated_files = \
1813-
$(builddir)/src/*.[ch] \
1814-
$(builddir)/src/*/*.[ch]
1810+
$(top_builddir)/src/*.[ch] \
1811+
$(top_builddir)/src/*/*.[ch]
18151812
18161813
_gl_translatable_string_re ?= \b(N?_|gettext *)\([^)"]*("|$$)
18171814
18181815
# sc_po_check can fail if generated files are not built first
1819-
sc_po_check: gen_source_files
1816+
sc_po_check:
18201817
@if test -f $(po_file); then \
18211818
$(GREP) -E -v '^(#|$$)' $(po_file) \
18221819
| $(GREP) -v '^src/false\.c$$' | sort > $@-1; \
18231820
{ $(VC_LIST_EXCEPT); echo $(generated_files); } \
18241821
| xargs perl $(perl_translatable_files_list_) \
18251822
| xargs $(GREP) -E -l '$(_gl_translatable_string_re)' \
1826-
| $(SED) 's|^$(_dot_escaped_srcdir)/|@SRCDIR@|' \
18271823
| $(SED) 's|^$(_dot_escaped_builddir)/|@BUILDDIR@|' \
1824+
| $(SED) 's|^$(_dot_escaped_srcdir)/|@SRCDIR@|' \
18281825
| sort -u > $@-2; \
18291826
diff -u -L $(po_file) -L $(po_file) $@-1 $@-2 \
18301827
|| { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; }; \
@@ -2074,3 +2071,6 @@ exclude_file_name_regexp--sc_prohibit_backslash_alignment = \
20742071
20752072
exclude_file_name_regexp--sc_prohibit_select = \
20762073
^build-aux/syntax-check\.mk|src/util/vireventglibwatch\.c$$
2074+
2075+
exclude_file_name_regexp--sc_prohibit_config_h_in_headers = \
2076+
^config\.h$$

meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,8 @@ subdir('po')
22332233

22342234
subdir('docs')
22352235

2236+
subdir('build-aux')
2237+
22362238

22372239
# install pkgconfig files
22382240
pkgconfig_files = [

0 commit comments

Comments
 (0)