]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
meson: add syntax-check
authorPavel Hrdina <phrdina@redhat.com>
Thu, 25 Jun 2020 21:29:43 +0000 (23:29 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 3 Aug 2020 07:27:06 +0000 (09:27 +0200)
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 <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
build-aux/Makefile.in [new file with mode: 0644]
build-aux/Makefile.nonreentrant [moved from Makefile.nonreentrant with 100% similarity]
build-aux/meson.build [new file with mode: 0644]
build-aux/syntax-check.mk
meson.build

diff --git a/build-aux/Makefile.in b/build-aux/Makefile.in
new file mode 100644 (file)
index 0000000..601f1ad
--- /dev/null
@@ -0,0 +1,9 @@
+# define variables
+
+top_srcdir = @top_srcdir@
+top_builddir = @top_builddir@
+FLAKE8 = @flake8_path@
+RUNUTF8 = @runutf8@
+
+# include syntax-check.mk file
+include $(top_srcdir)/build-aux/syntax-check.mk
diff --git a/build-aux/meson.build b/build-aux/meson.build
new file mode 100644 (file)
index 0000000..1dd85b8
--- /dev/null
@@ -0,0 +1,48 @@
+syntax_check_conf = configuration_data()
+syntax_check_conf.set('top_srcdir', meson.source_root())
+syntax_check_conf.set('top_builddir', meson.build_root())
+
+flake8_path = ''
+if flake8_prog.found()
+  flake8_path = flake8_prog.path()
+endif
+syntax_check_conf.set('flake8_path', flake8_path)
+syntax_check_conf.set('runutf8', ' '.join(runutf8))
+
+configure_file(
+  input: 'Makefile.in',
+  output: '@BASENAME@',
+  configuration: syntax_check_conf,
+)
+
+if host_machine.system() == 'freebsd'
+  make_prog = find_program('gmake')
+else
+  make_prog = find_program('make')
+endif
+
+rc = run_command(
+  'sed', '-n',
+  's/^\\(sc_[a-zA-Z0-9_-]*\\):.*/\\1/p',
+  meson.current_source_dir() / 'syntax-check.mk',
+  check: true,
+)
+
+sc_tests = rc.stdout().strip().split()
+
+
+# Skip syntax-check if not building from git because we get the list of files
+# to check using git commands and it fails if we are not in git repository.
+if git
+  foreach target : sc_tests
+    test(
+      target,
+      make_prog,
+      args: [ '-C', meson.current_build_dir(), target ],
+      depends: [
+        potfiles_dep,
+      ],
+      suite: 'syntax-check',
+    )
+  endforeach
+endif
index 3d7b644f01f7100325cd0832d929def4a60da2c6..1fe2da4e637fd3a6957253564fc273d5b49f7e8a 100644 (file)
@@ -21,7 +21,7 @@
 
 # This is reported not to work with make-3.79.1
 # ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
-ME := $(_build-aux)/syntax-check.mk
+ME := build-aux/syntax-check.mk
 
 # These variables ought to be defined through the configure.ac section
 # of the module description. But some packages import this file directly,
@@ -42,29 +42,29 @@ _equal = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
 GIT = git
 VC = $(GIT)
 
-VC_LIST = $(srcdir)/$(_build-aux)/vc-list-files -C $(srcdir)
+VC_LIST = $(top_srcdir)/build-aux/vc-list-files -C $(top_srcdir)
 
 # You can override this variable in syntax-check.mk to set your own regexp
 # matching files to ignore.
 VC_LIST_ALWAYS_EXCLUDE_REGEX ?= ^$$
 
 # This is to preprocess robustly the output of $(VC_LIST), so that even
-# when $(srcdir) is a pathological name like "....", the leading sed command
+# when $(top_srcdir) is a pathological name like "....", the leading sed command
 # removes only the intended prefix.
-_dot_escaped_srcdir = $(subst .,\.,$(srcdir))
-_dot_escaped_builddir = $(subst .,\.,$(builddir))
+_dot_escaped_srcdir = $(subst .,\.,$(top_srcdir))
+_dot_escaped_builddir = $(subst .,\.,$(top_builddir))
 
-# Post-process $(VC_LIST) output, prepending $(srcdir)/, but only
-# when $(srcdir) is not ".".
-ifeq ($(srcdir),.)
+# Post-process $(VC_LIST) output, prepending $(top_srcdir)/, but only
+# when $(top_srcdir) is not ".".
+ifeq ($(top_srcdir),.)
   _prepend_srcdir_prefix =
 else
-  _prepend_srcdir_prefix = | $(SED) 's|^|$(srcdir)/|'
+  _prepend_srcdir_prefix = | $(SED) 's|^|$(top_srcdir)/|'
 endif
 
 # In order to be able to consistently filter "."-relative names,
-# (i.e., with no $(srcdir) prefix), this definition is careful to
-# remove any $(srcdir) prefix, and to restore what it removes.
+# (i.e., with no $(top_srcdir) prefix), this definition is careful to
+# remove any $(top_srcdir) prefix, and to restore what it removes.
 _sc_excl = \
   $(or $(exclude_file_name_regexp--$@),^$$)
 VC_LIST_EXCEPT = \
@@ -84,11 +84,11 @@ export LC_ALL = C
 ## Sanity checks.  ##
 ## --------------- ##
 
-_cfg_mk := $(wildcard $(srcdir)/$(_build-aux)/syntax-check.mk)
+_cfg_mk := $(wildcard $(top_srcdir)/build-aux/syntax-check.mk)
 
 # Collect the names of rules starting with 'sc_'.
 syntax-check-rules := $(sort $(shell $(SED) -n \
-   's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(srcdir)/$(ME) $(_cfg_mk)))
+   's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(top_srcdir)/$(ME) $(_cfg_mk)))
 .PHONY: $(syntax-check-rules)
 
 ifeq ($(shell $(VC_LIST) >/dev/null 2>&1; echo $$?),0)
@@ -333,11 +333,11 @@ sc_flags_debug:
 # than d).  The existence of long long, and of documentation about
 # flags, makes the regex in the third test slightly harder.
 sc_flags_usage:
-       @test "$$(cat $(srcdir)/include/libvirt/libvirt-domain.h \
-           $(srcdir)/include/libvirt/virterror.h \
-           $(srcdir)/include/libvirt/libvirt-qemu.h \
-           $(srcdir)/include/libvirt/libvirt-lxc.h \
-           $(srcdir)/include/libvirt/libvirt-admin.h \
+       @test "$$(cat $(top_srcdir)/include/libvirt/libvirt-domain.h \
+           $(top_srcdir)/include/libvirt/virterror.h \
+           $(top_srcdir)/include/libvirt/libvirt-qemu.h \
+           $(top_srcdir)/include/libvirt/libvirt-lxc.h \
+           $(top_srcdir)/include/libvirt/libvirt-admin.h \
          | $(GREP) -c '\(long\|unsigned\) flags')" != 4 && \
          { echo '$(ME): new API should use "unsigned int flags"' 1>&2; \
            exit 1; } || :
@@ -496,7 +496,7 @@ sc_prohibit_PATH_MAX:
        halt='dynamically allocate paths, do not use PATH_MAX' \
          $(_sc_search_regexp)
 
-include $(srcdir)/Makefile.nonreentrant
+include $(top_srcdir)/build-aux/Makefile.nonreentrant
 sc_prohibit_nonreentrant:
        @prohibit="\\<(${NON_REENTRANT_RE}) *\\(" \
        halt="use re-entrant functions (usually ending with _r)" \
@@ -833,7 +833,7 @@ sc_prohibit_gettext_markup:
 
 # Our code is divided into modular subdirectories for a reason, and
 # lower-level code must not include higher-level headers.
-cross_dirs=$(patsubst $(srcdir)/src/%.,%,$(wildcard $(srcdir)/src/*/.))
+cross_dirs=$(patsubst $(top_srcdir)/src/%.,%,$(wildcard $(top_srcdir)/src/*/.))
 cross_dirs_re=($(subst / ,/|,$(cross_dirs)))
 mid_dirs=access|admin|conf|cpu|locking|logging|rpc|security
 sc_prohibit_cross_inclusion:
@@ -1177,7 +1177,7 @@ sc_prohibit_dirent_d_type:
 #     grep-E-style regexp selecting the files to check.  For in_vc_files,
 #     the regexp is used to select matching files from the list of all
 #     version-controlled files; for in_files, it's from the names printed
-#     by "find $(srcdir)".  When neither is specified, use all files that
+#     by "find $(top_srcdir)".  When neither is specified, use all files that
 #     are under version control.
 #
 #  containing | non_containing
@@ -1249,7 +1249,7 @@ define _sc_search_regexp
                                                                        \
    : Filter by file name;                                              \
    if test -n "$$in_files"; then                                       \
-     files=$$(find $(srcdir) | $(GREP) -E "$$in_files"                 \
+     files=$$(find $(top_srcdir) | $(GREP) -E "$$in_files"                     \
               | $(GREP) -Ev '$(_sc_excl)');                            \
    else                                                                        \
      files=$$($(VC_LIST_EXCEPT));                                      \
@@ -1293,7 +1293,7 @@ sc_avoid_if_before_free:
        @$(VC_LIST_EXCEPT)                                              \
          | $(GREP) -v useless-if-before-free                           \
          | xargs                                                       \
-             $(srcdir)/$(_build-aux)/useless-if-before-free            \
+             $(top_srcdir)/build-aux/useless-if-before-free            \
              $(useless_free_options)                                   \
          && { printf '$(ME): found useless "if"'                       \
                      ' before "free" above\n' 1>&2;                    \
@@ -1781,9 +1781,6 @@ sc_const_long_option:
        halt='add "const" to the above declarations'                    \
          $(_sc_search_regexp)
 
-gen_source_files:
-       $(MAKE) -C src generated-sources
-
 fix_po_file_diag = \
 'you have changed the set of files with translatable diagnostics;\n\
 apply the above patch\n'
@@ -1805,26 +1802,26 @@ perl_translatable_files_list_ =                                         \
 
 # Verify that all source files using _() (more specifically, files that
 # match $(_gl_translatable_string_re)) are listed in po/POTFILES.in.
-po_file ?= $(srcdir)/po/POTFILES.in
+po_file ?= $(top_srcdir)/po/POTFILES.in
 
 # List of additional files that we want to pick up in our POTFILES.in
 # This is all generated files for RPC code.
 generated_files = \
-  $(builddir)/src/*.[ch] \
-  $(builddir)/src/*/*.[ch]
+  $(top_builddir)/src/*.[ch] \
+  $(top_builddir)/src/*/*.[ch]
 
 _gl_translatable_string_re ?= \b(N?_|gettext *)\([^)"]*("|$$)
 
 # sc_po_check can fail if generated files are not built first
-sc_po_check: gen_source_files
+sc_po_check:
        @if test -f $(po_file); then                                    \
          $(GREP) -E -v '^(#|$$)' $(po_file)                            \
            | $(GREP) -v '^src/false\.c$$' | sort > $@-1;               \
          { $(VC_LIST_EXCEPT); echo $(generated_files); }               \
            | xargs perl $(perl_translatable_files_list_)               \
            | xargs $(GREP) -E -l '$(_gl_translatable_string_re)'       \
-           | $(SED) 's|^$(_dot_escaped_srcdir)/|@SRCDIR@|'             \
            | $(SED) 's|^$(_dot_escaped_builddir)/|@BUILDDIR@|'         \
+           | $(SED) 's|^$(_dot_escaped_srcdir)/|@SRCDIR@|'             \
            | sort -u > $@-2;                                           \
          diff -u -L $(po_file) -L $(po_file) $@-1 $@-2                 \
            || { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; };   \
@@ -2074,3 +2071,6 @@ exclude_file_name_regexp--sc_prohibit_backslash_alignment = \
 
 exclude_file_name_regexp--sc_prohibit_select = \
   ^build-aux/syntax-check\.mk|src/util/vireventglibwatch\.c$$
+
+exclude_file_name_regexp--sc_prohibit_config_h_in_headers = \
+  ^config\.h$$
index 78abeb4dc28dcb6b8dd1297eb607ce2dd6652b93..f528c29ed7e6d4ac3c0b6fb6e86c5c54aa9673b9 100644 (file)
@@ -2233,6 +2233,8 @@ subdir('po')
 
 subdir('docs')
 
+subdir('build-aux')
+
 
 # install pkgconfig files
 pkgconfig_files = [