mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
build: prohibit cross-inclusion
Make it easier to detect invalid cross-directory includes, by adding a syntax check. The check is designed to be extensible: the default case lists only the non-driver directories, and specific directories can list a different set (for example, util/ can only use itself, network/ can only use itself, util/, or conf/). * .gnulib: Update to latest, for syntax check improvment. * cfg.mk (sc_prohibit_cross_inclusion): New check. (sc_prohibit_strncmp, sc_libvirt_unmarked_diagnostics): Simplify.
This commit is contained in:
parent
362077e752
commit
5c3a15647d
2
.gnulib
2
.gnulib
@ -1 +1 @@
|
||||
Subproject commit b856fadc1c8dcb53e7efcbb2d0ae7edc022fdb6a
|
||||
Subproject commit d5612c714c87555f1059d71d347e20271dced322
|
38
cfg.mk
38
cfg.mk
@ -348,11 +348,10 @@ sc_prohibit_access_xok:
|
||||
# Use STREQLEN or STRPREFIX rather than comparing strncmp == 0, or != 0.
|
||||
snp_ = strncmp *\(.+\)
|
||||
sc_prohibit_strncmp:
|
||||
@grep -nE '! *strncmp *\(|\<$(snp_) *[!=]=|[!=]= *$(snp_)' \
|
||||
$$($(VC_LIST_EXCEPT)) \
|
||||
| grep -vE ':# *define STR(N?EQLEN|PREFIX)\(' && \
|
||||
{ echo '$(ME): use STREQLEN or STRPREFIX instead of str''ncmp' \
|
||||
1>&2; exit 1; } || :
|
||||
@prohibit='! *strncmp *\(|\<$(snp_) *[!=]=|[!=]= *$(snp_)' \
|
||||
exclude=':# *define STR(N?EQLEN|PREFIX)\(' \
|
||||
halt='$(ME): use STREQLEN or STRPREFIX instead of str''ncmp' \
|
||||
$(_sc_search_regexp)
|
||||
|
||||
# Use virAsprintf rather than as'printf since *strp is undefined on error.
|
||||
sc_prohibit_asprintf:
|
||||
@ -569,11 +568,10 @@ func_re := ($(func_or))
|
||||
# _("...: "
|
||||
# "%s", _("no storage vol w..."
|
||||
sc_libvirt_unmarked_diagnostics:
|
||||
@grep -nE \
|
||||
'\<$(func_re) *\([^"]*"[^"]*[a-z]{3}' $$($(VC_LIST_EXCEPT)) \
|
||||
| grep -v '_''(' && \
|
||||
{ echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
|
||||
exit 1; } || :
|
||||
@prohibit='\<$(func_re) *\([^"]*"[^"]*[a-z]{3}' \
|
||||
exclude='_\(' \
|
||||
halt='$(ME): found unmarked diagnostic(s)' \
|
||||
$(_sc_search_regexp)
|
||||
@{ grep -nE '\<$(func_re) *\(.*;$$' $$($(VC_LIST_EXCEPT)); \
|
||||
grep -A1 -nE '\<$(func_re) *\(.*,$$' $$($(VC_LIST_EXCEPT)); } \
|
||||
| sed 's/_("[^"][^"]*"//;s/[ ]"%s"//' \
|
||||
@ -624,6 +622,26 @@ sc_prohibit_gettext_markup:
|
||||
halt='do not mark these strings for translation' \
|
||||
$(_sc_search_regexp)
|
||||
|
||||
# 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_re=($(subst / ,/|,$(cross_dirs)))
|
||||
sc_prohibit_cross_inclusion:
|
||||
@for dir in $(cross_dirs); do \
|
||||
case $$dir in \
|
||||
util/) safe="util";; \
|
||||
cpu/ | locking/ | network/ | rpc/ | security/) \
|
||||
safe="($$dir|util|conf)";; \
|
||||
xenapi/ | xenxs/ ) safe="($$dir|util|conf|xen)";; \
|
||||
*) safe="($$dir|util|conf|cpu|network|locking|rpc|security)";; \
|
||||
esac; \
|
||||
in_vc_files="^src/$$dir" \
|
||||
prohibit='^# *include .$(cross_dirs_re)' \
|
||||
exclude="# *include .$$safe" \
|
||||
halt='unsafe cross-directory include' \
|
||||
$(_sc_search_regexp) \
|
||||
done
|
||||
|
||||
# When converting an enum to a string, make sure that we track any new
|
||||
# elements added to the enum by using a _LAST marker.
|
||||
sc_require_enum_last_marker:
|
||||
|
Loading…
Reference in New Issue
Block a user