1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

maint: split long lines for BSD syntax-check

Similar to the gnulib changes we just incorporated into maint.mk,
it's time to use '$(VC_LIST) | xargs program' instead of
'program $$($(VC_LIST))', in order to bypass the problem of hitting
argv limits due to our large set of files.

Drop several uses of $$files as a temporary variable when we can
instead directly use xargs. While at it, fix a typo in the
prohibit_windows_special_chars error message.

Note that 'grep $pattern $(generate list)' has be be rewritten
as 'generate list | xargs grep $pattern /dev/null' - this is
because for a list that is just long enough, and without /dev/null,
xargs could make a worst-case split of 'grep $pattern all but one;
grep $pattern last' which has different output (grep includes the
filename when there was more than one file, but omits it for a
single file), while our conversion gives 'grep $pattern /dev/null
all but one; grep $pattern /dev/null last'. We are less concerned
about the empty list case (why would we run the syntax check if we
didn't have at least one file?), but grepping /dev/null happens to
produce no output and thus nicely also solves that problem without
relying on the GNU extension of 'xargs -r'.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Eric Blake 2019-01-03 13:30:39 -06:00
parent 2e258dae61
commit ab51b22c07

75
cfg.mk
View File

@ -639,8 +639,10 @@ sc_libvirt_unmarked_diagnostics:
exclude='_\(' \ exclude='_\(' \
halt='found unmarked diagnostic(s)' \ halt='found unmarked diagnostic(s)' \
$(_sc_search_regexp) $(_sc_search_regexp)
@{ $(GREP) -nE '\<$(func_re) *\(.*;$$' $$($(VC_LIST_EXCEPT)); \ @{ $(VC_LIST_EXCEPT) | xargs \
$(GREP) -A1 -nE '\<$(func_re) *\(.*,$$' $$($(VC_LIST_EXCEPT)); } \ $(GREP) -nE '\<$(func_re) *\(.*;$$' /dev/null; \
$(VC_LIST_EXCEPT) | xargs \
$(GREP) -A1 -nE '\<$(func_re) *\(.*,$$' /dev/null; } \
| $(SED) 's/_("\([^\"]\|\\.\)\+"//;s/[ ]"%s"//' \ | $(SED) 's/_("\([^\"]\|\\.\)\+"//;s/[ ]"%s"//' \
| $(GREP) '[ ]"' && \ | $(GREP) '[ ]"' && \
{ echo '$(ME): found unmarked diagnostic(s)' 1>&2; \ { echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
@ -654,8 +656,8 @@ sc_libvirt_unmarked_diagnostics:
# there are functions to which this one applies but that do not get marked # there are functions to which this one applies but that do not get marked
# diagnostics. # diagnostics.
sc_prohibit_newline_at_end_of_diagnostic: sc_prohibit_newline_at_end_of_diagnostic:
@$(GREP) -A2 -nE \ @$(VC_LIST_EXCEPT) | xargs $(GREP) -A2 -nE \
'\<$(func_re) *\(' $$($(VC_LIST_EXCEPT)) \ '\<$(func_re) *\(' /dev/null \
| $(GREP) '\\n"' \ | $(GREP) '\\n"' \
&& { echo '$(ME): newline at end of message(s)' 1>&2; \ && { echo '$(ME): newline at end of message(s)' 1>&2; \
exit 1; } || : exit 1; } || :
@ -664,8 +666,10 @@ sc_prohibit_newline_at_end_of_diagnostic:
# allow VIR_ERROR to do this, and ignore functions that take a single # allow VIR_ERROR to do this, and ignore functions that take a single
# string rather than a format argument. # string rather than a format argument.
sc_prohibit_diagnostic_without_format: sc_prohibit_diagnostic_without_format:
@{ $(GREP) -nE '\<$(func_re) *\(.*;$$' $$($(VC_LIST_EXCEPT)); \ @{ $(VC_LIST_EXCEPT) | xargs \
$(GREP) -A2 -nE '\<$(func_re) *\(.*,$$' $$($(VC_LIST_EXCEPT)); } \ $(GREP) -nE '\<$(func_re) *\(.*;$$' /dev/null; \
$(VC_LIST_EXCEPT) | xargs \
$(GREP) -A2 -nE '\<$(func_re) *\(.*,$$' /dev/null; } \
| $(SED) -rn -e ':l; /[,"]$$/ {N;b l;}' \ | $(SED) -rn -e ':l; /[,"]$$/ {N;b l;}' \
-e '/(xenapiSessionErrorHandler|vah_(error|warning))/d' \ -e '/(xenapiSessionErrorHandler|vah_(error|warning))/d' \
-e '/\<$(func_re) *\([^"]*"([^%"]|"\n[^"]*")*"[,)]/p' \ -e '/\<$(func_re) *\([^"]*"([^%"]|"\n[^"]*")*"[,)]/p' \
@ -687,7 +691,7 @@ sc_prohibit_useless_translation:
# When splitting a diagnostic across lines, ensure that there is a space # When splitting a diagnostic across lines, ensure that there is a space
# or \n on one side of the split. # or \n on one side of the split.
sc_require_whitespace_in_translation: sc_require_whitespace_in_translation:
@$(GREP) -n -A1 '"$$' $$($(VC_LIST_EXCEPT)) \ @$(VC_LIST_EXCEPT) | xargs $(GREP) -n -A1 '"$$' /dev/null \
| $(SED) -ne ':l; /"$$/ {N;b l;}; s/"\n[^"]*"/""/g; s/\\n/ /g' \ | $(SED) -ne ':l; /"$$/ {N;b l;}; s/"\n[^"]*"/""/g; s/\\n/ /g' \
-e '/_(.*[^\ ]""[^\ ]/p' | $(GREP) . && \ -e '/_(.*[^\ ]""[^\ ]/p' | $(GREP) . && \
{ echo '$(ME): missing whitespace at line split' 1>&2; \ { echo '$(ME): missing whitespace at line split' 1>&2; \
@ -803,7 +807,8 @@ sc_prohibit_cross_inclusion:
# When converting an enum to a string, make sure that we track any new # When converting an enum to a string, make sure that we track any new
# elements added to the enum by using a _LAST marker. # elements added to the enum by using a _LAST marker.
sc_require_enum_last_marker: sc_require_enum_last_marker:
@$(GREP) -A1 -nE '^[^#]*VIR_ENUM_IMPL *\(' $$($(VC_LIST_EXCEPT)) \ @$(VC_LIST_EXCEPT) | xargs \
$(GREP) -A1 -nE '^[^#]*VIR_ENUM_IMPL *\(' /dev/null \
| $(SED) -ne '/VIR_ENUM_IMPL[^,]*,$$/N' \ | $(SED) -ne '/VIR_ENUM_IMPL[^,]*,$$/N' \
-e '/VIR_ENUM_IMPL[^,]*,[^,]*[^_,][^L,][^A,][^S,][^T,],/p' \ -e '/VIR_ENUM_IMPL[^,]*,[^,]*[^_,][^L,][^A,][^S,][^T,],/p' \
-e '/VIR_ENUM_IMPL[^,]*,[^,]\{0,4\},/p' \ -e '/VIR_ENUM_IMPL[^,]*,[^,]\{0,4\},/p' \
@ -866,8 +871,7 @@ sc_prohibit_atoi:
$(_sc_search_regexp) $(_sc_search_regexp)
sc_prohibit_wrong_filename_in_comment: sc_prohibit_wrong_filename_in_comment:
@fail=0; \ @$(VC_LIST_EXCEPT) | $(GREP) '\.[ch]$$' | xargs awk 'BEGIN { \
awk 'BEGIN { \
fail=0; \ fail=0; \
} FNR < 3 { \ } FNR < 3 { \
n=match($$0, /[[:space:]][^[:space:]]*[.][ch][[:space:]:]/); \ n=match($$0, /[[:space:]][^[:space:]]*[.][ch][[:space:]:]/); \
@ -883,11 +887,8 @@ sc_prohibit_wrong_filename_in_comment:
if (fail == 1) { \ if (fail == 1) { \
exit 1; \ exit 1; \
} \ } \
}' $$($(VC_LIST_EXCEPT) | $(GREP) '\.[ch]$$') || fail=1; \ }' || { echo '$(ME): The file name in comments must match the' \
if test $$fail -eq 1; then \ 'actual file name' 1>&2; exit 1; }
{ echo '$(ME): The file name in comments must match the' \
'actual file name' 1>&2; exit 1; } \
fi;
sc_prohibit_virConnectOpen_in_virsh: sc_prohibit_virConnectOpen_in_virsh:
@prohibit='\bvirConnectOpen[a-zA-Z]* *\(' \ @prohibit='\bvirConnectOpen[a-zA-Z]* *\(' \
@ -918,22 +919,21 @@ sc_require_if_else_matching_braces:
$(_sc_search_regexp) $(_sc_search_regexp)
sc_curly_braces_style: sc_curly_braces_style:
@files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.[ch]$$'); \ @if $(VC_LIST_EXCEPT) | $(GREP) '\.[ch]$$' | xargs $(GREP) -nHP \
if $(GREP) -nHP \
'^\s*(?!([a-zA-Z_]*for_?each[a-zA-Z_]*) ?\()([_a-zA-Z0-9]+( [_a-zA-Z0-9]+)* ?\()?(\*?[_a-zA-Z0-9]+(,? \*?[_a-zA-Z0-9\[\]]+)+|void)\) ?\{' \ '^\s*(?!([a-zA-Z_]*for_?each[a-zA-Z_]*) ?\()([_a-zA-Z0-9]+( [_a-zA-Z0-9]+)* ?\()?(\*?[_a-zA-Z0-9]+(,? \*?[_a-zA-Z0-9\[\]]+)+|void)\) ?\{' \
$$files; then \ /dev/null; then \
echo '$(ME): Non-K&R style used for curly braces around' \ echo '$(ME): Non-K&R style used for curly braces around' \
'function body' 1>&2; exit 1; \ 'function body' 1>&2; exit 1; \
fi; \ fi; \
if $(GREP) -A1 -En ' ((if|for|while|switch) \(|(else|do)\b)[^{]*$$'\ if $(VC_LIST_EXCEPT) | $(GREP) '\.[ch]$$' | xargs \
$$files | $(GREP) '^[^ ]*- *{'; then \ $(GREP) -A1 -En ' ((if|for|while|switch) \(|(else|do)\b)[^{]*$$' \
/dev/null | $(GREP) '^[^ ]*- *{'; then \
echo '$(ME): Use hanging braces for compound statements' 1>&2; exit 1; \ echo '$(ME): Use hanging braces for compound statements' 1>&2; exit 1; \
fi fi
sc_prohibit_windows_special_chars_in_filename: sc_prohibit_windows_special_chars_in_filename:
@files=$$($(VC_LIST_EXCEPT) | $(GREP) '[:*?"<>|]'); \ @$(VC_LIST_EXCEPT) | $(GREP) '[:*?"<>|]' && \
test -n "$$files" && { echo '$(ME): Windows special chars' \ { echo '$(ME): Windows special chars in filename not allowed' 1>&2; echo exit 1; } || :
'in filename not allowed:' 1>&2; echo $$files 1>&2; exit 1; } || :
sc_prohibit_mixed_case_abbreviations: sc_prohibit_mixed_case_abbreviations:
@prohibit='Pci|Usb|Scsi' \ @prohibit='Pci|Usb|Scsi' \
@ -949,11 +949,11 @@ sc_require_locale_h:
$(_sc_search_regexp) $(_sc_search_regexp)
sc_prohibit_empty_first_line: sc_prohibit_empty_first_line:
@awk 'BEGIN { fail=0; } \ @$(VC_LIST_EXCEPT) | xargs awk 'BEGIN { fail=0; } \
FNR == 1 { if ($$0 == "") { print FILENAME ":1:"; fail=1; } } \ FNR == 1 { if ($$0 == "") { print FILENAME ":1:"; fail=1; } } \
END { if (fail == 1) { \ END { if (fail == 1) { \
print "$(ME): Prohibited empty first line" > "/dev/stderr"; \ print "$(ME): Prohibited empty first line" > "/dev/stderr"; \
} exit fail; }' $$($(VC_LIST_EXCEPT)); } exit fail; }'
sc_prohibit_paren_brace: sc_prohibit_paren_brace:
@prohibit='\)\{$$' \ @prohibit='\)\{$$' \
@ -996,8 +996,9 @@ sc_prohibit_sysconf_pagesize:
$(_sc_search_regexp) $(_sc_search_regexp)
sc_prohibit_virSecurity: sc_prohibit_virSecurity:
@$(GREP) -Pn 'virSecurityManager(?!Ptr)' $$($(VC_LIST_EXCEPT) | $(GREP) 'src/qemu/' | \ @$(VC_LIST_EXCEPT) | $(GREP) 'src/qemu/' | \
$(GREP) -v 'src/qemu/qemu_security') && \ $(GREP) -v 'src/qemu/qemu_security' | \
xargs $(GREP) -Pn 'virSecurityManager(?!Ptr)' /dev/null && \
{ echo '$(ME): prefer qemuSecurity wrappers' 1>&2; exit 1; } || : { echo '$(ME): prefer qemuSecurity wrappers' 1>&2; exit 1; } || :
sc_prohibit_pthread_create: sc_prohibit_pthread_create:
@ -1128,25 +1129,25 @@ endif
# Don't include duplicate header in the source (either *.c or *.h) # Don't include duplicate header in the source (either *.c or *.h)
prohibit-duplicate-header: prohibit-duplicate-header:
$(AM_V_GEN)files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.[chx]$$'); \ $(AM_V_GEN)$(VC_LIST_EXCEPT) | $(GREP) '\.[chx]$$' | xargs \
$(PERL) -W $(top_srcdir)/build-aux/prohibit-duplicate-header.pl $$files $(PERL) -W $(top_srcdir)/build-aux/prohibit-duplicate-header.pl
spacing-check: spacing-check:
$(AM_V_GEN)files=`$(VC_LIST) | $(GREP) '\.c$$'`; \ $(AM_V_GEN)$(VC_LIST) | $(GREP) '\.c$$' | xargs \
$(PERL) $(top_srcdir)/build-aux/check-spacing.pl $$files || \ $(PERL) $(top_srcdir)/build-aux/check-spacing.pl || \
{ echo '$(ME): incorrect formatting' 1>&2; exit 1; } { echo '$(ME): incorrect formatting' 1>&2; exit 1; }
mock-noinline: mock-noinline:
$(AM_V_GEN)files=`$(VC_LIST) | $(GREP) '\.[ch]$$'`; \ $(AM_V_GEN)$(VC_LIST) | $(GREP) '\.[ch]$$' | xargs \
$(PERL) $(top_srcdir)/build-aux/mock-noinline.pl $$files $(PERL) $(top_srcdir)/build-aux/mock-noinline.pl
header-ifdef: header-ifdef:
$(AM_V_GEN)files=`$(VC_LIST) | $(GREP) '\.[h]$$'`; \ $(AM_V_GEN)$(VC_LIST) | $(GREP) '\.[h]$$' | xargs \
$(PERL) $(top_srcdir)/build-aux/header-ifdef.pl $$files $(PERL) $(top_srcdir)/build-aux/header-ifdef.pl
test-wrap-argv: test-wrap-argv:
$(AM_V_GEN)files=`$(VC_LIST) | $(GREP) -E '\.(ldargs|args)'`; \ $(AM_V_GEN)$(VC_LIST) | $(GREP) -E '\.(ldargs|args)' | xargs \
$(PERL) $(top_srcdir)/tests/test-wrap-argv.pl --check $$files $(PERL) $(top_srcdir)/tests/test-wrap-argv.pl --check
group-qemu-caps: group-qemu-caps:
$(AM_V_GEN)$(PERL) $(top_srcdir)/tests/group-qemu-caps.pl --check $(top_srcdir)/ $(AM_V_GEN)$(PERL) $(top_srcdir)/tests/group-qemu-caps.pl --check $(top_srcdir)/